public ChartCounter GetChartData(DateTime startDate, DateTime endDate) { var counter = new ChartCounter(); counter = dashboardService.LoadChartCounter(startDate, endDate); return(counter); }
/// <summary>TOP 5 most used severity categories and source IPs</summary> /// <param name="startDate">start date for the method.</param> /// <param name="endDate">end date for the method.</param> /// <returns>counter</returns> public ChartCounter LoadChartCounter(DateTime startDate, DateTime endDate) { var counter = new ChartCounter(); var selectedData = _appDbContext.Attacks.Where(o => o.Timestamp >= startDate && o.Timestamp <= endDate) .ToList(); if (selectedData.Count == 0) { return(counter); } var srcDictionary = new Dictionary <string, int>(); var categoryDictionary = new Dictionary <string, int>(); for (int i = 0; i < selectedData.Count; i++) { if (!srcDictionary.ContainsKey(selectedData[i].Src_ip)) { srcDictionary.Add(selectedData[i].Src_ip, 1); } else { srcDictionary[selectedData[i].Src_ip] += 1; } if (!categoryDictionary.ContainsKey(selectedData[i].Category)) { categoryDictionary.Add(selectedData[i].Category, 1); } else { categoryDictionary[selectedData[i].Category] += 1; } } srcDictionary = srcDictionary.OrderByDescending(o => o.Value).Take(5).ToDictionary(o => o.Key, o => o.Value); categoryDictionary = categoryDictionary.OrderByDescending(o => o.Value).Take(5).ToDictionary(o => o.Key, o => o.Value); foreach (var item in srcDictionary) { counter.LabelSrc.Add(item.Key); counter.CounterSrc.Add(item.Value); } foreach (var item in categoryDictionary) { counter.LabelCategory.Add(item.Key); counter.CounterCategory.Add(item.Value); } return(counter); }