Last active
November 11, 2022 16:18
-
-
Save Baumchen/b8b9aaf5ba0aebef173a4f956a3b4290 to your computer and use it in GitHub Desktop.
COVID-19 Inzidenz-Widget für iOS innerhalb Österreichs 🇦🇹
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Lizenz: AGES Dashboard COVID19 AT | |
// 3-stellige GKZ verwenden (zweite Spalte in https://covid19-dashboard.ages.at/data/CovidFaelle_GKZ.csv). | |
// Widget Parameter: "204,KFL;312;706" für Klagenfurt Land (angezeigt als KFL), Korneuburg und Landeck | |
// | |
// Basiert auf der deutschen Variante von | |
// - kevinkub https://gist.github.com/kevinkub/46caebfebc7e26be63403a7f0587f664 | |
// - Baumchen https://gist.github.com/Baumchen/6d91df0a4c76c45b15576db0632e4329 | |
// | |
// Angaben ohne Gewähr. | |
const apiUrl = "https://covid19-dashboard.ages.at/data/CovidFaelle_GKZ.csv" | |
function parseLocation (location) { | |
const components = location.split(",") | |
return { | |
gkz: components[0], | |
name: components.length >= 2 ? components[1] : null, | |
} | |
} | |
function dataForLocation(data, location) { | |
for (line of data) { | |
const components = line.split(";") | |
if (components[1] === location["gkz"]) { | |
return { | |
incidence: Math.round(parseFloat(components[5]) * (100000 / parseFloat(components[2]))), | |
name: location["name"] ? location["name"] : components[0], | |
} | |
} | |
} | |
return { | |
error: "GKZ unbekannt.", | |
} | |
} | |
let widget = await createWidget() | |
if (!config.runsInWidget) { | |
await widget.presentSmall() | |
} | |
Script.setWidget(widget) | |
Script.complete() | |
async function createWidget(items) { | |
if (!args.widgetParameter) { | |
const list = new ListWidget() | |
list.addText("GKZ als Parameter definieren.") | |
return list | |
} | |
const locations = args.widgetParameter.split(";").map(parseLocation) | |
const apidata = await new Request(apiUrl).loadString() | |
const apidata_lines = apidata.split("\n") | |
const list = new ListWidget() | |
const header = list.addText("🦠 Inzidenz".toUpperCase()) | |
header.font = Font.mediumSystemFont(13) | |
list.addSpacer() | |
for (location of locations) { | |
const data = dataForLocation(apidata_lines, location) | |
if (data["error"]) { | |
list.addText(data["error"]) | |
continue | |
} | |
const incidence = data["incidence"] | |
const cityName = data["name"] | |
const line = list.addStack() | |
line.layoutHorizontally() | |
line.centerAlignContent() | |
line.useDefaultPadding() | |
const label = line.addText(incidence+"") | |
label.font = Font.boldSystemFont(24) | |
label.leftAlignText() | |
if(incidence >= 50) { | |
label.textColor = Color.red() | |
} else if(incidence >= 35) { | |
label.textColor = Color.orange() | |
} else { | |
label.textColor = Color.green() | |
} | |
line.addSpacer() | |
const name = line.addText(cityName) | |
name.minimumScaleFactor = 0.3 | |
name.font = Font.caption2() | |
name.lineLimit = 1 | |
name.rightAlignText() | |
} | |
return list | |
} |
Wo genau muss ich die GKZ einfügen? Bin nich so fit im coding 🙈
Coole Sache, vielen Dank!
Super, vielen Dank
Forked this gist and added a little more information: https://gist.github.com/pasrom/9627958cd3d936c302f30a692373bb9c
Sehr gelungen und informativ! Vielleicht kann man die Inzidenzzahlen noch etwas Größer darstellen? Gibt es dies Darstellungen auch für Deutschland?
Heute zeigt es einen Fehler
Line 329:60
Jetzt geht es wieder, ohne das ich was gemacht habe
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sieht dann zum Beispiel so aus: