From c40698fbec99bd7fade23731bd95d6ff5ad3e3db Mon Sep 17 00:00:00 2001 From: y2k Date: Sat, 27 Apr 2024 22:22:55 -0400 Subject: [PATCH] Add options for hours and summary stats --- TeamsTimecardHelperClient/ClientSettings.cs | 22 +++++++++++++++ TeamsTimecardHelperClient/Pages/Index.razor | 27 +++++++++++-------- .../Pages/Settings.razor | 21 +++++++++++++-- .../Shared/HoursGauge.razor | 17 +++++++++--- 4 files changed, 70 insertions(+), 17 deletions(-) diff --git a/TeamsTimecardHelperClient/ClientSettings.cs b/TeamsTimecardHelperClient/ClientSettings.cs index 7deba5c..588fbff 100644 --- a/TeamsTimecardHelperClient/ClientSettings.cs +++ b/TeamsTimecardHelperClient/ClientSettings.cs @@ -11,4 +11,26 @@ public string? theteamid { get => _localstorage.GetItem("theteamid"); set =>_localstorage.SetItem("theteamid", value); } + + public DateOnly statsstartdate { + get { + string date_stamp = _localstorage.GetItem("statsstartdate"); + try { + return DateOnly.FromDateTime(DateTime.Parse(date_stamp)); + } + catch (Exception) + { + return new DateOnly(DateTime.Now.Year, 1, 1); + } + } + set { + string date_stamp = value.ToString(); + _localstorage.SetItem("statsstartdate", date_stamp); + } + } + + public int targetweeklyhours { + get => _localstorage.GetItem("targetweeklyhours"); + set => _localstorage.SetItem("targetweeklyhours", value); + } } diff --git a/TeamsTimecardHelperClient/Pages/Index.razor b/TeamsTimecardHelperClient/Pages/Index.razor index 070f184..d449de2 100644 --- a/TeamsTimecardHelperClient/Pages/Index.razor +++ b/TeamsTimecardHelperClient/Pages/Index.razor @@ -23,13 +23,16 @@

Timecard Total

-

Average Weekly Hours since @(new DateOnly(year:2024, month:1, day:31)): @(FormatDuration(average_weekly_hours_since(new DateTime(year:2024, month:1, day:31))))

- - @{ var excess = excess_hours_banked(new DateTime(year:2024, month:1, day:31), new TimeSpan(25, 0, 0)); } +
Since @clientsettings.statsstartdate:
+
+

Average: @(average_weekly_hours_since(clientsettings.statsstartdate).TotalHours.ToString("F1")) hr/wk

+ @{ var excess = excess_hours_banked(clientsettings.statsstartdate, new TimeSpan(clientsettings.targetweeklyhours, 0, 0)); } @if (excess > new TimeSpan(0)) - {

Excess Hours Banked: @(FormatDuration(excess))

} + {

Excess Hours Banked: @(FormatDuration(excess))

} else - {

Behind by: @(FormatDuration(-1 * excess))

} + {

Behind by: @(FormatDuration(-1 * excess))

} +

@@@clientsettings.targetweeklyhours hr/wk

+
@@ -83,24 +86,26 @@ && (x.ClockInEvent.DateTime <= StartOfWeek.AddDays(7)) ).ToList(); // todo: handle case where timecard spans midnight at end of week - private TimeSpan average_weekly_hours_since(DateTime start) + private TimeSpan average_weekly_hours_since(DateOnly start) { - start = start.AddDays(-1 * (7 + (start.DayOfWeek - System.DayOfWeek.Sunday)) % 7).Date; - var weeks_since_start_week = 1+((StartOfWeek - start).TotalDays / 7); + var start_dt = start.ToDateTime(TimeOnly.MinValue); + start_dt = start_dt.AddDays(-1 * (7 + (start_dt.DayOfWeek - System.DayOfWeek.Sunday)) % 7).Date; + var weeks_since_start_week = 1+((StartOfWeek - start_dt).TotalDays / 7); var timecards_since_start_week = all_timecards?.Where( - x => (x.ClockInEvent.DateTime >= start) + x => (x.ClockInEvent.DateTime >= start_dt) && (x.ClockInEvent.DateTime <= StartOfWeek.AddDays(7)) ).ToList(); TimeSpan hours_since_start_week = TotalTimespan(timecards_since_start_week) ?? new TimeSpan(); return hours_since_start_week / weeks_since_start_week; } - private TimeSpan excess_hours_banked(DateTime start, TimeSpan target_weekly_hours) + private TimeSpan excess_hours_banked(DateOnly start_do, TimeSpan target_weekly_hours) { + var start = start_do.ToDateTime(TimeOnly.MinValue); start = start.AddDays(-1 * (7 + (start.DayOfWeek - System.DayOfWeek.Sunday)) % 7).Date; var weeks_since_start_week = 1+((StartOfWeek - start).TotalDays / 7); var target_hours = weeks_since_start_week * target_weekly_hours; - var actual_hours = weeks_since_start_week * average_weekly_hours_since(start); + var actual_hours = weeks_since_start_week * average_weekly_hours_since(DateOnly.FromDateTime(start)); return actual_hours - target_hours; } diff --git a/TeamsTimecardHelperClient/Pages/Settings.razor b/TeamsTimecardHelperClient/Pages/Settings.razor index e514df8..2f97ef3 100644 --- a/TeamsTimecardHelperClient/Pages/Settings.razor +++ b/TeamsTimecardHelperClient/Pages/Settings.razor @@ -1,4 +1,4 @@ -@page "/settings" +@page "/settings" @using Microsoft.AspNetCore.Authorization @using Microsoft.Graph @attribute [Authorize] @@ -8,7 +8,7 @@

Settings

-Back + Back
@@ -18,11 +18,28 @@ @bind-Value=@clientsettings.theteamid class="align-middle"/>
+
+ + +
+
+ + +
@code { + DateTime statsstartdate_backing + { + get => clientsettings.statsstartdate.ToDateTime(TimeOnly.MinValue); + set => clientsettings.statsstartdate = DateOnly.FromDateTime(value); + } private IUserJoinedTeamsCollectionWithReferencesPage? teams; protected override async Task OnInitializedAsync() { diff --git a/TeamsTimecardHelperClient/Shared/HoursGauge.razor b/TeamsTimecardHelperClient/Shared/HoursGauge.razor index 7f01e9f..9402630 100644 --- a/TeamsTimecardHelperClient/Shared/HoursGauge.razor +++ b/TeamsTimecardHelperClient/Shared/HoursGauge.razor @@ -2,10 +2,19 @@ @using CurrieTechnologies.Razor.PageVisibility @using static TimeCardDuration @inject GraphServiceClient GraphClient +@inject ClientSettings clientsettings @inject PageVisibilityService visibility - + @{ + int target = clientsettings.targetweeklyhours; + int lower = target - 5; + // snap to the nearest 5 + lower = (lower / 5) * 5; + int upper = target + 5; + upper = (upper / 5) * 5; + } + - - - + + +