public async Task <SystemMonitorViewModel> GetSystemMonitorViewModel(DateTimeOffset lastCreatedAt) { IEnumerable <SensorListing> sensorListings = await sensorsService.GetAllSensors(lastCreatedAt); SystemMonitorViewModel systemMonitorViewModel = new SystemMonitorViewModel(); foreach (SensorListing sensorListing in sensorListings) { DateTimeOffset sensorListingTime = sensorListing.Time.ToDateTimeOffset(); foreach (Sensor sensor in sensorListing.Sensors) { if (sensor.Type == SensorType.WasteAbsorbanceDetector1) { systemMonitorViewModel.WasteChannelAbsorbancePoints.Add(new PointViewModel() { Time = sensorListingTime, Value = sensor.Value, }); } else if (sensor.Type == SensorType.TargetAbsorbanceDetector1) { systemMonitorViewModel.TargetChannelAbsorbancePoints.Add(new PointViewModel() { Time = sensorListingTime, Value = sensor.Value, }); } else if (sensor.Type == SensorType.EnvironmentTemperature) { systemMonitorViewModel.EnvironmentTemperaturePoints.Add(new PointViewModel() { Time = sensorListingTime, Value = sensor.Value, }); } } } SetLastCreatedAt(systemMonitorViewModel, sensorListings); return(systemMonitorViewModel); }
public async Task <JsonResult> GetSystemMonitorViewModel(DateTimeOffset?lastCreatedAt) { SystemMonitorViewModel systemMonitorViewModel = await systemMonitorService.GetSystemMonitorViewModel(lastCreatedAt ?? DateTimeOffset.MinValue); return(Json(systemMonitorViewModel, JsonRequestBehavior.AllowGet)); }
public async Task <ActionResult> Index() { SystemMonitorViewModel systemMonitorViewModel = await systemMonitorService.GetSystemMonitorViewModel(DateTimeOffset.MinValue); return(View(systemMonitorViewModel)); }
private void SetLastCreatedAt(SystemMonitorViewModel systemMonitorViewModel, IEnumerable <SensorListing> sensorListings) { SensorListing lastSensorListing = sensorListings.LastOrDefault(); systemMonitorViewModel.LastCreatedAt = lastSensorListing?.CreatedAt ?? DateTimeOffset.MinValue; }