using System; using System.Collections.Generic; using System.Linq; using System.Text; using Aitex.UI.Charting.ViewModel; using System.Windows.Input; using Abt.Controls.SciChart; using Abt.Controls.SciChart.Visuals; using Abt.Controls.SciChart.Model.DataSeries; namespace DataAnalysisControl.Charting.ViewModel { public class RunTimeStatisticViewModel : ChartingBaseViewModel { public RunTimeStatisticViewModel(SciChartSurface plot) { _plot = plot; #if false DataSet = new DataSeriesSet(); Show1YearCommand = new Aitex.UI.Charting.Command.ChartingCommand((o) => true, (o) => { UpdateData(DateTime.Now - new TimeSpan(365, 0, 0, 0), DateTime.Now); }); ShowAllCommand = new Aitex.UI.Charting.Command.ChartingCommand((o) => true, (o) => { UpdateData(DateTime.MinValue, DateTime.MaxValue); }); Show1YearCommand.Execute(null); #endif } private SciChartSurface _plot; #if false public ICommand Show1YearCommand { get; set; } public ICommand ShowAllCommand { get; set; } public XyDataSeries DataSet { get; set; } /// /// 更新数据 /// /// /// void UpdateData(DateTime begin, DateTime end) { var dataset = new DataSeriesSet(); string[] chamNames = new string[] { "ReactorA", "ReactorB", "ReactorC", "ReactorD" }; foreach (var cham in chamNames) { var commonViewModel = Aitex.UI.Charting.ViewModel.CommonViewModel.Instance; var ret = commonViewModel.GetSusceptorList(begin, end, cham); Dictionary runtimeDic = new Dictionary(); foreach (var recipe in ret) { string pStartTimeStr = recipe.ProcessBeginTime; string pEndTimeStr = recipe.ProcessEndTime; if (string.IsNullOrEmpty(pStartTimeStr) || string.IsNullOrEmpty(pEndTimeStr)) continue; DateTime pStartTime = DateTime.Parse(pStartTimeStr); DateTime pEndTime = DateTime.Parse(pEndTimeStr); if (pStartTime >= pEndTime) continue; for (DateTime d = pStartTime.Date; d <= pEndTime.Date; d += new TimeSpan(1, 0, 0, 0)) { if (d == pStartTime.Date) { if (!runtimeDic.ContainsKey(d.Date)) { runtimeDic.Add(d.Date, 0); } if (d != pEndTime.Date) { runtimeDic[d.Date] += (new DateTime(d.Year, d.Month, d.Day, 23, 59, 59) - pStartTime).TotalHours; } else { runtimeDic[d.Date] += (pEndTime - pStartTime).TotalHours; } } else if (d == pEndTime.Date) { if (!runtimeDic.ContainsKey(d.Date)) { runtimeDic.Add(d.Date, 0); } if (d != pStartTime.Date) { runtimeDic[d.Date] += (new TimeSpan(pEndTime.Hour, pEndTime.Minute, pEndTime.Second)).TotalHours; } else { System.Diagnostics.Debug.Assert(false); } } else { if (!runtimeDic.ContainsKey(d.Date)) { runtimeDic.Add(d.Date, 0); } runtimeDic[d.Date] += 24; } } } var series = dataset.AddSeries>(); if (begin == DateTime.MinValue) series.SeriesName = string.Format("{0} 所有运行时间统计", cham); else series.SeriesName = string.Format("{0} 最近1年运行时间统计", cham); var timeList = runtimeDic.Keys.ToList(); timeList.Sort(); if (timeList.Count > 0) { var s1 = timeList[0]; var s2 = timeList[timeList.Count - 1]; for (var day = s1; day <= s2; day+= new TimeSpan(1, 0, 0, 0)) { if (runtimeDic.ContainsKey(day)) series.Append(day, 0, runtimeDic[day]); else series.Append(day, 0, 0); } } } DataSet = dataset; _plot.XAxis.AutoRange = Abt.Controls.SciChart.Visuals.Axes.AutoRange.Never; _plot.YAxis.AutoRange = Abt.Controls.SciChart.Visuals.Axes.AutoRange.Never; InvokePropertyChanged(); _plot.ZoomExtents(); } #endif } }