-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLondonDemo
More file actions
361 lines (341 loc) · 14.2 KB
/
LondonDemo
File metadata and controls
361 lines (341 loc) · 14.2 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
Import-Module PowershellAI
$env:OpenAIKey = "xxxxxx"
function Find-Crime {
[CmdletBinding()]
Param
(
[Parameter(Mandatory = $true,
Position = 0,
HelpMessage = "Type the location name of interest such as Gosport or maybe a location in Gosport, like Alverstoke. Keep this to a single word"
)]
[Alias("Town")]
[Alias("City")]
[Alias("Village")]
[string]$LocationName,
[Parameter(Mandatory = $true)]
[ValidateSet("2019","2020", "2021", "2022","2023")]
[string]$Year,
[Parameter(Mandatory = $true)]
#[ValidateSet("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12")]
[string]$Month
)
Begin {
Write-Verbose -Message "Obtaining the latitude and longitude of the location entered"
$place = Invoke-RestMethod "https://geocode.maps.co/search?q={$LocationName}"
if ($place.lat.count -gt 1) {
$placeLat = $place.lat[0]
$placeLon = $place.lon[0]
}
else {
$placeLat = $place.lat
$placeLon = $place.lon
}
}
Process {
try {
$crime = Invoke-RestMethod "https://data.police.uk/api/crimes-street/all-crime?lat=$placeLat&lng=$placeLon&date=$Year-$Month" -ErrorAction Stop
$Props = @()
foreach ($item in $crime){
$Props += [PSCustomObject]@{
Category = $item.category
Type = $item.location_type
Latitude = $item.location | select -ExpandProperty latitude
Longitude = $item.location | select -ExpandProperty longitude
Street = ($item.location).street | Select -ExpandProperty name
Outcome = ($item.outcome_status).category
OutcomeDate = ($item.outcome_status).date
Reported = $item.month
ID = $item.id
PersistentID = $item.persistent_id
}
}
}
catch {
Write-Warning "Crumbs something went wrong most likely an invalid location name $($_)"
}
}
End {$Props.count}
}
function Find-CrimeUK {
[CmdletBinding()]
Param
(
[Parameter(Mandatory = $true,
Position = 0,
HelpMessage = "Type the location name of interest such as Gosport or maybe a location in Gosport, like Alverstoke. Keep this to a single word"
)]
[Alias("Town")]
[Alias("City")]
[Alias("Village")]
[string]$LocationName,
[Parameter(Mandatory = $true)]
[ValidateSet("2019", "2020", "2021", "2022","2023")]
[string]$Year,
[Parameter(Mandatory = $true)]
[ValidateSet("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12")]
[string]$Month
)
Begin {
Write-Verbose -Message "Obtaining the latitude and longitude of the location entered"
$place = Invoke-RestMethod "https://geocode.maps.co/search?q={$LocationName}"
if ($place.lat.count -gt 1) {
$placeLat = $place.lat[0]
$placeLon = $place.lon[0]
}
else {
$placeLat = $place.lat
$placeLon = $place.lon
}
}
Process {
try {
$crime = Invoke-RestMethod "https://data.police.uk/api/crimes-street/all-crime?lat=$placeLat&lng=$placeLon&date=$Year-$Month" -ErrorAction Stop
$Props = @()
foreach ($item in $crime){
$Props += [PSCustomObject]@{
Category = $item.category
Type = $item.location_type
Latitude = $item.location | select -ExpandProperty latitude
Longitude = $item.location | select -ExpandProperty longitude
Street = ($item.location).street | Select -ExpandProperty name
Outcome = ($item.outcome_status).category
OutcomeDate = ($item.outcome_status).date
Reported = $item.month
ID = $item.id
PersistentID = $item.persistent_id
}
}
}
catch {
Write-Warning "Crumbs something went wrong most likely an invalid location name $($_)"
}
}
End {
$Props | Export-Csv /PowershellUniversal/Crime.csv -notypeinformation
Write-Verbose -Message "Script Finished $(Get-Date)"
}
}
$Navigation = @(
New-UDListItem -Label 'Home' -Icon (New-UDIcon -Icon Home) -OnClick {
Invoke-UDRedirect -Url '/Home'
}
New-UDListItem -Label 'Statistics' -Icon (New-UDIcon -Icon ChartBar) -OnClick {
Invoke-UDRedirect -Url '/Statistics'
}
New-UDListItem -Label 'Map' -Icon (New-UDIcon -Icon MapPin) -OnClick {
Invoke-UDRedirect -Url '/Map'
}
)
$HomePage = New-UDPage -Name 'Home' -Content {
New-UDTypography -Text "Find Crime" -FontWeight 600 -Variant 'h4'
New-UDRow -Columns {
New-UDColumn -Id 'col1' -Content {
$(New-UDDateTime -InputObject (Get-Date) -Format 'DD/MM/YYYY')
New-UDUnDraw -Name 'security'
} -SmallSize 2 -MediumSize 2 -LargeSize 2
New-UDColumn -Content {
New-UDTypography -Text "Search Here" -Variant 'h5'
New-UDTextbox -Id 'txtLocation' -Label 'Enter Location' -Icon (New-UDIcon -Icon 'Map') -Autofocus -Placeholder 'Type a name of a city or town'
New-UDParagraph -Content {}
New-UDDatePicker -Id 'datePicker' -Label 'Select Month and Year' -MaximumDate (Get-Date) -Format 'MM yyyy' -OnChange {
Show-UDToast -Message $body -MessageColor 'green' -Duration 5000
}
New-UDParagraph -Content {}
New-UDButton -Text "Find Crime" -Icon (New-UDIcon -Icon 'DoorOpen') -Color Primary -OnClick {
$Cache:psLocation = (Get-UDElement -Id 'txtLocation').value
$psMonth = [string](Get-UDElement -Id 'datePicker').value.ToString('MM')
$Cache:psYear = [string](Get-UDElement -Id 'datePicker').value.ToString('yyyy')
Show-UDToast -Message "Seaching the location $($Cache:psLocation) for the $psMonth month and in the year $($Cache:psYear)" -Duration 10000
Find-CrimeUK -LocationName "$($Cache:psLocation)" -Year $($Cache:psYear) -Month $($psMonth)
}
} -SmallSize 2 -MediumSize 2 -LargeSize 2
New-UDColumn -Content {
New-UDDynamic -AutoRefresh -AutoRefreshInterval 30 -Content {
$ai = ai "Crime in $($Cache:psLocation) UK"
New-UDCard -Content {
New-UDTypography -Variant h5 -Text "$($Cache:psLocation) Crime"
New-UDTypography -Text "$ai"
}
}
}-SmallSize 5 -MediumSize 5 -LargeSize 5
New-UDColumn -Content {
New-UDDynamic -AutoRefresh -AutoRefreshInterval 30 -Content {
$ai = ai "Population $($Cache:psLocation) UK $($Cache:psYear)"
New-UDCard -Content {
New-UDTypography -Variant h5 -Text "Population"
New-UDTypography -Text "$ai"
}
}
} -SmallSize 3 -MediumSize 3 -LargeSize 3
New-UDColumn -Content {
New-UDDynamic -AutoRefresh -AutoRefreshInterval 20 -Content {
$CSV = Import-Csv /PowershellUniversal/Crime.csv
$Coloumns = @(
New-UDTableColumn -Property Type -Title Type
New-UDTableColumn -Property Category -Title Category
New-UDTableColumn -Property Street -Title Street
New-UDTableColumn -Property Reported -Title Reported
New-UDTableColumn -Property Outcome -Title Outcome
)
New-UDTable -Id 'CrimeTable' -Title "Crime Reported In $($Cache:psLocation)" -Icon (New-UDIcon -Icon 'Table') -Data $CSV -ShowFilter -ShowExport -ShowPagination -ShowSearch -PageSize 15 -ShowSort -ShowRefresh -Columns $Coloumns
}
} -SmallSize 9 -MediumSize 9 -LargeSize 9
New-UDColumn -Content {
New-UDunDraw -Name 'file-searching'
New-UDunDraw -Name 'code-typing'
New-UDunDraw -Name 'filing-system'
New-UDunDraw -Name 'programming'
} -SmallSize 3 -MediumSize 3 -LargeSize 3
}
}
$Statistics = New-UDPage -Name 'Statistics' -Content {
New-UDTypography -Text "Crime Statistics Outcomes for $($Cache:psLocation)" -FontWeight 600 -Variant 'h4'
New-UDRow -Columns {
New-UDColumn -Content {
New-UDDynamic -AutoRefresh -AutoRefreshInterval 20 -Content {
$CSV2 = Import-Csv /PowershellUniversal/Crime.csv
$Grouped = $CSV2 | Group-Object -Property Outcome | sort Count -Descending | Select Name,Count
New-UDChartJS -Type 'bar' -Data $Grouped -DataProperty Count -LabelProperty Name -Options @{
indexAxis = "y"
plugins = @{
legend = @{
position = "top"
}
}
}
}
} -SmallSize 12 -MediumSize 6 -LargeSize 6
New-UDColumn -SmallSize 12 -MediumSize 6 -LargeSize 3 -Content {
New-UDDynamic -AutoRefresh -AutoRefreshInterval 20 -Content {
$gdata = Import-Csv /PowershellUniversal/Crime.csv
$value = $gdata | ? {$_.Outcome.Length -gt 2 -and $_.Outcome -notmatch "no suspect identified|Unable|Under"}
$gTotal = $gdata.count
New-UDTypography -Variant h5 -Text "Crimes Solved in $($Cache:psLocation)"
New-UDGauge -value $value.count -MaxValue $gTotal
New-UDTypography -Variant h3 -Text "$($value.count)" -FontWeight 700 -Style @{
"padding-left" = "150px"
}
}
}
New-UDColumn -Content {
New-UDunDraw -Name 'data-report'
} -SmallSize 3 -MediumSize 3 -LargeSize 3
New-UDColumn -SmallSize 12 -MediumSize 6 -LargeSize 3 -Content {
New-UDDynamic -AutoRefresh -AutoRefreshInterval 20 -Content {
$pieD = Import-Csv /PowershellUniversal/Crime.csv
$pieG = $pieD | Group-Object -Property Category | Select Name,Count
$MultiArray = @()
$MultiArray += , @('Type', 'Total' )
foreach ($obj in $pieG){
$MultiArray += , @("$($obj.Name)",$($obj.Count))
}
new-udpiechart3d -Id "PIECHART" -Title "Type Of Crime" -data @($MultiArray)
}
}
New-UDColumn -Content {
New-UDDynamic -AutoRefreshInterval 60 -Content {
New-UDParagraph -Content {}
New-UDTypography -Variant h4 -Text "$($Cache:psLocation) Crime Breakdown $($Cache:psYear)" -Style @{
"padding-left" = "180px"
"display" = "Grid"
}
New-UDTypography -Text "Below is a heatmap showing a report of each month throughout the year, and reporting on the total crime recorded for that month. As these statistics are only on a monthly basis I can only produce one figure for the total month." -Style @{
"padding-left" = "180px"
"display" = "Grid"
}
$months = @("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12")
$Data = @()
$Year = $Cache:psYear
$CURRENTDATE= GET-DATE -Year $Year -Month $months[1] -Hour 0 -Minute 0 -Second 0
$MonthAgo = $CURRENTDATE.AddMonths(-1)
$FIRSTDAYOFMONTH=GET-DATE $MonthAgo -Day 1
$months | Foreach-Object -begin {
$Data += @{
day = ($FIRSTDAYOFMONTH).ToString("yyyy-MM-dd")
value = (Find-Crime -LocationName "$($Cache:psLocation)" -Year $($Cache:psYear) -Month 01)
}
} -Process{ $Data += @{
day = ($FIRSTDAYOFMONTH).AddMonths($_ * 1).ToString("yyyy-MM-dd")
value = (Find-Crime -LocationName "$($Cache:psLocation)" -Year $($Cache:psYear) -Month $_)
} } -End{
$Cache:CalData = $Data
}
$From = $FIRSTDAYOFMONTH
$To = $FIRSTDAYOFMONTH.AddMonths(11)
New-UDNivoChart -Calendar -Data $Data -From $From -To $To -Height 100 -Width 650 -MarginTop 10 -MarginRight 10 -MarginBottom 5 -MarginLeft 165
New-UDElement -Tag 'h4' -Attributes @{
style = @{
"padding-left" = '200px'
}
} -Content {
New-UDNumber -Start $(($Cache:CalData.value | Measure-Object -sum).Sum / 2) -End $(($Cache:CalData.value | Measure-Object -sum).Sum) -Delay 2 -Prefix "This equates to" -PostFix "crimes committed"
}
}
} -SmallSize 12 -MediumSize 6 -LargeSize 6
New-UDColumn -Content {
New-UDunDraw -Name 'data-trends'
} -SmallSize 6 -MediumSize 6 -LargeSize 3
New-UDColumn -Content {
$DataLine = $Cache:CalData
New-UDChartJS -Type 'line' -Data $DataLine -DataProperty value -LabelProperty day
} -SmallSize 12 -MediumSize 6 -LargeSize 6
New-UDColumn -Content {
New-UDDynamic -Content {
$ai2 = ai "worst crime to have ever happened in $($Cache:psLocation) uk"
New-UDTypography -Variant h4 -Text "Worst Crime Reported"
New-UDTypography -Text "$ai2"
} -AutoRefresh -AutoRefreshInterval 30
} -SmallSize 12 -MediumSize 6 -LargeSize 3
New-UDColumn -Content {New-UDunDraw -Name 'news'} -SmallSize 3 -MediumSize 3 -LargeSize 3
New-UDColumn -SmallSize 10 -MediumSize 10 -LargeSize 10 -Content {
New-UDDynamic -AutoRefresh -AutoRefreshInterval 50 -Content {
$PData = Import-Csv /PowershellUniversal/Crime.csv
$hash = @()
foreach ($item in $PData) {
$hash += @{
Category = $item.Category
Type = $item.Type
Street = $item.Steet
Outcome = $item.Outcome
Reported = $item.Reported
}
}
New-UDPivotTable -Data { $hash }
}
}
New-UDColumn -Content {New-UDunDraw -Name 'data'} -SmallSize 2 -MediumSize 2 -LargeSize 2
} #End Row
} #End Page
$Map = New-UDPage -Name 'Map' -Content {
New-UDTypography -Text "Crime Map Statistics for $($Cache:psLocation)" -FontWeight 600 -Variant 'h4'
New-UDRow -Columns {
New-UDColumn -Content {
$CSV3 = Import-Csv /PowershellUniversal/Crime.csv
New-UDDynamic -Content {
New-UDMap -Endpoint {
New-UDMapRasterLayer -TileServer 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
for ($i = 1; $i -lt $($CSV3.count); $i++)
{
New-UDMapMarker -Latitude "$($CSV3.Latitude[$i])" -Longitude "$($CSV3.Longitude[$i])"
}
} -Latitude $($CSV3.Latitude[0]) -Longitude $($CSV3.Longitude[0]) -Zoom 14 -Height '100vh'
} -AutoRefresh -AutoRefreshInterval 60
} -SmallSize 9 -MediumSize 9 -LargeSize 9
New-UDColumn -Content {
New-UDDynamic -AutoRefresh -AutoRefreshInterval 30 -Content {
$words = Import-Csv /PowershellUniversal/Crime.csv | Select -ExpandProperty Category
[System.Collections.ArrayList]$UDWordTreeData = @()
#foreach file content and add to list
$words | % {
$UDWordTreeData.Add(@([string]$_)) | Out-Null
}
New-UDWordTree -Id "WORDTREE"-width "100%" -height "325px" -data { $UDWordTreeData } -word $Session:filter
}
} -SmallSize 3 -MediumSize 3 -LargeSize 3
}
}
New-UDDashboard -Title 'Crime UK' -Pages @(
$HomePage
$Statistics
$Map
) -Navigation $Navigation #-Stylesheets /PowershellUniversal/style.css