7 day average daily max
Posted: Mon Dec 17, 2018 11:20 pm
I'm stuck on a "data processing" problem, and I suspect the answer is easier than I've been making it.
My task: calculate the "7 day average daily max" of a variable (auxiliary or level). More than that, I'd like to see each day when that value is greater than a certain (perhaps varying) upper limit. It's probably best if the 7DADM variable works like the output of a sample-and-hold: on each day, it takes on the 7 day average daily max for the appropriate range of 7 days and keeps that value until the start of the next day.
For example, today is December 17. The value for today is found by taking the max data values for each of December 14, ... through December 20, taking the average of those peak values, and then assigning the average of the peaks to December 17 (today). Yes, I know that doesn't sound like a causal system, except that I get to wait until December 21 to report the value for December 17.
I have an auxiliary representing the variable I want to track (it's a subscripted variable, as I'm tracking 5 or 6 variables at the same time), and I've got an integer variable that represents the number of days since the start of the simulation (units for time = hour).
I'll attach one attempt. "Peak Data" obviously shows the peak to date over the entire 4-week horizon. "Peak Daily Data Try 1" shows the same thing, even though I tried to condition both on the change of a day and the data (it obviously only triggers if a new cumulative peak happens at the start of a day). I tried a "Peak Daily Data Try 2", but the best I have come up with so far is
SAMPLE IF TRUE (:NOT: (Day = The Day from an Hour Ago)), SAMPLE IF TRUE (Data > Peak Daily Data Try 2, Data, Data), Data)
which Vensim doesn't like.
Of course, when that works, I need to average over 7 days to calculate 7DADM.
I've searched the archives and the help system, but I haven't seen a way to do that. Any ideas?
My task: calculate the "7 day average daily max" of a variable (auxiliary or level). More than that, I'd like to see each day when that value is greater than a certain (perhaps varying) upper limit. It's probably best if the 7DADM variable works like the output of a sample-and-hold: on each day, it takes on the 7 day average daily max for the appropriate range of 7 days and keeps that value until the start of the next day.
For example, today is December 17. The value for today is found by taking the max data values for each of December 14, ... through December 20, taking the average of those peak values, and then assigning the average of the peaks to December 17 (today). Yes, I know that doesn't sound like a causal system, except that I get to wait until December 21 to report the value for December 17.
I have an auxiliary representing the variable I want to track (it's a subscripted variable, as I'm tracking 5 or 6 variables at the same time), and I've got an integer variable that represents the number of days since the start of the simulation (units for time = hour).
I'll attach one attempt. "Peak Data" obviously shows the peak to date over the entire 4-week horizon. "Peak Daily Data Try 1" shows the same thing, even though I tried to condition both on the change of a day and the data (it obviously only triggers if a new cumulative peak happens at the start of a day). I tried a "Peak Daily Data Try 2", but the best I have come up with so far is
SAMPLE IF TRUE (:NOT: (Day = The Day from an Hour Ago)), SAMPLE IF TRUE (Data > Peak Daily Data Try 2, Data, Data), Data)
which Vensim doesn't like.
Of course, when that works, I need to average over 7 days to calculate 7DADM.
I've searched the archives and the help system, but I haven't seen a way to do that. Any ideas?