in Kiosk/Views/AnomalyDetector/AnomalyChartControl.xaml.cs [251:324]
private async Task StartLiveDemoProcessAsync()
{
try
{
double yScale = resultGrid.ActualHeight / MaxVolumeValue;
double xOffset = resultGrid.ActualWidth / DefaultDurationOfLiveDemoInSecond;
DateTime currentTime = DateTime.Now;
DateTime startTime = currentTime.AddMinutes((double)DefaultDurationOfLiveDemoInSecond * -1);
progressLine.X1 = progressIndicator.CenterPoint.X;
progressLine.X2 = progressIndicator.CenterPoint.X;
dataPolyline.Points.Clear();
int startIndex = AnomalyDetectionScenario.DefaultRequiredPoints;
for (int i = 0; i < startIndex; i++)
{
float volume = GetCurrentVolumeValue();
curScenario.AllData.Insert(i, new TimeSeriesData(startTime.ToString(), volume));
startTime = startTime.AddMinutes(AnomalyDetectorScenarioLoader.GetTimeOffsetInMinute(curScenario.Granularity));
double yOffset = yScale * (curScenario.AllData[i].Value - BaseVolume);
Point point = new Point(xOffset * i, resultGrid.ActualHeight - yOffset);
dataPolyline.Points.Add(point);
Point newUpperPoint = new Point(dataPolyline.Points[i].X, 0);
Point newLowerPoint = new Point(dataPolyline.Points[i].X, resultGrid.ActualHeight);
int endOfUpper = detectWindowPolyline.Points.Count / 2;
int endOfLower = detectWindowPolyline.Points.Count / 2 + 1;
detectWindowPolyline.Points.Insert(endOfUpper, newUpperPoint);
detectWindowPolyline.Points.Insert(endOfLower, newLowerPoint);
}
for (int i = startIndex; i < DefaultDurationOfLiveDemoInSecond; i++)
{
if (shouldStopCurrentRun)
{
break;
}
float volume = GetCurrentVolumeValue();
curScenario.AllData.Insert(i, new TimeSeriesData(startTime.ToString(), volume));
startTime = startTime.AddMinutes(AnomalyDetectorScenarioLoader.GetTimeOffsetInMinute(curScenario.Granularity));
double yOffset = yScale * (curScenario.AllData[i].Value - BaseVolume);
Point point = new Point(xOffset * i, resultGrid.ActualHeight - yOffset);
dataPolyline.Points.Add(point);
AnomalyLastDetectResult result = await GetLiveDemoAnomalyDetectionResultAsync(i);
if (result != null)
{
result.ExpectedValue -= BaseVolume;
AnomalyInfo anomalyInfo = new AnomalyInfo
{
Text = i.ToString(),
Value = (volume - BaseVolume).ToString("F2"),
ExpectedValue = result.ExpectedValue.ToString("F2")
};
DrawProgressByDetectionResult(dataPolyline.Points[i], result, anomalyInfo, yScale);
}
}
this.StopLiveAudio?.Invoke(this, EventArgs.Empty);
}
catch (Exception ex)
{
await Util.GenericApiCallExceptionHandler(ex, "Failure during streaming detection.");
}
}