< Summary

Class:BIWAnalytics
Assembly:BIWAnalytics
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/BuilderMode/Analytics/BIWAnalytics.cs
Covered lines:41
Uncovered lines:95
Coverable lines:136
Total lines:262
Line coverage:30.1% (41 of 136)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PlayerOpenPanel(...)0%110100%
PlayerClosesPanel(...)0%110100%
PlayerJumpOrEdit(...)0%2100%
PlayerUnpublishScene(...)0%110100%
StartEditorFlow(...)0%110100%
EnterEditor(...)0%110100%
ExitEditor(...)0%110100%
StartScenePublish(...)0%2100%
EndScenePublish(...)0%2100%
SceneLimitsExceeded(...)0%2100%
NewObjectPlaced(...)0%2100%
NewObjectPlacedChunk(...)0%30500%
QuickAccessAssigned(...)0%2100%
FavoriteAdded(...)0%110100%
CatalogItemSearched(...)0%2100%
ConvertSceneMetricsModelToDictionary(...)0%2100%
GetLimitsPassedArray(...)0%56700%
AddSceneInfo(...)0%2100%
SendEditorEvent(...)0%110100%
SendEvent(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/BuilderMode/Analytics/BIWAnalytics.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using DCL;
 4using Newtonsoft.Json;
 5using UnityEngine;
 6
 7/// <summary>
 8/// This class include all the analytics that we are tracking for builder-in-world, if you want to add a new one
 9/// Please do it inside this class and call the SendEditorEvent method to include all the default info
 10/// </summary>
 11public static class BIWAnalytics
 12{
 13
 14    #region BuilderPanel
 15
 16    public static void PlayerOpenPanel(int landsOwned, int landsOperator)
 17    {
 418        Dictionary<string, string> events = new Dictionary<string, string>();
 419        events.Add("Lands Owned", landsOwned.ToString());
 420        events.Add("Lands Operator", landsOperator.ToString());
 421        SendEvent("player_open_panel", events);
 422    }
 23
 24    public static void PlayerClosesPanel(int landsOwned, int landsOperator)
 25    {
 126        Dictionary<string, string> events = new Dictionary<string, string>();
 127        events.Add("Lands Owned", landsOwned.ToString());
 128        events.Add("Lands Operator", landsOperator.ToString());
 129        SendEvent("player_closes_panel", events);
 130    }
 31
 32    /// <summary>
 33    /// When the user interact with the panel to go to a land or a scene
 34    /// </summary>
 35    /// <param name="source">From where it is comming: scenes, lands, projects</param>
 36    /// <param name="mode">The button he has been pressed: Editor, Jump in</param>
 37    /// <param name="coords">Coords of the land where the scene is deployed or land coords</param>
 38    /// <param name="ownership">It is owner or operator</param>
 39    public static void PlayerJumpOrEdit(string source, string mode, Vector2 coords, string ownership)
 40    {
 041        Dictionary<string, string> events = new Dictionary<string, string>();
 042        events.Add("source", source);
 043        events.Add("mode", mode);
 044        events.Add("coords", coords.ToString());
 045        events.Add("ownership", ownership);
 046        SendEvent("player_jump_or_edit", events);
 047    }
 48
 49    /// <summary>
 50    /// When the user unpublished a scene
 51    /// </summary>
 52    /// <param name="type">What type of scene is unpublished: Builder, Builder-in-world, SDK</param>
 53    /// <param name="coords">Coords of the land where the scene is deployed </param>
 54    public static void PlayerUnpublishScene(string type, Vector2Int coords)
 55    {
 256        Dictionary<string, string> events = new Dictionary<string, string>();
 257        events.Add("type", type);
 258        events.Add("coords", coords.ToString());
 259        SendEvent("player_unpublish_scene", events);
 260    }
 61
 62    #endregion
 63
 64    #region BuilderEditor
 65
 66    /// <summary>
 67    /// Everytime we start the flow of the editor
 68    /// </summary>
 69    /// <param name="source">It comes from the shortcut or from BuilderPanel</param>
 70    public static void StartEditorFlow(string source)
 71    {
 872        Dictionary<string, string> events = new Dictionary<string, string>();
 873        events.Add("source", source);
 874        SendEditorEvent("start_editor_flow", events);
 875    }
 76
 77    public static void EnterEditor(float loadingTime)
 78    {
 779        Dictionary<string, string> events = new Dictionary<string, string>();
 780        events.Add("loading_time", loadingTime.ToString());
 781        SendEditorEvent("enter_editor", events);
 782    }
 83
 84    public static void ExitEditor(float timeInvestedInTheEditor)
 85    {
 486        Dictionary<string, string> events = new Dictionary<string, string>();
 487        events.Add("time_in_the_editor", timeInvestedInTheEditor.ToString());
 488        SendEditorEvent("exit_editor", events);
 489    }
 90
 91    public static void StartScenePublish(SceneMetricsModel sceneLimits)
 92    {
 093        Dictionary<string, string> events = new Dictionary<string, string>();
 094        events.Add("scene_limits", JsonConvert.SerializeObject(ConvertSceneMetricsModelToDictionary(sceneLimits)));
 095        SendEditorEvent("start_publish_of_the_scene", events);
 096    }
 97
 98    public static void EndScenePublish(SceneMetricsModel sceneLimits, string successOrError, float publicationTime)
 99    {
 0100        Dictionary<string, string> events = new Dictionary<string, string>();
 0101        events.Add("success", successOrError);
 0102        events.Add("publication_time", publicationTime.ToString());
 0103        events.Add("scene_limits", JsonConvert.SerializeObject(ConvertSceneMetricsModelToDictionary(sceneLimits)));
 0104        SendEditorEvent("end_scene_publish", events);
 0105    }
 106
 107    public static void SceneLimitsExceeded(SceneMetricsModel sceneUsage, SceneMetricsModel sceneLimits)
 108    {
 0109        Dictionary<string, string> events = new Dictionary<string, string>();
 0110        events.Add("limits_passed", GetLimitsPassedArray(sceneUsage, sceneLimits));
 0111        events.Add("scene_limits", JsonConvert.SerializeObject(ConvertSceneMetricsModelToDictionary(sceneLimits)));
 0112        events.Add("current_usage", JsonConvert.SerializeObject(ConvertSceneMetricsModelToDictionary(sceneUsage)));
 0113        SendEditorEvent("scene_limits_exceeded", events);
 0114    }
 115
 116    /// <summary>
 117    /// When a new item is placed from the catalog
 118    /// </summary>
 119    /// <param name="catalogItem">The item that has been added</param>
 120    /// <param name="source">It has been added from Categories, Asset pack, Favorites or Quick Access</param>
 121    public static void NewObjectPlaced(CatalogItem catalogItem, string source)
 122    {
 0123        Dictionary<string, string> events = new Dictionary<string, string>();
 0124        events.Add("name", catalogItem.name);
 0125        events.Add("assetPack", catalogItem.assetPackName);
 0126        events.Add("category", catalogItem.category);
 0127        events.Add("category_name", catalogItem.categoryName);
 0128        events.Add("source", source);
 0129        events.Add("type", catalogItem.itemType.ToString());
 0130        SendEditorEvent("new_object_placed", events);
 0131    }
 132
 133    /// <summary>
 134    /// This will send all the items placed in a period of time in a single message
 135    /// </summary>
 136    /// <param name="catalogItem">The item that has been added</param>
 137    /// <param name="source">It has been added from Categories, Asset pack, Favorites or Quick Access</param>
 138    public static void NewObjectPlacedChunk(List<KeyValuePair<CatalogItem, string>> itemsToSendAnalytics)
 139    {
 0140        Dictionary<string, string> events = new Dictionary<string, string>();
 0141        List<string> items = new List<string>();
 0142        foreach (var catalogItem in itemsToSendAnalytics)
 143        {
 0144            if (events.ContainsKey(catalogItem.Key.name))
 145                continue;
 146
 0147            Dictionary<string, string> item = new Dictionary<string, string>();
 0148            int amountOfItems = 0;
 0149            foreach (var itemsToCompare in itemsToSendAnalytics)
 150            {
 0151                if (catalogItem.Key == itemsToCompare.Key)
 0152                    amountOfItems++;
 153            }
 154
 0155            item.Add("name", catalogItem.Key.name);
 0156            item.Add("amount", amountOfItems.ToString());
 0157            item.Add("assetPack", catalogItem.Key.assetPackName);
 0158            item.Add("category", catalogItem.Key.category);
 0159            item.Add("category_name", catalogItem.Key.categoryName);
 0160            item.Add("source", catalogItem.Value);
 0161            item.Add("type", catalogItem.Key.ToString());
 162
 0163            items.Add( JsonConvert.SerializeObject(item));
 164        }
 0165        events.Add("items", JsonConvert.SerializeObject(items));
 0166        SendEditorEvent("new_object_placed", events);
 0167    }
 168
 169    public static void QuickAccessAssigned(CatalogItem catalogItem, string source)
 170    {
 0171        Dictionary<string, string> events = new Dictionary<string, string>();
 0172        events.Add("name", catalogItem.name);
 0173        events.Add("assetPack", catalogItem.assetPackName);
 0174        events.Add("category", catalogItem.category);
 0175        events.Add("category Name", catalogItem.categoryName);
 0176        events.Add("source", source);
 0177        events.Add("type", catalogItem.itemType.ToString());
 0178        SendEditorEvent("quick_access_assigned", events);
 0179    }
 180
 181    public static void FavoriteAdded(CatalogItem catalogItem)
 182    {
 1183        Dictionary<string, string> events = new Dictionary<string, string>();
 1184        events.Add("name", catalogItem.name);
 1185        events.Add("assetPack", catalogItem.assetPackName);
 1186        events.Add("category", catalogItem.category);
 1187        events.Add("category Name", catalogItem.categoryName);
 1188        events.Add("type", catalogItem.itemType.ToString());
 1189        SendEditorEvent("favorite_added", events);
 1190    }
 191
 192    public static void CatalogItemSearched(string searchQuery, int resultAmount)
 193    {
 0194        Dictionary<string, string> events = new Dictionary<string, string>();
 0195        events.Add("search_query", searchQuery);
 0196        events.Add("result_amount", resultAmount.ToString());
 0197        SendEditorEvent("catalog_item_searched", events);
 0198    }
 199
 200    private static Dictionary<string, string> ConvertSceneMetricsModelToDictionary(SceneMetricsModel sceneLimits)
 201    {
 0202        Dictionary<string, string> sceneLimitsDictionary = new Dictionary<string, string>();
 0203        sceneLimitsDictionary.Add("meshes", sceneLimits.meshes.ToString());
 0204        sceneLimitsDictionary.Add("bodies", sceneLimits.bodies.ToString());
 0205        sceneLimitsDictionary.Add("materials", sceneLimits.materials.ToString());
 0206        sceneLimitsDictionary.Add("textures", sceneLimits.textures.ToString());
 0207        sceneLimitsDictionary.Add("triangles", sceneLimits.triangles.ToString());
 0208        sceneLimitsDictionary.Add("entities", sceneLimits.entities.ToString());
 0209        sceneLimitsDictionary.Add("scene_height", sceneLimits.sceneHeight.ToString());
 210
 0211        return sceneLimitsDictionary;
 212    }
 213
 214    public static string GetLimitsPassedArray(SceneMetricsModel sceneUsage, SceneMetricsModel sceneLimits)
 215    {
 0216        string limitsPassed = "[";
 217
 0218        if (sceneUsage.bodies >= sceneLimits.bodies)
 0219            limitsPassed += "bodies,";
 0220        if (sceneUsage.entities >= sceneLimits.entities)
 0221            limitsPassed += "entities,";
 0222        if (sceneUsage.textures >= sceneLimits.textures)
 0223            limitsPassed += "textures,";
 0224        if (sceneUsage.triangles >= sceneLimits.triangles)
 0225            limitsPassed += "triangles,";
 0226        if (sceneUsage.materials >= sceneLimits.materials)
 0227            limitsPassed += "materials,";
 0228        if (sceneUsage.meshes >= sceneLimits.meshes)
 0229            limitsPassed += "meshes,";
 230
 0231        limitsPassed = limitsPassed.Substring(0, limitsPassed.Length - 1);
 0232        limitsPassed += "]";
 0233        return limitsPassed;
 234    }
 235
 236    #endregion
 237
 238    #region CommonInfo
 239
 240    private static Vector2Int coords;
 241    private static string ownership;
 242    private static Vector2Int size;
 243
 244    public static void AddSceneInfo(Vector2Int sceneCoords,  string sceneOwnership, Vector2Int sceneSize)
 245    {
 0246        coords = sceneCoords;
 0247        ownership = sceneOwnership;
 0248        size = sceneSize;
 0249    }
 250
 251    #endregion
 252
 253    private static void SendEditorEvent(string eventName, Dictionary<string, string> events)
 254    {
 20255        events.Add("ownership", ownership);
 20256        events.Add("coords", coords.ToString());
 20257        events.Add("scene_size", size.ToString());
 20258        SendEvent(eventName, events);
 20259    }
 260
 54261    private static void SendEvent(string eventName, Dictionary<string, string> events) { Analytics.i.SendAnalytic(eventN
 262}