Anwendungsbeispiel JsonMod #2: CORONA Verbreitung

Begonnen von herrmannj, 22 März 2020, 21:11:18

Vorheriges Thema - Nächstes Thema

Otto123

Feature Request hat Jörg schon und er hat auch einen momentaner Workaround https://forum.fhem.de/index.php/topic,109413.msg1034742.html#msg1034742

Corona ist auch nur ein kleiner Virus - die Menge machts ;) - ok es wären selbst bei allen FHEM Usern nur 300 Anfragen pro sek.  8)
Viele Grüße aus Leipzig  ⇉  nächster Stammtisch an der Lindennaundorfer Mühle
RaspberryPi B B+ B2 B3 B3+ ZeroW,HMLAN,HMUART,Homematic,Fritz!Box 7590,WRT3200ACS-OpenWrt,Sonos,VU+,Arduino nano,ESP8266,MQTT,Zigbee,deconz

Andy89

Zitat von: Otto123 am 25 März 2020, 19:38:29
Feature Request hat Jörg schon und er hat auch einen momentaner Workaround https://forum.fhem.de/index.php/topic,109413.msg1034742.html#msg1034742

Corona ist auch nur ein kleiner Virus - die Menge machts ;) - ok es wären selbst bei allen FHEM Usern nur 300 Anfragen pro sek.  8)
danke dafür - ich habe das tatsächlich nicht gelesen/überlesen. Dann kann ich nun die Zeit locker hoch setzen.  :)

du hast Recht - die Menge machts. Ich hab ja nun einen besseren Weg, wo ich nicht mal bis zur nächsten vollen Minute warten muss.

Beste Grüße
Andy
FHEM 6.0 auf rPi4 docker (mit Alexa & Siri); dbLog, FTUI, Sonos, XiaomiMapCreator auf rPi4 docker;
raspimatic auf rPi3+ > diverse Aktoren und Sensoren;
LGW > (PCA301),EC3000,LaCrosse; MQTT2 > WLAN-Steckdosen,Xiaomi Map;
Harmony Hub;Sonos;Onkyo AVR;RGB WLAN Controller;Netatmo;Withings;Unifi;AMAD

Jamo

Hallo Hermann,
ZitatMoin Jamo,
hmm, ok ich verstehe. Eigentlich ja, die Herausforderung ist da shutdown/restart. Stell mal bitte ein komplettes List ein
vg, &bleib auch gesund!

Das hat mit dem Shutdown/restart aber nichts zu tun. Anbei zwei listings, einmal um 19:44 mit den entsprechenden readings "_yesterday", und dann um 20:00 nach dem nächsten automatischen Update. Alle "_yesterday" readings sind verschwunden.

