-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenerateStatistic.ps1
140 lines (116 loc) · 5.08 KB
/
generateStatistic.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env pwsh
#Requires -Version 7
Write-Information "Generate statistic"
If (!(Test-Path -Path ./archiveRate.json)) {
Write-Error -Message "archiveRate.json is required to generate the file" -ErrorId "archiveRate.jsonNotFound" -ErrorAction Stop
}
Write-Verbose "Loading json as hashtable"
$jsonIndex = (Get-Content -Path ./archiveRate.json -Raw | ConvertFrom-Json).data
$markdown = @"
<!-- markdownlint-disable MD036 -->
# The Newbie Club Archival Statistic
*This file is automatically generated from [archiveRate.json](./archiveRate.json) for database and [generateStatistic.ps1](./generateStatistic.md) using GitHub Actions*
***__Do not modify the file__***
**Last Updated:** $(Get-Date -Format "h:mm:ss tt 'UTC'zzz, MMMM d, yyyy")
## Global Statistics$(
$archived = 0; $invalid = 0; $progress = 0; $halted = 0; $unknown = 0; $staff = 0; $edition = 0
ForEach ($cat in $jsonIndex) {
ForEach ($edi in $cat.editions) {
For ($i=0; $i -le ($edi.emojiVisualIdentifier).Count; $i++){
$edition = $edition + 1
}
For ($i=0; $i -le ($edi.contributors).Count; $i++) {
$staff = $staff + 1
If ($edi.contributors[$i].status -eq 'archived') {
$archived = $archived + 1
} ElseIf ($edi.contributors[$i].status -eq 'invalid') {
$invalid = $invalid + 1
} ElseIf ($edi.contributors[$i].status -eq 'progress') {
$progress = $progress + 1
} ElseIf ($edi.contributors[$i].status -eq 'halted') {
$halted = $halted + 1
} ElseIf ($edi.contributors[$i].status -eq 'unknown') {
$unknown = $unknown + 1
}
}
}
}
$edition = $edition / 2
)
| Data | Values |
| :-------------------------- | :----: |
| Edition released | $($edition) |
| Total club staff | $(($jsonIndex.editions.contributors.id | Select-Object -Unique).Count) |
| Total of participations | $($staff - $edition) |
| Archived | $($archived) |
| Missing/invalid links | $($invalid) |
| Currently designing | $($progress) |
| Halted | $($halted) |
| Unknown | $($unknown) |
| **Archival rate, globally** | $(($archived / ($staff - $edition) * 100).ToString('#.###'))% |
## By Categories/Year of Releases
"@
ForEach ($cat in $jsonIndex) {
$markdown += "`n`n### $($cat.category)`n"
If ($cat.category -eq '2019') {
$markdown += "`n> Status for delivered designer's cards on this year but not archived is on `Unknown` column due to missing information when the card was delivered and last date of participation of respective staff`n"
}
$markdown += @"
`n| ID | Edition Title | Staff | Archived | Invalid/Missing | Progress | Halted | Unknown | Rate |
| :-: | :------------ | :---: | :------: | :-------------: | :------: | :----: | :-----: | :--: |
"@
ForEach ($edi in $cat.editions){
$itemPath = "./$($cat.category)/$($edi.path)"
$archived = 0; $invalid = 0; $progress = 0; $halted = 0; $unknown = 0
$staff = ($edi.contributors).Count
For ($i=0; $i -le ($cat.editions).Count; $i++) {
If ($edi.contributors[$i].status -eq 'archived') {
$archived = $archived + 1
} ElseIf ($edi.contributors[$i].status -eq 'invalid') {
$invalid = $invalid + 1
} ElseIf ($edi.contributors[$i].status -eq 'progress') {
$progress = $progress + 1
} ElseIf ($edi.contributors[$i].status -eq 'halted') {
$halted = $halted + 1
} ElseIf ($edi.contributors[$i].status -eq 'unknown') {
$unknown = $unknown + 1
}
}
If ($archived -eq 0) {
$archived = "-"
}
If ($invalid -eq 0) {
$invalid = "-"
}
If ($progress -eq 0) {
$progress = "-"
}
If ($halted -eq 0) {
$halted = "-"
}
If ($unknown -eq 0) {
$unknown = "-"
}
$markdown += @"
`n| [``$($edi.id)``]($($itemPath)) | $($edi.emojiVisualIdentifier) $($edi.title) | $($staff) | $($archived) | $($invalid) | $($progress) | $($halted) | $($unknown) | $(If ($archived -eq 0 -or $archived -eq '-') {"**0**"} Else {($archived / $staff * 100).ToString('**#**.##')})% |
"@
}
}
$markdown += @"
`n`n## By Staff
*Coming soon*
<!-- | Username | Contributions | Archived | Invalid/Missing | Progress | Halted | Unknown | Rate |
| --------------: | :-----------: | :------: | :-------------: | :------: | :----: | :-----: | :-----: | -->
"@
<#
$csv = "edition,username,status`n"
ForEach ($cat in $jsonIndex) {
ForEach ($edi in $cat.editions) {
ForEach ($staff in $edi.contributors) {
$csv += "`n`"$($edi.id)`",$($staff.id),$($staff.status)"
}
}
}
$csv | ConvertFrom-CSV | Select-Object -Property "username" | Group-Object -NoElement
#>
$markdown | Out-File -Path './archiveRate.md'