From e2db8acb132a6774a3d8db53597c6e30bf86fc8b Mon Sep 17 00:00:00 2001 From: Manos Date: Fri, 24 Sep 2021 13:26:48 +0200 Subject: [PATCH] code: Goal thresholds --- code/parse_hue.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/code/parse_hue.py b/code/parse_hue.py index 3228000..5f237a8 100644 --- a/code/parse_hue.py +++ b/code/parse_hue.py @@ -35,7 +35,7 @@ def main(args): ''' Load data ''' - # Get consumption data from previous parsing + # Get consumption data [timestamp, consumption] from previous parsing cons_data = lmdk_lib.load_data(args, 'cons') if cons_data.size == 0: # Consumption [dt, hr, kwh] @@ -61,6 +61,37 @@ def main(args): print('[Error: %s]' %(e)) # Save to results lmdk_lib.save_data(args, np.array(cons, np.float32), 'cons') + ''' + Find thresholds for goals. + 0.2: 0.30 + 0.4: 0.23 + 0.6: 0.15 + 0.8: 0.13 + ''' + # {goal: theta} + lmdk = {} + # Percentage of landmarks + goal = [.2, .4, .6, .8] + # Find max consumpton to start from + theta = max(cons_data[:, 1]) + cons_data_cur = np.copy(cons_data) + # Find thetas for each goal + for g in goal: + print('Looking for %.1f... ' %(g), end='', flush=True) + while theta > 0: + # Reduce threshold gradually + theta -= .01 + # Find data below the current theta + cons_data_cur = cons_data_cur[cons_data_cur[:, 1] < theta] + # Calculate the percentage of landmarks + diff = (len(cons_data) - len(cons_data_cur))/len(cons_data) + # Check if it is close enough to what we need + if abs(diff - g)/g < .05: + print('%.2f' %(theta)) + lmdk[g] = theta + # Continue with the next goal + break + '''