Last active
February 26, 2021 19:05
-
-
Save moeskerv/74b48b5170b2124da37836c9a1339efb to your computer and use it in GitHub Desktop.
Covid Widget für den Kreis Friesland (iOS, braucht App Scriptable), inspiriert durch https://gist.github.com/kevinkub/46caebfebc7e26be63403a7f0587f664
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
// Licence: Robert Koch-Institut (RKI), dl-de/by-2-0 | |
const newCasesApiUrl = `https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_COVID19/FeatureServer/0/query?f=json&where=NeuerFall%20IN(1%2C%20-1)&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&outStatistics=%5B%7B%22statisticType%22%3A%22sum%22%2C%22onStatisticField%22%3A%22AnzahlFall%22%2C%22outStatisticFieldName%22%3A%22value%22%7D%5D&resultType=standard&cacheHint=true`; | |
const currentCasesUrl = `https://services9.arcgis.com/NdRIoRRHq1CjkAY8/arcgis/rest/services/Covid19aktuell/FeatureServer/0/query?f=json&where=1%3D1&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&orderByFields=GMD%20asc&outSR=102100&resultOffset=0&resultRecordCount=50&resultType=standard&cacheHint=true` | |
const incidenceUrl = (today, yesterday) => encodeURI(`https://services9.arcgis.com/NdRIoRRHq1CjkAY8/arcgis/rest/services/Covid19_Inzidenz/FeatureServer/0/query?f=json&where=Datum BETWEEN timestamp '${yesterday}' AND timestamp '${today}'&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&resultOffset=0&resultRecordCount=50&resultType=standard&cacheHint=true`) | |
const commune1 = "Jever" | |
const commune2 = "Zetel" | |
let widget = await createWidget() | |
if (!config.runsInWidget) { | |
await widget.presentMedium() | |
} | |
Script.setWidget(widget) | |
Script.complete() | |
function formatTotalText(totalAttr) { | |
return "🦠 Friesland Inzidenz: " + totalAttr.Inzidenz__Einwohner_98_820_ + " \nAkut: " + totalAttr.Fälle_akut_alle + " (" + totalAttr.Faelle_akut_alle_Veraenderung + "/" + "-" + String(parseInt(totalAttr.genesen_Veraenderung) + parseInt(totalAttr.verstorben_Veraenderung)) + ")" | |
} | |
function formatCommuneText(communeAttr) { | |
return communeAttr.GMD + ": " + communeAttr.Infizierte | |
} | |
async function createWidget(items) { | |
let data, header, label, city | |
const list = new ListWidget() | |
// set widget background color | |
const bgGradient = new LinearGradient(); | |
bgGradient.locations = [0, 1]; | |
bgGradient.colors = Device.isUsingDarkAppearance() | |
? [new Color('111'), new Color('222')] | |
: [new Color('fff'), new Color('fafafa')]; | |
list.backgroundGradient = bgGradient; | |
// fetch new cases for DE total | |
data = await new Request(newCasesApiUrl).loadJSON() | |
if (!data || !data.features || !data.features.length) { | |
const errorList = new ListWidget() | |
errorList.addText("Keine Ergebnisse für die Anfrage nach den Neuinfektionen.") | |
return errorList | |
} | |
header = list.addText("🦠 Neu (DE): ".toUpperCase() + "+" + data.features[0].attributes.value.toLocaleString()) | |
header.centerAlignText() | |
header.font = Font.mediumSystemFont(18) | |
list.addSpacer() | |
// fetch cases for communes | |
data = await new Request(currentCasesUrl).loadJSON() | |
if (!data || !data.features || !data.features.length) { | |
const errorList = new ListWidget() | |
errorList.addText("Keine Ergebnisse für den aktuellen Ort gefunden.") | |
return errorList | |
} | |
// search communes | |
for (var i = 0; i < data.features.length; i++) { | |
entry = data.features[i] | |
if (entry.attributes.GMD.includes(commune1)) { | |
var commune1Attr = entry.attributes | |
} | |
else if (entry.attributes.GMD.includes(commune2)) { | |
var commune2Attr = entry.attributes | |
} | |
} | |
// get current values for district | |
let today = new Date().toISOString().slice(0, 10) + " 22:59:59" | |
let yesterday = new Date() | |
yesterday.setDate(yesterday.getDate() - 1) | |
yesterday = yesterday.toISOString().slice(0, 10) + " 23:00:00" | |
data = await new Request(incidenceUrl(today, yesterday)).loadJSON() | |
var incidence = data.features[0].attributes.Inzidenz__Einwohner_98_820_.toFixed(1) | |
header = list.addText(formatTotalText(data.features[0].attributes)) | |
header.centerAlignText() | |
header.font = Font.mediumSystemFont(20) | |
if (incidence >= 50) { | |
header.textColor = Color.red() | |
} else if (incidence >= 25) { | |
header.textColor = Color.orange() | |
} | |
city = list.addText(formatCommuneText(commune1Attr) + " / " + formatCommuneText(commune2Attr)) | |
city.centerAlignText() | |
city.font = Font.mediumSystemFont(18) | |
city.textColor = Color.gray() | |
label = list.addText("letztes Update: " + data.features[0].attributes.Datenaktualitaet) | |
label.centerAlignText() | |
label.font = Font.mediumSystemFont(12) | |
return list | |
} |
Ok, dennoch vielen lieben Dank :-)
…
Am 26.02.2021 um 20:01 schrieb moeskerv ***@***.***>:
***@***.*** commented on this gist.
Hallo ampy511,
ich habe mir das GeoPortal vom Kreis Warendorf mal angesehen. Leider wird dort ein anderes Format (XML statt JSON) verwendet sodass die Anpassung aufwändiger ist. Da muss ich leider passen.
Viele Grüße!
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hallo ampy511,
ich habe mir das GeoPortal vom Kreis Warendorf mal angesehen. Leider wird dort ein anderes Format (XML statt JSON) verwendet sodass die Anpassung aufwändiger ist. Da muss ich leider passen.
Viele Grüße!