OSU-Sustainability-Office / energy-dashboard

Oregon State University's energy dashboard.
https://dashboard.sustainability.oregonstate.edu
GNU General Public License v3.0
11 stars 0 forks source link

[PR] Negative Power Fixes (originally for Nash) #296

Closed solderq35 closed 7 months ago

solderq35 commented 8 months ago

Fixes https://github.com/OSU-Sustainability-Office/energy-dashboard/issues/280

Findings

Conclusion

Other

The changes to backend\dependencies\nodejs\models\meter.js are in a GET endpoint, which will affect for example https://api.sustainability.oregonstate.edu/v2/energy/allbuildings (replace https://api.sustainability.oregonstate.edu with http://localhost:3000 if testing locally). Therefore, there should not be any worries about overwriting old data etc.

solderq35 commented 8 months ago

If we end up manually recalculating the total real and reactive power, we can probably do it in chart.module.js: https://github.com/OSU-Sustainability-Office/energy-dashboard/blob/master/src/store/chart.module.js#L47

Check Reqpayload.point, then make 3? calls to metergroup with different point values (phase A / B / C), then set to positive and sum up.

Also need to remember to ask if all values are meant to be positive. Voltage, apparent power, etc.

edit- also need to do this for download_data.vue probably

solderq35 commented 8 months ago

Other wrinkles:

There are at least 2 places in the frontend src/store where the Energy Dashboard tries to flip values to positive sign.

accumulated_real.js (known about):

meter_group.module.js (new find)

solderq35 commented 8 months ago

Changes

Regex / Python Script for reference (fix unit tests)

Input (example from backend\tests\assertedData\meter_group_relation_insert.sql):

INSERT INTO `` (`id`,`meter_id`,`operation`,`group_id`) VALUES (160,8,9,1);
INSERT INTO `` (`id`,`meter_id`,operation`,`group_id`) VALUES (161,9,9,1);
INSERT INTO `` (`id`,`meter_id`,operation`,`group_id`) VALUES (166,40,11,1);

Remove operation (or whichever variable) with just "find and replace" in text editor / vscode. image

Script

For VALUES (166,40,11,1);, you can use script (tested on python 3.8.0)

import re

# replace line below to match input file name in directory
input_file_path = 'meter_group_relation_insert.sql'

output_file_path = 'modified_' + input_file_path

# originally 5 items in parentheses, remove 4th item
# regex_pattern = r'\(([^,]+),([^,]+),([^,]+),[^,]+,([^,]+)\);'

# originally 4 items in parentheses, remove 4th item
regex_pattern = r'\(([^,]+),([^,]+),([^,]+),[^,]+\);'

with open(input_file_path, 'r') as input_file, open(output_file_path, 'w') as output_file:
    for line in input_file:
        # originally 5 items in parentheses, remove 4th item
        # modified_line = re.sub(regex_pattern, r'(\1,\2,\3,\4);', line)

        # originally 4 items in parentheses, remove 4th item
        modified_line = re.sub(regex_pattern, r'(\1,\2,\3);', line)
        output_file.write(modified_line)

print('output saved to: ' + output_file_path) 

Next todo

solderq35 commented 8 months ago

Since the only changes here are either changes to frontend (VueX store), or GET requests on the backend, I think it is safe to review and merge this PR (if there are no obvious issues), and if anything needs to be changed later we can open a new PR.

Follow Up Tasks