浏览代码

Remove all old analytics defines. (#5168)

/check-for-ModelOverriders
GitHub 3 年前
当前提交
da010ecf
共有 3 个文件被更改,包括 32 次插入28 次删除
  1. 18
      com.unity.ml-agents/Runtime/Analytics/InferenceAnalytics.cs
  2. 29
      com.unity.ml-agents/Runtime/Analytics/TrainingAnalytics.cs
  3. 13
      com.unity.ml-agents/Tests/Editor/Analytics/TrainingAnalyticsTest.cs

18
com.unity.ml-agents/Runtime/Analytics/InferenceAnalytics.cs


const int k_MaxNumberOfElements = 1000;
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE
#endif
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE
#elif MLA_UNITY_ANALYTICS_MODULE
AnalyticsResult result = AnalyticsResult.UnsupportedPlatform;
if (result == AnalyticsResult.Ok)
{
s_EventRegistered = true;
}
#endif
#else // no editor, no analytics
s_EventRegistered = false;
#endif
return s_EventRegistered;
}

IList<IActuator> actuators
)
{
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE
// The event shouldn't be able to report if this is disabled but if we know we're not going to report
// Lets early out and not waste time gathering all the data
if (!IsAnalyticsEnabled())

var data = GetEventForModel(nnModel, behaviorName, inferenceDevice, sensors, actionSpec, actuators);
// Note - to debug, use JsonUtility.ToJson on the event.
// Debug.Log(JsonUtility.ToJson(data, true));
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE
#else
return;
#endif
}

29
com.unity.ml-agents/Runtime/Analytics/TrainingAnalytics.cs


namespace Unity.MLAgents.Analytics
{
internal class TrainingAnalytics
internal static class TrainingAnalytics
{
const string k_VendorKey = "unity.ml-agents";
const string k_TrainingEnvironmentInitializedEventName = "ml_agents_training_environment_initialized";

};
/// <summary>
/// Whether or not we've registered this particular event yet
/// </summary>
static bool s_EventsRegistered = false;
/// <summary>
/// Hourly limit for this event name
/// </summary>
const int k_MaxEventsPerHour = 1000;

const int k_MaxNumberOfElements = 1000;
private static bool s_SentEnvironmentInitialized;
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE
/// <summary>
/// Whether or not we've registered this particular event yet
/// </summary>
static bool s_EventsRegistered = false;
#endif
private static Guid s_TrainingSessionGuid;

static bool EnableAnalytics()
internal static bool EnableAnalytics()
#if MLA_UNITY_ANALYTICS_MODULE
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE
if (s_EventsRegistered)
{
return true;

#if UNITY_EDITOR
#else
return false;
#endif // UNITY_EDITOR
}
s_EventsRegistered = true;

IList<IActuator> actuators
)
{
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE
if (!IsAnalyticsEnabled())
return;

// Debug.Log(
// $"Would send event {k_RemotePolicyInitializedEventName} with body {JsonUtility.ToJson(data, true)}"
// );
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE
if (AnalyticsUtils.s_SendEditorAnalytics)
{
EditorAnalytics.SendEventWithLimit(k_RemotePolicyInitializedEventName, data);

[Conditional("MLA_UNITY_ANALYTICS_MODULE")]
public static void TrainingBehaviorInitialized(TrainingBehaviorInitializedEvent tbiEvent)
{
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE
if (!IsAnalyticsEnabled())
return;

// Debug.Log(
// $"Would send event {k_TrainingBehaviorInitializedEventName} with body {JsonUtility.ToJson(tbiEvent, true)}"
// );
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE
#else
return;
#endif
}

13
com.unity.ml-agents/Tests/Editor/Analytics/TrainingAnalyticsTest.cs


using Unity.MLAgents.Actuators;
using Unity.MLAgents.Analytics;
using Unity.MLAgents.Policies;
using UnityEditor;
namespace Unity.MLAgents.Tests.Analytics
{

Assert.AreEqual(2, remotePolicyEvent.ActuatorInfos[0].NumContinuousActions);
Assert.AreEqual(0, remotePolicyEvent.ActuatorInfos[0].NumDiscreteActions);
}
[Test]

}
Academy.Instance.Dispose();
}
[Test]
public void TestEnableAnalytics()
{
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE
Assert.IsTrue(EditorAnalytics.enabled == TrainingAnalytics.EnableAnalytics());
#else
Assert.IsFalse(TrainingAnalytics.EnableAnalytics());
#endif
}
}
}
正在加载...
取消
保存