def report(): from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas assert_data() df = session['df'] # For example, user could sumbit 2013-10:2014-02 but we need to make this # into '2013-10':'2014-10' if 'idx' in session.keys() and len(session['idx'])>0: session['_filter'] idx = session['idx'] if idx.find(':') > -1: lidx, ridx = idx.split(':') df = df[lidx:ridx] else: df = df[idx] startDate = session['startDate'] endDate = session['endDate'] if startDate != '' and endDate != '': # Filter the data frame to only be a subset of full time range startDate = pandas.Timestamp(startDate) endDate = pandas.Timestamp(endDate) df = df[startDate:endDate] figures = [] if 'tags' in session.keys() and len(session['tags'])>0: figures += GBA.density_cloud_by_tags(df, session['tags'], silent=True) if 'pnodes' in session.keys() and len(session['pnodes'])>0: import matplotlib.pylab as plt plt.ioff() pnodes = session['pnodes'] df = GBA.price_at_pnodes(df, pnodes) cols = ['COST',] + ['pnode_'+p for p in pnodes] figures.append(df[cols].plot().figure) figures.append(df[cols].cumsum().plot().figure) session.drop('tags') s = '<h1>Figures</h1>' figures_rendered = [] for n, fig in enumerate(figures): s+='<img src="plt/%d.png" /><br />' % n canvas=FigureCanvas(fig) png_output = StringIO() canvas.print_png(png_output) figures_rendered.append(png_output.getvalue()) session['figures'] = figures_rendered s += '<p><a href="/dashboard">Back to dashboard</a></p><br /><br />' return s
def report(): from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas assert_data() df = session['df'] if 'idx' in session.keys() and len(session['idx'])>0: idx = session['idx'] if idx.find(':') > -1: lidx, ridx = idx.split(':') df = df[lidx:ridx] else: df = df[idx] figures = [] if 'tags' in session.keys() and len(session['tags'])>0: figures += GBA.density_cloud_by_tags(df, session['tags'], silent=True) if 'pnodes' in session.keys() and len(session['pnodes'])>0: import matplotlib.pylab as plt plt.ioff() pnodes = session['pnodes'] df = GBA.price_at_pnodes(df, pnodes) cols = ['COST',] + ['pnode_'+p for p in pnodes] figures.append(df[cols].plot().figure) figures.append(df[cols].cumsum().plot().figure) session.drop('tags') s = '<h1>Figures</h1>' figures_rendered = [] for n, fig in enumerate(figures): s+='<img src="plt/%d.png" /><br />' % n canvas=FigureCanvas(fig) png_output = StringIO() canvas.print_png(png_output) figures_rendered.append(png_output.getvalue()) session['figures'] = figures_rendered s += '<p><a href="/dashboard">Back to dashboard</a></p><br /><br />' return s
def drop_dataframe(): for k in session.keys(): session.drop(k) return redirect(url_for('read_usage'))
def drop_dataframe(): for k in session.keys(): session.drop(k) return "Your data has been removed from the server"