浏览代码

draft 1 of engine analytics

/package-analytics
Aryan Mann 3 年前
当前提交
65d2c69b
共有 3 个文件被更改,包括 154 次插入0 次删除
  1. 19
      com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs
  2. 132
      com.unity.perception/Runtime/PerceptionEngineAnalytics.cs
  3. 3
      com.unity.perception/Runtime/PerceptionEngineAnalytics.cs.meta

19
com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine.Perception.GroundTruth;
using UnityEngine.SceneManagement;
namespace UnityEngine.Perception.Randomization.Scenarios
{

{
foreach (var randomizer in activeRandomizers)
randomizer.ScenarioComplete();
TrackScenarioCompleted();
OnComplete();
state = State.Idle;
OnIdle();

/// The scenario has finished and is idle
/// </summary>
Idle
}
static void TrackScenarioCompleted()
{
var perceptionCamera = SceneManager.GetActiveScene()
.GetRootGameObjects()
.Select(obj => obj.GetComponentInChildren<PerceptionCamera>())
.FirstOrDefault(x => x != null);
PerceptionEngineAnalytics.ReportScenarioCompleted(
perceptionCamera,
activeScenario.randomizers
);
}
public void RestartIteration()

132
com.unity.perception/Runtime/PerceptionEngineAnalytics.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using JetBrains.Annotations;
using UnityEngine;
using UnityEngine.Analytics;
using UnityEngine.Perception.GroundTruth;
using UnityEngine.Perception.Randomization.Randomizers;
using EngineAnalytics = UnityEngine.Analytics.Analytics;
namespace UnityEngine.Perception
{
static class PerceptionEngineAnalytics
{
const string k_VendorKey = "unity.perception";
// Events
/// <summary>
/// When a Scenario completes in editor, player, or USim
/// </summary>
const string k_ScenarioCompletedName = "perceptionscenariocompleted";
/*
static int k_MaxItems = 100;
static int k_MaxEventsPerHour = 100;
*/
static bool s_IsRegistered;
static readonly string[] LabelAllowlist = new[]
{
"BoundingBox2DLabeler"
};
static bool TryRegisterEvents()
{
if (s_IsRegistered)
return true;
var success = true;
/*
success &= EngineAnalytics.RegisterEvent(k_ScenarioCompletedName, k_MaxEventsPerHour, k_MaxItems,
k_VendorKey) == AnalyticsResult.Ok;
*/
s_IsRegistered = success;
return success;
}
#region perceptionscenariocompleted
struct PerceptionCameraData
{
[UsedImplicitly]
public string captureTriggerMode;
[UsedImplicitly]
public int startAtFrame;
[UsedImplicitly]
public int framesBetweenCaptures;
}
/*struct LabelerData
{
[UsedImplicitly]
public string name;
[UsedImplicitly]
public int labelConfigCount;
}*/
struct MemberData
{
[UsedImplicitly]
public string name;
[UsedImplicitly]
public object value;
}
struct ParameterData
{
[UsedImplicitly]
public string name;
[UsedImplicitly]
public string distribution;
[UsedImplicitly]
public (string name, string distribution)[] values;
}
struct RandomizerData
{
[UsedImplicitly]
public string name;
[UsedImplicitly]
public MemberData[] members;
[UsedImplicitly]
public ParameterData[] parameters;
}
struct ScenarioCompletedData
{
[UsedImplicitly]
public PerceptionCameraData perceptionCamera;
[UsedImplicitly]
public string[] labelers;
[UsedImplicitly]
public RandomizerData[] randomizers;
}
public static void ReportScenarioCompleted(PerceptionCamera cam, IEnumerable<Randomizer> randomizers)
{
if (!TryRegisterEvents())
return;
var randomizer = randomizers.First();
var randomizerType = randomizer.GetType();
var randomizerName = randomizerType.Name;
var randomizerFields = randomizerType.GetFields(BindingFlags.Public | BindingFlags.Instance);
var data = new ScenarioCompletedData()
{
perceptionCamera = (cam == null)
? new PerceptionCameraData()
: new PerceptionCameraData()
{
captureTriggerMode = cam.captureTriggerMode.ToString(),
startAtFrame = cam.firstCaptureFrame,
framesBetweenCaptures = cam.framesBetweenCaptures
},
labelers = (cam == null)
? new string[]{}
: cam.labelers
.Select(labeler => labeler.GetType().Name)
.Where(labeler => LabelAllowlist.Contains(labeler)).ToArray(),
randomizers = null
};
// EngineAnalytics.SendEvent(k_ScenarioCompletedName, data);
}
#endregion
}
}

3
com.unity.perception/Runtime/PerceptionEngineAnalytics.cs.meta


fileFormatVersion: 2
guid: 38657354e82b4c9b8370c9c55a39b1e3
timeCreated: 1629939608
正在加载...
取消
保存