/// <summary>Checks how many times a color scheme was applied within a report.</summary> protected override void ProcessToolUsageData(StatisticsReport report, ToolUsageData tool) { foreach (var stat in tool.ExecutorStats) { // Make regex match in the statistic name to find out if the it's what we are looking for. Match colorSchemeMatch = Regex.Match(stat.Key, @"(?<=(ColorScheme\.)).*"); if (!colorSchemeMatch.Success) { continue; } // Skip if it's not about color schemes. string color = colorSchemeMatch.Value; // Else get the color name. // If there was no information about this scheme before, add a container for the info if (!stats.ContainsKey(color)) { stats.Add(color, new Dictionary <string, int>()); } // Also add a container for the info about the scheme usage if (!stats[color].ContainsKey("Кол-во использований")) { stats[color].Add("Кол-во использований", 0); } // Add the new value to the old info. stats[color]["Кол-во использований"] += int.Parse(stat.Value); } }
/// <summary>Gets amount of times objects of different types were used by a tool within a report.</summary> protected override void ProcessToolUsageData(StatisticsReport report, ToolUsageData tool) { // Go through all statisticts of the tool foreach (var stat in tool.ExecutorStats) { // Make regex match in the statistic name to find out if the statistic is what we are looking for. Match dataTypeMatch = Regex.Match(stat.Key, $@"(?<=({(DoesAnalyseInput ? "Input" : "Output")}Data\.Type\.)).*"); if (!dataTypeMatch.Success) { continue; } // Skip if it's not about data types. string dataType = dataTypeMatch.Value; // Else get the type name. string objKey = SelectedGrouping == ToolGrouping ? tool.ToolName : report.ProductVersion; // If there was no information about this object of analysis before, add a container for it. if (!stats.ContainsKey(objKey)) { stats.Add(objKey, new Dictionary <string, int>()); } // Also add a container for the info about the type and place the new information here if (!stats[objKey].ContainsKey(dataType)) { stats[objKey].Add(dataType, int.Parse(stat.Value)); } // If there already is a container, just sum old and new values. else { stats[objKey][dataType] += int.Parse(stat.Value); } } }
/// <summary>Collects info about amounts of data on the input of a tool for one report.</summary> protected override void ProcessToolUsageData(StatisticsReport report, ToolUsageData tool) { int objAmountFromReport = 0; // Go through all statisticts of the tool foreach (var stat in tool.ExecutorStats) { // Make regex match in the statistic name to find out if it contains amount of objects of certain type. Match dataTypeMatch = Regex.Match(stat.Key, $@"InputData\.Type\."); if (!dataTypeMatch.Success) { continue; } // Skip if it's not about data types. objAmountFromReport += int.Parse(stat.Value); // Else get the amount of objects. } // Exit if there's no input objects here if (objAmountFromReport == 0) { return; } // If there was no information about average input of this tool before, add a container for it. if (!statsAverageData.ContainsKey(tool.ToolName)) { statsAverageData.Add(tool.ToolName, new StatAverageInfo()); } StatAverageInfo averageInfo = statsAverageData[tool.ToolName]; // Add info to count average averageInfo.StatSum += objAmountFromReport; averageInfo.ReportsCount++; // If there was no information about min/max input of this tool before, add containers for it if (!stats.ContainsKey(tool.ToolName)) { stats.Add(tool.ToolName, new Dictionary <string, int>()); stats[tool.ToolName].Add(minSeriesIdentifier, objAmountFromReport); stats[tool.ToolName].Add(maxSeriesIdentifier, objAmountFromReport); } else { // Check if current min is greater than this new value and set this value as min if it is if (stats[tool.ToolName][minSeriesIdentifier] > objAmountFromReport) { stats[tool.ToolName][minSeriesIdentifier] = objAmountFromReport; } // Check if current max is lower than this new value and set this value as max if it is else if (stats[tool.ToolName][maxSeriesIdentifier] < objAmountFromReport) { stats[tool.ToolName][maxSeriesIdentifier] = objAmountFromReport; } } }
/// <summary>Checks how many times a tool was called within one report.</summary> protected override void ProcessToolUsageData(StatisticsReport report, ToolUsageData tool) { // Skip if there's no information about tool calls if (!tool.CommandStats.ContainsKey("Click")) { return; } // Else get the info int clicksFromReport = int.Parse(tool.CommandStats["Click"]); // Add tool to the dictionary if it wasn't done before if (!stats.ContainsKey(tool.ToolName)) { stats.Add(tool.ToolName, new Dictionary <string, int>()); // Add tool stats[tool.ToolName].Add(Name, 0); // Add container for the statistic } stats[tool.ToolName][Name] += clicksFromReport; }
/// <summary>Collects something in a single ToolUsageData (depends on the info a concrete analysis needs).</summary> protected abstract void ProcessToolUsageData(StatisticsReport report, ToolUsageData tool);
/// <summary>Collects statistics for each user from JSONs given.</summary> private static List <StatisticsReport> GetInfoFromJsons(List <string> jsons) { List <StatisticsReport> reports = new List <StatisticsReport>(); // List to return foreach (string json in jsons) { if (string.IsNullOrEmpty(json)) { continue; } StatisticsReport infoFromReport = new StatisticsReport(); // Will contain info from one JSON file JObject rootJObj = JObject.Parse(json); // The whole JSON in a JObject // Get info about the product where the report came from string productName = rootJObj.GetValue("ProductName")?.ToString(); string productVersion = (rootJObj.GetValue("ProductVersion") ?? rootJObj.GetValue("Version"))?.ToString(); // Get info about the period when statistics were collected string startDateStr = (rootJObj.GetValue("StartDate") ?? rootJObj.GetValue("StartDateUtc"))?.ToString(); string endDateStr = (rootJObj.GetValue("EndDate") ?? rootJObj.GetValue("EndDateUtc"))?.ToString(); // Convert dates from string to DateTime DateTime startDate, endDate; // If a string is in an uncommon format, suppose that the format is "dd.mm.yyyy" and parse exactly from it if (!DateTime.TryParse(startDateStr, out startDate)) { startDate = DateTime.ParseExact(startDateStr, "dd.mm.yyyy", CultureInfo.InvariantCulture); } if (!DateTime.TryParse(endDateStr, out endDate)) { endDate = DateTime.ParseExact(endDateStr, "dd.mm.yyyy", CultureInfo.InvariantCulture); } // Place the info from the report into corresponding containers infoFromReport.ProductName = productName; infoFromReport.ProductVersion = productVersion; infoFromReport.StartDate = startDate; infoFromReport.EndDate = endDate; // Get list of tools from the value of the "Items" property IEnumerable <JProperty> toolsUsed = rootJObj.GetValue("Items").ToObject <JObject>().Properties(); // Collect statistics from each tool foreach (var toolJProp in toolsUsed) { // Will contain statistics for one XTool usage within a period ToolUsageData toolData = new ToolUsageData(toolJProp.Name); JObject toolJObj = toolJProp.Value.ToObject <JObject>(); JObject commandJObj = toolJObj.GetValue("Command")?.ToObject <JObject>(); JObject executorJObj = toolJObj.GetValue("Executor")?.ToObject <JObject>(); JObject uiJObj = toolJObj.GetValue("UI")?.ToObject <JObject>(); if (commandJObj != null) { foreach (KeyValuePair <string, JToken> property in commandJObj) { toolData.CommandStats.Add(property.Key, property.Value.ToString()); } } if (executorJObj != null) { foreach (KeyValuePair <string, JToken> property in executorJObj) { toolData.ExecutorStats.Add(property.Key, property.Value.ToString()); } } if (uiJObj != null) { foreach (KeyValuePair <string, JToken> property in uiJObj) { toolData.UIStats.Add(property.Key, property.Value.ToString()); } } infoFromReport.ToolsUsed.Add(toolData); } reports.Add(infoFromReport); } return(reports); }