public async Task <IMetering> GetLastMetering(string terminalId) { // Get last metering MeteringDAO lastMetering = await _context.Meterings .Include(x => x.SensorValueRelations) .OrderByDescending(x => x.Time) .FirstOrDefaultAsync(x => x.TerminalId == terminalId); // Map to Metering model Metering res = new Metering() { TerminalId = lastMetering.TerminalId, Latitude = lastMetering.Latitude, Longitude = lastMetering.Longitude, Time = lastMetering.Time, }; // Get sensor vals for last metering var sensorVals = await _context.MeteringSensorRelations .Include(x => x.Metering) .Include(x => x.SensorValue) .Where(x => x.Metering.Id == lastMetering.Id) .ToListAsync(); foreach (var sv in sensorVals) { Property prop = DynamicPropertyManagers.Sensors.GetProperty(sv.PropertyName); res.SensorValues.SetValue(prop, DAOHelper.ByteArrayToObject(prop.TypeOfValue, sv.SensorValue.Value)); } return(res); }
public async Task <double> GetSumPropertyValue(string terminalId, SensorProperty prop, DateTime start, DateTime end) { // Try cast to double if (typeof(double).IsAssignableFrom(prop.TypeOfValue)) { return ((await Filter(terminalId, prop, start, end)).Sum( selector => (double)DAOHelper.ByteArrayToObject(prop.TypeOfValue, selector.SensorValue.Value))); } // Try convert to double return((await Filter(terminalId, prop, start, end)) .Sum(selector => Convert.ToDouble(DAOHelper.ByteArrayToObject(prop.TypeOfValue, selector.SensorValue.Value)))); }
public async Task <List <Metering> > GetMeterings(string terminalId, DateTime start, DateTime end, SensorProperty prop) { return((await FilterQuery(start, end, terminalId, prop) .OrderBy(x => x.Metering.Time) .ToListAsync()) .Select(x => new Metering() { TerminalId = x.Metering.TerminalId, Longitude = x.Metering.Longitude, Latitude = x.Metering.Latitude, Time = x.Metering.Time, SensorValues = new PropertiesCollection(new [] { new KeyValuePair <Property, object>( DynamicPropertyManagers.Sensors.GetProperty(prop.Name), DAOHelper.ByteArrayToObject(prop.TypeOfValue, x.SensorValue.Value)), }) }) .ToList()); }
public async Task <double> GetLastFirstDifferencePropertyValue(string terminalId, SensorProperty prop, DateTime start, DateTime end) { var fltr = FilterQuery(start, end, terminalId, prop); if (!fltr.Any()) { return(0); } var first = fltr.OrderBy(x => x.Metering.Time).First(); var last = fltr.OrderByDescending(x => x.Metering.Time).First(); // Try cast to double if (typeof(double).IsAssignableFrom(prop.TypeOfValue)) { return ((double)DAOHelper.ByteArrayToObject(prop.TypeOfValue, last.SensorValue.Value) - (double)DAOHelper.ByteArrayToObject(prop.TypeOfValue, first.SensorValue.Value)); } // Try convert to double return (Convert.ToDouble(DAOHelper.ByteArrayToObject(prop.TypeOfValue, last.SensorValue.Value)) - Convert.ToDouble(DAOHelper.ByteArrayToObject(prop.TypeOfValue, first.SensorValue.Value))); }
/// <inheritdoc /> public async Task <object> GetMaxPropertyValue(string terminalId, SensorProperty prop, DateTime start, DateTime end) { return((await Filter(terminalId, prop, start, end)).Max(selector => DAOHelper.ByteArrayToObject(prop.TypeOfValue, selector.SensorValue.Value))); }