-
Notifications
You must be signed in to change notification settings - Fork 0
/
COVID-19 Inzidenz Widget (Standort, Fälle, Bundesland, Datenstand)
123 lines (102 loc) · 4.03 KB
/
COVID-19 Inzidenz Widget (Standort, Fälle, Bundesland, Datenstand)
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
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: deep-gray; icon-glyph: magic;
// Licence: Robert Koch-Institut (RKI), dl-de/by-2-0
const apiUrl = (location) => `https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_Landkreisdaten/FeatureServer/0/query?where=1%3D1&outFields=BL,cases,cases7_per_100k,cases7_bl_per_100k,GEN,county,last_update&geometry=${location.longitude.toFixed(3)}%2C${location.latitude.toFixed(3)}&geometryType=esriGeometryPoint&inSR=4326&spatialRel=esriSpatialRelWithin&returnGeometry=false&outSR=4326&f=json`
const INCIDENCE_CRITICAL = 50;
const INCIDENCE_WARN = 35;
const BUNDESLAENDER_SHORT = {
'Baden-Württemberg': 'BW',
'Bayern': 'BY',
'Berlin': 'BE',
'Brandenburg': 'BB',
'Bremen': 'HB',
'Hamburg': 'HH',
'Hessen': 'HE',
'Mecklenburg-Vorpommern': 'MV',
'Niedersachsen': 'NI',
'Nordrhein-Westfalen': 'NRW',
'Rheinland-Pfalz': 'RLP',
'Saarland': 'SL',
'Sachsen': 'SN',
'Sachsen-Anhalt': 'ST',
'Schleswig-Holstein': 'SH',
'Thüringen': 'TH'
}
const getIncidenceColor = (incidence) => {
if (incidence >= INCIDENCE_CRITICAL) {
return Color.red()
} else if (incidence >= INCIDENCE_WARN) {
return Color.orange()
} else {
return Color.green()
}
}
let widget = await createWidget()
if (!config.runsInWidget) {
await widget.presentLarge()
}
Script.setWidget(widget)
Script.complete()
async function createWidget(items) {
let location = {}
let customLandkreisName
if (args.widgetParameter) {
const params = args.widgetParameter.split(",")
location = {
latitude: parseFloat(params[0]),
longitude: parseFloat(params[1])
}
customLandkreisName = params[2]
} else {
Location.setAccuracyToThreeKilometers()
location = await Location.current()
}
const data = await new Request(apiUrl(location)).loadJSON()
if (!data || !data.features || !data.features.length) {
const errorList = new ListWidget()
errorList.addText("Keine Ergebnisse für den aktuellen Ort gefunden.")
return errorList
}
const attributes = data.features[0].attributes
const lastUpdated = attributes.last_update
const incidenceLandkreis = attributes.cases7_per_100k.toFixed(1)
const incidenceBundesland = attributes.cases7_bl_per_100k.toFixed(1)
const casesLandkreis = attributes.cases
const bundeslandName = BUNDESLAENDER_SHORT[attributes.BL]
const landkreisBezeichnung = attributes.county
const isKreisfreieStadt = !!landkreisBezeichnung.match(/^SK \w+$/)
const landkreisName = customLandkreisName || attributes.GEN
const list = new ListWidget()
const header = list.addText(`🦠 INZIDENZ`)
header.font = Font.mediumSystemFont(13)
list.addSpacer()
const mainContent = list.addStack()
mainContent.layoutHorizontally()
mainContent.useDefaultPadding()
mainContent.centerAlignContent()
const incidenceLabel = mainContent.addText(`${incidenceLandkreis}`)
incidenceLabel.font = Font.boldSystemFont(24)
incidenceLabel.textColor = getIncidenceColor(incidenceLandkreis)
const casesLandkreisLabel = mainContent.addText(` (${casesLandkreis})`)
casesLandkreisLabel.font = Font.systemFont(14)
casesLandkreisLabel.textColor = Color.gray()
list.addText(landkreisName)
if (isKreisfreieStadt) {
list.addText('(Stadt)')
}
list.addSpacer()
const line = list.addStack()
line.layoutHorizontally()
line.useDefaultPadding()
const bl_incidence = line.addText(`${incidenceBundesland}`)
bl_incidence.font = Font.boldSystemFont(14)
bl_incidence.textColor = getIncidenceColor(incidenceBundesland)
const bundeslandLabel = line.addText(` ${bundeslandName}`)
bundeslandLabel.font = Font.systemFont(14)
bundeslandLabel.textColor = Color.gray()
const updateLabel = list.addText(`Stand: ${lastUpdated.substr(0,10)}`)
updateLabel.font = Font.systemFont(10)
updateLabel.textColor = Color.gray()
return list
}