-
-
Save malakka/0576bb922e7b81b95137a06b619bba1b to your computer and use it in GitHub Desktop.
// 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 incidenceUrl = (location) => `https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_Landkreisdaten/FeatureServer/0/query?where=1%3D1&outFields=GEN,last_update,cases,cases7_per_100k&geometry=${location.longitude.toFixed(3)}%2C${location.latitude.toFixed(3)}&geometryType=esriGeometryPoint&inSR=4326&spatialRel=esriSpatialRelWithin&returnGeometry=false&outSR=4326&f=json` | |
const saveIncidenceLatLon = (location) => { | |
let fm = FileManager.iCloud() | |
let path = fm.joinPath(fm.documentsDirectory(), "covid19latlon.json") | |
fm.writeString(path, JSON.stringify(location)) | |
} | |
const getsavedIncidenceLatLon = () => { | |
let fm = FileManager.iCloud() | |
let path = fm.joinPath(fm.documentsDirectory(), "covid19latlon.json") | |
let data = fm.readString(path) | |
return JSON.parse(data) | |
} | |
let widget = await createWidget() | |
if (!config.runsInWidget) { | |
await widget.presentSmall() | |
} | |
Script.setWidget(widget) | |
Script.complete() | |
async function createWidget(items) { | |
let data, attr, header, label | |
const list = new ListWidget() | |
// 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("🦠 Neuinfektionen ".toUpperCase()) | |
header.centerAlignText() | |
header.font = Font.mediumSystemFont(10) | |
label = list.addText("+"+data.features[0].attributes.value) | |
label.font = Font.mediumSystemFont(20) | |
label.centerAlignText() | |
const country = list.addText("Deutschland") | |
country.centerAlignText() | |
country.font = Font.mediumSystemFont(12) | |
country.textColor = Color.gray() | |
list.addSpacer() | |
// fetch new incidents | |
let location | |
if(args.widgetParameter) { | |
const fixedCoordinates = args.widgetParameter.split(",").map(parseFloat) | |
location = { | |
latitude: fixedCoordinates[0], | |
longitude: fixedCoordinates[1] | |
} | |
} else { | |
Location.setAccuracyToThreeKilometers() | |
try { | |
location = await Location.current() | |
console.log('get current lat/lon') | |
saveIncidenceLatLon(location) | |
} catch(e) { | |
console.log('using saved lat/lon') | |
location = getsavedIncidenceLatLon() | |
} | |
} | |
data = await new Request(incidenceUrl(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 | |
} | |
attr = data.features[0].attributes | |
const incidence = attr.cases7_per_100k.toFixed(1) | |
const cityName = attr.GEN | |
const cases =attr.cases | |
const lastUpdate = attr.last_update | |
header = list.addText("🦠 Inzidenz".toUpperCase()) | |
header.centerAlignText() | |
header.font = Font.mediumSystemFont(10) | |
label = list.addText(incidence) | |
label.centerAlignText() | |
label.font = Font.mediumSystemFont(24) | |
label2 = list.addText("("+cases+")") | |
label2.centerAlignText() | |
label2.font = Font.mediumSystemFont(12) | |
if(incidence >= 50) { | |
label.textColor = Color.red() | |
} else if(incidence >= 25) { | |
label.textColor = Color.orange() | |
} | |
const city = list.addText(cityName) | |
city.centerAlignText() | |
city.font = Font.mediumSystemFont(12) | |
city.textColor = Color.gray() | |
list.addSpacer() | |
label3 = list.addText ("letztes Update: "+lastUpdate.substr(0,10)) | |
label3.centerAlignText() | |
label3.font = Font.mediumSystemFont(6) | |
return list | |
} |
Wenn man bei der incidenceURL bei outFields=* angibt, statt der kommaseparierten Liste, dann liefert der Server alles was er hat... z.B. auch Tote 🙈... aber vielleicht wollen wir das lieber gar nicht wissen
Kannst du das genauer angeben? Wie muss der Zeilencode exakt lauten? Ich bekommen trotz *️⃣ denselben output... 🤔 🤷♂️
#Wenn man bei der incidenceURL bei outFields=* angibt, statt der kommaseparierten Liste, dann liefert der Server alles was er hat... z.B. auch Tote 🙈... aber vielleicht wollen wir das lieber gar nicht wissen
Kannst du das genauer erklären?
Hallo,
da sich die Situation immer mehr zugespitzt, wäre es für mich auch sinnvoll, die aktuellen Todeszahlen für Deutschland hinzuzufügen. Das unterstreicht noch mal wie kritisch die Situation sich aktuell weiter entwickelt.
Wäre das möglich!
Wie kann man bei den Neuinfektionen ein 1000er Trennzeichen in Form eines Punktes einfügen?
Das geht mit .toLocaleString() .
Also Zeile 46
label = list.addText("+"+data.features[0].attributes.value)
ersetzen durch
label = list.addText("+"+data.features[0].attributes.value.toLocaleString())
Cool vielen dank, und ist es möglich noch die Uhrzeit hinter dem Aktualisierungsdatum hinzuzufügen ?
Super Sache. Kann ich auch einen festen Standort hinterlegen? Falls ja, an welcher Stelle trage ich die Koordinaten ein?
Ich hätte gerne das Widget wie gehabt, mit der Inzidenz vom aktuellen Standort und auch ein Widget mir meiner Homebase, da diese Zahl ausschlaggebend ist für den 15 km Radius.
@Eeewald85 hatte ja bereits den Vorschlag gemacht, finde ich gut und sinnvoll. Für einen selbst ist ja der Wert am Wohnort wichtig für die Einschränkungen, nicht der Ort an dem man sich gerade befindet.
Hallo, kenne mich nicht aus, aber kann mir von euch Profis jemand sagen wie ich erstellen kann, dass ich zum Beispiel 3 Landkreise sehe?
Was ist denn die Zahl in Klammern über Düsseldorf?
Das ist die Anzahl der aktuellen Fälle in Düsseldorf
Kann nicht sein, in meinem Landkreis sind aktuell 132 Fälle laut Landratsamt Seite und das Script zeigt mir 6521 an 🤷🏻♂️
Vielleicht hat malakka die Lust und Zeit dazu den Source Code von Risklayer KIT auseinander zu nehmen.
<script type=„text/javascript“ async=„“ src=„https://www.google-analytics.com/analytics.js“></script><script src=„https://connect.facebook.net/en_US/sdk.js?hash=35d64584812ef6825142247d4e379d9f“ async=„“ crossorigin=„anonymous“></script><script id=„facebook-jssdk“ src=„https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v3.0“></script><script async=„“ src=„https://www.googletagmanager.com/gtag/js?id=UA-151745207-3“></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag(‚js‘, new Date());gtag(‚config‘, ‚UA-151745207-3‘,{ ‚anonymize_ip‘: true });
</script>
<title>Risklayer Explorer</title>
<meta name=„viewport“ content=„width=device-width, initial-scale=1“>
<!—Bootstrap—>
<script src=„https://code.jquery.com/jquery-3.4.1.min.js“ integrity=„sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=„ crossorigin=„anonymous“></script> <script src=„https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js“ integrity=„sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1“ crossorigin=„anonymous“></script> <script src=„https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js“ integrity=„sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM“ crossorigin=„anonymous“></script><!—FontAwesome—>
<script src=„https://use.fontawesome.com/releases/v5.12.1/js/all.js“ data-auto-add-css=„false“></script> <script src=„https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js“ charset=„utf-8“></script><!—Loading jquery—>
<script src=„https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js“></script> <script src=„https://code.jquery.com/ui/1.12.1/jquery-ui.js“></script><!—Mapbox—>
<script src=„https://api.mapbox.com/mapbox-gl-js/v1.8.0/mapbox-gl.js“></script> <script src=„https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v4.0.0/mapbox-gl-geocoder.min.js“></script><!—Loading css stylesheet—>
<!—d3.js —>
<script src=„https://d3js.org/d3.v5.min.js“></script> <script type=„text/javascript“ src=„https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.bundle.js“></script><style type=„text/css“>/* Chart.js */@-webkit-keyframes chartjs-render-animation{from{opacity:0.99}to{opacity:1}}@Keyframes chartjs-render-animation{from{opacity:0.99}to{opacity:1}}.chartjs-render-monitor{-webkit-animation:chartjs-render-animation 0.001s;animation:chartjs-render-animation 0.001s;}</style>
<title>COVID-19 | Coronavirus in Germany</title> <script src=„https://cdnjs.cloudflare.com/ajax/libs/chroma-js/2.1.0/chroma.min.js“></script> <style type=„text/css“ data-fbcssmodules=„css:fb.css.basecss:fb.css.dialog css:fb.css.iframewidget“>.fb_hidden{position:absolute;top:-10000px;z-index:10001}.fb_reposition{overflow:hidden;position:relative}.fb_invisible{display:none}.fb_reset{background:none;border:0;border-spacing:0;color:#000;cursor:auto;direction:ltr;font-family:“lucida grande“, tahoma, verdana, arial, sans-serif;font-size:11px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:1;margin:0;overflow:visible;padding:0;text-align:left;text-decoration:none;text-indent:0;text-shadow:none;text-transform:none;visibility:visible;white-space:normal;word-spacing:normal}.fb_reset>div{overflow:hidden}@Keyframes fb_transform{from{opacity:0;transform:scale(.95)}to{opacity:1;transform:scale(1)}}.fb_animate{animation:fb_transform .3s forwards} .fb_dialog{background:rgba(82, 82, 82, .7);position:absolute;top:-10000px;z-index:10001}.fb_dialog_advanced{border-radius:8px;padding:10px}.fb_dialog_content{background:#fff;color:#373737}.fb_dialog_close_icon{background:url(https://static.xx.fbcdn.net/rsrc.php/v3/yq/r/IE9JII6Z1Ys.png) no-repeat scroll 0 0 transparent;cursor:pointer;display:block;height:15px;position:absolute;right:18px;top:17px;width:15px}.fb_dialog_mobile .fb_dialog_close_icon{left:5px;right:auto;top:5px}.fb_dialog_padding{background-color:transparent;position:absolute;width:1px;z-index:-1}.fb_dialog_close_icon:hover{background:url(https://static.xx.fbcdn.net/rsrc.php/v3/yq/r/IE9JII6Z1Ys.png) no-repeat scroll 0 -15px transparent}.fb_dialog_close_icon:active{background:url(https://static.xx.fbcdn.net/rsrc.php/v3/yq/r/IE9JII6Z1Ys.png) no-repeat scroll 0 -30px transparent}.fb_dialog_iframe{line-height:0}.fb_dialog_content .dialog_title{background:#6d84b4;border:1px solid #365899;color:#fff;font-size:14px;font-weight:bold;margin:0}.fb_dialog_content .dialog_title>span{background:url(https://static.xx.fbcdn.net/rsrc.php/v3/yd/r/Cou7n-nqK52.gif) no-repeat 5px 50%;float:left;padding:5px 0 7px 26px}body.fb_hidden{height:100%;left:0;margin:0;overflow:visible;position:absolute;top:-10000px;transform:none;width:100%}.fb_dialog.fb_dialog_mobile.loading{background:url(https://static.xx.fbcdn.net/rsrc.php/v3/ya/r/3rhSv5V8j3o.gif) white no-repeat 50% 50%;min-height:100%;min-width:100%;overflow:hidden;position:absolute;top:0;z-index:10001}.fb_dialog.fb_dialog_mobile.loading.centered{background:none;height:auto;min-height:initial;min-width:initial;width:auto}.fb_dialog.fb_dialog_mobile.loading.centered #fb_dialog_loader_spinner{width:100%}.fb_dialog.fb_dialog_mobile.loading.centered .fb_dialog_content{background:none}.loading.centered #fb_dialog_loader_close{clear:both;color:#fff;display:block;font-size:18px;padding-top:20px}#fb-root #fb_dialog_ipad_overlay{background:rgba(0, 0, 0, .4);bottom:0;left:0;min-height:100%;position:absolute;right:0;top:0;width:100%;z-index:10000}#fb-root #fb_dialog_ipad_overlay.hidden{display:none}.fb_dialog.fb_dialog_mobile.loading iframe{visibility:hidden}.fb_dialog_mobile .fb_dialog_iframe{position:sticky;top:0}.fb_dialog_content .dialog_header{background:linear-gradient(from(#738aba), to(#2c4987));border-bottom:1px solid;border-color:#043b87;box-shadow:white 0 1px 1px -1px inset;color:#fff;font:bold 14px Helvetica, sans-serif;text-overflow:ellipsis;text-shadow:rgba(0, 30, 84, .296875) 0 -1px 0;vertical-align:middle;white-space:nowrap}.fb_dialog_content .dialog_header table{height:43px;width:100%}.fb_dialog_content .dialog_header td.header_left{font-size:12px;padding-left:5px;vertical-align:middle;width:60px}.fb_dialog_content .dialog_header td.header_right{font-size:12px;padding-right:5px;vertical-align:middle;width:60px}.fb_dialog_content .touchable_button{background:linear-gradient(from(#4267B2), to(#2a4887));background-clip:padding-box;border:1px solid #29487d;border-radius:3px;display:inline-block;line-height:18px;margin-top:3px;max-width:85px;padding:4px 12px;position:relative}.fb_dialog_content .dialog_header .touchable_button input{background:none;border:none;color:#fff;font:bold 12px Helvetica, sans-serif;margin:2px -12px;padding:2px 6px 3px 6px;text-shadow:rgba(0, 30, 84, .296875) 0 -1px 0}.fb_dialog_content .dialog_header .header_center{color:#fff;font-size:16px;font-weight:bold;line-height:18px;text-align:center;vertical-align:middle}.fb_dialog_content .dialog_content{background:url(https://static.xx.fbcdn.net/rsrc.php/v3/y9/r/jKEcVPZFk-2.gif) no-repeat 50% 50%;border:1px solid #4a4a4a;border-bottom:0;border-top:0;height:150px}.fb_dialog_content .dialog_footer{background:#f5f6f7;border:1px solid #4a4a4a;border-top-color:#ccc;height:40px}#fb_dialog_loader_close{float:left}.fb_dialog.fb_dialog_mobile .fb_dialog_close_icon{visibility:hidden}#fb_dialog_loader_spinner{animation:rotateSpinner 1.2s linear infinite;background-color:transparent;background-image:url(https://static.xx.fbcdn.net/rsrc.php/v3/yD/r/t-wz8gw1xG1.png);background-position:50% 50%;background-repeat:no-repeat;height:24px;width:24px}@Keyframes rotateSpinner{0%{transform:rotate(0deg)}100%{transform:rotate(360deg)}} .fb_iframe_widget{display:inline-block;position:relative}.fb_iframe_widget span{display:inline-block;position:relative;text-align:justify}.fb_iframe_widget iframe{position:absolute}.fb_iframe_widget_fluid_desktop,.fb_iframe_widget_fluid_desktop span,.fb_iframe_widget_fluid_desktop iframe{max-width:100%}.fb_iframe_widget_fluid_desktop iframe{min-width:220px;position:relative}.fb_iframe_widget_lift{z-index:1}.fb_iframe_widget_fluid{display:inline}.fb_iframe_widget_fluid span{width:100%}</style><script charset=„utf-8“ src=„https://platform.twitter.com/js/button.63c51c903061d0dbd843c41e8a00aa5a.js“></script>COVID-19 | Coronavirus
Sources can be found by clicking through the admin zones on the map above. Each data point was retrieved at about the same time 0:00 o’clock of the given date.
We are going to put more subnational trends on the Explorer in the coming days and keep you up to date with Google’s amazing analysis. This combined with our subnational data gives a new perspective on the relative impacts across countries of COVID-19.
Source
After 2 weeks of doing the statistics at Risklayer and CEDIM full-time, a platform via Google Sheets was set up with 3-way verification, to enable for crowd-sourcing of the Kreis und Gemeinde Daten which has had around 150 contributors from Germany so far. We have worked with BNN, Tagespiegel, MDR, Wikipedia and other news entities to integrate these numbers in their platforms as it eliminates the errors, and they have even helped join the crowd sourcing initiative.
The nightly reports of this data have been done from the 4th March until now and released via news agencies, on the Risklayer Explorer and first on the Twitter and Facebook feeds. The global subnational database is only updated every 3-4 days given the amount of focus on the German platform.
Get in touch