Skip to content

Commit

Permalink
New monitoring page on port 80 (openaps#863)
Browse files Browse the repository at this point in the history
* Automate the steps to install flask as a service

Automate the steps to install flask as a service so can monitoring your rig OFFLINE with an Offline web page

IPHONE USERS To access this from an iphone browser, enter something like the following: http://172.20.10:5000

ex : http://IP_address__rig:5000

* Automate the steps to install flask as a service (openaps#839)

Automate the steps to install flask as a service so can monitoring your rig OFFLINE with an Offline web page

IPHONE USERS To access this from an iphone browser, enter something like the following: http://172.20.10:5000

ex : http://IP_address__rig:5000

* use port 8080 for flask to avoid conflicts

* add meta refresh and title

* Change the port of offline webpage to 5001

* Create new webpage offline to monitoring the rig. Change the port of FLASK to port 80.

* Create new webpage offline to monitoring the rig. Change the port of FLASK to port 80.

* should we add a flask.log? (openaps#850)

* added check for custom OPENAPSDIR enviornment var (openaps#851)

* added check for custom OPENAPSDIR enviornment var

* change environment variable to OPENAPS_DIR

* convert tabs to spaces

* show Sensitivity Ratio in topbox instead of BASAL T

* Add indexError.html to handle JSON Value error (openaps#848)

* do openaps#849 manually

* clearer error message

* allow smartphones to zoom out to see the whole page un-scrunched

* catch IOErrors too

* make BG black

* improve column layout

* display 4h past and future

* use suggested predBGs, not enacted

* display Temp Targets

* calculate and display BG delta

* syntax

* print BG delta correctly

* shorter chart forecast legends

* 70% scale; units

* more readability improvements
  • Loading branch information
scottleibrand authored Dec 11, 2017
1 parent 959981d commit 6b1c6ca
Show file tree
Hide file tree
Showing 11 changed files with 19,107 additions and 41 deletions.
2 changes: 1 addition & 1 deletion bin/oref0-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ if [[ $REPLY =~ ^[Yy]$ ]]; then
(crontab -l; crontab -l | grep -q "oref0-pushover" || echo "* * * * * cd $directory && oref0-pushover $PUSHOVER_TOKEN $PUSHOVER_USER 2>&1 >> /var/log/openaps/pushover.log" ) | crontab -
fi
(crontab -l; crontab -l | grep -q "cd $directory && oref0-version --check-for-updates" || echo "0 * * * * cd $directory && oref0-version --check-for-updates > /tmp/oref0-updates.txt") | crontab -
(crontab -l; crontab -l | grep -q "flask run" || echo "@reboot cd ~/src/oref0/www && export FLASK_APP=app.py && flask run -p 8080 --host=0.0.0.0" | tee -a /var/log/openaps/flask.log) | crontab -
(crontab -l; crontab -l | grep -q "flask run" || echo "@reboot cd ~/src/oref0/www && export FLASK_APP=app.py && flask run -p 80 --host=0.0.0.0" | tee -a /var/log/openaps/flask.log) | crontab -

crontab -l | tee $HOME/crontab.txt
fi
Expand Down
60 changes: 40 additions & 20 deletions www/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,52 @@ def index():
except KeyError:
myopenaps_dir = "/root/myopenaps/"
data=dict()
data['hostname']=socket.gethostname()
glucose = json.load(open(os.path.join(myopenaps_dir, "monitor/glucose.json")))
data['glucose']=glucose[0]
# TODO: calculate delta properly when glucose[1] isn't 5m ago
delta=glucose[0]['glucose']-glucose[1]['glucose']
tick=""
if delta >= 0:
tick += "+"
tick += str(delta)
data['tick']=tick
iob = json.load(open(os.path.join(myopenaps_dir, "monitor/iob.json")))
data['iob'] = iob[0]
data['meal'] = json.load(open(os.path.join(myopenaps_dir, "monitor/meal.json")))
data['suggested'] = json.load(open(os.path.join(myopenaps_dir, "enact/suggested.json")))
data['enacted'] = json.load(open(os.path.join(myopenaps_dir, "enact/enacted.json")))
data['temp_basal'] = json.load(open(os.path.join(myopenaps_dir, "monitor/temp_basal.json")))
# print(data)
return render_template('index.html', data=data )
# return "Hello World!"
try:
data['hostname']=socket.gethostname()
data['glucose'] = json.load(open(os.path.join(myopenaps_dir, "monitor/glucose.json")))
iob = json.load(open(os.path.join(myopenaps_dir, "monitor/iob.json")))
data['iob'] = iob[0]
data['battery'] = json.load(open(os.path.join(myopenaps_dir, "monitor/battery.json")))
data['edison_battery'] = json.load(open(os.path.join(myopenaps_dir, "monitor/edison-battery.json")))
data['meal'] = json.load(open(os.path.join(myopenaps_dir, "monitor/meal.json")))

data['suggested'] = json.load(open(os.path.join(myopenaps_dir, "enact/suggested.json")))
data['smb_suggested'] = json.load(open(os.path.join(myopenaps_dir, "enact/smb-suggested.json")))

data['enacted'] = json.load(open(os.path.join(myopenaps_dir, "enact/enacted.json")))
data['smb_enacted'] = json.load(open(os.path.join(myopenaps_dir, "enact/smb-enacted.json")))

data['temp_basal'] = json.load(open(os.path.join(myopenaps_dir, "monitor/temp_basal.json")))
except ValueError:
return render_template('indexError.html', data=data )
except IOError:
return render_template('indexError.html', data=data )
else:
return render_template('index.html', data=data )

@app.route("/suggested")
def suggested():
json_url = os.path.join("/root/myopenaps/enact/suggested.json")
data = json.load(open(json_url))
return jsonify(data)

@app.route("/enacted")
def enacted():
#SITE_ROOT = os.path.realpath(os.path.dirname(__file__))
json_url = os.path.join("/root/myopenaps/enact/enacted.json")
data = json.load(open(json_url))
return jsonify(data)

@app.route("/glucose")
def glucose():
json_url = os.path.join("/root/myopenaps/monitor/glucose.json")
data = json.load(open(json_url))
return jsonify(data)

@app.route("/temptargets")
def temptargets():
json_url = os.path.join("/root/myopenaps/settings/temptargets.json")
data = json.load(open(json_url))
return jsonify(data)

if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')
7 changes: 7 additions & 0 deletions www/static/css/bootstrap.min.css

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions www/static/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
body {
background: white;
color: black;
}
.row{margin: 10px}
.bg{font-size:40px;font-weight:bold}
.delta,.timeago-bg{font-size:14px;}

.topbox{
font-size:20px;
background-color:#cccccc;
border-radius:8px;
margin: 13px 0 10px;
}

.box2{
background-color:#cccccc;
border-radius:8px;
margin:0px 10px;
}

.delta-box{
padding:30px 0 0 0;
}

@media (max-device-width:768px) {
.delta-box{
padding:0;
}
}
Loading

0 comments on commit 6b1c6ca

Please sign in to comment.