-
Notifications
You must be signed in to change notification settings - Fork 1
/
Measure-TimeSheet.ps1
71 lines (60 loc) · 2.39 KB
/
Measure-TimeSheet.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
function Measure-TimeSheet {
<#
.SYNOPSIS
Measures the timesheets and returns aggregate information.
.DESCRIPTION
Measures the timesheets passed in and returns aggregate information,
i.e. Subject, Date, Total time taken, and Total time taken in 15 min
increments.
.EXAMPLE
PS C:\> Get-TimeSheet -Directory $HOME | Measure-TimeSheet
Subject Date TotalDuration TotalDuration15Mins
------- ---- ------------- -------------------
Call with PM: Issue 28/07/2022 00:00:00 00:45:00 00:45:00
Coffee Break 28/07/2022 00:00:00 00:49:00 00:45:00
Daily Checks 28/07/2022 00:00:00 01:08:00 01:15:00
Daily Standup 28/07/2022 00:00:00 00:53:00 01:00:00
Dedicated Code Review 28/07/2022 00:00:00 00:15:00 00:15:00
Prep for Upgrade 28/07/2022 00:00:00 00:24:00 00:30:00
Review Upgrade plan 28/07/2022 00:00:00 00:28:00 00:30:00
Update Meeting 28/07/2022 00:00:00 00:36:00 00:45:00
#>
[CmdletBinding()]
param (
# Timesheet to measure
[Parameter(
Mandatory,
ValueFromPipeline,
ValueFromPipelineByPropertyName
)]
[PSTypeName('TimeSheet')] $TimeSheet
)
begin {
$sheets = [System.Collections.Generic.List[PSObject]]::new()
}
process {
foreach ($sheet in $TimeSheet) {
$null = $sheets.Add($sheet)
}
}
end {
Write-PSFMessage -Level Verbose -Message 'Grouping timesheet subjects'
$subjects = $Sheets |
Where-Object Action -eq 'End' |
Group-Object -Property Subject
Write-PSFMessage -Level Verbose -Message 'Calculating sheet duration'
$subjects |
ForEach-Object -Process {
$durationSecs = ($_.Group.Duration |
Measure-Object -Property TotalSeconds -Sum).Sum
$durationAggSecs = ($_.Group.DurationToNearest15 |
Measure-Object -Property TotalSeconds -Sum).Sum
[PSCustomObject]@{
Subject = $_.Name
Date = $_.Group[0].Date.Date
TotalDuration = New-TimeSpan -Seconds $durationSecs
TotalDuration15Mins = New-TimeSpan -Seconds $durationAggSecs
}
}
}
}