Generate casually chosen arbitrary peak values based on originals set by the user
(peaks)
| 136 | |
| 137 | |
| 138 | def stochasticity(peaks): |
| 139 | """Generate casually chosen arbitrary peak values based on originals |
| 140 | set by the user""" |
| 141 | # in future, stochasticity percentage can be added to th QS parameters |
| 142 | # for users to define |
| 143 | stoch_percent = random.randint(70, 85) # over 70, below 85 would be good |
| 144 | |
| 145 | orig_peaks = configuration["stochasticity"]["original_peaks"] |
| 146 | latesttime = configuration["stochasticity"]["latesttime"] |
| 147 | latesttime_h = latesttime["hourly"] |
| 148 | latesttime_d = latesttime["daily"] |
| 149 | realtime = epoch_time.time() |
| 150 | |
| 151 | # renew peak values at relative range just after an hour |
| 152 | hourly_cycle = (realtime - latesttime_h) >= 3750 |
| 153 | # about ~one day (most people will not reach 86400 seconds, so, smaller |
| 154 | # is better) |
| 155 | daily_cycle = (realtime - latesttime_d) >= 27144 |
| 156 | |
| 157 | if hourly_cycle or daily_cycle: |
| 158 | # simplify 2 (possible) STEPs into 1 sequenced loop |
| 159 | while hourly_cycle or daily_cycle: |
| 160 | interval = "hourly" if hourly_cycle else "daily" |
| 161 | stochast_values(peaks, orig_peaks, interval, stoch_percent) |
| 162 | # update the latest time of value renewal in the given interval |
| 163 | latesttime[interval] = epoch_time.time() |
| 164 | |
| 165 | if hourly_cycle: |
| 166 | logger.info( |
| 167 | "Quota Supervisor: just updated hourly peak rates in " |
| 168 | "stochastic probablity!" |
| 169 | ) |
| 170 | # turn off hourly cycle to avoid recycling |
| 171 | hourly_cycle = False |
| 172 | |
| 173 | elif daily_cycle: |
| 174 | logger.info( |
| 175 | "Quota Supervisor: just updated daily peak rates in " |
| 176 | "stochastic probablity!" |
| 177 | ) |
| 178 | # turn off daily cycle to avoid recycling |
| 179 | daily_cycle = False |
| 180 | |
| 181 | |
| 182 | def stochast_values(peaks, orig_peaks, interval, percent): |
no test coverage detected