Ctr

Daily ER Visits

You are a software engineer working in logistics for a hypothetical hospital in Iceland. You are responsible for software that determines which supplies to ship where. Your task is to help ensure that the emergency room (ER) remains adequately stocked with vital supplies. This depends on the number of patients incoming each day. The data for daily number of visits each day is in the daily_er_visits table.


daily_er_visits
column_name type
date_t
DATE
visit_count
INTEGER

To help the logistics team make forecasts, your software needs to display a moving average, a.k.a. "rolling mean", of the number of people that visit the ER each day. When you have a value that changes over time, a moving average is an average of the current value and n past values. In our case, our moving average should be for a week. So the moving average on 2022-01-09 should be an average of the number of patient visits from 2022-01-03 to 2022-01-09.

For each date in the daily_er_visits table, select the date, the number of new visitors that day, and the moving average for the week (name this column avg_visit_count).

If you were to graph it, it would look something like this.

2022-09-15T14:07:18.330455 image/svg+xml Matplotlib v3.5.2, https://matplotlib.org/ 2022-01 2022-02 2022-03 2022-04 2022-05 2022-06 Date 500 550 600 650 700 750 No. ER Visits Daily ER Visits avg_visit_count visit_count

© 2022 Andrew Carlson. All rights reserved.

date_t
DATE
visit_count
INTEGER
avg_visit_count
NUMERIC
1
2022-01-02
526
526.0000000000000000
2
2022-01-03
595
560.5000000000000000
3
2022-01-04
526
549.0000000000000000
4
2022-01-05
622
567.2500000000000000
5
2022-01-06
584
570.6000000000000000
6
2022-01-07
666
586.5000000000000000
7
2022-01-08
670
598.4285714285714286
8
2022-01-09
579
606.0000000000000000
9
2022-01-10
570
602.4285714285714286
10
2022-01-11
603
613.4285714285714286
11
2022-01-12
619
613.0000000000000000
12
2022-01-13
557
609.1428571428571429
13
2022-01-14
696
613.4285714285714286
14
2022-01-15
703
618.1428571428571429
15
2022-01-16
609
622.4285714285714286
16
2022-01-17
585
624.5714285714285714
17
2022-01-18
603
624.5714285714285714
18
2022-01-19
531
612.0000000000000000
19
2022-01-20
546
610.4285714285714286
20
2022-01-21
664
605.8571428571428571
21
2022-01-22
682
602.8571428571428571
22
2022-01-23
516
589.5714285714285714
23
2022-01-24
616
594.0000000000000000
24
2022-01-25
554
587.0000000000000000
25
2022-01-26
541
588.4285714285714286
26
2022-01-27
621
599.1428571428571429
27
2022-01-28
719
607.0000000000000000
28
2022-01-29
750
616.7142857142857143
29
2022-01-30
615
630.8571428571428571
30
2022-01-31
564
623.4285714285714286
31
2022-02-01
641
635.8571428571428571
32
2022-02-02
587
642.4285714285714286
33
2022-02-03
597
639.0000000000000000
34
2022-02-04
685
634.1428571428571429
35
2022-02-05
685
624.8571428571428571
36
2022-02-06
632
627.2857142857142857
37
2022-02-07
559
626.5714285714285714
38
2022-02-08
577
617.4285714285714286
39
2022-02-09
515
607.1428571428571429
40
2022-02-10
518
595.8571428571428571
41
2022-02-11
666
593.1428571428571429
42
2022-02-12
710
596.7142857142857143
43
2022-02-13
527
581.7142857142857143
44
2022-02-14
608
588.7142857142857143
45
2022-02-15
585
589.8571428571428571
46
2022-02-16
603
602.4285714285714286
47
2022-02-17
627
618.0000000000000000
48
2022-02-18
670
618.5714285714285714
49
2022-02-19
681
614.4285714285714286
50
2022-02-20
579
621.8571428571428571
51
2022-02-21
559
614.8571428571428571
52
2022-02-22
576
613.5714285714285714
53
2022-02-23
599
613.0000000000000000
54
2022-02-24
579
606.1428571428571429
55
2022-02-25
737
615.7142857142857143
56
2022-02-26
666
613.5714285714285714
57
2022-02-27
520
605.1428571428571429
58
2022-02-28
577
607.7142857142857143
59
2022-03-01
586
609.1428571428571429
60
2022-03-02
570
605.0000000000000000
61
2022-03-03
528
597.7142857142857143
62
2022-03-04
717
594.8571428571428571
63
2022-03-05
659
593.8571428571428571
64
2022-03-06
599
605.1428571428571429
65
2022-03-07
549
601.1428571428571429
66
2022-03-08
586
601.1428571428571429
67
2022-03-09
549
598.1428571428571429
68
2022-03-10
572
604.4285714285714286
69
2022-03-11
637
593.0000000000000000
70
2022-03-12
703
599.2857142857142857
71
2022-03-13
617
601.8571428571428571
72
2022-03-14
598
608.8571428571428571
73
2022-03-15
560
605.1428571428571429
74
2022-03-16
619
615.1428571428571429
75
2022-03-17
569
614.7142857142857143
76
2022-03-18
658
617.7142857142857143
77
2022-03-19
679
614.2857142857142857
78
2022-03-20
615
614.0000000000000000
79
2022-03-21
556
608.0000000000000000
80
2022-03-22
544
605.7142857142857143
81
2022-03-23
606
603.8571428571428571
82
2022-03-24
571
604.1428571428571429
83
2022-03-25
750
617.2857142857142857
84
2022-03-26
689
618.7142857142857143
85
2022-03-27
555
610.1428571428571429
86
2022-03-28
563
611.1428571428571429
87
2022-03-29
593
618.1428571428571429
88
2022-03-30
557
611.1428571428571429
89
2022-03-31
595
614.5714285714285714
90
2022-04-01
667
602.7142857142857143
91
2022-04-02
738
609.7142857142857143
92
2022-04-03
574
612.4285714285714286
93
2022-04-04
568
613.1428571428571429
94
2022-04-05
602
614.4285714285714286
95
2022-04-06
553
613.8571428571428571
96
2022-04-07
561
609.0000000000000000
97
2022-04-08
667
609.0000000000000000
98
2022-04-09
747
610.2857142857142857
99
2022-04-10
591
612.7142857142857143
100
2022-04-11
593
616.2857142857142857
101
2022-04-12
551
609.0000000000000000
102
2022-04-13
528
605.4285714285714286
103
2022-04-14
565
606.0000000000000000
104
2022-04-15
672
606.7142857142857143
105
2022-04-16
693
599.0000000000000000
106
2022-04-17
610
601.7142857142857143
107
2022-04-18
548
595.2857142857142857
108
2022-04-19
599
602.1428571428571429
109
2022-04-20
577
609.1428571428571429
110
2022-04-21
559
608.2857142857142857
111
2022-04-22
700
612.2857142857142857
112
2022-04-23
705
614.0000000000000000
113
2022-04-24
588
610.8571428571428571
114
2022-04-25
509
605.2857142857142857
115
2022-04-26
529
595.2857142857142857
116
2022-04-27
593
597.5714285714285714
117
2022-04-28
534
594.0000000000000000
118
2022-04-29
710
595.4285714285714286
119
2022-04-30
672
590.7142857142857143
120
2022-05-01
595
591.7142857142857143
121
2022-05-02
651
612.0000000000000000
122
2022-05-03
566
617.2857142857142857
123
2022-05-04
564
613.1428571428571429
124
2022-05-05
651
629.8571428571428571
125
2022-05-06
669
624.0000000000000000
126
2022-05-07
717
630.4285714285714286
127
2022-05-08
559
625.2857142857142857
128
2022-05-09
567
613.2857142857142857
129
2022-05-10
585
616.0000000000000000
130
2022-05-11
610
622.5714285714285714
131
2022-05-12
642
621.2857142857142857
132
2022-05-13
750
632.8571428571428571
133
2022-05-14
708
631.5714285714285714
134
2022-05-15
568
632.8571428571428571
135
2022-05-16
610
639.0000000000000000
136
2022-05-17
499
626.7142857142857143
137
2022-05-18
563
620.0000000000000000
138
2022-05-19
564
608.8571428571428571
139
2022-05-20
736
606.8571428571428571
140
2022-05-21
715
607.8571428571428571
141
2022-05-22
574
608.7142857142857143
142
2022-05-23
557
601.1428571428571429
143
2022-05-24
594
614.7142857142857143
144
2022-05-25
598
619.7142857142857143
145
2022-05-26
540
616.2857142857142857
146
2022-05-27
715
613.2857142857142857
147
2022-05-28
654
604.5714285714285714
148
2022-05-29
586
606.2857142857142857
149
2022-05-30
552
605.5714285714285714
150
2022-05-31
592
605.2857142857142857
150 rows

You haven't solved this challenge yet!
Are you sure you want to reveal the answer?