Skip to content

Commit

Permalink
Add options for hours and summary stats
Browse files Browse the repository at this point in the history
  • Loading branch information
y2kbugger committed Apr 28, 2024
1 parent a7edfd4 commit c40698f
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 17 deletions.
22 changes: 22 additions & 0 deletions TeamsTimecardHelperClient/ClientSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,26 @@ public string? theteamid {
get => _localstorage.GetItem<string>("theteamid");
set =>_localstorage.SetItem("theteamid", value);
}

public DateOnly statsstartdate {
get {
string date_stamp = _localstorage.GetItem<string>("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<int>("targetweeklyhours");
set => _localstorage.SetItem("targetweeklyhours", value);
}
}
27 changes: 16 additions & 11 deletions TeamsTimecardHelperClient/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@
<h2 class="text-center">Timecard Total</h2>
<div class="d-flex flex-column justify-content-center mx-auto" style="max-width:fit-content">
<HoursGauge TimeCards="@current_timecards" />
<p>Average Weekly Hours since @(new DateOnly(year:2024, month:1, day:31)): <b>@(FormatDuration(average_weekly_hours_since(new DateTime(year:2024, month:1, day:31))))</b></p>

@{ var excess = excess_hours_banked(new DateTime(year:2024, month:1, day:31), new TimeSpan(25, 0, 0)); }
<h6>Since <em>@clientsettings.statsstartdate:</em></h6>
<div class="ms-3">
<p class="m-0"> <small>Average: <em>@(average_weekly_hours_since(clientsettings.statsstartdate).TotalHours.ToString("F1")) hr/wk</em></small> </p>
@{ var excess = excess_hours_banked(clientsettings.statsstartdate, new TimeSpan(clientsettings.targetweeklyhours, 0, 0)); }
@if (excess > new TimeSpan(0))
{ <p>Excess Hours Banked: <b>@(FormatDuration(excess))</b></p> }
{ <p class="m-0"><small>Excess Hours Banked: <em>@(FormatDuration(excess))</em></small></p>}
else
{ <p>Behind by: <b>@(FormatDuration(-1 * excess))</b></p> }
{ <p class="m-0"><small>Behind by: <em>@(FormatDuration(-1 * excess))</em></small></p>}
<p class="m-0 ms-4" style="color:rgb(93, 93, 93)"><small>@@@clientsettings.targetweeklyhours hr/wk</small></p>
</div>
</div>

<RadzenCard class="w-100 mt-3 p-3">
Expand Down Expand Up @@ -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;
}

Expand Down
21 changes: 19 additions & 2 deletions TeamsTimecardHelperClient/Pages/Settings.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@page "/settings"
@page "/settings"
@using Microsoft.AspNetCore.Authorization
@using Microsoft.Graph
@attribute [Authorize]
Expand All @@ -8,7 +8,7 @@

<div class="d-flex" style="align-items:center; gap: 1.4em;">
<h1>Settings</h1>
<a href="/">Back</a>
<a href="/">Back</a>
</div>
<form>
<div>
Expand All @@ -18,11 +18,28 @@
@bind-Value=@clientsettings.theteamid
class="align-middle"/>
</div>
<div>
<RadzenLabel Text="Stats Start Date:" Component="stats-start-date" class="align-middle"/>
<RadzenDatePicker Name="stats-start-date" ShowTime="false" DateFormat="d"
@bind-Value=@statsstartdate_backing
class="align-middle"/>
</div>
<div>
<RadzenLabel Text="Target Weekly Hours:" Component="target-weekly-hours" class="align-middle"/>
<RadzenNumeric Name="target-weekly-hours"
@bind-Value=@clientsettings.targetweeklyhours
class="align-middle"/>
</div>
</form>

<UploadCSV />

@code {
DateTime statsstartdate_backing
{
get => clientsettings.statsstartdate.ToDateTime(TimeOnly.MinValue);
set => clientsettings.statsstartdate = DateOnly.FromDateTime(value);
}
private IUserJoinedTeamsCollectionWithReferencesPage? teams;
protected override async Task OnInitializedAsync()
{
Expand Down
17 changes: 13 additions & 4 deletions TeamsTimecardHelperClient/Shared/HoursGauge.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@
@using CurrieTechnologies.Razor.PageVisibility
@using static TimeCardDuration
@inject GraphServiceClient GraphClient
@inject ClientSettings clientsettings
@inject PageVisibilityService visibility

<RadzenRadialGauge>
<RadzenRadialGaugeScale Min="0" Max="30" Step=5 TickPosition="GaugeTickPosition.Outside" MinorStep="1">
@{
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;
}
<RadzenRadialGaugeScale Min="0" Max=@upper Step=5 TickPosition="GaugeTickPosition.Outside" MinorStep="1">
<RadzenRadialGaugeScalePointer Value="@(TotalTimespan(TimeCards)?.TotalHours ?? 0)">
<Template Context="pointer">
<div class="totalhours-container">
Expand All @@ -18,9 +27,9 @@
</div>
</Template>
</RadzenRadialGaugeScalePointer>
<RadzenRadialGaugeScaleRange From="0" To="20" Fill="green" />
<RadzenRadialGaugeScaleRange From="20" To="25" Fill="orange" />
<RadzenRadialGaugeScaleRange From="25" To="30" Fill="red" />
<RadzenRadialGaugeScaleRange From="0" To=@lower Fill="green" />
<RadzenRadialGaugeScaleRange From=@lower To=@target Fill="orange" />
<RadzenRadialGaugeScaleRange From=@target To=@upper Fill="red" />
</RadzenRadialGaugeScale>
</RadzenRadialGauge>

Expand Down

0 comments on commit c40698f

Please sign in to comment.