Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
COVID-19 Inzidenz-Widget für iOS innerhalb Deutschlands 🇩🇪
// Licence: Robert Koch-Institut (RKI), dl-de/by-2-0
const apiUrl = (location) => `https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_Landkreisdaten/FeatureServer/0/query?where=1%3D1&outFields=GEN,cases7_per_100k,cases_per_100k,BL,cases7_bl_per_100k&geometry=${location.longitude.toFixed(3)}%2C${location.latitude.toFixed(3)}&geometryType=esriGeometryPoint&inSR=4326&spatialRel=esriSpatialRelWithin&returnGeometry=false&outSR=4326&f=json`
let widget = await createWidget()
if (!config.runsInWidget) {
await widget.presentSmall()
}
Script.setWidget(widget)
Script.complete()
async function createWidget(items) {
let location
if(args.widgetParameter) {
const fixedCoordinates = args.widgetParameter.split(",").map(parseFloat)
location = {
latitude: fixedCoordinates[0],
longitude: fixedCoordinates[1]
}
} else {
Location.setAccuracyToThreeKilometers()
location = await Location.current()
}
const data = await new Request(apiUrl(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
}
const attr = data.features[0].attributes
const incidence = attr.cases7_per_100k.toFixed(1)
const cityName = attr.GEN
const incidenceBL = attr.cases7_bl_per_100k.toFixed(1)
const state = attr.BL
const incidenceDay = attr.cases_per_100k.toFixed(1)
const list = new ListWidget()
if(Device.isUsingDarkAppearance()){
const gradient = new LinearGradient()
gradient.locations = [0, 1]
gradient.colors = [
new Color("111111"),
new Color("222222")
]
list.backgroundGradient = gradient
}
const header = list.addText("🦠 Inzidenz".toUpperCase())
header.font = Font.mediumSystemFont(13)
let trend = " 🔻"
if (incidence > incidenceDay) {
trend = " 🔺"
}
const label = list.addText(incidence+trend)
label.font = Font.boldSystemFont(24)
label.textColor = Color.green()
if(incidence >= 50) {
label.textColor = Color.red()
} else if(incidence >= 35) {
label.textColor = Color.orange()
}
list.addText(cityName)
const labelBL = list.addText(incidenceBL+"")
labelBL.font = Font.boldSystemFont(24)
labelBL.textColor = Color.green()
list.addText(state)
return list
}
@barclay-reg

This comment has been minimized.

Copy link

@barclay-reg barclay-reg commented Oct 22, 2020

Hi @MK-2001

deine Trendberechnung ist nicht ganz nachvollziehbar.
Erstes vergleichst du nicht die nummerischen Werte (dazu müsstest du z.B. const incidence = parseFloat(attr.cases7_per_100k.toFixed(1)) )schreiben. Zweitens ergeben die Werte nicht immer Sinn - siehe auch den Fork von @rphl (https://gist.github.com/rphl/0491c5f9cb345bf831248732374c4ef5)

@Teledux

This comment has been minimized.

Copy link

@Teledux Teledux commented Oct 24, 2020

Hallo,
tolles Widget, aber sollte der Wert für das Bundesland nicht auch in der richtigen Farbe, abhängig von der Höhe der Inzidenz (35, 50) sein?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.