Internals:
   API_LAST_RES 1585161000.79775
   API__LAST_MSG invalid server response
   API__NEXT_REQ 1585115160.71333
   CFGFN     
   DEF        https://corona.lmao.ninja/countries
   FUUID      5e7a69e2-f33f-97bf-7b72-3a12da173d23c379
   NAME       coronaSpread
   NEXT       2020-03-25 20:00:00
   NR         38498
   NTFY_ORDER 50-coronaSpread
   SOURCE     https://corona.lmao.ninja/countries (200)
   SVN        21497 2020-03-23 20:44:04
   TYPE       JsonMod
   CONFIG:
     IN_REQUEST 0
     SOURCE     https://corona.lmao.ninja/countries
     SECRET:
   OLDREADINGS:
   READINGS:
     2020-03-25 19:30:00   Austria_active  5549
     2020-03-25 19:30:00   Austria_cases   5588
     2020-03-25 19:44:31   Austria_casesnewyesterday 305
     2020-03-25 19:30:00   Austria_casestoday 305
     2020-03-25 19:44:31   Austria_casesyesterday 5588
     2020-03-25 19:30:00   Austria_cpm     620
     2020-03-25 19:30:00   Austria_critical 28
     2020-03-25 19:30:00   Austria_deaths  30
     2020-03-25 19:30:00   Austria_deathstoday 2
     2020-03-25 19:44:31   Austria_deathsyesterday 2
     2020-03-25 19:30:00   Austria_recovered 9
     2020-03-25 19:30:00   France_active   20002
     2020-03-25 19:30:00   France_cases    25233
     2020-03-25 19:44:31   France_casesnewyesterday 2929
     2020-03-25 19:30:00   France_casestoday 2929
     2020-03-25 19:44:31   France_casesyesterday 25233
     2020-03-25 19:30:00   France_cpm      387
     2020-03-25 19:30:00   France_critical 2827
     2020-03-25 19:30:00   France_deaths   1331
     2020-03-25 19:30:00   France_deathstoday 231
     2020-03-25 19:44:31   France_deathsyesterday 231
     2020-03-25 19:30:00   France_recovered 3900
     2020-03-25 19:30:00   Germany_active  33346
     2020-03-25 19:30:00   Germany_cases   37098
     2020-03-25 19:44:31   Germany_casesnewyesterday 4107
     2020-03-25 19:30:00   Germany_casestoday 4107
     2020-03-25 19:44:31   Germany_casesyesterday 37098
     2020-03-25 19:30:00   Germany_cpm     443
     2020-03-25 19:30:00   Germany_critical 23
     2020-03-25 19:30:00   Germany_deaths  205
     2020-03-25 19:30:00   Germany_deathstoday 46
     2020-03-25 19:44:31   Germany_deathsyesterday 46
     2020-03-25 19:30:00   Germany_recovered 3547
     2020-03-25 19:30:00   Israel_active   2107
     2020-03-25 19:30:00   Israel_cases    2170
     2020-03-25 19:44:31   Israel_casesnewyesterday 240
     2020-03-25 19:30:00   Israel_casestoday 240
     2020-03-25 19:44:31   Israel_casesyesterday 2170
     2020-03-25 19:30:00   Israel_cpm      251
     2020-03-25 19:30:00   Israel_critical 37
     2020-03-25 19:30:00   Israel_deaths   5
     2020-03-25 19:30:00   Israel_deathstoday 2
     2020-03-25 19:44:31   Israel_deathsyesterday 2
     2020-03-25 19:30:00   Israel_recovered 58
     2020-03-25 19:30:00   Italy_active    57521
     2020-03-25 19:30:00   Italy_cases     74386
     2020-03-25 19:44:31   Italy_casesnewyesterday 5210
     2020-03-25 19:30:00   Italy_casestoday 5210
     2020-03-25 19:44:31   Italy_casesyesterday 74386
     2020-03-25 19:30:00   Italy_cpm       1230
     2020-03-25 19:30:00   Italy_critical  3489
     2020-03-25 19:30:00   Italy_deaths    7503
     2020-03-25 19:30:00   Italy_deathstoday 683
     2020-03-25 19:44:31   Italy_deathsyesterday 683
     2020-03-25 19:30:00   Italy_recovered 9362
     2020-03-25 19:30:00   Spain_active    38809
     2020-03-25 19:30:00   Spain_cases     47610
     2020-03-25 19:44:31   Spain_casesnewyesterday 5552
     2020-03-25 19:30:00   Spain_casestoday 5552
     2020-03-25 19:44:31   Spain_casesyesterday 47610
     2020-03-25 19:30:00   Spain_cpm       1018
     2020-03-25 19:30:00   Spain_critical  2636
     2020-03-25 19:30:00   Spain_deaths    3434
     2020-03-25 19:30:00   Spain_deathstoday 443
     2020-03-25 19:44:31   Spain_deathsyesterday 443
     2020-03-25 19:30:00   Spain_recovered 5367
     2020-03-25 19:30:00   UK_active       7694
     2020-03-25 19:30:00   UK_cases        8264
     2020-03-25 19:44:31   UK_casesnewyesterday 187
     2020-03-25 19:30:00   UK_casestoday   187
     2020-03-25 19:44:31   UK_casesyesterday 8264
     2020-03-25 19:30:00   UK_cpm          122
     2020-03-25 19:30:00   UK_critical     20
     2020-03-25 19:30:00   UK_deaths       435
     2020-03-25 19:30:00   UK_deathstoday  13
     2020-03-25 19:44:31   UK_deathsyesterday 13
     2020-03-25 19:30:00   UK_recovered    135
     2020-03-25 19:30:00   USA_active      59853
     2020-03-25 19:30:00   USA_cases       61081
     2020-03-25 19:44:31   USA_casesnewyesterday 6225
     2020-03-25 19:30:00   USA_casestoday  6225
     2020-03-25 19:44:31   USA_casesyesterday 61081
     2020-03-25 19:30:00   USA_cpm         185
     2020-03-25 19:30:00   USA_critical    1307
     2020-03-25 19:30:00   USA_deaths      841
     2020-03-25 19:30:00   USA_deathstoday 61
     2020-03-25 19:44:31   USA_deathsyesterday 61
     2020-03-25 19:30:00   USA_recovered   387
