Linking issue between python script, flask framework, and html -
i having odd issue transferring correct data python script graph (highcharts) in html. using flask web framework , ubuntu server. have 2 identical html webpages in structure differ in data passed them (data originates 2 separate dbs). each webpage have multiple graphs (highcharts), 1 particular graph on second webpage returns incorrect data points. returns data points intended first webpage. issue not show when test on local host, when running on server (yes have correctly copied files server). might not able pinpoint issue, ideas in terms of troubleshooting or reasons why ubuntu server wouldn't refresh welcome. apologize if question unclear, isn't easiest problem convey through text. here example code...i run scripts in python on server , relayed html through flask init file.
python script
import os, sqlite3, datetime, pandas pd, numpy np project_root = os.path.dirname(os.path.realpath(__file__)) database = os.path.join(project_root, 'folder', 'my.db') conn = sqlite3.connect(database) c = conn.cursor() averages_lm = (pd.read_sql("select avg(points_for) points_for, avg(points_against) points_against, \ avg(num_moves) moves, avg(num_trades) trades, avg(wins) wins, avg(losses) losses, \ manager_name standings curweek > 14 group manager_name", conn)) averages_ex = (pd.read_sql("select avg(points_for) points_for, avg(points_against) points_against, \ avg(num_moves) moves, avg(num_trades) trades, avg(wins) wins, avg(losses) losses, \ manager_name standings_ex curweek > 14 group manager_name", conn)) def averages_lm(): global averages_lm return averages_lm def averages_ex(): global averages_ex return averages_ex
init file
from flask import flask, render_template, session, request, jsonify, json import requests import os, sys project_root = os.path.dirname(os.path.realpath(__file__)) sys.path.append(os.path.join(project_root, 'yahoo_fantasy')) stats_fantasy import * app = flask(__name__) @app.route('/html1') def lowermerion(): averages = averages_lm() len_averages = len(averages['managers']) return render_template("html-1.html", title="title", averages=averages, len_averages=len_averages) @app.route('/html2') def simgachi(): averages = averages_ex() len_averages = len(averages['managers']) return render_template("html-2.html", title="title", averages=averages, len_averages=len_averages) if __name__ == "__main__": app.run(debug=true)
html (snippet)
<script> $(function () { $('#chart-4').highcharts({ chart: { type: 'column' }, title: { text: 'career averages per season ' }, subtitle: { text: 'regular season' }, xaxis: { categories: [ {% in range(len_managers) %} '{{ averages.manager_name[i] }}', {% endfor %} ], crosshair: true }, yaxis: { min: 0, title: { text: 'total per season' } }, tooltip: { headerformat: '<span style="font-size:10px">{point.key}</span><table>', pointformat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' + '<td style="padding:0"><b>{point.y:.1f} pts</b></td></tr>', footerformat: '</table>', shared: true, usehtml: true }, plotoptions: { column: { pointpadding: 0.2, borderwidth: 0 } }, series: [{ name: 'avg wins', data: [{% in range(len_managers) %} {{ averages.wins[i] }}, {% endfor %}] }, { name: 'avg losses', data: [{% in range(len_managers) %} {{ averages.losses[i] }}, {% endfor %}] }, { name: 'avg moves', data: [{% in range(len_managers) %} {{ averages.moves[i] }}, {% endfor %}] }, { name: 'avg trades', data: [{% in range(len_managers) %} {{ averages.trades[i] }}, {% endfor %}] }, { name: 'avg draft pick', data: [{% in range(len_managers) %} {{ draft_pos.pick[i] }}, {% endfor %}] }, ] }); }); </script>
again, odd going on...as script change when modify text graphs, whatever reason data being passed data function averages_lm(). think incorrectly passed data beginning , doesn't seem want change.
after first @ code, seems returning same datas in 2 views. line:
averages = averages_lm()
is same on both view, shouldn't 1 of them
averages = averages_ex()
?
also, if 2 html templates identical, don't need create 2 separate pages, can have 1 template both views, content of template depends on data pass view.
Comments
Post a Comment