|
|
|
|
|
|
using UnityEngine.Profiling; |
|
|
|
using System.Runtime.Serialization; |
|
|
|
using System.Runtime.Serialization.Json; |
|
|
|
using UnityEngine.SceneManagement; |
|
|
|
|
|
|
|
namespace MLAgents |
|
|
|
{ |
|
|
|
|
|
|
[DataContract] |
|
|
|
public class GaugeNode |
|
|
|
{ |
|
|
|
const float k_SmoothingFactor = .25f; // weight for exponential moving average.
|
|
|
|
|
|
|
|
[DataMember] |
|
|
|
public float value; |
|
|
|
[DataMember(Name = "min")] |
|
|
|
|
|
|
[DataMember(Name = "weightedAverage")] |
|
|
|
public float weightedAverage; |
|
|
|
weightedAverage = value; |
|
|
|
minValue = value; |
|
|
|
maxValue = value; |
|
|
|
count = 1; |
|
|
|
|
|
|
{ |
|
|
|
minValue = Mathf.Min(minValue, newValue); |
|
|
|
maxValue = Mathf.Max(maxValue, newValue); |
|
|
|
// update exponential moving average
|
|
|
|
weightedAverage = (k_SmoothingFactor * newValue) + ((1f - k_SmoothingFactor) * weightedAverage); |
|
|
|
value = newValue; |
|
|
|
++count; |
|
|
|
} |
|
|
|
|
|
|
/// <param name="filename"></param>
|
|
|
|
public void SaveJsonTimers(string filename = null) |
|
|
|
{ |
|
|
|
if (filename == null) |
|
|
|
# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
|
|
|
|
try |
|
|
|
var fullpath = Path.GetFullPath("."); |
|
|
|
filename = $"{fullpath}/csharp_timers.json"; |
|
|
|
if (filename == null) |
|
|
|
{ |
|
|
|
var activeScene = SceneManager.GetActiveScene(); |
|
|
|
var timerDir = Path.Combine(Application.dataPath, "ML-Agents", "Timers"); |
|
|
|
Directory.CreateDirectory(timerDir); |
|
|
|
|
|
|
|
filename = Path.Combine(timerDir, $"{activeScene.name}_timers.json"); |
|
|
|
} |
|
|
|
|
|
|
|
var fs = new FileStream(filename, FileMode.Create, FileAccess.Write); |
|
|
|
SaveJsonTimers(fs); |
|
|
|
fs.Close(); |
|
|
|
var fs = new FileStream(filename, FileMode.Create, FileAccess.Write); |
|
|
|
SaveJsonTimers(fs); |
|
|
|
fs.Close(); |
|
|
|
catch (IOException) |
|
|
|
{ |
|
|
|
// It's possible we don't have write access to the directory.
|
|
|
|
Debug.LogWarning($"Unable to save timers to file {filename}"); |
|
|
|
} |
|
|
|
#endif
|
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|