got a graph drawing
This commit is contained in:
parent
ff17350222
commit
b4e5c8806a
61
src/flask/chart_test.html
Normal file
61
src/flask/chart_test.html
Normal file
@ -0,0 +1,61 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Bokeh Plot</title>
|
||||
<style>
|
||||
html, body {
|
||||
box-sizing: border-box;
|
||||
display: flow-root;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-3.5.0.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
Bokeh.set_log_level("info");
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="a2129a8b-778e-490c-ba6b-d8dbb5956510" data-root-id="p1001" style="display: contents;"></div>
|
||||
|
||||
<script type="application/json" id="f9173064-b3c3-4120-bd9c-e9094743f5a6">
|
||||
{"665fa898-b488-4b51-a790-cd13b33e7a78":{"version":"3.5.0","title":"Bokeh Application","roots":[{"type":"object","name":"Figure","id":"p1001","attributes":{"height":350,"x_range":{"type":"object","name":"FactorRange","id":"p1011","attributes":{"factors":["2024-03-27","2024-03-25","2024-03-15","2024-03-13"]}},"y_range":{"type":"object","name":"DataRange1d","id":"p1003","attributes":{"start":0}},"x_scale":{"type":"object","name":"CategoricalScale","id":"p1012"},"y_scale":{"type":"object","name":"LinearScale","id":"p1013"},"title":{"type":"object","name":"Title","id":"p1004","attributes":{"text":"Pool Ph"}},"renderers":[{"type":"object","name":"GlyphRenderer","id":"p1030","attributes":{"data_source":{"type":"object","name":"ColumnDataSource","id":"p1024","attributes":{"selected":{"type":"object","name":"Selection","id":"p1025","attributes":{"indices":[],"line_indices":[]}},"selection_policy":{"type":"object","name":"UnionRenderers","id":"p1026"},"data":{"type":"map","entries":[["x",["2024-03-27","2024-03-25","2024-03-15","2024-03-13"]],["top",[7.25,7.5,7.6,7.0]]]}}},"view":{"type":"object","name":"CDSView","id":"p1031","attributes":{"filter":{"type":"object","name":"AllIndices","id":"p1032"}}},"glyph":{"type":"object","name":"VBar","id":"p1027","attributes":{"x":{"type":"field","field":"x"},"width":{"type":"value","value":0.9},"top":{"type":"field","field":"top"},"line_color":{"type":"value","value":"#1f77b4"},"fill_color":{"type":"value","value":"#1f77b4"}}},"nonselection_glyph":{"type":"object","name":"VBar","id":"p1028","attributes":{"x":{"type":"field","field":"x"},"width":{"type":"value","value":0.9},"top":{"type":"field","field":"top"},"line_color":{"type":"value","value":"#1f77b4"},"line_alpha":{"type":"value","value":0.1},"fill_color":{"type":"value","value":"#1f77b4"},"fill_alpha":{"type":"value","value":0.1},"hatch_alpha":{"type":"value","value":0.1}}},"muted_glyph":{"type":"object","name":"VBar","id":"p1029","attributes":{"x":{"type":"field","field":"x"},"width":{"type":"value","value":0.9},"top":{"type":"field","field":"top"},"line_color":{"type":"value","value":"#1f77b4"},"line_alpha":{"type":"value","value":0.2},"fill_color":{"type":"value","value":"#1f77b4"},"fill_alpha":{"type":"value","value":0.2},"hatch_alpha":{"type":"value","value":0.2}}}}}],"toolbar":{"type":"object","name":"Toolbar","id":"p1010"},"toolbar_location":null,"left":[{"type":"object","name":"LinearAxis","id":"p1019","attributes":{"ticker":{"type":"object","name":"BasicTicker","id":"p1020","attributes":{"mantissas":[1,2,5]}},"formatter":{"type":"object","name":"BasicTickFormatter","id":"p1021"},"major_label_policy":{"type":"object","name":"AllLabels","id":"p1022"}}}],"below":[{"type":"object","name":"CategoricalAxis","id":"p1014","attributes":{"ticker":{"type":"object","name":"CategoricalTicker","id":"p1015"},"formatter":{"type":"object","name":"CategoricalTickFormatter","id":"p1016"},"major_label_policy":{"type":"object","name":"AllLabels","id":"p1017"}}}],"center":[{"type":"object","name":"Grid","id":"p1018","attributes":{"axis":{"id":"p1014"},"grid_line_color":null}},{"type":"object","name":"Grid","id":"p1023","attributes":{"dimension":1,"axis":{"id":"p1019"}}}]}}]}}
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
(function() {
|
||||
const fn = function() {
|
||||
Bokeh.safely(function() {
|
||||
(function(root) {
|
||||
function embed_document(root) {
|
||||
const docs_json = document.getElementById('f9173064-b3c3-4120-bd9c-e9094743f5a6').textContent;
|
||||
const render_items = [{"docid":"665fa898-b488-4b51-a790-cd13b33e7a78","roots":{"p1001":"a2129a8b-778e-490c-ba6b-d8dbb5956510"},"root_ids":["p1001"]}];
|
||||
root.Bokeh.embed.embed_items(docs_json, render_items);
|
||||
}
|
||||
if (root.Bokeh !== undefined) {
|
||||
embed_document(root);
|
||||
} else {
|
||||
let attempts = 0;
|
||||
const timer = setInterval(function(root) {
|
||||
if (root.Bokeh !== undefined) {
|
||||
clearInterval(timer);
|
||||
embed_document(root);
|
||||
} else {
|
||||
attempts++;
|
||||
if (attempts > 100) {
|
||||
clearInterval(timer);
|
||||
console.log("Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing");
|
||||
}
|
||||
}
|
||||
}, 10, root)
|
||||
}
|
||||
})(window);
|
||||
});
|
||||
};
|
||||
if (document.readyState != "loading") fn();
|
||||
else document.addEventListener("DOMContentLoaded", fn);
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -11,7 +11,36 @@ class PoolCharts():
|
||||
|
||||
def ph_line_chart(self):
|
||||
ph = self.db.pool_db
|
||||
query = {}
|
||||
data = ph.find({}).sort("date", -1).limit(10)
|
||||
data = ph.find({}).sort("date", -1).limit(50)
|
||||
dates = []
|
||||
ph_list = []
|
||||
date_count = {}
|
||||
for record in data:
|
||||
print (f'{record["date"]},{record["ph"]}')
|
||||
if record["ph"] != "None":
|
||||
if record["date"] not in dates:
|
||||
print("new date record")
|
||||
dates.append(record["date"])
|
||||
ph_list.append(float(record["ph"]))
|
||||
print (dates)
|
||||
print (ph_list)
|
||||
else:
|
||||
if record["date"] in date_count:
|
||||
date_count[record["date"]] += 1
|
||||
else:
|
||||
date_count[record["date"]] = 2
|
||||
print(len(ph_list))
|
||||
current_ph = ph_list[len(ph_list) - 1]
|
||||
ph_list[len(ph_list) - 1] = (float(record["ph"]) + current_ph) / date_count[record["date"]]
|
||||
|
||||
print(dates)
|
||||
print(ph_list)
|
||||
|
||||
p = figure(x_range=dates, height=350, title="Pool Ph",
|
||||
toolbar_location=None, tools="")
|
||||
|
||||
p.vbar(x=dates, top=ph_list, width=0.9)
|
||||
|
||||
p.xgrid.grid_line_color = None
|
||||
p.y_range.start = 0
|
||||
|
||||
show(p)
|
||||
|
Loading…
x
Reference in New Issue
Block a user