From f935db347fb78d937b69c4d4ce295492bdafacca Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Thu, 7 Mar 2024 12:41:43 +0100 Subject: [PATCH] initial version histo chart --- rowers/interactiveplots.py | 28 ++++++++++++++++--- rowers/templates/histo.html | 31 +++++++++++----------- rowers/templates/user_analysis_select.html | 7 ++--- rowers/urls.py | 1 + rowers/utils.py | 7 +---- rowers/views/analysisviews.py | 1 + rowers/views/otherviews.py | 11 ++++++++ static/css/rowsandall2.css | 3 +++ 8 files changed, 62 insertions(+), 27 deletions(-) diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index ad456ad2..5356755c 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -88,16 +88,23 @@ from rowers.serializers import * activate(settings.TIME_ZONE) thetimezone = get_current_timezone() -def get_chart(end_point, chart_data): - +def get_chart(end_point, chart_data, debug=False): + if debug: + print(chart_data) url = settings.ROWSANDALL_CHARTS_URL+end_point headers = {'authorization':"Bearer {token}".format(token=settings.ROWSANDALL_CHARTS_TOKEN)} try: response = requests.post(url, json=chart_data, headers=headers) - except: + except ConnectionError as err: + if debug: + print("Chart Server Error") + print(err) script = '' div = 'Chart Server Error' return script, div + + if debug: + print("Status Code",response.status_code) if response.status_code == 200: script = response.json()['script'] @@ -108,6 +115,16 @@ def get_chart(end_point, chart_data): return script, div +# Example for 3D +def filmdeaths(): + data = pd.read_csv("~/Downloads/filmdeathcounts.csv") + + chart_data = data.to_dict("records") + chart_data_dict = {"data": chart_data} + + script, div = get_chart("/filmdeaths", chart_data_dict) + return script, div + # Example for BokehJS def sleep(): data = { @@ -2090,6 +2107,11 @@ def interactive_histoall(theworkouts, histoparam, includereststrokes, histopwr = histopwr[histopwr > yaxminima[histoparam]] histopwr = histopwr[histopwr < yaxmaxima[histoparam]] + data_dict = {"data": histopwr.tolist()} + script, div = get_chart("/histogram", data_dict, debug=False) + + return script, div + plot = figure(tools=TOOLS, width=900, toolbar_sticky=False, toolbar_location="above" diff --git a/rowers/templates/histo.html b/rowers/templates/histo.html index a46d9d5e..a3bf496f 100644 --- a/rowers/templates/histo.html +++ b/rowers/templates/histo.html @@ -6,6 +6,7 @@ {% block main %} + diff --git a/rowers/templates/user_analysis_select.html b/rowers/templates/user_analysis_select.html index dfc64a46..9ebbb5b9 100644 --- a/rowers/templates/user_analysis_select.html +++ b/rowers/templates/user_analysis_select.html @@ -14,6 +14,7 @@ } +