protected void SplitDataPointsOnHourBoundary(ref List <WalkingDataPointModel> dataPoints) { for (int i = 0; i < dataPoints.Count; ++i) { var dp = dataPoints[i]; var hourDelta = dp.Stop.Hour - dp.Start.Hour; var nDpsAdded = 0; while (hourDelta != 0) { var newStart = dp.Start .AddHours(1) .AddMinutes(-dp.Start.Minute) .AddSeconds(-dp.Start.Second) .AddMilliseconds(-dp.Start.Millisecond); //NOTE: This causes us to drop a millisecond of counted time. Should be reasonable var oldStop = newStart.AddMilliseconds(-1); WalkingDataPointModel newDp = new WalkingDataPointModel(newStart, dp.Stop, dp.AverageSpeedMetersPerSecond); dp.Stop = oldStop; nDpsAdded++; dataPoints.Insert(i + nDpsAdded, newDp); dp = newDp; hourDelta = dp.Stop.Hour - dp.Start.Hour; } i += nDpsAdded; } }
private async Task <List <WalkingDataPointModel> > QuerySpeedDataBetween(DateTime bucketStart, DateTime bucketStop) { var speedRequest = new DataReadRequest.Builder() .Aggregate(DataType.TypeSpeed, DataType.AggregateSpeedSummary) .BucketByTime(1, TimeUnit.Minutes) .SetTimeRange(bucketStart.ToUnixTime(), bucketStop.ToUnixTime(), TimeUnit.Milliseconds) .Build(); var speedResponse = await fitnessHistoryClient.ReadDataAsync(speedRequest); if (speedResponse.Status.IsSuccess) { var dataSets = speedResponse.Buckets.SelectMany(b => b.DataSets).ToList(); var dataPoints = dataSets.SelectMany(ds => ds.DataPoints).ToList(); return(speedResponse.Buckets .SelectMany(b => b.DataSets) .SelectMany(ds => ds.DataPoints) .Select(dp => { //convert the times var start = dp.GetStartTime(TimeUnit.Milliseconds).DateTimeFromUnixTime(); var end = dp.GetEndTime(TimeUnit.Milliseconds).DateTimeFromUnixTime(); if (start == end) { end = end.AddMinutes(1); } var average = dp.GetValue(Field.FieldAverage).AsFloat(); if (average > 0.1f && average < 12) { #if DUMP_DATA WalkingDataPointModel res = new WalkingDataPointModel(start, end, average); using (System.IO.FileStream fs = new System.IO.FileStream(dumpFilePath, System.IO.FileMode.Append)) { dumpSerializer.Serialize(fs, res); } return res; #else return new WalkingDataPointModel(start, end, average); #endif } return null; }) .Where(dp => dp != null) .ToList()); } #if DEBUG Debug.WriteLine($"Failed to poll speed data: {speedResponse.Status.StatusMessage}"); #else Crashes.TrackError(new Exception($"Failed to poll speed data: {speedResponse.Status.StatusMessage}"), new Dictionary <string, string> { { "StatusMessage", speedResponse.Status.StatusMessage } }); #endif return(null); }
private SKRoundRect WalkingDataRect(WalkingDataPointModel value, float totalWidth, float totalHeight) { var d = totalWidth / (HOUR - 1); // divide into minutes var xStart = d * value.Start.Minute + (float)minMargin.Left; var xEnd = d * value.Stop.Minute - (float)minMargin.Right; var rect = new SKRect(xStart, 0, xEnd, totalHeight); var roundedRect = new SKRoundRect(rect, CornerRadius, CornerRadius); return(roundedRect); }
public async Task StoreWalkingDataPoint(WalkingDataPointModel dataPoint) { await connection.InsertAsync(dataPoint); }