Flatten the TimeLogsList object.

put DayOfWeek and Day into the DailyLogs object to help flatten.
changed GetTimeLogList to return List<DailyLogs>.
#15
This commit is contained in:
Chris.Watts90@outlook.com 2017-02-15 16:51:19 +00:00
parent 8756964f0b
commit 59e27c2991
3 changed files with 48 additions and 24 deletions

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
namespace Interfaces
{
@ -8,6 +9,8 @@ namespace Interfaces
{
Logs = new List<TimeLog>();
}
public DayOfWeek Day { get; set; }
public string DayOfWeek { get; set; }
public int LogCount { get { return Logs.Count; } }
public double DailyTotal { get; set; }
public List<TimeLog> Logs { get; set; }

View File

@ -8,14 +8,14 @@ namespace Interfaces
{
public TimeLogList()
{
TimeLogs = new Dictionary<DayOfWeek, DailyLogs>();
TimeLogs = new List<DailyLogs>();
}
public DateTime SelectedDate { get; set; }
public int CalendarWeek { get; set; }
public int TimeLogCount { get { return TimeLogs.Values.Sum(x => x.LogCount); } }
public Dictionary<DayOfWeek,DailyLogs> TimeLogs { get; set; }
public int TimeLogCount { get { return TimeLogs.Sum(x => x.LogCount); } }
public List<DailyLogs> TimeLogs { get; set; }
public double WeeklyTotal {
get { return TimeLogs.Values.Sum(x => x.DailyTotal); }
get { return TimeLogs.Sum(x => x.DailyTotal); }
}
public float HoursPerWeekMinutes { get; set; }
}

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using Interfaces;
using SQLite.Net;
using SQLite.Net.Platform.Win32;
@ -368,7 +369,7 @@ namespace SQLiteRepository
return OperationResponse.SUCCESS;
}
private Dictionary<DayOfWeek, DailyLogs> GetTimeLogList(int userId, int calendarWeek, int year)
private List<DailyLogs> GetTimeLogList(int userId, int calendarWeek, int year)
{
var timeLogList = _connection.Query<TimeLogDb>(
SQLiteProcedures.GET_TIMELOGS,
@ -386,6 +387,7 @@ namespace SQLiteRepository
}).ToList();
var dict = new Dictionary<DayOfWeek, DailyLogs>();
var logList = new List<DailyLogs>();
//make sure each day of the week is accounted for in the dictionary.
foreach (DayOfWeek day in Enum.GetValues(typeof(DayOfWeek)))
@ -398,13 +400,32 @@ namespace SQLiteRepository
{
dict[log.EventTime.DayOfWeek].Logs.Add(log);
}
var logGroups = timeLogs.GroupBy(x => x.EventTime.DayOfWeek);
foreach (var group in logGroups)
{
var groupLogs = group.ToList();
var dailyLog = new DailyLogs
{
Logs = groupLogs,
Day = group.Key,
DayOfWeek = group.Key.ToString()
};
dailyLog.DailyTotal = CalculateDailyTotal(dailyLog);
logList.Add(dailyLog);
}
foreach (DayOfWeek day in Enum.GetValues(typeof(DayOfWeek)))
{
if (logList.Any(x => x.Day == day)) continue;
var dailyLog = new DailyLogs {Day = day, DayOfWeek = day.ToString()};
logList.Add(dailyLog);
}
foreach (var dailyCollection in dict)
{
dailyCollection.Value.DailyTotal = CalculateDailyTotal(dailyCollection.Value);
}
return dict.OrderBy(x => ((int)x.Key + 6) % 7).ToDictionary(x=>x.Key, x=>x.Value);
return logList.OrderBy(x => ((int) x.Day + 6)%7).ToList();
}
private double CalculateDailyTotal(DailyLogs dailyLogs)