public void HumiditySummary_Date_IsRowKey() { var date = new LocalDate(2017, 06, 10); var summary = new HumiditySummaryEntity("Lounge", date, new List <HumidityEntity>()); Assert.AreEqual(date.ToString("yyyy-MM-dd", null), summary.RowKey); }
public void HumiditySummary_Location_IsPartitionKey() { var date = new LocalDate(2017, 06, 10); var summary = new HumiditySummaryEntity("Lounge", date, new List <HumidityEntity>()); Assert.AreEqual("Lounge", summary.PartitionKey); }
public void HumiditySummary_NoDataPoints_NoSummary() { var summary = new HumiditySummaryEntity("Lounge", new LocalDate(2017, 06, 10), new List <HumidityEntity>()); Assert.IsNull(summary.Min); Assert.IsNull(summary.Max); }
public async Task <IActionResult> Summary(string location, DateTime startDate, DateTime endDate, string ianaTimeZone) { var dateTimeZone = DateTimeZoneProviders.Tzdb.GetZoneOrNull(ianaTimeZone); if (dateTimeZone == null) { return(BadRequest($"Unknown IANA time zone: {ianaTimeZone}")); } var localStartDate = new LocalDateTime(startDate.Year, startDate.Month, startDate.Day, 0, 0); var localEndDate = new LocalDateTime(endDate.Year, endDate.Month, endDate.Day, 0, 0); if (localStartDate > localEndDate) { return(BadRequest("Given startDate must be less than or equal to given endDate")); } var result = new List <HumiditySummaryEntity>(); for (var requestStartDate = localStartDate; requestStartDate <= localEndDate; requestStartDate = requestStartDate.PlusDays(1)) { var humidityRecords = await GetHumidityEntitiesForDate(location, requestStartDate.InZoneLeniently(dateTimeZone)); var humiditySummaryEntity = new HumiditySummaryEntity(location, requestStartDate, humidityRecords); result.Add(humiditySummaryEntity); } return(base.Ok(Mapper.Map <List <HumiditySummaryViewModel> >(result, opts => { opts.Items["DateTimeZone"] = dateTimeZone; }))); }
public void HumiditySummary_Max_IsLargest() { var location = "Lounge"; var date = new LocalDate(2017, 06, 10); var dataPoints = new List <HumidityEntity> { new HumidityEntity(location, 70), new HumidityEntity(location, 50), new HumidityEntity(location, 12), new HumidityEntity(location, 100), new HumidityEntity(location, 15) }; var summary = new HumiditySummaryEntity(location, date, dataPoints); Assert.AreEqual(100, summary.Max); }
private object GetLocalDateFromContextOrRowKey(HumiditySummaryEntity source, HumiditySummaryViewModel destination, string destMember, ResolutionContext context) { context.Items.TryGetValue("LocalDate", out var localDate); if (localDate is LocalDate) { return(((LocalDate)localDate).ToString("yyyy-MM-dd", null)); } context.Items.TryGetValue("DateTimeZone", out var dateTimeZone); if (dateTimeZone is DateTimeZone && !string.IsNullOrWhiteSpace(source.RowKey)) { return(ReverseTicks.ToZonedDateTime(source.RowKey, (DateTimeZone)dateTimeZone).ToString("yyyy-MM-dd", null)); } return(null); }