From 89fbfa060cdda500c9799c5bc5ccebc6a8cd1c5c Mon Sep 17 00:00:00 2001 From: Liu Yihao Date: Wed, 21 Aug 2024 02:50:24 +0800 Subject: [PATCH] feat(genie): support new version of brick server --- apps/genie-brickified/.gitignore | 1 + apps/genie-brickified/build.sh | 12 ++ .../configs/backend_configs.json | 18 +- apps/genie-brickified/geniebackend/api.py | 172 ++++++++---------- .../geniebackend/endpoints.py | 63 ++++--- apps/genie-brickified/package.json | 7 +- apps/genie-brickified/src/client/Homepage.jsx | 8 +- .../src/client/components/Segment/EnvInfo.js | 48 ++--- .../src/client/components/Segment/HVACCtl.js | 109 +++++------ apps/genie-brickified/src/config.js | 3 +- projects/sbos-playground/.gitignore | 1 + 11 files changed, 201 insertions(+), 241 deletions(-) create mode 100644 apps/genie-brickified/build.sh diff --git a/apps/genie-brickified/.gitignore b/apps/genie-brickified/.gitignore index 9b7a553..38dd803 100644 --- a/apps/genie-brickified/.gitignore +++ b/apps/genie-brickified/.gitignore @@ -1,4 +1,5 @@ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. +*.zip # dependencies /node_modules diff --git a/apps/genie-brickified/build.sh b/apps/genie-brickified/build.sh new file mode 100644 index 0000000..5a72a05 --- /dev/null +++ b/apps/genie-brickified/build.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +rm backend.zip frontend.zip + +# build backend +zip -r backend.zip configs geniebackend Dockerfile requirements.txt + +# build frontend +# yarn build +cd build +zip -r ../frontend.zip . +cd .. diff --git a/apps/genie-brickified/configs/backend_configs.json b/apps/genie-brickified/configs/backend_configs.json index 229bb48..6e6d963 100644 --- a/apps/genie-brickified/configs/backend_configs.json +++ b/apps/genie-brickified/configs/backend_configs.json @@ -1,23 +1,9 @@ { - "ssl": { - "cert": "/datadrive/synergy/repo/genie-brickified/genie_ssl.crt", - "key": "/datadrive/synergy/repo/genie-brickified/genie_ssl.key" - }, "brickapi": { - "API_URL": "http://brick-server-playground-core-1:9000/brickapi/v1", + "API_URL": "https://brickserver.ucsd.edu/brickapi/v1", "AUTH_URL": "{API_URL}/auth/login/genie-loc" }, - "google_oauth": { - "client_id": "ayeNFhq65ZsmtSH", - "client_secret": "FlbsBn8nGffwPR9WFjGtWfon0" - }, - "genie_index": "https://bd-datas3.ucsd.edu:5000", "host": "0.0.0.0", - "port": "5000", - "brick": { - "brick_prefix": "https://brickschema.org/schema/1.1.0/Brick#", - "building_prefix_dep": "http://ucsd.edu/building/ontology/ebu3b#", - "building_prefix": "bldg:" - } + "port": "5000" } diff --git a/apps/genie-brickified/geniebackend/api.py b/apps/genie-brickified/geniebackend/api.py index 56a7cbd..9c4264b 100644 --- a/apps/genie-brickified/geniebackend/api.py +++ b/apps/genie-brickified/geniebackend/api.py @@ -14,18 +14,19 @@ API_URL = config['brickapi']['API_URL'] bs_url = config['brickapi']['API_URL'] -rawqueries_url = bs_url + '/rawqueries' +rawqueries_url = bs_url + '' entity_url = bs_url + '/entities' user_url = bs_url + '/user' # TODO: This should be updated. ts_url = bs_url + '/data/timeseries' actuation_url = bs_url + '/actuation' domain_url = bs_url + '/domains' +app_url = bs_url + '/apps' -brick_prefix = config['brick']['brick_prefix'] -ebu3b_prefix = config['brick']['building_prefix'] +# brick_prefix = config['brick']['brick_prefix'] +# ebu3b_prefix = config['brick']['building_prefix'] -cid = config['google_oauth']['client_id'] -csec = config['google_oauth']['client_secret'] +# cid = config['google_oauth']['client_id'] +# csec = config['google_oauth']['client_secret'] production = False @@ -34,17 +35,17 @@ def parse_header_token(): return request.headers['Authorization'][7:] -def get_token(): - user_token = parse_header_token() - body = { - 'user_access_token': user_token, - 'client_id': cid, - 'client_secret': csec, - } - url = API_URL + '/auth/get_token' - resp = requests.post(url, json=body, verify=False) - token = resp.json()['token'] - return token +# def get_token(): +# user_token = parse_header_token() +# body = { +# 'user_access_token': user_token, +# 'client_id': cid, +# 'client_secret': csec, +# } +# url = API_URL + '/auth/get_token' +# resp = requests.post(url, json=body, verify=False) +# token = resp.json()['token'] +# return token def parse_api_token(api_token): @@ -84,7 +85,7 @@ def query_sparql(qstr, api_token): def query_user_profiles_arguments(api_token): payload = parse_api_token(api_token) resp = requests.get( - f"{domain_url}/{payload['domain']}/user_profiles_arguments", + f"{app_url}/me", headers=get_headers(api_token), verify=False ) @@ -98,25 +99,11 @@ def query_user_profiles_arguments(api_token): def query_data(uuid, api_token, value_type="number"): payload = parse_api_token(api_token) - if production: - start_time = arrow.get().shift(minutes=-30).timestamp - end_time = arrow.get().timestamp - else: - # start_time = arrow.get(2019,3,1).timestamp - start_time = 1581161300 - # end_time = arrow.get(2019,3,30).timestamp - end_time = 2581161311 - - params = { - 'start_time': start_time, - 'end_time': end_time, - 'entity_id': uuid, - 'value_types': value_type, - } - query_url = f"{ts_url}/domains/{payload['domain']}" - resp = requests.get( + query_url = f"{actuation_url}/domains/{payload['domain']}/read" + body = {f'{uuid}': [""]} + resp = requests.post( query_url, - params=params, + json=body, headers=get_headers(api_token), verify=False, ) @@ -125,18 +112,16 @@ def query_data(uuid, api_token, value_type="number"): app.logger.info("query data result: %s", resp.json()) if resp.status_code != 200: return None - data = resp.json()["data"] - if data: - data.sort(key=lambda d: d[1], reverse=True) - app.logger.debug(data[0][2]) - return data[0][2] - else: + if "results" not in resp.json()["data"]: return None + data = resp.json()["data"]["results"] + print(data) + return float(data[0]["detail"]) def query_actuation(uuid, value, api_token): payload = parse_api_token(api_token) - body = {uuid: [value]} + body = {f'{uuid}': [str(value)]} resp = requests.post( f"{actuation_url}/domains/{payload['domain']}", json=body, @@ -191,8 +176,8 @@ def iterate_extract(list, prefix_tagset): res.append({ 'room': s['s']['value'], 'college': 'UCSD', - 'campus': 'Warren', - 'building': 'BLDG', + 'campus': 'Central', + 'building': 'Center Hall', }) return res @@ -210,31 +195,30 @@ def get_user(jwt_token): return None -def _get_hvac_zone_point(tagset, room, api_token): - q = f""" - select ?s where {{ - <{room}> rdf:type brick:HVAC_Zone . - <{room}> brick:hasPoint ?s. - ?s rdf:type brick:{tagset} . - }} - """ - resp = query_sparql(q, api_token) - if resp == None: - return None - # res = resp['tuples'] - # return extract(res[0][0], ebu3b_prefix) - res = resp['results']['bindings'][0] - return res['s']['value'] +# def _get_hvac_zone_point(tagset, room, api_token): +# q = f""" +# select ?s where {{ +# # <{room}> rdf:type brick:HVAC_Zone . +# ?e brick:feeds {room} . +# ?p brick:isPointOf ?e . +# ?p a {tagset} . +# }} +# """ +# resp = query_sparql(q, api_token) +# if resp == None: +# return None +# res = resp["data"] +# print(res) +# return res['s'] def _get_vav_point(tagset, room, api_token): q = f""" select ?s where {{ - <{room}> rdf:type brick:HVAC_Zone . - ?vav brick:feeds <{room}> . - ?vav rdf:type brick:VAV . + ?vav brick:feeds {room} . + ?vav a brick:Equipment . ?vav brick:hasPoint ?s . - ?s rdf:type brick:{tagset} . + ?s a brick:{tagset} . }} """ # print(q) @@ -242,13 +226,14 @@ def _get_vav_point(tagset, room, api_token): if resp == None: return None # res = resp['tuples'] - # print(resp) - res = resp['results']['bindings'][0] - return res['s']['value'] + res = resp["data"] + print(res) + if len(res.get('s', [])) > 0: + return res['s'][0] def get_temperature_setpoint(room, api_token): - tagset = 'Zone_Air_Temperature_Setpoint' + tagset = 'Warm_Cool_Adjust_Sensor' return _get_vav_point(tagset, room, api_token) @@ -256,33 +241,36 @@ def get_zone_temperature_sensor(room, api_token): tagset = 'Zone_Air_Temperature_Sensor' return _get_vav_point(tagset, room, api_token) +def get_zone_carbon_sensor(room, api_token): + tagset = 'CO2_Sensor' + return _get_vav_point(tagset, room, api_token) -def get_thermal_power_sensor(room, api_token): - # q = """ - # select ?s where {{ - # <{0}> user:hasOffice {1} . - # {1} rdf:type brick:HVAC_Zone . - # ?vav brick:feeds {1}. - # ?vav brick:hasPoint ?s. - # ?s a/rdfs:subClassOf* brick:Thermal_Power_Sensor . - # }} - # """.format(user_email, room) - q = f""" - select ?s where {{ - ?vav brick:feeds <{room}>. - ?vav brick:hasPoint ?s. - ?s a brick:Thermal_Power_Sensor. - }} - """ - resp = query_sparql(q, api_token) - if resp is None: - return None - # res = resp['tuples'] - # return res[0][0] - res = resp['results']['bindings'][0] - return res['s']['value'] +# def get_thermal_power_sensor(room, api_token): +# # q = """ +# # select ?s where {{ +# # <{0}> user:hasOffice {1} . +# # {1} rdf:type brick:HVAC_Zone . +# # ?vav brick:feeds {1}. +# # ?vav brick:hasPoint ?s. +# # ?s a/rdfs:subClassOf* brick:Thermal_Power_Sensor . +# # }} +# # """.format(user_email, room) +# q = f""" +# select ?s where {{ +# ?vav brick:feeds {room}. +# ?vav brick:hasPoint ?s. +# ?s a brick:Thermal_Power_Sensor. +# }} +# """ +# resp = query_sparql(q, api_token) +# if resp is None: +# return None +# # res = resp['tuples'] +# # return res[0][0] +# res = resp['results']['bindings'][0] +# return res['s']['value'] def get_occupancy_command(room, api_token): - tagset = 'On_Off_Command' + tagset = 'Occupancy_Sensor' return _get_vav_point(tagset, room, api_token) diff --git a/apps/genie-brickified/geniebackend/endpoints.py b/apps/genie-brickified/geniebackend/endpoints.py index cc0f55e..03de86a 100644 --- a/apps/genie-brickified/geniebackend/endpoints.py +++ b/apps/genie-brickified/geniebackend/endpoints.py @@ -10,15 +10,13 @@ from werkzeug import exceptions from .app import app -from .api import json_response, get_user, query_sparql, query_actuation, query_data, query_entity_tagset, \ - iterate_extract, get_zone_temperature_sensor, get_occupancy_command, get_temperature_setpoint, \ - get_thermal_power_sensor, API_URL, get_token, cid, csec, parse_api_token, get_headers, query_user_profiles_arguments +from .api import * from .configs import config -INDEX_URL = config['genie_index'] -AUTH_URL = config['brickapi']['AUTH_URL'].format(API_URL=API_URL) -ebu3b_prefix = 'http://ucsd.edu/building/ontology/ebu3b#' -mock_prefix = 'ebu3b:EBU3B_Rm_' +# INDEX_URL = config['genie_index'] +# AUTH_URL = config['brickapi']['AUTH_URL'].format(API_URL=API_URL) +# ebu3b_prefix = 'http://ucsd.edu/building/ontology/ebu3b#' +# mock_prefix = 'ebu3b:EBU3B_Rm_' production = False @@ -85,16 +83,18 @@ def get_all_rooms(): resp = query_user_profiles_arguments(api_token) if resp is None: return json_response({'message': 'error'}, 200) - # print(resp) + print(resp) rooms = [] - for arguments_dict in resp: - for value in arguments_dict.values(): - rooms.append({ - 'room': value, - 'college': 'UCSD', - 'campus': 'Warren', - 'building': 'BLDG', - }) + rooms.append({ + 'room': resp["data"]["arguments"]["room"], + 'college': 'UCSD', + 'campus': 'Central', + 'building': resp["data"]["domain"]["name"], + }) + # for arguments_dict in resp: + # print(arguments_dict) + # for value in arguments_dict.values(): + # res = resp['results']['bindings'] # rooms = iterate_extract(res, ebu3b_prefix) if res else [] # print(rooms) @@ -143,9 +143,11 @@ def get_temp_setpoint(room): def set_temp_setpoint(room): api_token = config["api_token"] uuid = get_temperature_setpoint(room, api_token) + print(uuid) if not uuid: return json_response({'value': None}) req_data = request.get_json() + # req_data = {"value": 1} query_actuation(uuid, req_data['value'], api_token) return json_response({'value': req_data['value']}) @@ -155,6 +157,7 @@ def get_room_temperature(room): api_token = config["api_token"] uuid = get_zone_temperature_sensor(room, api_token) # uuid = bldg:BLDG_RM101_ZN_T + print(uuid) if not uuid: return json_response({'value': None}) # app_token = session['app_token'] @@ -164,16 +167,16 @@ def get_room_temperature(room): @app.route("/api/point/energy/", methods=["GET"]) -def get_energy_usage(room): +def get_energy_usage(room): # too lazy change the function name api_token = config["api_token"] - uuid = get_thermal_power_sensor(room, api_token) + uuid = get_zone_carbon_sensor(room, api_token) # app.logger.info(f"get_energy_usage of {uuid}") # uuid = bldg:BLDG_RM101_MTR if not uuid: return json_response({'value': None}) # app_token = session['app_token'] value = query_data(uuid, api_token) - app.logger.info('get_energy_usage: %s', value) + app.logger.info('get_co2: %s', value) return json_response({'value': value}) @@ -194,17 +197,17 @@ def get_status(room): return resp -@app.route("/api/point/status/", methods=["POST"]) -def set_status(room): - api_token = config["api_token"] - uuid = get_occupancy_command(room, api_token) - # uuid = bldg:BLDG_RM101_ONOFF - if not uuid: - return json_response({'value': None}) - req_data = request.get_json() - # 3 means on, 1 means off - resp = query_actuation(uuid, req_data['value'], api_token) - return json_response({'value': req_data['value']}) +# @app.route("/api/point/status/", methods=["POST"]) +# def set_status(room): +# api_token = config["api_token"] +# uuid = get_occupancy_command(room, api_token) +# # uuid = bldg:BLDG_RM101_ONOFF +# if not uuid: +# return json_response({'value': None}) +# req_data = request.get_json() +# # 3 means on, 1 means off +# resp = query_actuation(uuid, req_data['value'], api_token) +# return json_response({'value': req_data['value']}) @app.route("/api/user", methods=["GET"]) diff --git a/apps/genie-brickified/package.json b/apps/genie-brickified/package.json index a49e5df..9b1cede 100644 --- a/apps/genie-brickified/package.json +++ b/apps/genie-brickified/package.json @@ -22,7 +22,7 @@ "semantic-ui-react": "^0.86.0" }, "scripts": { - "start": "cross-env HOST=127.0.0.1 HTTPS=false PORT=11003 react-scripts start", + "start": "cross-env HOST=0.0.0.0 HTTPS=false PORT=11003 react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" @@ -40,5 +40,8 @@ "devDependencies": { "cross-env": "^7.0.3" }, - "homepage": "http://127.0.0.1:9000/brickapi/v1/apps/genie/static/" + "devServer": { + "allowedHosts": "all" + }, + "homepage": "http://mesl-exp.ucsd.edu:9000/brickapi/v1/apps/genie/static/" } diff --git a/apps/genie-brickified/src/client/Homepage.jsx b/apps/genie-brickified/src/client/Homepage.jsx index 177e74d..430f4bd 100644 --- a/apps/genie-brickified/src/client/Homepage.jsx +++ b/apps/genie-brickified/src/client/Homepage.jsx @@ -197,11 +197,11 @@ class DesktopContainer extends Component { this.setState({about: true, activeItem: "about"})} active={activeItem === "about"}> About - + {/* - + */} {heading} @@ -299,11 +299,11 @@ class MobileContainer extends Component { - + {/* - + */} {heading} diff --git a/apps/genie-brickified/src/client/components/Segment/EnvInfo.js b/apps/genie-brickified/src/client/components/Segment/EnvInfo.js index d61cd16..f8040e8 100644 --- a/apps/genie-brickified/src/client/components/Segment/EnvInfo.js +++ b/apps/genie-brickified/src/client/components/Segment/EnvInfo.js @@ -108,21 +108,18 @@ class SegmentComponent extends Component { this.get_room_temperature.bind(this) } - get_statuses(option, user_email) { - this.get_room_temperature(option, user_email); - this.get_energy_usage(option, user_email); + get_statuses(option) { + this.get_room_temperature(option); + this.get_energy_usage(option); } - get_energy_usage(option, user_email) { + get_energy_usage(option) { //const roomkey = option.building.value.toLowerCase() + ':' + // option.building.value + '_Rm_' + option.room.value const roomkey = option.room.value axios.get(BASE_API_URL+'/api/point/energy/' + roomkey, { - params: { - user_email: user_email.data, - }, - headers: getBrickHeaders() + headers: getBrickHeaders() }) .then(res => { if(res != null @@ -139,14 +136,11 @@ class SegmentComponent extends Component { }) } - get_room_temperature(option, user_email) { + get_room_temperature(option) { //const roomkey = option.building.value.toLowerCase() + ':' + // option.building.value + '_Rm_' + option.room.value const roomkey = option.room.value axios.get(BASE_API_URL+'/api/point/temp/' + roomkey, { - params: { - user_email: user_email.data - }, headers: getBrickHeaders() }) .then(res => { @@ -180,35 +174,15 @@ class SegmentComponent extends Component { } componentDidMount(prevProps, prevState) { - const { option, user_email } = this.props; - var intervalId; - if(user_email != null) { - if(typeof prevProps === 'undefined' || user_email !== prevProps.user_email) { - //this.get_statuses(option, user_email); - intervalId = setInterval(this.get_statuses.bind(this), 3000, option, user_email); - /* - this.get_energy_usage(option, user_email); - this.get_room_temperature(option, user_email); - */ - } - } - else if(localStorage.getItem('user_id')) { - let user_id = JSON.parse(localStorage.getItem('user_id')) - //this.get_statuses(option, user_id); - intervalId = setInterval(this.get_statuses.bind(this), 3000, option, user_id); - /* - this.get_energy_usage(option, user_id); - this.get_room_temperature(option, user_id); - */ - } else { - console.log('THIS SHOULD NOT BE REACHED') - } + const { option } = this.props; + const intervalId = setInterval(this.get_statuses.bind(this), 60000, option); this.setState({intervalId: intervalId}); + this.get_statuses(option); } render() { const { energy_value, temperature_value, energy_error, temperature_error } = this.state; - const energy_progress = energy_value / 10.0 * 100.0; + const energy_progress = energy_value / 1600 * 100; const temperature_progress = (temperature_value - 60.0) / 20.0 * 100.0; const mobile_labels = (this.props.mobile) ? [60,65,70,75,80] : [60,64,68,72,76,80]; const EnergyPanel = (energy_error) ? ( @@ -217,7 +191,7 @@ class SegmentComponent extends Component { ) : ( ); const TemperaturePanel = (temperature_error) ? ( diff --git a/apps/genie-brickified/src/client/components/Segment/HVACCtl.js b/apps/genie-brickified/src/client/components/Segment/HVACCtl.js index 59cd411..8edf5ca 100644 --- a/apps/genie-brickified/src/client/components/Segment/HVACCtl.js +++ b/apps/genie-brickified/src/client/components/Segment/HVACCtl.js @@ -1,4 +1,4 @@ -import React, { Component } from 'react'; +import React, { Component, useEffect } from 'react'; import axios from 'axios'; import { Grid, Icon, Header, Segment, Divider, Statistic, Button, Message } from 'semantic-ui-react'; import './Segment.css'; @@ -46,7 +46,12 @@ const WarningObject = ({icon, color, title, mobile, msg}) => ( ); -const SegmentObject = ({icon, color, title, value, label, handleChangeTemp, mobile}) => ( +const SegmentObject = ({icon, color, title, value, label, handleChangeTemp, mobile}) => { + const [newValue, setNewValue] = React.useState(value); + useEffect(() => { + setNewValue(value); + }, [value]) + return ( @@ -85,25 +90,37 @@ const SegmentObject = ({icon, color, title, value, label, handleChangeTemp, mobi } }} axis="x" - xmin={67} - xmax={73} + xmin={-3} + xmax={3} xstep={0.5} - x={value} - onChange={({x}) => handleChangeTemp(x)} + x={newValue} + onChange={async ({x}) => { + console.log("onChange", x); + setNewValue(x) + }} + onDragEnd={async (e) => { + console.log("onDragEnd", newValue) + console.log(e); + setTimeout(() => { + console.log("onDragEndDelay", newValue) + handleChangeTemp(newValue); + }, 0.05) + }} /> - {value}{label} + {newValue}{label} -); +) +}; const SwitchObject = ({icon, color, title, value, toggleStatus, mobile, loading}) => ( @@ -144,7 +161,7 @@ const SwitchObject = ({icon, color, title, value, toggleStatus, mobile, loading} marginTop: 20, }} > - {value} + {value === "ON" ? "Occupied": "Unoccupied"} @@ -158,7 +175,7 @@ class SegmentComponent extends Component { super(props, context) this.state = { status: 1, - temperature: 73, + temperature: 0, status_error: false, setpoint_error: false, loading: false @@ -171,25 +188,25 @@ class SegmentComponent extends Component { const { option, user_email } = this.props; const status = (this.state.status === 3) ? 1 : 3 this.setState({loading: true}) - this.set_status(option, status.toString(), status, user_email) + this.set_status(option, status.toString(), status) } handleChangeTemp = (temperature) => { - const { option, user_email } = this.props; - this.set_temp_setpoint(option, temperature, user_email) - this.setState({ - temperature: temperature - }) + const { option } = this.props; + if (this.state.temperature !== temperature) { + console.log("handleChangeTemp", temperature); + this.setState({ + temperature: temperature + }); + this.set_temp_setpoint(option, temperature); + } } - get_status(option, user_email) { + get_status(option) { //const roomkey = option.building.value.toLowerCase() + ':' + // option.building.value + '_Rm_' + option.room.value const roomkey = option.room.value axios.get(BASE_API_URL+'/api/point/status/' + roomkey, { - params: { - user_email: user_email.data - }, headers: getBrickHeaders(), }).then(res => { if (res.data.status_code === 401) { @@ -207,14 +224,11 @@ class SegmentComponent extends Component { }) } - get_temp_setpoint(option, user_email) { + get_temp_setpoint(option) { //const roomkey = option.building.value.toLowerCase() + ':' + // option.building.value + '_Rm_' + option.room.value const roomkey = option.room.value axios.get(BASE_API_URL+'/api/point/setpoint/' + roomkey, { - params: { - user_email: user_email.data - }, headers: getBrickHeaders(), }) .then(res => { @@ -235,14 +249,11 @@ class SegmentComponent extends Component { }) } - set_status(option, status, numStatus, user_email) { + set_status(option, status, numStatus) { //const roomkey = option.building.value.toLowerCase() + ':' + // option.building.value + '_Rm_' + option.room.value const roomkey = option.room.value axios.post(BASE_API_URL+'/api/point/status/' + roomkey, { value: status }, { - params: { - user_email: user_email.data - }, headers: getBrickHeaders(), }) .then(res => { @@ -256,14 +267,11 @@ class SegmentComponent extends Component { }); } - set_temp_setpoint(option, temp, user_email) { + set_temp_setpoint(option, temp) { //const roomkey = option.building.value.toLowerCase() + ':' + // option.building.value + '_Rm_' + option.room.value const roomkey = option.room.value axios.post(BASE_API_URL+'/api/point/setpoint/' + roomkey, { value: temp }, { - params: { - user_email: user_email.data - }, headers: getBrickHeaders(), }) .then(function (response) { @@ -289,34 +297,17 @@ class SegmentComponent extends Component { return null; } - get_ctrls(option, user_email) { - this.get_status(option, user_email); + get_ctrls(option) { + this.get_status(option); // this.get_temp_setpoint(option, user_email); } componentDidMount(prevProps, prevState) { - const { option, user_email } = this.props; - var intervalId; - if(user_email != null) { - if(typeof prevProps === 'undefined' || user_email !== prevProps.user_email) { - /* - this.get_status(option, user_email); - this.get_temp_setpoint(option, user_email); - */ - this.get_temp_setpoint(option, user_email); - intervalId = setInterval(this.get_ctrls.bind(this), 3000, option, user_email); - } - } - else if(localStorage.getItem('user_id')) { - let user_id = JSON.parse(localStorage.getItem('user_id')) - this.get_temp_setpoint(option, user_id); - intervalId = setInterval(this.get_ctrls.bind(this), 3000, option, user_id); - /* - this.get_status(option, user_id); - this.get_temp_setpoint(option, user_id); - */ - } + const { option } = this.props; + const intervalId = setInterval(this.get_ctrls.bind(this), 60000, option); this.setState({intervalId: intervalId}); + this.get_status(option); + this.get_temp_setpoint(option); } render() { @@ -336,7 +327,7 @@ class SegmentComponent extends Component { } else { StatusPanel = ( ); } @@ -354,17 +345,17 @@ class SegmentComponent extends Component { if (setpoint_error === 401) { SetpointPanel = ( + title={"Warm Cool Adjust"} mobile={this.props.mobile} msg={"Unauthorized"}/> ) } else if (setpoint_error === 400) { SetpointPanel = ( + title={"Warm Cool Adjust"} mobile={this.props.mobile} msg={"No data found"}/> ) } else { SetpointPanel = ( ) } diff --git a/apps/genie-brickified/src/config.js b/apps/genie-brickified/src/config.js index 81dd818..2d7424b 100644 --- a/apps/genie-brickified/src/config.js +++ b/apps/genie-brickified/src/config.js @@ -1,3 +1,4 @@ export const LOGIN_URL = 'http://127.0.0.1:5000/api/log'; -export const BASE_API_URL = 'http://127.0.0.1:9000/brickapi/v1/apps/domains/bldg/api'; +export const BASE_API_URL = 'https://brickserver.ucsd.edu/brickapi/v1/apps/api'; +// export const BASE_API_URL = 'http://brickserver.ucsd.edu:5000'; // /api/v1/appapi/Genie diff --git a/projects/sbos-playground/.gitignore b/projects/sbos-playground/.gitignore index a3aeccf..0b4ce35 100644 --- a/projects/sbos-playground/.gitignore +++ b/projects/sbos-playground/.gitignore @@ -5,6 +5,7 @@ app_static backend.zip frontend.zip static +data # Created by https://www.toptal.com/developers/gitignore/api/vscode,python # Edit at https://www.toptal.com/developers/gitignore?templates=vscode,python