Attributes:
   interval   */30 * * * *
   readingList multi(jsonPath("\$.[?(\@.country in ['Austria', 'Germany', 'Italy', 'Spain', 'France', 'Israel', 'UK', 'USA'])]"), concat(property('country'), '_cases'), property('cases'));
multi(jsonPath("\$.[?(\@.country in ['Austria', 'Germany', 'Italy', 'Spain', 'France', 'Israel', 'UK', 'USA'])]"), concat(property('country'), '_casestoday'), property('todayCases'));
multi(jsonPath("\$.[?(\@.country in ['Austria', 'Germany', 'Italy', 'Spain', 'France', 'Israel', 'UK', 'USA'])]"), concat(property('country'), '_active'), property('active'));
multi(jsonPath("\$.[?(\@.country in ['Austria', 'Germany', 'Italy', 'Spain', 'France', 'Israel', 'UK', 'USA'])]"), concat(property('country'), '_deaths'), property('deaths'));
multi(jsonPath("\$.[?(\@.country in ['Austria', 'Germany', 'Italy', 'Spain', 'France', 'Israel', 'UK', 'USA'])]"), concat(property('country'), '_deathstoday'), property('todayDeaths'));
multi(jsonPath("\$.[?(\@.country in ['Austria', 'Germany', 'Italy', 'Spain', 'France', 'Israel', 'UK', 'USA'])]"), concat(property('country'), '_recovered'), property('recovered'));
multi(jsonPath("\$.[?(\@.country in ['Austria', 'Germany', 'Italy', 'Spain', 'France', 'Israel', 'UK', 'USA'])]"), concat(property('country'), '_critical'), property('critical'));
multi(jsonPath("\$.[?(\@.country in ['Austria', 'Germany', 'Italy', 'Spain', 'France', 'Israel', 'UK', 'USA'])]"), concat(property('country'), '_cpm'), property('casesPerOneMillion'));
   room       Info


