Skip to content

Instantly share code, notes, and snippets.

@moeskerv
Last active November 25, 2020 21:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moeskerv/a3e0c10faccd0c6c5e3faf1edd4c8f4c to your computer and use it in GitHub Desktop.
Save moeskerv/a3e0c10faccd0c6c5e3faf1edd4c8f4c to your computer and use it in GitHub Desktop.
Covid19 Widget für den Kreis Borken (iOS, braucht App Scriptable), Inspiriert durch https://gist.github.com/kevinkub/46caebfebc7e26be63403a7f0587f664
// 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://services2.arcgis.com/297hbk2d6K4DqSw4/arcgis/rest/services/Covid19_AGOL/FeatureServer/1/query?f=json&where=1=1&returnGeometry=false&outFields=INFIZIERTE_AKTUELL_SUM,INFIZIERTE_AKTUELL_SUM_VORTAG,INFIZIERTE,GESUNDETE,VERSTORBENE,STAND,KOMMUNE&orderByFields=DATUM%20desc,KOMMUNE%20asc&resultOffset=0&resultRecordCount=18&resultType=standard&cacheHint=true`
const incidenceUrl = `https://services2.arcgis.com/297hbk2d6K4DqSw4/arcgis/rest/services/Covid19_AGOL/FeatureServer/5/query?f=json&where=1=1&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&resultOffset=0&resultRecordCount=1&resultType=standard&cacheHint=true`
const commune1 = "Borken"
const commune2 = "Bocholt"
let widget = await createWidget()
if (!config.runsInWidget) {
await widget.presentMedium()
}
Script.setWidget(widget)
Script.complete()
function formatCommuneText(communeAttr) {
return communeAttr.KOMMUNE.substring(5) + ": " + communeAttr.INFIZIERTE_AKTUELL_SUM + " Vortag: " + communeAttr.INFIZIERTE_AKTUELL_SUM_VORTAG + " (" + communeAttr.INFIZIERTE + "/" + "-" + String(parseInt(communeAttr.GESUNDETE) + parseInt(communeAttr.VERSTORBENE)) + ")"
}
async function createWidget(items) {
let data, header, label
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
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 communities
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
}
// iterate through features
for (var i = 0; i < data.features.length; i++) {
entry = data.features[i]
if (entry.attributes.KOMMUNE.includes(commune1)) {
var commune1Attr = entry.attributes
}
else if (entry.attributes.KOMMUNE.includes(commune2)) {
var commune2Attr = entry.attributes
}
}
// get current incidence
data = await new Request(incidenceUrl).loadJSON()
const incidence = data.features[0].attributes.ZUWACHS_7_100T.toFixed(1)
header = list.addText("🦠 Inzidenz".toUpperCase() + " (BOR): " + incidence.replace(".", ","))
header.centerAlignText()
header.font = Font.mediumSystemFont(20)
if (incidence >= 50) {
header.textColor = Color.red()
} else if (incidence >= 25) {
header.textColor = Color.orange()
}
const city = list.addText(formatCommuneText(commune1Attr))
city.centerAlignText()
city.font = Font.mediumSystemFont(18)
city.textColor = Color.gray()
const city2 = list.addText(formatCommuneText(commune2Attr))
city2.centerAlignText()
city2.font = Font.mediumSystemFont(18)
city2.textColor = Color.gray()
list.addSpacer()
label = list.addText("letztes Update: " + commune1Attr.STAND.substr(0, 17))
label.centerAlignText()
label.font = Font.mediumSystemFont(12)
return list
}
@moeskerv
Copy link
Author

moeskerv commented Oct 29, 2020

image

Hier ein Beispiel für die Städte Borken und Bocholt.

Folgendes wird angezeigt:

  • Obere Zeile: Neuinfektionen DE
  • Zweite Zeile: 7-Tage Inzidenz Kreis Borken
  • Dritte und vierte Zeile: Stadt/Kommune: Aktueller Wert, Vortageswert (+Neu/-(Gesundet+Verstorben))

@caliban73
Copy link

Sieht gut aus. Wie bekommt man den Link für seinen Landkreis bei Arcgis heraus?

@moeskerv
Copy link
Author

Sieht gut aus. Wie bekommt man den Link für seinen Landkreis bei Arcgis heraus?

Das weiß ich leider nicht. Ich hatte die örtliche Webseite des Kreis Borken untersucht.

@moeskerv
Copy link
Author

Du, gib mir doch bitte einen Tipp wie ich das für unsere Landkreis einsetze, Link:

https://friesland.maps.arcgis.com/apps/opsdashboard/index.html?fbclid=IwAR1f6_j5KBkl3jLcayuAvmq1JQjzYOhuhjsE4n6wieP5M4LuG__UBpTU2aE#/f65fe24015d84a45893b11d1c6e7b6e9

Würde auch kleines Trinkgeld losmachen per Paypal...

Kein Problem, mache ich dir heute fertig als eigenes Widget. Es gibt im Datensatz allerdings für die Gemeinden (Zetel, Varel etc) keine Daten vom Vortag, d.h. ich kann nur die aktuellen Werte anzeigen. Ich schaue aber nochmal. Mache ich gerne auch ohne Trinkgeld!

@moeskerv
Copy link
Author

Du, gib mir doch bitte einen Tipp wie ich das für unsere Landkreis einsetze, Link:
https://friesland.maps.arcgis.com/apps/opsdashboard/index.html?fbclid=IwAR1f6_j5KBkl3jLcayuAvmq1JQjzYOhuhjsE4n6wieP5M4LuG__UBpTU2aE#/f65fe24015d84a45893b11d1c6e7b6e9
Würde auch kleines Trinkgeld losmachen per Paypal...

Kein Problem, mache ich dir heute fertig als eigenes Widget. Es gibt im Datensatz allerdings für die Gemeinden (Zetel, Varel etc) keine Daten vom Vortag, d.h. ich kann nur die aktuellen Werte anzeigen. Ich schaue aber nochmal. Mache ich gerne auch ohne Trinkgeld!

Das wäre echt Klasse! Danke Dir!

Schau mal hier: https://gist.github.com/moeskerv/74b48b5170b2124da37836c9a1339efb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment