Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong calculation of averagewindDirection #1095

Merged
merged 11 commits into from
Apr 15, 2022
Merged

Fix wrong calculation of averagewindDirection #1095

merged 11 commits into from
Apr 15, 2022

Conversation

sidey79
Copy link
Contributor

@sidey79 sidey79 commented Apr 14, 2022

Calle Code Time instead of global fromm hires

  • Please check if the PR fulfills these requirements
  • Tests for the changes have been added / modified (needed for for bug fixes / features)
  • commandref has been added / updated (needed for bug fixes / features)
  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
  • Bugfix (please link issue)
  • Feature enhancement
  • Documentation update
  • Unittest enhancement
  • other
  • What is the current behavior?
    (You can also link to an open issue here, if this describes the current behavior)

Average is incorrect die to upstream change

  • What is the new behavior (if this is a feature change)?

Using time from Code which returns integer instead of float.

  • Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)

No

  • Other information:

Rootcause is a change in fhem.pl
https://forum.fhem.de/index.php/topic,127125

sidey79 and others added 2 commits April 14, 2022 22:37
Calle Code Time instead of global fromm hires
@codecov
Copy link

codecov bot commented Apr 14, 2022

Codecov Report

Merging #1095 (b0a1d26) into master (765322e) will decrease coverage by 26.01%.
The diff coverage is 75.86%.

@@             Coverage Diff             @@
##           master    #1095       +/-   ##
===========================================
- Coverage   90.37%   64.35%   -26.02%     
===========================================
  Files          41      133       +92     
  Lines        2328     9520     +7192     
  Branches      151     1510     +1359     