Internals:
   API_LAST_RES 1585162800.6157
   API__LAST_MSG invalid server response
   API__NEXT_REQ 1585115160.71333
   CFGFN     
   DEF        https://corona.lmao.ninja/countries
   FUUID      5e7a69e2-f33f-97bf-7b72-3a12da173d23c379
   NAME       coronaSpread
   NEXT       2020-03-25 20:30:00
   NR         38498
   NTFY_ORDER 50-coronaSpread
   SOURCE     https://corona.lmao.ninja/countries (200)
   STATE     
   SVN        21497 2020-03-23 20:44:04
   TYPE       JsonMod
   CONFIG:
     IN_REQUEST 0
     SOURCE     https://corona.lmao.ninja/countries
     SECRET:
   OLDREADINGS:
   READINGS:
     2020-03-25 20:00:00   Austria_active  5549
     2020-03-25 20:00:00   Austria_cases   5588
     2020-03-25 20:00:00   Austria_casestoday 305
     2020-03-25 20:00:00   Austria_cpm     620
     2020-03-25 20:00:00   Austria_critical 28
     2020-03-25 20:00:00   Austria_deaths  30
     2020-03-25 20:00:00   Austria_deathstoday 2
     2020-03-25 20:00:00   Austria_recovered 9
     2020-03-25 20:00:00   France_active   20002
     2020-03-25 20:00:00   France_cases    25233
     2020-03-25 20:00:00   France_casestoday 2929
     2020-03-25 20:00:00   France_cpm      387
     2020-03-25 20:00:00   France_critical 2827
     2020-03-25 20:00:00   France_deaths   1331
     2020-03-25 20:00:00   France_deathstoday 231
     2020-03-25 20:00:00   France_recovered 3900
     2020-03-25 20:00:00   Germany_active  33345
     2020-03-25 20:00:00   Germany_cases   37098
     2020-03-25 20:00:00   Germany_casestoday 4107
     2020-03-25 20:00:00   Germany_cpm     443
     2020-03-25 20:00:00   Germany_critical 23
     2020-03-25 20:00:00   Germany_deaths  206
     2020-03-25 20:00:00   Germany_deathstoday 47
     2020-03-25 20:00:00   Germany_recovered 3547
     2020-03-25 20:00:00   Israel_active   2306
     2020-03-25 20:00:00   Israel_cases    2369
     2020-03-25 20:00:00   Israel_casestoday 439
     2020-03-25 20:00:00   Israel_cpm      274
     2020-03-25 20:00:00   Israel_critical 37
     2020-03-25 20:00:00   Israel_deaths   5
     2020-03-25 20:00:00   Israel_deathstoday 2
     2020-03-25 20:00:00   Israel_recovered 58
     2020-03-25 20:00:00   Italy_active    57521
     2020-03-25 20:00:00   Italy_cases     74386
     2020-03-25 20:00:00   Italy_casestoday 5210
     2020-03-25 20:00:00   Italy_cpm       1230
     2020-03-25 20:00:00   Italy_critical  3489
     2020-03-25 20:00:00   Italy_deaths    7503
     2020-03-25 20:00:00   Italy_deathstoday 683
     2020-03-25 20:00:00   Italy_recovered 9362
     2020-03-25 20:00:00   Spain_active    38809
     2020-03-25 20:00:00   Spain_cases     47610
     2020-03-25 20:00:00   Spain_casestoday 5552
     2020-03-25 20:00:00   Spain_cpm       1018
     2020-03-25 20:00:00   Spain_critical  2636
     2020-03-25 20:00:00   Spain_deaths    3434
     2020-03-25 20:00:00   Spain_deathstoday 443
     2020-03-25 20:00:00   Spain_recovered 5367
     2020-03-25 20:00:00   UK_active       7694
     2020-03-25 20:00:00   UK_cases        8264
     2020-03-25 20:00:00   UK_casestoday   187
     2020-03-25 20:00:00   UK_cpm          122
     2020-03-25 20:00:00   UK_critical     20
     2020-03-25 20:00:00   UK_deaths       435
     2020-03-25 20:00:00   UK_deathstoday  13
     2020-03-25 20:00:00   UK_recovered    135
     2020-03-25 20:00:00   USA_active      61238
     2020-03-25 20:00:00   USA_cases       62505
     2020-03-25 20:00:00   USA_casestoday  7649
     2020-03-25 20:00:00   USA_cpm         189
     2020-03-25 20:00:00   USA_critical    1382
     2020-03-25 20:00:00   USA_deaths      880
     2020-03-25 20:00:00   USA_deathstoday 100
     2020-03-25 20:00:00   USA_recovered   387
Attributes:
   interval   */30 * * * *
   readingList multi(jsonPath("\$.[?(\@.country in ['Austria', 'Germany', 'Italy', 'Spain', 'France', 'Israel', 'UK', 'USA'])]"), concat(property('country'), '_cases'), property('cases'));
multi(jsonPath("\$.[?(\@.country in ['Austria', 'Germany', 'Italy', 'Spain', 'France', 'Israel', 'UK', 'USA'])]"), concat(property('country'), '_casestoday'), property('todayCases'));
multi(jsonPath("\$.[?(\@.country in ['Austria', 'Germany', 'Italy', 'Spain', 'France', 'Israel', 'UK', 'USA'])]"), concat(property('country'), '_active'), property('active'));
multi(jsonPath("\$.[?(\@.country in ['Austria', 'Germany', 'Italy', 'Spain', 'France', 'Israel', 'UK', 'USA'])]"), concat(property('country'), '_deaths'), property('deaths'));
multi(jsonPath("\$.[?(\@.country in ['Austria', 'Germany', 'Italy', 'Spain', 'France', 'Israel', 'UK', 'USA'])]"), concat(property('country'), '_deathstoday'), property('todayDeaths'));
multi(jsonPath("\$.[?(\@.country in ['Austria', 'Germany', 'Italy', 'Spain', 'France', 'Israel', 'UK', 'USA'])]"), concat(property('country'), '_recovered'), property('recovered'));
multi(jsonPath("\$.[?(\@.country in ['Austria', 'Germany', 'Italy', 'Spain', 'France', 'Israel', 'UK', 'USA'])]"), concat(property('country'), '_critical'), property('critical'));
multi(jsonPath("\$.[?(\@.country in ['Austria', 'Germany', 'Italy', 'Spain', 'France', 'Israel', 'UK', 'USA'])]"), concat(property('country'), '_cpm'), property('casesPerOneMillion'));
   room       Info
