123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- 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<DateTime, double>();
- 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<DateTime, double> DataSet { get; set; }
- /// <summary>
- /// 更新数据
- /// </summary>
- /// <param name="begin"></param>
- /// <param name="end"></param>
- void UpdateData(DateTime begin, DateTime end)
- {
- var dataset = new DataSeriesSet<DateTime, double>();
- 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<DateTime, double> runtimeDic = new Dictionary<DateTime, double>();
- 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<XyyDataSeries<DateTime, double>>();
- 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
- }
- }
|