//NOTE: Make sure this does not make it into production anywhere! public async Task GenerateTieredAchievementsTestData() { //NOTE: does not delete todays data await DeleteDataBaseTables(Table.GoalsAndAchievements | Table.WalkingDays); #if true const int DAYS_TO_GENERATE = 31; #else const int DAYS_TO_GENERATE = 21; #endif List <WalkingDayModel> days = new List <WalkingDayModel>(DAYS_TO_GENERATE); for (int i = 0; i < DAYS_TO_GENERATE; ++i) { //generate goal models with this pattern // XXXXXXX 0 XXX 0 //where X is goal reached and 0 is not reached #if true bool reachedGoal = false; int period = i % 12; if (period <= 6 || (period >= 8 && period <= 10)) { reachedGoal = true; } #else bool reachedGoal = true; //int period = i % 9; //if (period < 5) // reachedGoal = true; #endif DateTime date = DateTime.Today.AddDays(-DAYS_TO_GENERATE + i + 1); GoalStorageModel goal = new GoalStorageModel { Day = date, MinutesToReach = 10, HasBeenReached = reachedGoal, }; await StoreDailyGoalResult(goal); days.Add(new WalkingDayModel { Day = date, MinutesBriskWalking = (uint)(reachedGoal ? 30 : 1), MinutesRegularWalking = (uint)(reachedGoal ? 1 : 30), }); } await connection.InsertAllAsync(days); }
public async Task StoreDailyGoalResult(GoalStorageModel dailyGoal) { if (await connection.FindAsync <GoalStorageModel>(dailyGoal.Day) != null) { Console.WriteLine("Updating goal with latest values"); await connection.UpdateAsync(dailyGoal); } else { Console.WriteLine("Storing goal: {0}\n", dailyGoal); await connection.InsertAsync(dailyGoal); } }
public async Task GenerateGoalsTestData() { const int DAYS_TO_GENERATE = 30; for (int i = 0; i < DAYS_TO_GENERATE; ++i) { GoalStorageModel goalResult = new GoalStorageModel { Day = DateTime.Today.AddDays(-DAYS_TO_GENERATE + i), HasBeenReached = (i % 14) >= 7, }; await StoreDailyGoalResult(goalResult); } }
public async Task <bool> CheckIfGoalCompleted(TodaysWalkingModel todaysWalking) { if (checkTask == null || checkTask.IsCompleted) { try { var goal = goals.Find(g => (Goal)g.Id == Settings.CurrentGoal); var goalResult = new GoalStorageModel { Day = DateTime.Today, Id = goal.Id, HasBeenReached = false, MinutesToReach = goal.MinutesToReach }; // check if goal is complete if (todaysWalking.minutesBriskWalkToday >= goal.MinutesToReach) { var previousToday = await storageService.GetTodaysGoal(); // check if already achieved goal today or if goal has changed to a greater goal if (previousToday == null || previousToday.MinutesToReach < goal.MinutesToReach) { goalResult.HasBeenReached = true; await storageService.StoreDailyGoalResult(goalResult); // Return true (new goal achieved today) Analytics.TrackEvent(GoalAccomplished, new GoalAccomplishedArgs(Enum.GetName(typeof(Goal), (Goal)goal.Id))); return(true); } } } catch (Exception e) { Crashes.TrackError(e); } } return(false); }