Bullseye auf iNUC, Homematic + HMIP(UART/HMUSB), Debmatic, HUEBridge, Zigbee/ConbeeII, FB, Alexa (fhem-lazy), Livetracking, LaCrosse JeeLink, LoRaWan / TTN / Chirpstack

herrmannj

So, dann mal der Reihe nach ;)

RKI: ich weiß nicht was die rauchen um so 'n JSON zum machen. (Wobei es sehr gut ist, dass die die Daten bereitstellen)
Der JSON ist gleich dreifach spannend, ein sehr guter TestCase. Fix im svn, ab morgen per update, rev 21515

Unten das list zum device mit 2 Ausdrücken (einer davon auskommentiert).

#1: alle Fallzahlen. Der kann jetzt für andere Felder (macht nur für faelle_100000_EW und Death Sinn) multipliziert werden. Wenn es nur die Fallzahlen sind kann man concat weglassen.
readingList multi(jsonPath('$.features[*]'), concat(property('attributes.LAN_ew_GEN'),'_cases'), property('attributes.Fallzahl'));

#2 mit Filter. Weil beim Filter die Länder (String) in ein Hochkomma müssen, muss der gesamte Ausdruck in doppelte Hochkommas und daher müssen @ und $ escaped werden. Das @Andy: das war bei Dir nicht aber daran lags auch nicht. Nur Hinweis. Wenn jetzt nur ein Land angezeigt werden soll würde anstelle des 'in' auch " == 'Hamburg'" gehen. Groß- Kleinschreibung macht einen Unterschied!
multi(jsonPath("\$.features[?(\@.attributes.LAN_ew_GEN in ['Hamburg', 'Berlin', 'Bremen'])]"), property('attributes.LAN_ew_GEN'), property('attributes.Fallzahl'));

Läuft also soweit. Bis auf... wieder mal Sonderzeichen Murks. :( Das wird erfahrungsgemäß hässlich ... Aber: So weit. so gut

Internals:
   API_LAST_RES 1585164937.82149
   API__LAST_MSG 200
   DEF        https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/Coronaf%C3%A4lle_in_den_Bundesl%C3%A4ndern/FeatureServer/0/query?where=1%3D1&outFields=LAN_ew_GEN,Fallzahl,Aktualisierung,faelle_100000_EW,Death&returnGeometry=false&outSR=4326&f=json
   FUUID      5e7b4174-f33f-a6e8-dea1-1ac51dcf4db92252
   NAME       rki
   NEXT       2020-03-25 21:00:00
   NR         28
   NTFY_ORDER 50-rki
   SOURCE     https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/Coronaf%C3%A4lle_in_den_Bundesl%C3%A4ndern/FeatureServer/0/query?where=1%3D1&outFields=LAN_ew_GEN,Fallzahl,Aktualisierung,faelle_100000_EW,Death&returnGeometry=false&outSR=4326&f=json (200)
   STATE      ???
   SVN        21504 2020-03-24 22:27:59 UTC
   TYPE       JsonMod
   CONFIG:
     IN_REQUEST 0
     SOURCE     https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/Coronaf%C3%A4lle_in_den_Bundesl%C3%A4ndern/FeatureServer/0/query?where=1%3D1&outFields=LAN_ew_GEN,Fallzahl,Aktualisierung,faelle_100000_EW,Death&returnGeometry=false&outSR=4326&f=json
     SECRET:
   OLDREADINGS:
   READINGS:
     2020-03-25 20:35:37   Baden-W�rttemberg_cases 6069
     2020-03-25 20:35:37   Bayern_cases    6558
     2020-03-25 20:35:37   Berlin_cases    1428
     2020-03-25 20:35:37   Brandenburg_cases 429
     2020-03-25 20:35:37   Bremen_cases    200
     2020-03-25 20:35:37   Hamburg_cases   1262
     2020-03-25 20:35:37   Hessen_cases    1754
     2020-03-25 20:35:37   Mecklenburg-Vorpommern_cases 218
     2020-03-25 20:35:37   Niedersachsen_cases 2140
     2020-03-25 20:35:37   Nordrhein-Westfalen_cases 7197
     2020-03-25 20:35:37   Rheinland-Pfalz_cases 1591
     2020-03-25 20:35:37   Saarland_cases  403
     2020-03-25 20:35:37   Sachsen-Anhalt_cases 375
     2020-03-25 20:35:37   Sachsen_cases   959
     2020-03-25 20:35:37   Schleswig-Holstein_cases 577
     2020-03-25 20:35:37   Th�ringen_cases 394
Attributes:
   readingList multi(jsonPath('$.features[*]'), concat(property('attributes.LAN_ew_GEN'),'_cases'), property('attributes.Fallzahl'));
#multi(jsonPath("\$.features[?(\@.attributes.LAN_ew_GEN in ['Hamburg', 'Berlin', 'Bremen'])]"), property('attributes.LAN_ew_GEN'), property('attributes.Fallzahl'));

herrmannj

Zitat von: Jamo am 25 März 2020, 20:07:37
Hallo Hermann,
Das hat mit dem Shutdown/restart aber nichts zu tun. Anbei zwei listings, einmal um 19:44 mit den entsprechenden readings "_yesterday", und dann um 20:00 nach dem nächsten automatischen Update. Alle "_yesterday" readings sind verschwunden.

Jo, Thnx. Doch hat mit shutdown/restart was zu tun, nur anders als Du denkst ;)

