Skip to content

Commit

Permalink
More Precise Cache Key Name
Browse files Browse the repository at this point in the history
  • Loading branch information
leoherzog committed Sep 16, 2024
1 parent 8534333 commit a4d5613
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions code.gs
Original file line number Diff line number Diff line change
Expand Up @@ -1074,15 +1074,15 @@ function getCalculatedHourlyPrecipAccum_(currentPrecipRate) {

const ONE_HOUR_MS = 3600000; // 1 hour in milliseconds

let precipHistory = JSON.parse(CacheService.getScriptCache().get('calculatedHourlyPrecipAccum') || '[]');
let precipHistory = JSON.parse(CacheService.getScriptCache().get('hourlyPrecipHistory') || '[]');
const currentTime = new Date().getTime();

// add the new reading and remove old entries
precipHistory.push({ "rate": currentPrecipRate, "timestamp": currentTime });
precipHistory = precipHistory.filter(entry => entry.timestamp >= currentTime - ONE_HOUR_MS);

// save the updated history back to cache
CacheService.getScriptCache().put('calculatedHourlyPrecipAccum', JSON.stringify(precipHistory), 21600); // 6 hours cache
CacheService.getScriptCache().put('hourlyPrecipHistory', JSON.stringify(precipHistory), 21600); // 6 hours cache

// calculate the accumulation if we have sufficient data
if (precipHistory.length > 1 && currentTime - precipHistory[0].timestamp >= ONE_HOUR_MS * 0.95) { // are there two or more readings spanning almost an hour?
Expand Down

0 comments on commit a4d5613

Please sign in to comment.