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:
parent
8756964f0b
commit
59e27c2991
@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Interfaces
|
namespace Interfaces
|
||||||
{
|
{
|
||||||
@ -8,6 +9,8 @@ namespace Interfaces
|
|||||||
{
|
{
|
||||||
Logs = new List<TimeLog>();
|
Logs = new List<TimeLog>();
|
||||||
}
|
}
|
||||||
|
public DayOfWeek Day { get; set; }
|
||||||
|
public string DayOfWeek { get; set; }
|
||||||
public int LogCount { get { return Logs.Count; } }
|
public int LogCount { get { return Logs.Count; } }
|
||||||
public double DailyTotal { get; set; }
|
public double DailyTotal { get; set; }
|
||||||
public List<TimeLog> Logs { get; set; }
|
public List<TimeLog> Logs { get; set; }
|
||||||
|
|||||||
@ -8,14 +8,14 @@ namespace Interfaces
|
|||||||
{
|
{
|
||||||
public TimeLogList()
|
public TimeLogList()
|
||||||
{
|
{
|
||||||
TimeLogs = new Dictionary<DayOfWeek, DailyLogs>();
|
TimeLogs = new List<DailyLogs>();
|
||||||
}
|
}
|
||||||
public DateTime SelectedDate { get; set; }
|
public DateTime SelectedDate { get; set; }
|
||||||
public int CalendarWeek { get; set; }
|
public int CalendarWeek { get; set; }
|
||||||
public int TimeLogCount { get { return TimeLogs.Values.Sum(x => x.LogCount); } }
|
public int TimeLogCount { get { return TimeLogs.Sum(x => x.LogCount); } }
|
||||||
public Dictionary<DayOfWeek,DailyLogs> TimeLogs { get; set; }
|
public List<DailyLogs> TimeLogs { get; set; }
|
||||||
public double WeeklyTotal {
|
public double WeeklyTotal {
|
||||||
get { return TimeLogs.Values.Sum(x => x.DailyTotal); }
|
get { return TimeLogs.Sum(x => x.DailyTotal); }
|
||||||
}
|
}
|
||||||
public float HoursPerWeekMinutes { get; set; }
|
public float HoursPerWeekMinutes { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using Interfaces;
|
using Interfaces;
|
||||||
using SQLite.Net;
|
using SQLite.Net;
|
||||||
using SQLite.Net.Platform.Win32;
|
using SQLite.Net.Platform.Win32;
|
||||||
@ -368,7 +369,7 @@ namespace SQLiteRepository
|
|||||||
return OperationResponse.SUCCESS;
|
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>(
|
var timeLogList = _connection.Query<TimeLogDb>(
|
||||||
SQLiteProcedures.GET_TIMELOGS,
|
SQLiteProcedures.GET_TIMELOGS,
|
||||||
@ -386,6 +387,7 @@ namespace SQLiteRepository
|
|||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
var dict = new Dictionary<DayOfWeek, DailyLogs>();
|
var dict = new Dictionary<DayOfWeek, DailyLogs>();
|
||||||
|
var logList = new List<DailyLogs>();
|
||||||
|
|
||||||
//make sure each day of the week is accounted for in the dictionary.
|
//make sure each day of the week is accounted for in the dictionary.
|
||||||
foreach (DayOfWeek day in Enum.GetValues(typeof(DayOfWeek)))
|
foreach (DayOfWeek day in Enum.GetValues(typeof(DayOfWeek)))
|
||||||
@ -398,13 +400,32 @@ namespace SQLiteRepository
|
|||||||
{
|
{
|
||||||
dict[log.EventTime.DayOfWeek].Logs.Add(log);
|
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)
|
foreach (var dailyCollection in dict)
|
||||||
{
|
{
|
||||||
dailyCollection.Value.DailyTotal = CalculateDailyTotal(dailyCollection.Value);
|
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)
|
private double CalculateDailyTotal(DailyLogs dailyLogs)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user