Wie bekommst Du denn die readings dazu ?

Jamo

#50
Hallo Herrmann,
ZitatWie bekommst Du denn die readings dazu ?

Ich habe eine Sub "myCoronaStoreOld", die ich um 23:59 anstosse, und die die heutigen Werte nach "_yesterday" kopiert.

Um das ganze dann als Tabelle in FHEMWEB darzustellen, gibts die "sub CoronaStateFormat2($name)" die aus dem ganzen eine HTML tabelle generiert.
Sieht dann so wie im Bild aus. Die Tabelle stimmt natürlich nicht, weil wie gesagt die Readings überschrieben werden.

Das "attr stateformat CoronaStateFormat2($name)" hatte ich im vorherigen listing weggelassen, war ja auch nicht von Bedeutung. Ausserdem habe ich im vergleich zu vorher, auch schon das array der Länderliste erweitert (will sagen passst nicht mehr zu der readinglist von den vorherigen listings.

my @countryList  = ("Italy", "USA", "Spain", "Germany", "France", "Switzerland", "UK", "Austria", "Sweden", "Israel", "Russia");


sub myCoronaStoreOld () {
  my $name2 = "coronaSpread";
  for my $countries (@countryList) {
    my $CasesAll      = ReadingsNum($name2, $countries."_cases",0);
    my $CasesTdy      = ReadingsNum($name2, $countries."_casestoday",0);
    my $DeathTdy      = ReadingsNum($name2, $countries."_deathstoday",0);
    my $readingAllYtd = $countries."_casesyesterday";
    my $readingNewYtd = $countries."_casesnewyesterday";
    my $readingDthYtd = $countries."_deathsyesterday";
    fhem ("setreading $name2 $readingAllYtd $CasesAll;setreading $name2 $readingNewYtd $CasesTdy;setreading $name2 $readingDthYtd $DeathTdy");
  }
}


sub CoronaStateFormat2($) {
  my ($name) = @_;
  my $sub    = "CoronaStateFormat";
  my $state  = "<style type=\"text/css\">                                                                                                                                           
</style>                                                                                                                                                                             
<table width=\"100\" border=\"1\">                                                                                                                                                   
  <tr>
    <th align=\"left\">Land  </th>
    <th style=\"text-align:right\"> Cases</th>
    <th style=\"text-align:right\"> Old</th>
    <th style=\"text-align:right\"> NewTdy</th>
    <th style=\"text-align:right\"> NewYdy</th>
    <th style=\"text-align:right\"> Crit</th>
    <th style=\"text-align:right\"> Recov</th>
    <th style=\"text-align:right\"> Growth</th>
    <th style=\"text-align:right\"> Death</th>
    <th style=\"text-align:right\"> NewTdy</th>
    <th style=\"text-align:right\"> NewYtd</th>
    <th style=\"text-align:right\"> Rate</th>
  </tr>";
    #print("@CCList\n");
    for my $CC (@countryList) {
        #print("$CC\n");
        my $CasesAll       = ReadingsNum($name, $CC."_cases",1);
        my $CasesNew       = ReadingsNum($name, $CC."_casestoday",0);
        my $CasesNewOld    = ReadingsNum($name, $CC."_casesnewyesterday",0);
        my $Casescrt       = ReadingsNum($name, $CC."_critical",0);
        my $DeathAll       = ReadingsNum($name, $CC."_deaths",0);
        my $DeathNew       = ReadingsNum($name, $CC."_deathstoday",0);
        my $DeathNewOld    = ReadingsNum($name, $CC."_deathsyesterday",0);
        my $Recovered      = ReadingsNum($name, $CC."_recovered",0);
        my $CasesAllOld    = ReadingsNum($name, $CC."_casesyesterday",1);
        my $CasesPct       = (($CasesAll/$CasesAllOld)-1)*100;
        my $DeathPct       = ($DeathAll/$CasesAll)*100;
        my $DeathRte       = sprintf("%.1f"."%",$DeathPct);
        my $CasesRte       = sprintf("%.1f"."%",$CasesPct);
        #Log 3, "[$sub] CasesAlln=$CasesAlln, CasesAllOld=CasesAllOld, CasesRte=$CasesRte";
        $state = $state . "<tr>
    <td align=\"left\">$CC</td>
    <td align=\"right\"> $CasesAll</td>
    <td align=\"right\"> $CasesAllOld</td>
    <td align=\"right\"> $CasesNew</td>
    <td align=\"right\"> $CasesNewOld</td>
    <td align=\"right\"> $Casescrt</td>
    <td align=\"right\"> $Recovered</td>
    <td align=\"right\"> $CasesRte</td>
    <td align=\"right\"> $DeathAll</td>
    <td align=\"right\"> $DeathNew</td>
    <td align=\"right\"> $DeathNewOld</td>
    <td align=\"right\"> $DeathRte</td>
  </tr>"

    }
    $state = $state ."</table>                                                                                                                                                       
      <span ></a></span>";

    return $state;

}

Bullseye auf iNUC, Homematic + HMIP(UART/HMUSB), Debmatic, HUEBridge, Zigbee/ConbeeII, FB, Alexa (fhem-lazy), Livetracking, LaCrosse JeeLink, LoRaWan / TTN / Chirpstack

herrmannj

#51
mit setreading also. Ich hab mir das so gedacht aber hilft ja auch mal drüber zu sprechen. :) 