===========================================
+ Hits         2104     6127     +4023     
- Misses         83     2222     +2139     
- Partials      141     1171     +1030     
Flag Coverage Δ
fhem 56.32% <75.86%> (?)
modules 64.35% <75.86%> (-26.02%) ⬇️
perl 90.59% <ø> (+0.21%) ⬆️
unittests 64.35% <75.86%> (-26.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
FHEM/14_SD_WS09.pm 72.35% <70.83%> (ø)
t/FHEM/14_SD_WS09/02_SD_WS09_WindDirAverage.t 100.00% <100.00%> (ø)
t/FHEM/00_SIGNALduino/08_DeviceData_rmsg.t 81.48% <0.00%> (ø)
t/FHEM/00_SIGNALduino/02_SIGNALduino_IdList.t 100.00% <0.00%> (ø)
FHEM/10_SD_Rojaflex.pm 68.69% <0.00%> (ø)
t/FHEM/14_Hideki/09_ParseData.t 88.88% <0.00%> (ø)
t/FHEM/00_SIGNALduino/01_SIGNALduino_Parse_MS.t 100.00% <0.00%> (ø)
t/FHEM/00_SIGNALduino/test_loadprotohash-ok.pm 80.00% <0.00%> (ø)
t/FHEM/00_SIGNALduino/01_SIGNALduino_Define.t 100.00% <0.00%> (ø)
t/FHEM/14_BresserTemeo/09_autocreate_devices.t 100.00% <0.00%> (ø)
... and 84 more

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@sidey79 sidey79 linked an issue Apr 14, 2022 that may be closed by this pull request
elektron-bbs
elektron-bbs previously approved these changes Apr 15, 2022
@sidey79 sidey79 changed the title Update 14_SD_WS09.pm Fix wrong calculation of windDirection Apr 15, 2022
@sidey79 sidey79 changed the title Fix wrong calculation of windDirection Fix wrong calculation of averagewindDirection Apr 15, 2022
@sidey79
Copy link
Contributor Author

sidey79 commented Apr 15, 2022

@elektron-bbs
@HomeAutoUser

Ich hadere gerade noch ein wenig ob ich hier merge oder vorher noch einen Test für die sub nach schiebe.

Die Berechnung des Durchschnittswertes wird nicht wirklich getestet. Es gibt ja in den Tests immer nur einen.

Ich habe mir den History Array für die Berechnung schon zurecht gelegt und mehrere Werte hinterlegt.
599 Sekunden, 300 Sekunden in der Vergangenheit und dann die aktuelle Zeit.
Da kommt bislang immer der zuletzt übergebene Wert als Durchschnitt zurück.

@elektron-bbs
Copy link
Contributor

Tja, ich blicke da nicht wirklich durch, wieviel Werte in 10 Minuten benötigt werden um den Mittelwert zu bilden. Ich vermute, das 3 zu wenig sind. Mir fehlen auch Testdaten.

@sidey79
Copy link
Contributor Author

sidey79 commented Apr 15, 2022

Tja, ich blicke da nicht wirklich durch, wieviel Werte in 10 Minuten benötigt werden um den Mittelwert zu bilden. Ich vermute, das 3 zu wenig sind. Mir fehlen auch Testdaten.

Ok, ich forsche weiter.
Zumindest das Log behauptet, dass es den Mittelwert über alle Werte berechnet.

2022.04.15 17:33:54 4: SD_WS09_WindDirAverage_08 WH1080 i=0 Speed=2.00 Dir=1.57 Time=17:23:55 vec=0.00/0.00 age=599 0.00
2022.04.15 17:33:54 4: SD_WS09_WindDirAverage_08 WH1080 i=1 Speed=2.00 Dir=1.57 Time=17:28:54 vec=0.00/0.00 age=300 0.00
2022.04.15 17:33:54 4: SD_WS09_WindDirAverage_08 WH1080 i=2 Speed=2.00 Dir=3.14 Time=17:33:54 vec=0.00/-2.00 age=0 1.00
2022.04.15 17:33:54 4: SD_WS09_WindDirAverage_09 WH1080 Mittelwert über 3 Werte ist 180, avspeed=0.7

@sidey79
Copy link
Contributor Author

sidey79 commented Apr 15, 2022

Ok, ich forsche weiter. Zumindest das Log behauptet, dass es den Mittelwert über alle Werte berechnet.

attr WH1080 WindDirAverageDecay 1 ist nötig, damit Werte mit in Betracht gezogen werden.

@elektron-bbs
Copy link
Contributor

Ich habe noch zwei Nachrichten gefunden:

2022.04.15 14:55:28 4: sduino_dummy: get rawmsg: MU;P0=-21688;P1=477;P2=-995;P3=1457;P4=-31036;D=01212121212121212321232321232123232121232323212121212123212321232123212321212323232323232323212323232323232123232323232323232123212121212321232323232321232123232321232321212341212121212121212321232321232123232121232323212121212123212321232123212321212323;CP=1;R=29;O;
2022.04.15 14:55:28 4: sduino_dummy: SD_WS09_Parse0 msg=FF4A63EAAC020402F4144C Bin=1111111101001010011000111110101010101100000000100000010000000010111101000001010001001100 syncp=1 length:88
2022.04.15 14:55:28 4: sduino_dummy: SD_WS09_Parse CRC_AUS:0 
2022.04.15 14:55:28 4: sduino_dummy: SD_WS09_Parse_SHIFT_1 NOK raw:FF4A63EAAC020402F4144C crc:230 -> shift
2022.04.15 14:55:28 4: sduino_dummy: SD_WS09_Parse_SHIFT_2 OK raw:FFA531F5560102017A0A26 msg:P9#FFA531F5560102017A0A26 crc:0
2022.04.15 14:55:28 4: sduino_dummy: SD_WS09_CRC_test2 rwa:FFA531F5560102017A0A26 msg:P9#FFA531F5560102017A0A26 CRC:0
2022.04.15 14:55:28 4: sduino_dummy: SD_WS09_Parse_1 msg=10100101001100011111010101010110000000010000001000000001011110100000101000100110 length:80
2022.04.15 14:55:28 4: sduino_dummy: SD_WS09_Parse_2 WH1080 id:83, Windspeed bit: 00000001 Dec: 0.3
2022.04.15 14:55:28 4: sduino_dummy: SD_WS09_Parse_3 WH1080 id:83, Windguest bit: 00000010 Dec: 0.7
2022.04.15 14:55:28 4: sduino_dummy: SD_WS09_Parse_4 WH1080 id:83, Rain bit: 000101111010 Dec: 113.4
2022.04.15 14:55:28 4: sduino_dummy: SD_WS09_Parse_5 WH1080 id:83, bat:ok, temp=10.1, hum=86, winddir=10:SW wS=0.3, wG=0.7, rain=113.4
2022.04.15 14:55:28 4: sduino_dummy: SD_WS09_Parse_19 WH1080 id:83 :10100101001100011111010101010110000000010000001000000001011110100000101000100110 
2022.04.15 14:55:28 4: SD_WS09_Parse_20: WH1080 (FFA531F5560102017A0A26)
2022.04.15 14:55:28 4: SD_WS09_Wind  Ws:0.3  Wg:0.7 m/s : Faktor:1
2022.04.15 14:55:28 4: SD_WS09_Wind  Ws:1.1  Wg:2.5 km/h : Faktor:3.6
2022.04.15 14:55:28 4: SD_WS09_Wind  Ws:1.0  Wg:2.3 ft/s : Faktor:3.28
2022.04.15 14:55:28 4: SD_WS09_Wind  Ws:0.7  Wg:1.6 mph : Faktor:2.24
2022.04.15 14:55:28 4: SD_WS09_Wind  Ws:0.6  Wg:1.4 kn : Faktor:1.94
2022.04.15 14:55:28 4: SD_WS09_Wind  Ws:0  Wg:1 bft 
2022.04.15 14:55:28 4: SD_WS09_Parse_rain_offset WH1080 rain:113.4 raintotal:1093.2 rainoffset:979.8 
2022.04.15 14:55:28 4: SD_WS09_WindDirAverage --- OK ----
2022.04.15 14:55:28 4: SD_WS09_WindDirAverage Math::Trig:OK
2022.04.15 14:55:28 4: SD_WS09_WindDirAverage_01 WH1080: time=1650027328.95799
2022.04.15 14:55:28 4: SD_WS09_WindDirAverage_01 WH1080 :Speed=0.3 DirR=3.93 Time=2022-04-15 14:55:28
2022.04.15 14:55:28 4: SD_WS09_WindDirAverage_02 WH1080 :avtime=600 decay=0 minspeed=0
2022.04.15 14:55:28 4: SD_WS09_WindDirAverage_04 WH1080 :Speed=0.3 Dir=3.93 Time=2022-04-15 14:55:28 minspeed=0 ctime=1650027328 ltime=1650025678 stime=1650025233 num=5
2022.04.15 14:55:28 4: SD_WS09_WindDirAverage_06 WH1080 :Speed=0.3 Dir=3.93 Time=2022-04-15 14:55:28 minspeed=0 num=5
2022.04.15 14:55:28 4: SD_WS09_WindDirAverage_07 WH1080 i=0 Speed=0.00 Dir=0.00 Time=14:21:51 ctime=1650027328 akt.=1650025311
2022.04.15 14:55:28 4: SD_WS09_WindDirAverage_07 WH1080 i=0 Speed=0.70 Dir=3.93 Time=14:22:56 ctime=1650027328 akt.=1650025376
2022.04.15 14:55:28 4: SD_WS09_WindDirAverage_07 WH1080 i=0 Speed=0.70 Dir=3.93 Time=14:26:05 ctime=1650027328 akt.=1650025565
2022.04.15 14:55:28 4: SD_WS09_WindDirAverage_07 WH1080 i=0 Speed=0.00 Dir=2.36 Time=14:27:58 ctime=1650027328 akt.=1650025678
2022.04.15 14:55:28 4: SD_WS09_WindDirAverage_08 WH1080 i=0 Speed=0.30 Dir=3.93 Time=14:55:28 vec=-0.21/-0.21 age=0 1.00
2022.04.15 14:55:28 4: SD_WS09_WindDirAverage_09 WH1080 Mittelwert über 1 Werte ist 224, avspeed=0.3
2022.04.15 14:55:28 4: SD_WS09_WindDirAverage_END WH1080 Mittelwert=224

2022.04.15 14:56:37 4: sduino_dummy: get rawmsg: MU;P0=-18408;P1=467;P2=-999;P3=1442;P4=-31032;P5=-5436;D=01212121212121212321232321232123232121232323212121212123212323232123212321212323232323232321232323232323232121232323232323232123212121212321232323232323212123232121232121232141512121212321232321232123232121232323212121212123212323232123212321212323232323;CP=1;R=28;O;
2022.04.15 14:56:37 4: sduino_dummy: SD_WS09_Parse0 msg=FF4A63E8AC040602F40CDA Bin=1111111101001010011000111110100010101100000001000000011000000010111101000000110011011010 syncp=1 length:88
2022.04.15 14:56:37 4: sduino_dummy: SD_WS09_Parse CRC_AUS:0 
2022.04.15 14:56:37 4: sduino_dummy: SD_WS09_Parse_SHIFT_1 NOK raw:FF4A63E8AC040602F40CDA crc:230 -> shift
2022.04.15 14:56:37 4: sduino_dummy: SD_WS09_Parse_SHIFT_2 OK raw:FFA531F4560203017A066D msg:P9#FFA531F4560203017A066D crc:0
2022.04.15 14:56:37 4: sduino_dummy: SD_WS09_CRC_test2 rwa:FFA531F4560203017A066D msg:P9#FFA531F4560203017A066D CRC:0
2022.04.15 14:56:37 4: sduino_dummy: SD_WS09_Parse_1 msg=10100101001100011111010001010110000000100000001100000001011110100000011001101101 length:80
2022.04.15 14:56:37 4: sduino_dummy: SD_WS09_Parse_2 WH1080 id:83, Windspeed bit: 00000010 Dec: 0.7
2022.04.15 14:56:37 4: sduino_dummy: SD_WS09_Parse_3 WH1080 id:83, Windguest bit: 00000011 Dec: 1.0
2022.04.15 14:56:37 4: sduino_dummy: SD_WS09_Parse_4 WH1080 id:83, Rain bit: 000101111010 Dec: 113.4
2022.04.15 14:56:37 4: sduino_dummy: SD_WS09_Parse_5 WH1080 id:83, bat:ok, temp=10, hum=86, winddir=6:SE wS=0.7, wG=1.0, rain=113.4
2022.04.15 14:56:37 4: sduino_dummy: SD_WS09_Parse_19 WH1080 id:83 :10100101001100011111010001010110000000100000001100000001011110100000011001101101 
2022.04.15 14:56:37 4: SD_WS09_Parse_20: WH1080 (FFA531F4560203017A066D)
2022.04.15 14:56:37 4: SD_WS09_Wind  Ws:0.7  Wg:1.0 m/s : Faktor:1
2022.04.15 14:56:37 4: SD_WS09_Wind  Ws:2.5  Wg:3.6 km/h : Faktor:3.6
2022.04.15 14:56:37 4: SD_WS09_Wind  Ws:2.3  Wg:3.3 ft/s : Faktor:3.28
2022.04.15 14:56:37 4: SD_WS09_Wind  Ws:1.6  Wg:2.2 mph : Faktor:2.24
2022.04.15 14:56:37 4: SD_WS09_Wind  Ws:1.4  Wg:1.9 kn : Faktor:1.94
2022.04.15 14:56:37 4: SD_WS09_Wind  Ws:1  Wg:1 bft 
2022.04.15 14:56:37 4: SD_WS09_Parse_rain_offset WH1080 rain:113.4 raintotal:1093.2 rainoffset:979.8 
2022.04.15 14:56:37 4: SD_WS09_WindDirAverage --- OK ----
2022.04.15 14:56:37 4: SD_WS09_WindDirAverage Math::Trig:OK
2022.04.15 14:56:37 4: SD_WS09_WindDirAverage_01 WH1080: time=1650027397.80313
2022.04.15 14:56:37 4: SD_WS09_WindDirAverage_01 WH1080 :Speed=0.7 DirR=2.36 Time=2022-04-15 14:56:37
2022.04.15 14:56:37 4: SD_WS09_WindDirAverage_02 WH1080 :avtime=600 decay=0 minspeed=0
2022.04.15 14:56:37 4: SD_WS09_WindDirAverage_04 WH1080 :Speed=0.7 Dir=2.36 Time=2022-04-15 14:56:37 minspeed=0 ctime=1650027397 ltime=1650027328 stime=1650027328 num=1
2022.04.15 14:56:37 4: SD_WS09_WindDirAverage_05 WH1080 :Speed=0.7 Dir=2.36 Time=2022-04-15 14:56:37 minspeed=0 num=1
2022.04.15 14:56:37 4: SD_WS09_WindDirAverage_08 WH1080 i=0 Speed=0.30 Dir=3.93 Time=14:55:28 vec=0.00/0.00 age=69 0.00
2022.04.15 14:56:37 4: SD_WS09_WindDirAverage_08 WH1080 i=1 Speed=0.70 Dir=2.36 Time=14:56:37 vec=0.49/-0.49 age=0 1.00
2022.04.15 14:56:37 4: SD_WS09_WindDirAverage_09 WH1080 Mittelwert über 2 Werte ist 135, avspeed=0.3
2022.04.15 14:56:37 4: SD_WS09_WindDirAverage_END WH1080 Mittelwert=135

Check average result with different values
- optimzed code a little bit, removed useless checks
@sidey79
Copy link
Contributor Author

sidey79 commented Apr 15, 2022

@elektron-bbs

Ich habe den Test fertig und zumindest in dieser sub noch die perlcritic warnungen beseitigt.
Würde mergen, wenn Du noch mal bestätigst

@elektron-bbs elektron-bbs self-requested a review April 15, 2022 18:39
Copy link
Contributor

@elektron-bbs elektron-bbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Da waren zwar noch mehr Änderungen, aber du wirst schon wissen, was du tust :-)

@sidey79 sidey79 merged commit cfa6d0d into master Apr 15, 2022
@sidey79 sidey79 deleted the Fix-winddir branch April 15, 2022 18:58
Devirex pushed a commit to Devirex/RFFHEM that referenced this pull request Apr 22, 2022
* Update 14_SD_WS09.pm

- usw CORE Time instead of global from hires
- optimzed code a little bit, removed useless checks
- few perlcritic fixes
Devirex pushed a commit to Devirex/RFFHEM that referenced this pull request Apr 22, 2022
* Update 14_SD_WS09.pm

- usw CORE Time instead of global from hires
- optimzed code a little bit, removed useless checks
- few perlcritic fixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SD_WS09_WindDirAverage - Ergebnis falsch
3 participants