Skip to content
Snippets Groups Projects
Commit 8ed9b42a authored by MarcusStorvangJonassen's avatar MarcusStorvangJonassen
Browse files

Fixed for two months in the same week

parent 026cd3e1
No related branches found
No related tags found
1 merge request!39Fixed for two months in the same week
......@@ -192,12 +192,20 @@ namespace BeSafePlus.ViewModels
var newWeeklyData = new List<StepCount>();
var monthCount = new Dictionary<int, int>();
int totalSteps = 0;
for (int i = 0; i < 7; i++)
{
var date = startOfWeek.AddDays(i);
int monthKey = date.Month + date.Year * 100;
if (!monthCount.ContainsKey(monthKey)) monthCount[monthKey] = 0;
monthCount[monthKey]++;
var stepData = await _database.GetStepCountByDate(date);
if (stepData != null)
......@@ -217,11 +225,17 @@ namespace BeSafePlus.ViewModels
TotalStepsThisWeek = totalSteps;
var currentWeekReferenceDate = today;
int dominantMonthKey = monthCount.OrderByDescending(kv => kv.Value).First().Key;
int dominantYear = dominantMonthKey / 100;
int dominantMonth = dominantMonthKey % 100;
var dominantMonthDate = new DateTime(dominantYear, dominantMonth, 1);
var realMonthOffset = (currentWeekReferenceDate.Year - DateTime.Now.Year) * 12 + (currentWeekReferenceDate.Month - DateTime.Now.Month);
var now = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
_currentMonthOffset = realMonthOffset;
_currentMonthOffset = ((dominantMonthDate.Year - now.Year) * 12) + (dominantMonthDate.Month - now.Month);
await LoadMonthlySteps();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment