Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
COVID-19 Inzidenz-Widget für iOS innerhalb Österreichs 🇦🇹
// 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
}
@Baumchen

This comment has been minimized.

Copy link
Owner Author

@Baumchen Baumchen commented Oct 23, 2020

Sieht dann zum Beispiel so aus:

IMG_8972

@jo1601

This comment has been minimized.

Copy link

@jo1601 jo1601 commented Oct 23, 2020

Wo genau muss ich die GKZ einfügen? Bin nich so fit im coding 🙈

@Baumchen

This comment has been minimized.

Copy link
Owner Author

@Baumchen Baumchen commented Oct 23, 2020

Wo genau muss ich die GKZ einfügen? Bin nich so fit im coding 🙈

Unten in den Widget Parametern (Editier-Modus des Widgets). Im Code musst du nichts verändern.
IMG_8973

@tirolerben

This comment has been minimized.

Copy link

@tirolerben tirolerben commented Oct 23, 2020

Coole Sache, vielen Dank!

@mgfall

This comment has been minimized.

Copy link

@mgfall mgfall commented Oct 23, 2020

Super, vielen Dank

@pasrom

This comment has been minimized.

Copy link

@pasrom pasrom commented Oct 29, 2020

Forked this gist and added a little more information: https://gist.github.com/pasrom/9627958cd3d936c302f30a692373bb9c

@hxperman

This comment has been minimized.

Copy link

@hxperman hxperman commented Nov 13, 2020

Sehr gelungen und informativ! Vielleicht kann man die Inzidenzzahlen noch etwas Größer darstellen? Gibt es dies Darstellungen auch für Deutschland?

@dennerforen

This comment has been minimized.

Copy link

@dennerforen dennerforen commented Nov 18, 2020

Heute zeigt es einen Fehler

Line 329:60

@dennerforen

This comment has been minimized.

Copy link

@dennerforen dennerforen commented Nov 18, 2020

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