as part of preparations for v14 I want to optimize and make the update script even better.
I am now in the process of optimizing the parsing of realtime.txt for Cumulus and we have a problem, which Im not sure how to solve – because there is no clear right or wrong answer.
So, in realtime.txt are these three parameters:
– wind speed average
– latest wind speed
– 10min wind gust
MT database includes 2 parameters – wind speed average and max wind gust for each interval.
Wind speed average
Here we have two options. Option one is to always cache the “wind speed average” parameter and then save avg of this to the db as wind speed average. This looks straight forward, but it in fact isn´t so. The db value would in such case be exactly the avg. However, the API does two things, it saves the parsed values to cache (and after 5 minutes uses this to update the db) and in addition, it saves currently parsed values into the file that includes the “current conditions”. So we have to choose now. If I take the “wind speed avg”, then the avg in the db will be spot on (it will be average of the averages in the cache), but your current value would correspond to the 1-min average, not the latest. Alternatively, I can use the latest wind parameter and in such case, the live conditions file would include the real latest value, but the average saved to db would not be average of averages, but average of the latest saved at the time of each execution of the api script.
What do we do with the gust…. cumulus does not send 5min max wind, but this is the interval in the db. So again we have two options:
First option is to cache the averages/latest values and then after 5 min save maximum of those values into the db as G. This of course creates a problem because if the gust occurs in between the interval at which you run the update CRON, it would not be registered. Theoretically you could overcome by setting the CRON update times to something very short in which case every realtime would be read by the api before being overwritten by another one.
Second option is to take the 10min max gust. This would ensure that the maximum value is registered – BUT – it would mean that this value would be duplicated in the db, because since the updates are at 5min intervals, the 10min max gust will be the same for both.
You have to tell me what you prefer…. obviously no matter what we choose it will be a compromise, but unfortunately this is the best we can do unless realtime.txt is changed or Cumulus sends data directly to the API – which is also not an option currently.