private void HistoricalDataUpdate(object junk)
{
if(!Visible) {
lock (_historicalUpdateThreadMutex) {
Thread.Sleep(100);
}
RequestHistoricalUpdate();
return;
}
lock (_historicalUpdateThreadMutex) {
System.Diagnostics.Debug.WriteLine("Begin Historical Data");
var now = DateTime.Now;
var histTimeRangeSelector = historicalTimeSelectHeader.TimeRange;
var histDateChooser = historicalTimeSelectHeader.DateEdit;
var histNowChk = historicalTimeSelectHeader.CheckEdit;
var histTimeChooser = historicalTimeSelectHeader.TimeEdit;
var histTimeSpan = histTimeRangeSelector.SelectedSpan;
var histStartDate = histNowChk.Checked
? now.Subtract(histTimeSpan)
: histDateChooser.DateTime.Date.Add(histTimeChooser.Time.TimeOfDay);
var cumTimeInfo = HistoricalGraphBreakdown.GetCumulativeWindows(
histStartDate.Add(histTimeSpan),
histTimeSpan,
!histNowChk.Checked
);
var historicalSelected =
_dbStore.GetAllSensorInfos()
.Where(si => _historicSensorViewPanelController.IsSensorSelected(si))
.ToList();
var sensorReadings = historicalSelected.Select(
sensor =>
_dbStore.GetReadingSummaries(
sensor.Name, cumTimeInfo.MaxStamp,
cumTimeInfo.MinStamp - cumTimeInfo.MaxStamp,
UnitUtility.ChooseBestSummaryUnit(histTimeSpan)
)
);
var historicalSummaries = StatsUtil
.JoinReadingSummaryEnumerable(sensorReadings)
.ToList();
if (!IsDisposed) {
BeginInvoke(new Action(() => {
windResourceGraph.TemperatureUnit = TemperatureUnit;
windResourceGraph.PressureUnit = PressureUnit;
windResourceGraph.SpeedUnit = SpeedUnit;
windResourceGraph.SetDataSource(historicalSummaries);
historicalGraphBreakdown.TemperatureUnit = TemperatureUnit;
historicalGraphBreakdown.PressureUnit = PressureUnit;
historicalGraphBreakdown.SpeedUnit = SpeedUnit;
historicalGraphBreakdown.StepBack = !histNowChk.Checked;
historicalGraphBreakdown.DrillStartDate = histStartDate;
historicalGraphBreakdown.CumulativeTimeSpan = histTimeSpan;
historicalGraphBreakdown.SetDataSource(historicalSummaries);
}));
}
}
}