-
Notifications
You must be signed in to change notification settings - Fork 1
/
Get-TimeSheetTotalPerDay.ps1
117 lines (99 loc) · 4.65 KB
/
Get-TimeSheetTotalPerDay.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
function Get-TimeSheetTotalPerDay {
<#
.SYNOPSIS
Returns total aggregated data for TimeSheets.
.DESCRIPTION
Parses passed in dates or days, aggregates the timesheet files found
and returns the data.
.EXAMPLE
PS C:\> Get-TimeSheetTotalPerDay -Directory $HOME | Format-Table
Subject SubjectDuration SubjectDurationAgg Date Duration DurationAgg
------- --------------- ------------------ ---- -------- -----------
Call with PM: Issue 00:45:00 00:45:00 28/07/2022 00:00:00 05:18:00 05:45:00
Coffee Break 00:49:00 00:45:00 28/07/2022 00:00:00 05:18:00 05:45:00
Daily Checks 01:08:00 01:15:00 28/07/2022 00:00:00 05:18:00 05:45:00
Daily Standup 00:53:00 01:00:00 28/07/2022 00:00:00 05:18:00 05:45:00
Dedicated Code Review 00:15:00 00:15:00 28/07/2022 00:00:00 05:18:00 05:45:00
Prep for Upgrade 00:24:00 00:30:00 28/07/2022 00:00:00 05:18:00 05:45:00
Review Upgrade plan 00:28:00 00:30:00 28/07/2022 00:00:00 05:18:00 05:45:00
Update Meeting 00:36:00 00:45:00 28/07/2022 00:00:00 05:18:00 05:45:00
#>
[CmdletBinding(DefaultParameterSetName = 'ByDays')]
[OutputType('TimeSheetTotalPerDay')]
param (
# How many days back in the timesheets we want to parse.
[Parameter(
Position = 0,
ValueFromPipelineByPropertyName,
ValueFromPipeline,
ParameterSetName = 'ByDays'
)]
[ValidateNotNullOrEmpty()]
[int] $DaysBack = 0,
# Parse a timesheet of a particular date.
[Parameter(
Position = 0,
ValueFromPipelineByPropertyName,
ValueFromPipeline,
Mandatory,
ParameterSetName = 'ByDate'
)]
[datetime] $Date = (Get-Date)
)
begin {
$funcsToImport = 'Get-TimeSheet', 'Measure-TimeSheet'
foreach ($func in $funcsToImport) {
if (Get-ChildItem -Path "Function:\$func" -ErrorAction SilentlyContinue) {continue}
Write-PSFMessage -Message "Importing function: $func" -Level Verbose
try {
. "$PSScriptRoot\$($func).ps1"
} catch {
Write-PSFMessage -Message "Issue importing function: $func" -Level PSFMessage -Level Warning -Message
break
}
}
$DaysTotal = [System.Collections.Generic.List[PSObject]]::new()
}
process {
if ($PSCmdlet.ParameterSetName -eq 'ByDays') {
Write-PSFMessage -Message "Gathering timesheet by days" -Level Verbose
foreach ($DayBack in ($DaysBack..0)) {
$TargetDate = ([datetime]::Today).AddDays(-$DayBack)
try {
$TimeSheet = Get-TimeSheet -FileDate $TargetDate
} catch {
Write-PSFMessage -Level Warning -Message "Cannot import timesheet: $TargetDate"
}
if (-not $TimeSheet) { continue }
$DaysTotal.Add(($TimeSheet | Measure-TimeSheet))
$TimeSheet = $null
}
}
if ($PSCmdlet.ParameterSetName -eq 'ByDate') {
Write-PSFMessage -Message "Gathering timesheet by date" -Level Verbose
try {
$TimeSheet = Get-TimeSheet -FileDate $Date
} catch {
Write-PSFMessage -Level Warning -Message "Cannot import timesheet: $Date"
}
$DaysTotal.Add(($TimeSheet | Measure-TimeSheet))
}
foreach ($Total in $DaysTotal.GetEnumerator()) {
$MeasuredSeconds = ($Total.TotalDuration.TotalSeconds | Measure-Object -Sum).Sum
$TotalSeconds = New-TimeSpan -Seconds $MeasuredSeconds
$MeasuredAggdSeconds = ($Total.TotalDuration15Mins.TotalSeconds | Measure-Object -Sum).Sum
$TotalAggSeconds = New-TimeSpan -Seconds $MeasuredAggdSeconds
foreach ($DayTotal in $Total) {
[PSCustomObject] @{
PSTypeName = 'TimeSheetTotalPerDay'
Subject = $DayTotal.Subject
SubjectDuration = $DayTotal.TotalDuration
SubjectDurationAgg = $DayTotal.TotalDuration15Mins
Date = $DayTotal.Date
Duration = $TotalSeconds
DurationAgg = $TotalAggSeconds
}
}
}
}
}