public AFValues ConvertToAFValues(TimeSeriesDataList tsDataList, FitbitStream stream, FitbitUser fitbitUser) { AFValues values = new AFValues(); foreach (var result in tsDataList.DataList) { AFValue val = null; if (stream.FitbitSource != TimeSeriesResourceType.TimeEnteredBed) { val = new AFValue(Convert.ToSingle(result.Value), new AFTime(result.DateTime), stream.UnitsOfMeasure); } else { val = new AFValue(result.Value, new AFTime(result.DateTime), stream.UnitsOfMeasure); } values.Add(val); } values.Attribute = fitbitUser.UserElement.Elements["Fitbit"].Attributes[stream.AttributeName]; return values; }
private AFValues GetFitbitDataForStream(FitbitStream stream, FitbitUser fitbitUser, DateTime startTime, DateTime endTime) { TimeSeriesDataList internalDataList = fitbitUser.ApiClient.GetTimeSeries(stream.FitbitSource, startTime, endTime); PIFitnessLog.Write(TraceEventType.Verbose, 0, string.Format("Returned data. Stream: {0}, User: {1}", stream.FitbitSource, fitbitUser.UserElement.Name)); AFValues vals = _fitbitConverter.ConvertToAFValues(internalDataList, stream, fitbitUser); return vals; //return null; }
private AFValues GetActiveHours(IList<AFValues> valsList, FitbitUser fitbitUser) { try { IEnumerable<AFValues> filteredValues = from vals in valsList where vals != null select vals; AFValues veryActiveValues = QueryAFValuesByName(filteredValues, "Minutes very active"); AFValues fairlyActiveValues = QueryAFValuesByName(filteredValues, "Minutes fairly active"); AFValues lightlyActiveValues = QueryAFValuesByName(filteredValues, "Minutes lightly active"); var combined = from valsActive in veryActiveValues join valsFairly in fairlyActiveValues on valsActive.Timestamp equals valsFairly.Timestamp join valsLightly in lightlyActiveValues on valsFairly.Timestamp equals valsLightly.Timestamp select new AFValue((Convert.ToSingle(valsActive.Value) + Convert.ToSingle(valsFairly.Value) + Convert.ToSingle(valsLightly.Value)) / 60, valsActive.Timestamp); AFValues values = new AFValues(); foreach (var val in combined) { values.Add(val); } values.Attribute = fitbitUser.UserElement.Elements["Fitbit"].Attributes["Active hours"]; return values; } catch (Exception ex) { return null; } }
private IList<AFValues> GetFitbitData(FitbitUser fitbitUser) { DateTime startTime = DateTime.Now.AddDays(-30); DateTime endTime = DateTime.Now; IList<AFValues> valsList = new List<AFValues>(); foreach (var stream in _fitbitStreams) { AFValues vals = GetFitbitDataForStream(stream, fitbitUser, startTime, endTime); valsList.Add(vals); } //get calculated attributes AFValues activeHours = GetActiveHours(valsList, fitbitUser); valsList.Add(activeHours); return valsList; }