diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index adc3fe61..57c1491b 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -95,7 +95,7 @@ def get_chart(end_point, chart_data, debug=False): headers = {'authorization':"Bearer {token}".format(token=settings.ROWSANDALL_CHARTS_TOKEN)} try: response = requests.post(url, json=chart_data, headers=headers) - except ConnectionError as err: + except Error as err: if debug: print("Chart Server Error") print(err) @@ -2651,8 +2651,8 @@ def interactive_otwcpchart(powerdf, promember=0, rowername="", r=None, fitpowerfair = 0*fitpower fitpoweraverage = 0*fitpower - sourcecomplex = ColumnDataSource( - data=dict( + + fit_data = pd.DataFrame(dict( CP=fitpower, CPmax=ratio*fitpower, duration=fitt/60., @@ -2664,94 +2664,19 @@ def interactive_otwcpchart(powerdf, promember=0, rowername="", r=None, fitpowerfair=fitpowerfair, fitpoweraverage=fitpoweraverage, # url = urls, - ) - ) + )) - # making the plot - plot = figure(tools=TOOLS, x_axis_type=x_axis_type, - width=900, - toolbar_location="above", - toolbar_sticky=False) - # add watermark - watermarkurl = "/static/img/logo7.png" - watermarkrange = Range1d(start=0, end=1) - watermarkalpha = 0.6 - watermarky = 0.01 - watermarkw = 184 - watermarkh = 35 - watermarkanchor = 'bottom_right' - plot.extra_y_ranges = {"watermark": watermarkrange} - #plot.sizing_mode = 'scale_both' - - plot.image_url([watermarkurl], 1.8*max(thesecs), watermarky, - watermarkw, watermarkh, - global_alpha=watermarkalpha, - w_units='screen', - h_units='screen', - anchor=watermarkanchor, - dilate=True, - y_range_name="watermark", - ) - - plot.circle('Deltaminutes', 'CP', source=source, fill_color='red', size=15, - legend_label='Power Data') - plot.xaxis.axis_label = "Duration (minutes)" - plot.yaxis.axis_label = "Power (W)" - - plot.y_range = Range1d(0, 1.5*max(theavpower)) - plot.x_range = Range1d(0.5*min(thesecs)/60., 2*max(thesecs)/60.) - plot.legend.orientation = "vertical" if not title: title = "Critical Power for "+rowername - plot.title.text = title + + chart_dict = { + 'data': powerdf2.to_dict("records"), + 'fitdata': fit_data.to_dict("records"), + 'title': title, + } - plot.xaxis[0].formatter = PrintfTickFormatter(format="%5f") - - - hover = plot.select(dict(type=HoverTool)) - - hover.tooltips = OrderedDict([ - ('Duration ', '@ftime'), - ('Power (W)', '@CP{int}'), - ('Power (W) upper', '@CPmax{int}'), - ('Workout', '@workout'), - ('World Class', '@fitpowerwc{int}') - ]) - - hover.mode = 'mouse' - - taptool = plot.select(type=TapTool) - taptool.callback = OpenURL(url='@url') - - plot.line('duration', 'CP', source=sourcecomplex, legend_label="CP Model", - color='green') - - plot.line('duration', 'CPmax', source=sourcecomplex, legend_label="CP Model", - color='red') - - if p1wc is not None: # pragma: no cover - plot.line('duration', 'fitpowerwc', source=sourcecomplex, - legend_label="Gold Medal Standard", - color='darkgoldenrod', line_dash='dotted') - - plot.line('duration', 'fitpowerexcellent', source=sourcecomplex, - legend_label="90% percentile", - color='goldenrod', line_dash='dotted') - - plot.line('duration', 'fitpowergood', source=sourcecomplex, - legend_label="75% percentile", - color='sandybrown', line_dash='dotted') - - plot.line('duration', 'fitpowerfair', source=sourcecomplex, - legend_label="50% percentile", - color='rosybrown', line_dash='dotted') - - plot.line('duration', 'fitpoweraverage', source=sourcecomplex, - legend_label="25% percentile", - color='tan', line_dash='dotted') - - script, div = components(plot) + script, div = get_chart("/cp", chart_dict) return [script, div, p1, ratio, message] diff --git a/rowers/views/analysisviews.py b/rowers/views/analysisviews.py index 57965e76..2ebdbb72 100644 --- a/rowers/views/analysisviews.py +++ b/rowers/views/analysisviews.py @@ -618,11 +618,11 @@ def histodata(workouts, options): extratitle=extratitle, workmin=workmin, workmax=workmax) - print(div) return(script, div) def cpdata(workouts, options): + start = timezone.now() userid = options['userid'] cpfit = options['cpfit'] cpoverlay = options['cpoverlay']