-
Notifications
You must be signed in to change notification settings - Fork 0
/
Herman's Cleanstat Code.R
639 lines (590 loc) · 24.1 KB
/
Herman's Cleanstat Code.R
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
# Libraries and prep parameters------------------
#Sample language to install packages
#install.packages("devtools")
#Packages you may need
library(tidyverse)
library(lubridate)
library(dplyr)
library(tidyr)
library(RODBC)
library(odbc)
library(xts)
library(reshape2)
#Setting working directory
setwd(dirname(rstudioapi::getSourceEditorContext()$path))
#Database Connection
con <- dbConnect(odbc(),
Driver = "SQL Server",
Server = "BALT-SQL-FC",
Database = "CitiStat",
Trusted_Connection = "True")
#Sample Import
######Crime Data data import------
####pulling crime data from SQL
Sr_created<- dbGetQuery(con,'SELECT \'\' as \'SALESFORCE_CREATED\',
q1.[SR Type],
q1.[Created Week],
Count(distinct [Service Request Number]) as [Created Count]
FROM (
SELECT [Service Request Number]
,[SR Type]
,[Created Date]
, CASE
WHEN [Created Date] BETWEEN \'2022-05-29\' AND \'2022-06-05\' THEN \'05/29-06/04\'
WHEN [Created Date] BETWEEN \'2022-06-05\' AND \'2022-06-12\' THEN \'06/05-06/11\'
WHEN [Created Date] BETWEEN \'2022-06-12\' AND \'2022-06-19\' THEN \'06/12-06/18\'
WHEN [Created Date] BETWEEN \'2022-06-19\' AND \'2022-06-26\' THEN \'06/19-06/25\'
END [Created Week]
FROM [CitiStat].[dbo].[CSR]
WHERE [SR Type] in(\'TRM-Grass Mowing\',\'SW-SIU Clean Up\',\'SW-Dirty Alley\',\'SW-Dirty Street\',\'SW-Dirty Alley Proactive\',\'SW-Dirty Street Proactive\',\'RP-Park Maintenance\',\'RP-Grass Cutting\')
AND
([SR Status] NOT LIKE \'%DUP%\' AND [SR Status] NOT LIKE \'%TRANS%\')
) q1
WHERE q1.[Created Week] is not null
GROUP BY q1.[SR Type], q1.[Created Week]
ORDER BY q1.[SR Type], q1.[Created Week]
;
')
Sr_closed<- dbGetQuery(con,'
with bqClosed AS(
SELECT
[Service Request Number]
,[SR Type]
,CASE
WHEN [Close Date] > [Due Date] THEN \'Missed\'
WHEN [Close Date] <= [Due date] THEN \'Met\'
END [Closure Status_calc]
,CASE
WHEN [Close Date] BETWEEN \'2022-05-29\' AND \'2022-06-05\' THEN \'05/29-06/04\'
WHEN [Close Date] BETWEEN \'2022-06-05\' AND \'2022-06-12\' THEN \'06/05-06/11\'
WHEN [Close Date] BETWEEN \'2022-06-12\' AND \'2022-06-19\' THEN \'06/12-06/18\'
WHEN [Close Date] BETWEEN \'2022-06-19\' AND \'2022-06-26\' THEN \'06/19-06/25\'
END [Closed Week]
FROM [CitiStat].[dbo].[CSR]
WHERE [SR Type] in(\'TRM-Grass Mowing\',\'SW-SIU Clean Up\',\'SW-Dirty Alley\',\'SW-Dirty Street\',\'SW-Dirty Alley Proactive\',\'SW-Dirty Street Proactive\',\'RP-Park Maintenance\',\'RP-Grass Cutting\')
AND
[Close Date] >= \'2022-05-29\'
AND
([SR Status] NOT LIKE \'%DUP%\' AND [SR Status] NOT LIKE \'%TRANS%\'))
,
count_closed AS(
SELECT
[SR Type]
,[Closed Week]
,Count(distinct [Service Request Number]) as [Total Closed Count]
FROM bqClosed
WHERE [Closed Week] is not null
GROUP BY [SR Type], [Closed Week])
,
Closed_by_status AS(
SELECT
[SR Type]
,[Closed Week]
,[Closure Status_Calc]
,Count([Closure Status_calc]) as closure_count
FROM bqClosed
WHERE [Closed Week] is not null
GROUP BY [SR Type],[Closed week],[Closure status_calc])
select * from count_closed order by [sr type],[closed week]
;
')
Sr_daclosed<- dbGetQuery(con,'
with bqClosed AS(
SELECT
[Service Request Number]
,[SR Type]
,datediff(day,[created date],[close date]) as days_to_close
,[created date]
,[close date]
,CASE
WHEN [Close Date] > [Due Date] THEN \'Missed\'
WHEN [Close Date] <= [Due date] THEN \'Met\'
END [Closure Status_calc]
,CASE
WHEN [Close Date] BETWEEN \'2022-05-29\' AND \'2022-06-05\' THEN \'05/29-06/04\'
WHEN [Close Date] BETWEEN \'2022-06-05\' AND \'2022-06-12\' THEN \'06/05-06/11\'
WHEN [Close Date] BETWEEN \'2022-06-12\' AND \'2022-06-19\' THEN \'06/12-06/18\'
WHEN [Close Date] BETWEEN \'2022-06-19\' AND \'2022-06-26\' THEN \'06/19-06/25\'
END [Closed Week]
FROM [CitiStat].[dbo].[CSR]
#/*Proactive work is not included because it is created/entered by DPW as it is completed*/
WHERE [SR Type] in(\'TRM-Grass Mowing\', \'SW-SIU Clean Up\',\'SW-Dirty Alley\',\'SW-Dirty Street\',\'RP-Park Maintenance\',\'RP-Grass Cutting\')
AND
[Close Date] >= \'2022-05-29\'
AND
([SR Status] NOT LIKE \'%DUP%\' AND [SR Status] NOT LIKE \'%TRANS%\'))
,
avg_closed AS(
SELECT [SR Type]
,[Closed Week]
,avg(cast([Days_to_Close] as decimal(10,2))) as avg_days_to_close
FROM bqClosed
WHERE [Closed week] is not null
GROUP BY [SR Type],[Closed Week])
,
count_closed AS(
SELECT
[SR Type]
,[Closed Week]
,Count(distinct [Service Request Number]) as [Total Closed Count]
FROM bqClosed
WHERE [Closed Week] is not null
GROUP BY [SR Type], [Closed Week])
select \'\' AS \'SR TIME TO CLOSE\'
,bq.[SR Type]
,bq.[Closed Week]
,min(ac.[avg_days_to_close]) as avg_days_to_close
,min(cc.[total closed count]) as total_count_closed
,sum(bq.days_to_close) as days_to_close
from bqclosed bq
left join count_closed cc
on bq.[sr type] = cc.[sr type]
and bq.[closed week]=cc.[closed week]
left join avg_closed ac
on bq.[sr type] = ac.[SR Type]
and bq.[Closed Week]=ac.[Closed Week]
where bq.[Closed Week] is not null
group by bq.[sr type], bq.[closed week]
order by [sr type],[closed week]
;
')
Sr_ontimep<- dbGetQuery(con,'
with bqClosed AS(
SELECT
[Service Request Number]
,[SR Type]
,datediff(day,[created date],[close date]) as days_to_close
,[created date]
,[close date]
,CASE
WHEN [Close Date] > [Due Date] THEN \'Missed\'
WHEN [Close Date] <= [Due date] THEN \'Met\'
END [Closure Status_calc]
,CASE
WHEN [Close Date] BETWEEN \'2022-05-29\' AND \'2022-06-05\' THEN \'05/29-06/04\'
WHEN [Close Date] BETWEEN \'2022-06-05\' AND \'2022-06-12\' THEN \'06/05-06/11\'
WHEN [Close Date] BETWEEN \'2022-06-12\' AND \'2022-06-19\' THEN \'06/12-06/18\'
WHEN [Close Date] BETWEEN \'2022-06-19\' AND \'2022-06-26\' THEN \'06/19-06/25\'
END [Closed Week]
FROM [CitiStat].[dbo].[CSR]
#/*Proactive work is not included because it is created/entered by DPW as it is completed*/
WHERE [SR Type] in(\'TRM-Grass Mowing\',\'SW-SIU Clean Up\',\'SW-Dirty Alley\',\'SW-Dirty Street\',\'RP-Park Maintenance\',\'RP-Grass Cutting\')
AND
[Close Date] >= \'2022-05-29\'
AND
([SR Status] NOT LIKE \'%DUP%\' AND [SR Status] NOT LIKE \'%TRANS%\'))
,
count_closed AS(
SELECT
[SR Type]
,[Closed Week]
,Count(distinct [Service Request Number]) as [Total Closed Count]
FROM bqClosed
WHERE [Closed Week] is not null
GROUP BY [SR Type], [Closed Week])
select \'\' AS \'SR ON TIME PERCENTAGE\'
,bq.[SR Type]
,bq.[Closed Week]
,bq.[Closure Status_calc]
,count(bq.[Closure Status_calc]) as count_by_closurestatus
,min(cc.[total closed count]) as total_count_closed
from bqclosed bq
left join count_closed cc
on bq.[sr type] = cc.[sr type]
and bq.[closed week]=cc.[closed week]
where bq.[Closed Week] is not null
group by bq.[sr type], bq.[closed week],bq.[Closure Status_calc]
order by bq.[closure status_calc],[sr type],[closed week]
;
')
Sr_opensr<- dbGetQuery(con,'
SELECT \'\' as \'SALESFORCE_OPEN_SRs\',
q1.[WeekEnding],
q1.[SR Type], q1.[calc_Status],
count(distinct [Service Request Number]) as [SR_Status_Count]
FROM (
SELECT
[Service Request Number]
,[SR Type]
,[SR Status]
,[Created Date]
,[Close Date]
,[Status Date]
,[Due Date]
/*Create Ontime/Overdue Classification for all SRs open as of end of reporting week. Manually replace dates with last day of reporting week */
, CASE
WHEN [Due Date] <= \'2022-06-05\' and [Close Date] > \'2022-06-05\' THEN \'Overdue\'
WHEN [Due Date] <= \'2022-06-05\' and [Close Date] is null THEN \'Overdue\'
WHEN [Created Date] <= \'2022-06-05\' and [Close Date] > \'2022-06-05\' THEN \'OnTime\'
WHEN [Created Date] <= \'2022-06-05\' and [Close Date] is null THEN \'OnTime\'
END [calc_Status]
/*Create a Keep/delete variable to use to select/de-select records in the outer query, as needed. Variable flags records to keep based on
whether the SR Status includes \'Duplicate\' or \'transferred\'. Usage depends on choice of methodology and analysis need. Manually replace dates with
last day of the reporting week. The date makes sure the SR status date happened after the end of reporting week to attempt to re-create what the
record looked like at the end of the reporting week and make selections from that. */
,CASE
WHEN UPPER([SR Status]) LIKE \'%TRANS%\' and [Status Date] >= \'2022-06-05\' THEN \'keep\'
WHEN UPPER([SR STATUS]) LIKE \'%DUP%\' and [Status Date] >= \'2022-06-05\' THEN \'keep\'
WHEN UPPER([SR Status]) NOT LIKE \'%TRANS%\' AND UPPER([SR Status]) NOT LIKE \'%DUP%\' THEN \'keep\'
END [calc_keep]
, \'2022-06-04\' as [WeekEnding]
FROM [CitiStat].[dbo].[CSR]
/*Manually replace SR Type to get the needed SR*/
WHERE [SR Type] in(\'TRM-Grass Mowing\',\'SW-SIU Clean Up\',\'SW-Dirty Alley\',\'SW-Dirty Street\',\'SW-Dirty Alley Proactive\',\'SW-Dirty Street Proactive\',\'RP-Park Maintenance\',\'RP-Grass Cutting\')
/*Based on prior code, it looks like only records created after 1/1/2021 were used. Running for after 1/1/2020 results in a much larger output of records.
Keep or run without as methodology/analysis requires */
AND
[Created Date] >= \'2021-01-01\' ) q1
WHERE
/* Select records where a calc_status exists per the above criteria. Any record not meeting the stated criteria will be null and not selected */
q1.[calc_Status] is not null
AND
/* Select records where a calc_keep exists per the above criteria. Any record not meeting the stated criteria will be null and not selected */
q1.[calc_keep] is not null
GROUP BY q1.[WeekEnding], q1.[SR Type], q1.[calc_Status]
ORDER BY q1.[WeekEnding], q1.[SR Type], q1.[calc_Status]
;
')
chip_created<- dbGetQuery(con,'
SELECT \'\' as \'CHIP_CREATED\',
q1.[work order type],
q1.[Cleaning Type],
q1.[Created week],
count(distinct [Record ID]) as [CHIP Created_count]
FROM (
SELECT [Record ID]
,[Work Order Type]
,[Status]
,CASE
WHEN UPPER([Clean Type]) like \'HIGH GRASS & WEEDS\' THEN \'HGW\'
ELSE [Work Order type]
END AS [Cleaning Type]
,[Date Create]
,CASE
WHEN [Date Create] BETWEEN \'2022-05-29\' AND \'2022-06-05\' THEN \'05/29-06/04\'
WHEN [Date Create] BETWEEN \'2022-06-05\' AND \'2022-06-12\' THEN \'06/05-06/11\'
WHEN [Date Create] BETWEEN \'2022-06-12\' AND \'2022-06-19\' THEN \'06/12-06/18\'
WHEN [Date Create] BETWEEN \'2022-06-19\' AND \'2022-06-26\' THEN \'06/19-06/25\'
END [Created Week]
FROM [CitiStat].[dbo].[CHIP_WorkOrders]
WHERE [Work Order Type] in(\'Boarding\',\'Cleaning\')
and [Status] <> \'PENDING\'
) q1
WHERE q1.[Created Week] is not null
GROUP BY q1.[Work order type], q1.[Cleaning Type], q1.[Created Week]
order by q1.[Work order type],q1.[Cleaning Type], q1.[created week]
;
')
chip_close<- dbGetQuery(con,'
with bqClosed AS(
SELECT [Record ID]
,[Work Order Type]
,CASE
WHEN UPPER([Clean Type]) like \'HIGH GRASS & WEEDS\' THEN \'HGW\'
ELSE [Work Order type]
END AS [Cleaning Type]
,[Status]
,[date create]
,[Date Finish]
,CASE
WHEN [Date Finish] BETWEEN \'2022-05-29\' AND \'2022-06-05\' THEN \'05/29-06/04\'
WHEN [Date Finish] BETWEEN \'2022-06-05\' AND \'2022-06-12\' THEN \'06/05-06/11\'
WHEN [Date Finish] BETWEEN \'2022-06-12\' AND \'2022-06-19\' THEN \'06/12-06/18\'
WHEN [Date Finish] BETWEEN \'2022-06-19\' AND \'2022-06-26\' THEN \'06/19-06/25\'
END [Closed Week]
FROM [CitiStat].[dbo].[CHIP_WorkOrders]
WHERE [work order Type] in(\'Boarding\',\'Cleaning\')
AND
[Date Finish] >= \'2022-05-29\'
AND
([Status] like \'%CLOSE%\' OR [Status] like \'%CANCEL%\' ) )
,
count_closed AS(
SELECT
[Work Order Type]
,[Cleaning Type]
,[Closed Week]
,Count(distinct [Record ID]) as [Total Closed Count]
FROM bqClosed
WHERE [Closed Week] is not null
GROUP BY [Work Order Type], [Cleaning Type], [Closed Week])
select * from count_closed order by [cleaning type],[closed week]
;
')
chip_ttc <- dbGetQuery(con,'
SELECT [Record ID]
,[Work Order Type]
,CASE
WHEN UPPER([Clean Type]) like \'HIGH GRASS & WEEDS\' THEN \'HGW\'
ELSE [Work Order type]
END AS [Cleaning Type]
,[Status]
,[date create]
,[Date Finish]
,CASE
WHEN [Date Finish] BETWEEN \'2022-05-29\' AND \'2022-06-05\' THEN \'05/29 - 06/04\'
WHEN [Date Finish] BETWEEN \'2022-06-05\' AND \'2022-06-12\' THEN \'06/05 - 06/11\'
WHEN [Date Finish] BETWEEN \'2022-06-12\' AND \'2022-06-19\' THEN \'06/12 - 06/18\'
WHEN [Date Finish] BETWEEN \'2022-06-19\' AND \'2022-06-26\' THEN \'06/19 - 06/25\'
END [Closed Week]
,datediff(day,[date create],[date finish]) as [DaysToClose]
FROM [CitiStat].[dbo].[CHIP_WorkOrders]
WHERE [work order Type] in(\'Boarding\',\'Cleaning\')
AND
[Date Finish] >= \'2022-05-29\'
AND
[Status] like \'%CLOSE%\';
')
chip_opensrs <- dbGetQuery(con,'SELECT \'\' as \'CHIP_OPEN_SRs\'
,q1.[work order type]
,q1.[cleaning type]
,q1.[week ending]
,q1.[calc_status]
,count(distinct [Record id]) as [Open_Status_Count]
FROM (
SELECT
[Record ID]
,[Work Order Type]
,[Status]
,CASE
WHEN UPPER([Clean Type]) like \'HIGH GRASS & WEEDS\' THEN \'HGW\'
ELSE [Work Order type]
END AS [Cleaning Type]
,[Date Create]
,[Date Finish]
, CASE
WHEN [Work Order Type] = \'Boarding\' and datediff(day,[Date Create],\'2022-06-05\') > 10 then \'Overdue\'
WHEN [Work Order Type] = \'Boarding\' AND datediff(day,[Date Create],\'2022-06-05\') <= 10 then \'OnTime\'
WHEN [Work Order Type] = \'Cleaning\' AND datediff(day,[date create],\'2022-06-05\') > 43 then \'Overdue\'
WHEN [Work order type] = \'Cleaning\' AND datediff(day,[Date Create],\'2022-06-05\') <= 43 then \'Ontime\'
END [calc_Status]
,\'2022-06-04\' as [Week Ending]
FROM [CitiStat].[dbo].[CHIP_WorkOrders]
WHERE
[Work Order Type] in(\'Boarding\',\'Cleaning\')
AND
[Status] <> \'PENDING\'
AND
(([Date Finish] is null and [Date Create] <= \'2022-06-05\')
OR
([Date Finish] >= \'2022-06-05\' AND [Date Create] <= \'2022-06-05\'))
) q1
GROUP BY q1.[work order type], q1.[cleaning type], q1.[week ending], q1.[calc_status]
ORDER BY q1.[work order type], q1.[cleaning type], q1.[week ending], q1.[calc_status]
;
')
#slide 5a
colnames(Sr_opensr)[colnames(Sr_opensr) == "SR Type"] <- "SR_Type"
colnames(Sr_created)[colnames(Sr_created) == "Created Week"] <- "week"
colnames(Sr_closed)[colnames(Sr_closed) == "Closed Week"] <- "week"
merge_sr_cc <- merge(Sr_created, Sr_closed, by=c("SR Type","week"), all.y = TRUE )
colnames(merge_sr_cc)[colnames(merge_sr_cc) == "Created Count"] <- "Created_Count"
colnames(merge_sr_cc)[colnames(merge_sr_cc) == "Total Closed Count"] <- "Closed_Count"
colnames(merge_sr_cc)[colnames(merge_sr_cc) == "SR Type"] <- "SR_Type"
dfm<-merge_sr_cc%>% gather(key = SALESFORCE_CREATED, value = Count, Created_Count :Closed_Count)
dfm%>%
filter(SR_Type == "TRM-Grass Mowing")%>%
ggplot(aes(x = week, y = Count))+
geom_bar(aes(fill = SALESFORCE_CREATED ),position = "dodge", stat = 'identity', alpha = .5)+
scale_fill_manual(values = c("Closed_Count"="black"
,"Created_Count"="orange2"))+
geom_text(aes(label = Count), vjust = 0)+
theme_bw()+
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = "bottom")+
labs(title = "TRM - Grass Mowing Service Request
count Per Week May 29 - June 25",
y = "",
x = "TRM - Grass Mowing")
#slide 5b
colnames(Sr_opensr)[colnames(Sr_opensr) == "SR Type"] <- "SR_Type"
Sr_opensr %>%
filter(SR_Type == "TRM-Grass Mowing")%>%
drop_na(calc_Status)%>%
ggplot(aes(x = WeekEnding, y = SR_Status_Count , fill = calc_Status))+
geom_bar(position = "dodge", stat = 'identity', alpha = .5)+
scale_fill_manual(values = c("OnTime"="deepskyblue3"
,"Overdue"="firebrick1"))+
geom_text(aes(label = SR_Status_Count), vjust = 0)+
theme_bw()+
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = "bottom")+
labs(title = "TRM - Grass Mowing Service Request
Status Per Week May 29 - June 25",
y = "",
x = "TRM - Grass Mowing")
#slide 5c
colnames(Sr_daclosed)[colnames(Sr_daclosed) == "SR Type"] <- "SR_Type"
colnames(Sr_daclosed)[colnames(Sr_daclosed) == "Closed Week"] <- "Closed_Week"
Sr_daclosed %>%
filter(SR_Type == "TRM-Grass Mowing")%>%
drop_na(Closed_Week)%>%
ggplot(aes(x = Closed_Week, y = avg_days_to_close))+
geom_bar(position = "dodge", stat = 'identity', alpha = .5)+
geom_text(aes(label = avg_days_to_close), vjust = 0)+
theme_bw()+
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = "bottom")+
labs(title = "TRM - Grass Mowing Service Request
Average Age Per Week May 29 - June 25",
y = "",
x = "TRM - Grass Mowing")
#slide 8a
colnames(chip_close) <- c("work_order_type","cleaning_type","week","total_closed_count")
colnames(chip_created) <- c("chip_created","work_order_type","cleaning_type","week","chip_created_count")
merge_chip_cc <- merge(chip_created, chip_close, by=c("cleaning_type","week","work_order_type"), all.y = TRUE )
df_chip<-merge_chip_cc%>% gather(key = chip_created, value = Counts, chip_created_count :total_closed_count)
df_chip%>%
filter(cleaning_type == "Boarding")%>%
ggplot(aes(x = week, y = Counts ))+
geom_bar(aes(fill = chip_created),position = "dodge", stat = 'identity', alpha = .5)+
scale_fill_manual(values = c("total_closed_count"="orange2"
,"chip_created_count"="black"))+
geom_text(aes(label = Counts), vjust = 0)+
theme_bw()+
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = "bottom")+
labs(title = "SW-Boarding SLA Status Count Per Week
May 29 - June 25",
y = "",
x = "SW-Boarding")
#slide 8b
colnames(chip_opensrs)[colnames(chip_opensrs) == "cleaning type"] <- "cleaning_type"
colnames(chip_opensrs)[colnames(chip_opensrs) == "week ending"] <- "week_ending"
chip_opensrs %>%
filter(cleaning_type == "Boarding")%>%
drop_na(calc_status)%>%
ggplot(aes(x = week_ending, y = Open_Status_Count , fill = calc_status))+
geom_bar(position = "dodge", stat = 'identity', alpha = .5)+
scale_fill_manual(values = c("OnTime"="deepskyblue3"
,"Overdue"="firebrick1"))+
theme_bw()+
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = "bottom")+
labs(title = "SW-Boarding SLA Status per Week
May 29 - June 25",
y = "",
x = "SW-Boarding")
#slide 8c
colnames(chip_ttc) <- c("record_id","work_order_type","cleaning_type"
,"status","date_create","date_finish",
"closed_week","days_to_close")
chip_ttc %>%
#apply.weekly(chip_ttc$days_to_close , mean)%>%
filter(days_to_close > 0)%>%
filter(cleaning_type == "Boarding")%>%
drop_na(closed_week)%>%
ggplot(aes(x = closed_week, y = days_to_close))+
geom_bar(position = "dodge", stat = 'identity', alpha = .5)+
geom_text(aes(label = days_to_close), vjust = 0)+
theme_bw()+
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = "bottom")+
labs(title = "SW-Boarding Average Age Per Week May 29 - June 25",
y = "",
x = "TRM - Grass Mowing")
#9a slide
df_chip<-merge_chip_cc%>% gather(key = chip_created, value = Counts, chip_created_count :total_closed_count)
df_chip%>%
filter(cleaning_type == "Cleaning")%>%
ggplot(aes(x = week, y = Counts ))+
geom_bar(aes(fill = chip_created),position = "dodge", stat = 'identity', alpha = .5)+
scale_fill_manual(values = c("total_closed_count"="orange2"
,"chip_created_count"="black"))+
geom_text(aes(label = Counts), vjust = 0)+
theme_bw()+
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = "bottom")+
labs(title = "SW-Cleaning SLA Status Count Per Week
May 29 - June 25",
y = "",
x = "SW-Cleaning")
#9b slide
chip_opensrs %>%
filter(cleaning_type == "Cleaning")%>%
drop_na(calc_status)%>%
ggplot(aes(x = week_ending, y = Open_Status_Count , fill = calc_status))+
geom_bar(position = "dodge", stat = 'identity', alpha = .5)+
scale_fill_manual(values = c("OnTime"="deepskyblue3"
,"Overdue"="firebrick1"))+
theme_bw()+
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = "bottom")+
labs(title = "SW-Cleaning SLA Status per Week
May 29 - June 25",
y = "",
x = "SW-Cleaning")
#9c slide
chip_ttc%>%
#apply.weekly(chip_ttc$days_to_close , mean)%>%
filter(days_to_close > 0)%>%
filter(cleaning_type == "Cleaning")%>%
drop_na(closed_week)%>%
ggplot(aes(x = closed_week, y = days_to_close))+
geom_bar(position = "dodge", stat = 'identity', alpha = .5)+
geom_text(aes(label = days_to_close), vjust = 0)+
theme_bw()+
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = "bottom")+
labs(title = "SW-Cleaning Average Days To Close
Per Week May 29 - June 25",
y = "",
x = "SW-Cleaning")
#10a slide
df_chip<-merge_chip_cc%>% gather(key = chip_created, value = Counts, chip_created_count :total_closed_count)
df_chip%>%
filter(cleaning_type == "HGW")%>%
ggplot(aes(x = week, y = Counts ))+
geom_bar(aes(fill = chip_created),position = "dodge", stat = 'identity', alpha = .5)+
scale_fill_manual(values = c("total_closed_count"="orange2"
,"chip_created_count"="black"))+
geom_text(aes(label = Counts), position=position_stack(vjust = 0.5))+
theme_bw()+
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = "bottom")+
labs(title = "SW-HGW SLA Status Count Per Week
May 29 - June 25",
y = "",
x = "SW-HGW")
#10b slide
chip_opensrs %>%
filter(cleaning_type == "HGW")%>%
drop_na(calc_status)%>%
ggplot(aes(x = week_ending, y = Open_Status_Count , fill = calc_status))+
geom_bar(position = "dodge", stat = 'identity', alpha = .5)+
scale_fill_manual(values = c("OnTime"="deepskyblue3"
,"Overdue"="firebrick1"))+
theme_bw()+
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = "bottom")+
labs(title = "SW-HGW SLA Status per Week
May 29 - June 25",
y = "",
x = "SW-HGW")
#10c slide
chip_ttc %>%
filter(days_to_close > 0)%>%
filter(cleaning_type == "HGW" )%>%
drop_na(closed_week)%>%
ggplot(aes(x = closed_week, y = days_to_close))+
geom_bar(position = "dodge", stat = 'identity', alpha = .5)+
geom_text(aes(label = days_to_close), vjust = 0)+
theme_bw()+
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = "bottom")+
labs(title = "SW-HGW Average Days To Close Per Week
May 29 - June 25",
y = "",
x = "SW-HGW")