internal void FinishTrip() { TripDebugLog.EndBikeTrip(); SetLocationUpdateEnabled(false); // Do we have a trip? if (lastLocation != null && currentDistance > MinimumDistanceForTrip && currentFix > startFix) { var trip = new BikeTrip { Distance = currentDistance, StartTime = Epoch + TimeSpan.FromMilliseconds(startFix), EndTime = Epoch + TimeSpan.FromMilliseconds(currentFix) }; var dataApi = DataApi.Obtain(this); dataApi.AddTrip(trip).Wait(); TripDebugLog.LogNewTrip(trip.EndTime - trip.StartTime, trip.Distance); } lastLocation = null; currentDistance = startFix = currentFix = 0; var oldState = currentBikingState; currentBikingState = BikingState.NotBiking; OnBikingStateChanged(oldState, currentBikingState); TripDebugLog.CommitTripLog(); StopSelf(); }
public override void OnCreate() { Android.Util.Log.Debug("BikrBackup", "Created backup agent"); var dataApi = DataApi.Obtain(this); var dbBackupHelper = new FileBackupHelper(this, dataApi.DbPath); AddHelper(DbPrefix, dbBackupHelper); }
public async void LoadData(Context context) { try { var circles = CircleBadges; var dataApi = DataApi.Obtain(context); var stats = await dataApi.GetStats(); /*var stats = new TripDistanceStats { * PrevDay = 4500, * PrevWeek = 25000, * PrevMonth = 100000, * Daily = 2800, * Weekly = 12000, * Monthly = 30000, * };*/ var mapping = new Dictionary <CircleBadge, double> { { circles[0], stats.Daily }, { circles[1], stats.Weekly }, { circles[2], stats.Monthly }, }; foreach (var map in mapping) { if (prefs.GetDisplayDistance(map.Value) != prefs.GetDisplayDistance(map.Key.Distance)) { map.Key.SetDistanceAnimated(map.Value, startDelay: 100); } } prefs.SetLastMeasure("day", stats.Daily); prefs.SetLastMeasure("week", stats.Weekly); prefs.SetLastMeasure("month", stats.Monthly); var lastTrips = await dataApi.GetTripsAfter(prefs.LastCheckin); /*var lastTrips = new List<BikeTrip> () { * new BikeTrip { EndTime = DateTime.Now, StartTime = DateTime.Now.AddMinutes (-30), Distance = 3000 } * };*/ if (lastTrips != null && lastTrips.Any()) { ShowLastTripNotification(TimeSpan.FromSeconds(lastTrips.Sum(bt => (bt.EndTime - bt.StartTime).TotalSeconds)), lastTrips.Count, lastTrips.Sum(t => t.Distance)); } SetCompletionLevel(circles[0], stats.Daily, stats.PrevDay); SetCompletionLevel(circles[1], stats.Weekly, stats.PrevWeek); SetCompletionLevel(circles[2], stats.Monthly, stats.PrevMonth); prefs.LastCheckin = DateTime.UtcNow; } catch (Exception e) { Log.Error("DataStats", e.ToString()); } }
async void LoadStats() { var dataApi = DataApi.Obtain(Activity); var stats = await dataApi.GetAggregatedStats(); /*var stats = new Dictionary<AggregatedStatsKey, double> { * { AggregatedStatsKey.DailyThisWeek, 4000 }, * { AggregatedStatsKey.DailyThisMonth, 5000 }, * { AggregatedStatsKey.BestTripToday, 6000 }, * { AggregatedStatsKey.BestTripInWeek, 7000 }, * { AggregatedStatsKey.BestTripInMonth, 8000 }, * { AggregatedStatsKey.MeanTripToday, 9000 }, * { AggregatedStatsKey.MeanTripInWeek, 10000 }, * { AggregatedStatsKey.MeanTripInMonth, 11000 }, * };*/ var fillScheme = new Tuple <int, AggregatedStatsKey, int>[] { Tuple.Create(0, AggregatedStatsKey.DailyThisWeek, Resource.Id.statEntry1), Tuple.Create(0, AggregatedStatsKey.DailyThisMonth, Resource.Id.statEntry2), Tuple.Create(1, AggregatedStatsKey.BestTripToday, Resource.Id.statEntry1), Tuple.Create(1, AggregatedStatsKey.BestTripInWeek, Resource.Id.statEntry2), Tuple.Create(1, AggregatedStatsKey.BestTripInMonth, Resource.Id.statEntry3), Tuple.Create(2, AggregatedStatsKey.MeanTripToday, Resource.Id.statEntry1), Tuple.Create(2, AggregatedStatsKey.MeanTripInWeek, Resource.Id.statEntry2), Tuple.Create(2, AggregatedStatsKey.MeanTripInMonth, Resource.Id.statEntry3), }; foreach (var fill in fillScheme) { double value = 0; stats.TryGetValue(fill.Item2, out value); sections [fill.Item1].FindViewById(fill.Item3).FindViewById <TextView> (Resource.Id.numericValue).Text = prefs.GetDisplayDistance(value, strictValue: true); sections [fill.Item1].FindViewById(fill.Item3).FindViewById <TextView> (Resource.Id.unitText).Text = prefs.GetUnitForDistance(value); } }