Ich muss da mal drüber nachdenken. Klar kann ich mir merken welche readings ich setze, ergo auch löschen kann.
Problem: ich bekomme die Info nicht über einen shutdown/restart gerettet. Beim restart schreibt fhem alle ("Deine" und "Meine") readings via setreading in das device zurück und ab da ist alles gemischt.

Was mir dazu einfällt wäre readings per regex vom löschen auszunehmen oder das per attribut ganz optional zu machen. Ist aber beides eher suboptimal .. readings sind halt eigentlich nicht als "user-storage" vorgesehen. Kannste das nicht anders lösen?

edit. Wenn Du das eh schon ausgelagert hast - schreib die Daten doch in einen dummy und führe die beim table machen wieder zusammen. Ginge doch, oder?

Jamo

#52
edit. Wenn Du das eh schon ausgelagert hast - schreib die Daten doch in einen dummy und führe die beim table machen wieder zusammen. Ginge doch, oder?

Yep, das kann ich machen, kein Problem. Aber hat mich halt gewundert, beim normalen HTTPMOD modul überleben meine eigene readings (wie auch eigentlich bei allen anderen Modulen) jeden shutdown/restart. Und man hat halt gerne alles in einem Modul.

Und dann muss ich alle meine subs anpassen  :(  :)

PS: Habs jetzt in mein anderes HTTPMOD device geschrieben, funktioniert erstmal.
Bullseye auf iNUC, Homematic + HMIP(UART/HMUSB), Debmatic, HUEBridge, Zigbee/ConbeeII, FB, Alexa (fhem-lazy), Livetracking, LaCrosse JeeLink, LoRaWan / TTN / Chirpstack

herrmannj

