WeatherService daily min/max temperature fixes (#1455)

* Min/Max function fixes
* Faster way to calculate day start
This commit is contained in:
kieranc 2022-11-25 18:45:33 +01:00 committed by GitHub
parent 7376c02bbf
commit f1d2a8ee50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -552,11 +552,12 @@ namespace Pinetime {
int16_t WeatherService::GetTodayMinTemp() const { int16_t WeatherService::GetTodayMinTemp() const {
uint64_t currentTimestamp = GetCurrentUnixTimestamp(); uint64_t currentTimestamp = GetCurrentUnixTimestamp();
uint64_t currentDayEnd = currentTimestamp - ((24 - dateTimeController.Hours()) * 60 * 60) - uint64_t currentDayEnd = currentTimestamp + ((24 - dateTimeController.Hours()) * 60 * 60) +
((60 - dateTimeController.Minutes()) * 60) - (60 - dateTimeController.Seconds()); ((60 - dateTimeController.Minutes()) * 60) + (60 - dateTimeController.Seconds());
uint64_t currentDayStart = currentDayEnd - 86400;
int16_t result = -32768; int16_t result = -32768;
for (auto&& header : this->timeline) { for (auto&& header : this->timeline) {
if (header->eventType == WeatherData::eventtype::Temperature && IsEventStillValid(header, currentTimestamp) && if (header->eventType == WeatherData::eventtype::Temperature && header->timestamp >= currentDayStart &&
header->timestamp < currentDayEnd && header->timestamp < currentDayEnd &&
reinterpret_cast<const std::unique_ptr<WeatherData::Temperature>&>(header)->temperature != -32768) { reinterpret_cast<const std::unique_ptr<WeatherData::Temperature>&>(header)->temperature != -32768) {
int16_t temperature = reinterpret_cast<const std::unique_ptr<WeatherData::Temperature>&>(header)->temperature; int16_t temperature = reinterpret_cast<const std::unique_ptr<WeatherData::Temperature>&>(header)->temperature;
@ -575,11 +576,12 @@ namespace Pinetime {
int16_t WeatherService::GetTodayMaxTemp() const { int16_t WeatherService::GetTodayMaxTemp() const {
uint64_t currentTimestamp = GetCurrentUnixTimestamp(); uint64_t currentTimestamp = GetCurrentUnixTimestamp();
uint64_t currentDayEnd = currentTimestamp - ((24 - dateTimeController.Hours()) * 60 * 60) - uint64_t currentDayEnd = currentTimestamp + ((24 - dateTimeController.Hours()) * 60 * 60) +
((60 - dateTimeController.Minutes()) * 60) - (60 - dateTimeController.Seconds()); ((60 - dateTimeController.Minutes()) * 60) + (60 - dateTimeController.Seconds());
uint64_t currentDayStart = currentDayEnd - 86400;
int16_t result = -32768; int16_t result = -32768;
for (auto&& header : this->timeline) { for (auto&& header : this->timeline) {
if (header->eventType == WeatherData::eventtype::Temperature && IsEventStillValid(header, currentTimestamp) && if (header->eventType == WeatherData::eventtype::Temperature && header->timestamp >= currentDayStart &&
header->timestamp < currentDayEnd && header->timestamp < currentDayEnd &&
reinterpret_cast<const std::unique_ptr<WeatherData::Temperature>&>(header)->temperature != -32768) { reinterpret_cast<const std::unique_ptr<WeatherData::Temperature>&>(header)->temperature != -32768) {
int16_t temperature = reinterpret_cast<const std::unique_ptr<WeatherData::Temperature>&>(header)->temperature; int16_t temperature = reinterpret_cast<const std::unique_ptr<WeatherData::Temperature>&>(header)->temperature;