/// <summary> /// valled to display the process graph /// </summary> /// <param name="startDate"></param> /// <param name="endDate"></param> private void displayChartProcess(DateTime startDate, DateTime endDate) { bool flag = true; List <DayProcessStats.FinalProcessStat> ProcessList = new List <DayProcessStats.FinalProcessStat>(); DateTime current = startDate; while (current <= endDate) { DayProcessStats dayProcessStats = new DayProcessStats(current); foreach (var process in dayProcessStats.FinalProcessStatList) { flag = true; foreach (var pro in ProcessList) { if (pro.Name.Equals(process.Name)) { pro.Period = pro.Period.Add(process.Period); flag = false; break; } } if (flag) { ProcessList.Add(new DayProcessStats.FinalProcessStat(process.Name, process.Period)); } } current = current.AddDays(1); } List <KeyValuePair <string, double> > valueList = new List <KeyValuePair <string, double> >(); List <KeyValuePair <string, double> > finalValueList = new List <KeyValuePair <string, double> >(); foreach (var process in ProcessList) { double period = process.Period.TotalHours < 0 ? 0 : process.Period.TotalHours; valueList.Add(new KeyValuePair <string, double>(process.Name, (double)period)); } valueList.Sort(compare); int k = 0; double p = 0; foreach (var entry in valueList) { if (k < 5) { finalValueList.Add(entry); k++; } else { p = p + entry.Value; } } finalValueList.Add(new KeyValuePair <string, double>("others", p)); ProcessStatGraph.DataContext = finalValueList; }
/// <summary> /// called to draw pc time graph /// </summary> /// <param name="startDate"></param> /// <param name="endDate"></param> private void laptopChartProcess(DateTime startDate, DateTime endDate) { List <KeyValuePair <string, double> > valueList = new List <KeyValuePair <string, double> >(); List <KeyValuePair <string, double> > finalValueList = new List <KeyValuePair <string, double> >(); DateTime current = startDate; TimeSpan period = new TimeSpan(); while (current <= endDate) { DayProcessStats dayProcessStats = new DayProcessStats(current); period = TimeSpan.Zero; foreach (var process in dayProcessStats.FinalProcessStatList) { period = period.Add(process.Period); } valueList.Add(new KeyValuePair <string, double>(current.ToString("dd-MM"), (double)period.TotalHours)); current = current.AddDays(1); } laptopStatGraph.DataContext = valueList; }