ja, verständlich. Aber das ist eher "form follows function", normalerweise gibts ja auch für einen Autor keinen Grund readings zu löschen. Hier ist das anders weil die Listen (im JSON) wachsen oder schrumpfen. Wenn ich die nicht lösche (n lasse) dann bleiben alte readings bis zum st Nimmerleinstag im device. Siehr Metar und Wolken schichten. Das sind 1..3. Strahlend blauer Himmel aber FHEM meldet dicke Suppe. ;) Daher halt hier angebracht

Andy89

wäre es vielleicht sinnvoll ein Attribut anzulegen, was der User selbst pflegen kann/muss, zB userReadingList. Alle Komma-getrennten Werte der userReadingList werden von dir einfach nicht gelöscht. So ist der User zum Teil selbst verantwortlich, wenn etwas für immer da bleibt?
Ich habe nämlich auch gerne alle zusammengehörenden Daten in einem Device - vor allem, wenn sie dann noch in die Datenbank geschrieben werden sollen.
FHEM 6.0 auf rPi4 docker (mit Alexa & Siri); dbLog, FTUI, Sonos, XiaomiMapCreator auf rPi4 docker;
raspimatic auf rPi3+ > diverse Aktoren und Sensoren;
LGW > (PCA301),EC3000,LaCrosse; MQTT2 > WLAN-Steckdosen,Xiaomi Map;
Harmony Hub;Sonos;Onkyo AVR;RGB WLAN Controller;Netatmo;Withings;Unifi;AMAD

TomLee

Zitat...(wie auch eigentlich bei allen anderen Modulen)...

Einfach mal so als Mitlesender und ohne genau zu wissen was die Hintergründe sind, hast du mal ausprobiert ob bei einem AT deine alten Readings erhalten bleiben.

Gruß

Thomas

Jamo

ZitatIch habe nämlich auch gerne alle zusammengehörenden Daten in einem Device - vor allem, wenn sie dann noch in die Datenbank geschrieben werden sollen.
stimmt, einen dblog kann man dann schlecht machen wenn man die Readings in verschiedenen Devices hat. Wie macht HTTPMOD das denn? Da muss es doch das gleiche Problem geben... Und der user ist ja selber verantwortlich, wenn seine eigenen Readings stehenbleiben und er darum dicke Suppe sieht. Das die Modulreadings gelöscht & neu angelegt werden, verstehe ich ja.
Bullseye auf iNUC, Homematic + HMIP(UART/HMUSB), Debmatic, HUEBridge, Zigbee/ConbeeII, FB, Alexa (fhem-lazy), Livetracking, LaCrosse JeeLink, LoRaWan / TTN / Chirpstack

herrmannj

Zitat von: Andy89 am 25 März 2020, 22:05:24
wäre es vielleicht sinnvoll ein Attribut anzulegen, was der User selbst pflegen kann/muss, zB userReadingList. Alle Komma-getrennten Werte der userReadingList werden von dir einfach nicht gelöscht. So ist der User zum Teil selbst verantwortlich, wenn etwas für immer da bleibt?
Ich habe nämlich auch gerne alle zusammengehörenden Daten in einem Device - vor allem, wenn sie dann noch in die Datenbank geschrieben werden sollen.
ja, das wäre quasi die regex variante. So richtig glücklich macht mich der Gedanke aber nicht.
ZitatWas mir dazu einfällt wäre readings per regex vom löschen auszunehmen oder das per attribut ganz optional zu machen. Ist aber beides eher suboptimal .. readings sind halt eigentlich nicht als "user-storage" vorgesehen. Kannste das nicht anders lösen?

Andy89

Wie löst du sowas denn, wenn du die readings auch loggen willst?
Oder nutzt du dann dafür Datenbankabfragen? Ich meine, mit grafana wäre das sicherlich lösbar, mit dem dblog und den svg-Plots eher schwieriger (zumindest für mich)
FHEM 6.0 auf rPi4 docker (mit Alexa & Siri); dbLog, FTUI, Sonos, XiaomiMapCreator auf rPi4 docker;
raspimatic auf rPi3+ > diverse Aktoren und Sensoren;
LGW > (PCA301),EC3000,LaCrosse; MQTT2 > WLAN-Steckdosen,Xiaomi Map;
Harmony Hub;Sonos;Onkyo AVR;RGB WLAN Controller;Netatmo;Withings;Unifi;AMAD

herrmannj