-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweeklycontacts_healthcare.py
More file actions
141 lines (131 loc) · 3.92 KB
/
Copy pathweeklycontacts_healthcare.py
File metadata and controls
141 lines (131 loc) · 3.92 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
import pandas as pd
import numpy as np
import json
from datetime import datetime as dt
import plotly.graph_objects as go
import plotly.express as px
import os
import argparse
aparser = argparse.ArgumentParser(description="Generate weekly contact blob")
aparser.add_argument(
"--output-dir",
nargs="?",
default="postcovid_plots",
help="Output directory where the files will be saved",
)
args = aparser.parse_args()
# Import and sort data
healthcare_contacts = pd.read_excel(
"https://www.socialstyrelsen.se/globalassets/sharepoint-dokument/dokument-webb/statistik/statistik-postcovid.xlsx",
sheet_name="Postcovid - diagnoser över tid",
header=4,
engine="openpyxl",
keep_default_na=False,
)
healthcare_contacts = healthcare_contacts.replace(
{
"v1": "1",
"v2": "2",
"v3": "3",
"v4": "4",
"v5": "5",
"v6": "6",
"v7": "7",
"v8": "8",
"v9": "9",
"X": "",
"2020 ": "",
"2021 ": "",
"2022 ": "",
"2023 ": "",
"2024 ": "",
},
regex=True,
)
healthcare_contacts["Year"] = np.nan
healthcare_contacts.loc[:32, "Year"] = 2020
healthcare_contacts.loc[32:84, "Year"] = 2021
healthcare_contacts.loc[84:136, "Year"] = 2022
healthcare_contacts.loc[136:188, "Year"] = 2023
healthcare_contacts.loc[188:240, "Year"] = 2024
# if this is still being used in 2025, we will need to add (written week 7 of 2024)
# Need to drop last 3 rows because notes are included in the datafile.
# remove/edit if this changes in future, but without it, you get an error generating the date.
healthcare_contacts.drop(index=healthcare_contacts.index[-3:], axis=0, inplace=True)
healthcare_contacts["day"] = 1
# generate a 'real' date from week info
healthcare_contacts["date"] = healthcare_contacts.apply(
lambda row: dt.fromisocalendar(
int(row["Year"]), int(row["Vecka"]), int(row["day"])
),
axis=1,
)
healthcare_contacts.rename(
columns={"U08.9": "U089", "U09.9": "U099", "Z86.1A": "Z861A"}, inplace=True
)
healthcare_contacts = healthcare_contacts.replace(r"^\s*$", np.nan, regex=True)
fig = go.Figure(
data=[
go.Scatter(
name="U08.9",
x=healthcare_contacts.date,
y=healthcare_contacts.U089,
mode="lines+markers",
marker=dict(color=px.colors.diverging.RdBu[0], size=3),
marker_symbol="square",
line=dict(color=px.colors.diverging.RdBu[0], width=1),
),
go.Scatter(
name="U09.9",
x=healthcare_contacts.date,
y=healthcare_contacts.U099,
mode="lines+markers",
marker=dict(color=px.colors.diverging.RdBu[8], size=3),
marker_symbol="square",
line=dict(color=px.colors.diverging.RdBu[8], width=1),
),
go.Scatter(
name="Z86.1A",
x=healthcare_contacts.date,
y=healthcare_contacts.Z861A,
mode="lines+markers",
marker=dict(color="gold", size=3),
marker_symbol="square",
line=dict(color="gold", width=1),
),
]
)
fig.update_layout(
plot_bgcolor="white",
autosize=True,
font=dict(size=12),
margin=dict(r=0, t=50, b=0, l=0),
legend=dict(
orientation="h",
# title="<b>Sex:</b>",
yanchor="bottom",
y=1,
xanchor="left",
x=-0.1,
),
hovermode="x unified",
hoverdistance=1,
)
fig.update_xaxes(
title="<br><b>Date (Week Commencing)</b>",
showgrid=True,
linecolor="black",
tickangle=45,
)
fig.update_yaxes(
title="<b>Contacts with healthcare<br></b>",
showgrid=True,
gridcolor="lightgrey",
linecolor="black",
range=[0, (max(healthcare_contacts.U089) * 1.15)],
rangemode="tozero",
)
# fig.show()
if not os.path.isdir(args.output_dir):
os.mkdir(args.output_dir)
fig.write_json(os.path.join(args.output_dir, "weeklycontacts_healthcare.json"))