-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Analytics (MAPCO-8806) #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fce85cf
82862ff
450d2e0
92458a9
25b49d2
031670d
0274a6d
032e3eb
1c14373
9f1cfc5
e28780e
e594de7
ad6226e
2360dff
4a53689
82db891
a9d39c4
ced26e0
b048c25
5230e8d
289ef0e
192d7b4
c4ff8e5
c09b76f
60adf88
6f53c0b
5d2ca6b
d7999bc
6879708
9a70d23
0026cb8
bbeaa3a
096bd7f
6ff1eef
df20daf
75938ed
4960089
09cc0b6
6066de3
b31d549
100c16c
66a9938
42d4e31
210d9e0
412bd81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| using System.IO; | ||
| using System.Threading.Tasks; | ||
| using com.mapcolonies.core.Services.Analytics.Enums; | ||
| using com.mapcolonies.core.Services.Analytics.Managers; | ||
| using com.mapcolonies.core.Services.Analytics.Model; | ||
| using NUnit.Framework; | ||
| using UnityEngine; | ||
|
|
||
| namespace EditorTests.Analytics | ||
| { | ||
| public class AnalyticsManagerFileWriteTests | ||
| { | ||
| [Test] | ||
| public async Task Publish_Writes_JSON_Line_To_Session_Log_File() | ||
| { | ||
| string logDirPath = Path.Combine(Application.persistentDataPath, AnalyticsManager.AnalyticsFileName); | ||
| if (Directory.Exists(logDirPath)) Directory.Delete(logDirPath, true); | ||
|
|
||
| AnalyticsManager am = new AnalyticsManager(); | ||
|
|
||
| try | ||
| { | ||
| am.Initialize(); | ||
| string logFilePath = Path.Combine(logDirPath, $"session-{am.SessionId}.log"); | ||
|
|
||
| LayerData msgParams = LayerData.Create("imagery", "layer-abc"); | ||
| LogObject log = LogObject.Create( | ||
| LogType.Log, | ||
| AnalyticsMessageTypes.LayerUseStarted.ToString(), | ||
| msgParams, | ||
| "General", | ||
| AnalyticsMessageTypes.LayerUseStarted); | ||
|
|
||
| await am.Publish(log); | ||
|
|
||
| Assert.IsTrue(File.Exists(logFilePath), $"Log file was not created at {logFilePath}"); | ||
|
|
||
| string content = await File.ReadAllTextAsync(logFilePath); | ||
| StringAssert.Contains("\"LayerDomain\":\"imagery\"", content); | ||
| StringAssert.Contains("\"UniqueLayerId\":\"layer-abc\"", content); | ||
| StringAssert.Contains("\"MessageType\":" + (int)AnalyticsMessageTypes.LayerUseStarted, content); | ||
| StringAssert.Contains("\"Severity\":\"Log\"", content); | ||
| } | ||
| finally | ||
| { | ||
| am.Dispose(); | ||
| if (Directory.Exists(logDirPath)) Directory.Delete(logDirPath, true); | ||
| } | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task Publish_Creates_Directory_If_Not_Exists() | ||
| { | ||
| string logDirPath = Path.Combine(Application.persistentDataPath, AnalyticsManager.AnalyticsFileName); | ||
| if (Directory.Exists(logDirPath)) Directory.Delete(logDirPath, true); | ||
| Assert.IsFalse(Directory.Exists(logDirPath), "Directory should not exist before test"); | ||
|
|
||
| AnalyticsManager am = new AnalyticsManager(); | ||
|
|
||
| try | ||
| { | ||
| am.Initialize(); | ||
| string logFilePath = Path.Combine(logDirPath, $"session-{am.SessionId}.log"); | ||
|
|
||
| LayerData msgParams = LayerData.Create("imagery", "layer-xyz"); | ||
| LogObject log = LogObject.Create( | ||
| LogType.Log, | ||
| AnalyticsMessageTypes.LayerUseStarted.ToString(), | ||
| msgParams, | ||
| "General", | ||
| AnalyticsMessageTypes.LayerUseStarted); | ||
|
|
||
| await am.Publish(log); | ||
|
|
||
| Assert.IsTrue(Directory.Exists(logDirPath), "Directory should be created"); | ||
| Assert.IsTrue(File.Exists(logFilePath), $"Log file was not created at {logFilePath}"); | ||
|
|
||
| string content = await File.ReadAllTextAsync(logFilePath); | ||
| StringAssert.Contains("\"LayerDomain\":\"imagery\"", content); | ||
| } | ||
| finally | ||
| { | ||
| am.Dispose(); | ||
| if (Directory.Exists(logDirPath)) Directory.Delete(logDirPath, true); | ||
| } | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| using System; | ||
| using com.mapcolonies.core.Services.Analytics.Enums; | ||
| using com.mapcolonies.core.Services.Analytics.Model; | ||
| using NUnit.Framework; | ||
| using UnityEngine; | ||
|
|
||
| namespace EditorTests.Analytics | ||
| { | ||
| public class LogObjectCreateTests | ||
| { | ||
| [Test] | ||
| public void Create_Sets_All_Fields() | ||
| { | ||
| LogType severity = LogType.Warning; | ||
| string message = "LayerUseStarted"; | ||
| LayerData parameters = LayerData.Create("imagery", "layer-001"); | ||
| string component = "General"; | ||
| AnalyticsMessageTypes type = AnalyticsMessageTypes.LayerUseStarted; | ||
|
|
||
| LogObject log = LogObject.Create(severity, message, parameters, component, type); | ||
|
|
||
| Assert.AreEqual(severity.ToString(), log.Severity); | ||
| Assert.AreEqual(message, log.Message); | ||
| Assert.AreSame(parameters, log.MessageParameters); | ||
| Assert.AreEqual(component, log.Component); | ||
| Assert.AreEqual(type, log.MessageType); | ||
| Assert.That(log.TimeStamp, Is.InRange(DateTime.UtcNow.AddMinutes(-1), DateTime.UtcNow.AddMinutes(1))); | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| using System.Runtime.Serialization; | ||
| using com.mapcolonies.core.Services.Analytics.Model; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace EditorTests.Analytics.SerializationTests | ||
| { | ||
| public class ApplicationDataSerializationTests | ||
| { | ||
| [Test] | ||
| public void ApplicationData_Serializes_Expected_Fields() | ||
| { | ||
| ApplicationData data = ApplicationData.Create("Yahalom", "1.2.3"); | ||
| SerializationInfo info = new SerializationInfo(typeof(ApplicationData), new FormatterConverter()); | ||
| data.GetObjectData(info, new StreamingContext()); | ||
|
|
||
| Assert.AreEqual("Yahalom", info.GetString(nameof(ApplicationData.ApplicationName))); | ||
| Assert.AreEqual("1.2.3", info.GetString(nameof(ApplicationData.ApplicationVersion))); | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| using System; | ||
| using System.Runtime.Serialization; | ||
| using com.mapcolonies.core.Services.Analytics.Model; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace EditorTests.Analytics.SerializationTests | ||
| { | ||
| public class ApplicationUsageDataSerializationTests | ||
| { | ||
| [Test] | ||
| public void ApplicationUsageData_Serializes_Expected_Fields() | ||
| { | ||
| TimeSpan timeSpan = TimeSpan.FromSeconds(123.45); | ||
| ApplicationUsageData data = ApplicationUsageData.Create(timeSpan); | ||
| SerializationInfo info = new SerializationInfo(typeof(ApplicationUsageData), new FormatterConverter()); | ||
| data.GetObjectData(info, new StreamingContext()); | ||
|
|
||
| TimeSpan storedTimeSpan = (TimeSpan)info.GetValue(nameof(ApplicationUsageData.Time), typeof(TimeSpan)); | ||
| Assert.AreEqual(123.45, storedTimeSpan.TotalSeconds, 0.0001); | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| using System.Runtime.Serialization; | ||
| using com.mapcolonies.core.Services.Analytics.Model; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace EditorTests.Analytics.SerializationTests | ||
| { | ||
| public class GameModeDataSerializationTests | ||
| { | ||
| [Test] | ||
| public void GameModeData_Serializes_Expected_Fields() | ||
| { | ||
| GameModeData data = GameModeData.Create("MissionPlanning", "TopDown"); | ||
| SerializationInfo info = new SerializationInfo(typeof(GameModeData), new FormatterConverter()); | ||
| data.GetObjectData(info, new StreamingContext()); | ||
|
|
||
| Assert.AreEqual("MissionPlanning", info.GetString(nameof(GameModeData.Mode))); | ||
| Assert.AreEqual("TopDown", info.GetString(nameof(GameModeData.ViewMode))); | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| using System.Runtime.Serialization; | ||
| using com.mapcolonies.core.Services.Analytics.Model; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace EditorTests.Analytics.SerializationTests | ||
| { | ||
| public class LayerDataSerializationTests | ||
| { | ||
| [Test] | ||
| public void LayerData_Serializes_Expected_Fields() | ||
| { | ||
| LayerData data = LayerData.Create("elevation", "lyr-42"); | ||
| SerializationInfo info = new SerializationInfo(typeof(LayerData), new FormatterConverter()); | ||
| data.GetObjectData(info, new StreamingContext()); | ||
|
|
||
| Assert.AreEqual("elevation", info.GetString(nameof(LayerData.LayerDomain))); | ||
| Assert.AreEqual("lyr-42", info.GetString(nameof(LayerData.UniqueLayerId))); | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| using System.Runtime.Serialization; | ||
| using com.mapcolonies.core.Services.Analytics.Model; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace EditorTests.Analytics.SerializationTests | ||
| { | ||
| public class LocationDataSerializationTests | ||
| { | ||
| [Test] | ||
| public void LocationData_Serializes_Expected_Fields() | ||
| { | ||
| LocationData data = LocationData.Create(34.5, 31.7); | ||
| SerializationInfo info = new SerializationInfo(typeof(LocationData), new FormatterConverter()); | ||
| data.GetObjectData(info, new StreamingContext()); | ||
|
|
||
| Assert.AreEqual(34.5, info.GetDouble(nameof(LocationData.Longitude))); | ||
| Assert.AreEqual(31.7, info.GetDouble(nameof(LocationData.Latitude))); | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| using com.mapcolonies.core.Services.Analytics.Enums; | ||
| using com.mapcolonies.core.Services.Analytics.Model; | ||
| using Newtonsoft.Json; | ||
| using NUnit.Framework; | ||
| using UnityEngine; | ||
|
|
||
| namespace EditorTests.Analytics.SerializationTests | ||
| { | ||
| public class LogObjectSerializationTests | ||
| { | ||
| [Test] | ||
| public void Serialize_ToJson_Contains_Expected_Fields() | ||
| { | ||
| var severity = LogType.Log; | ||
| var message = "LayerUseStarted"; | ||
| var parameters = LayerData.Create("imagery", "layer-001"); | ||
| var component = "General"; | ||
| var type = AnalyticsMessageTypes.LayerUseStarted; | ||
|
|
||
| var log = LogObject.Create(severity, message, parameters, component, type); | ||
|
|
||
| string json = JsonConvert.SerializeObject(log, Formatting.None); | ||
|
|
||
| StringAssert.Contains("\"Severity\":\"Log\"", json); | ||
| StringAssert.Contains("\"Message\":\"LayerUseStarted\"", json); | ||
| StringAssert.Contains("\"Component\":\"General\"", json); | ||
| StringAssert.Contains($"\"MessageType\":{(int)AnalyticsMessageTypes.LayerUseStarted}", json); | ||
| StringAssert.Contains("\"LayerDomain\":\"imagery\"", json); | ||
| StringAssert.Contains("\"UniqueLayerId\":\"layer-001\"", json); | ||
| StringAssert.Contains("\"TimeStamp\"", json); | ||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| using System.Runtime.Serialization; | ||
| using com.mapcolonies.core.Services.Analytics.Model; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace EditorTests.Analytics.SerializationTests | ||
| { | ||
| public class PerformanceDataSerializationTests | ||
| { | ||
| [Test] | ||
| public void PerformanceData_Serializes_Expected_Fields() | ||
| { | ||
| PerformanceData data = PerformanceData.Create(58.9f, 1024.5, 23.3); | ||
| SerializationInfo info = new SerializationInfo(typeof(PerformanceData), new FormatterConverter()); | ||
| data.GetObjectData(info, new StreamingContext()); | ||
|
|
||
| Assert.AreEqual(58.9f, info.GetSingle(nameof(PerformanceData.Fps))); | ||
| Assert.AreEqual(1024.5, info.GetDouble(nameof(PerformanceData.AllocatedMemoryInMB))); | ||
| Assert.AreEqual(23.3, info.GetDouble(nameof(PerformanceData.CpuUsagePercentage))); | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| using System.Runtime.Serialization; | ||
| using com.mapcolonies.core.Services.Analytics.Model; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace EditorTests.Analytics.SerializationTests | ||
| { | ||
| public class UserDetailsSerializationTests | ||
| { | ||
| [Test] | ||
| public void UserDetails_Serializes_Expected_Fields() | ||
| { | ||
| UserDetailsData detailsData = UserDetailsData.Create("username", "MAPCO", "DEVPC01"); | ||
| SerializationInfo info = new SerializationInfo(typeof(UserDetailsData), new FormatterConverter()); | ||
| detailsData.GetObjectData(info, new StreamingContext()); | ||
|
|
||
| Assert.AreEqual("username", info.GetString(nameof(UserDetailsData.UserName))); | ||
| Assert.AreEqual("MAPCO", info.GetString(nameof(UserDetailsData.UserDomainName))); | ||
| Assert.AreEqual("DEVPC01", info.GetString(nameof(UserDetailsData.MachineName))); | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| using System.Runtime.Serialization; | ||
| using com.mapcolonies.core.Services.Analytics.Model; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace EditorTests.Analytics.SerializationTests | ||
| { | ||
| public class UserInputDevicesSerializationTests | ||
| { | ||
| [Test] | ||
| public void UserInputDevices_Serializes_Expected_Fields() | ||
| { | ||
| UserInputDevicesData devs = UserInputDevicesData.Create(new[] { "Keyboard", "Mouse" }); | ||
| SerializationInfo info = new SerializationInfo(typeof(UserInputDevicesData), new FormatterConverter()); | ||
| devs.GetObjectData(info, new StreamingContext()); | ||
|
|
||
| string[] stored = (string[])info.GetValue(nameof(UserInputDevicesData.InputDevices), typeof(string[])); | ||
| CollectionAssert.AreEqual(new[] { "Keyboard", "Mouse" }, stored); | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.