Skip to content

Instantly share code, notes, and snippets.

@pavanKavvuri
Created April 18, 2017 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pavanKavvuri/d6d0b593dc6f77d45742e39028a02de7 to your computer and use it in GitHub Desktop.
Save pavanKavvuri/d6d0b593dc6f77d45742e39028a02de7 to your computer and use it in GitHub Desktop.
import pandas as pk
import numpy as np
from flask import Flask, jsonify
from flask import render_template
app = Flask(__name__)
df = pk.read_excel(
'/home/pavan/PAVANKUMAR/MachineLearning/CaseStudy/MLCP_VIsualize/DayFile_EntriesCount.xlsx', sheetname=0)
WeekList = []
WeekSum = []
ValueList = []
IndexList = []
e = [0, 1, 2, 3, 4, 5, 6]
Last = df['U.Date'][0]
#print Last
startIndex = 0
df['x'] = map(lambda x: str(x), df['x'])
def WeakString(t):
weekStr = []
string = "Week"
map(lambda z: weekStr.append(string + `z`), range(t))
return weekStr
llr = [0,0,0,0,0,0,0]
def fun(k):
#print (yy)
llr[k] = yy.pop()
return llr
ppp = []
for r in range(0, 5):
WeekDate = Last + np.timedelta64(1, 'W')
WeekIndex = df[df['U.Date'] == WeekDate].index.tolist()
nextIndex = WeekIndex[0]
df_2 = df[startIndex:nextIndex].sort_values(by=['DayNo'])
Last = WeekDate
startIndex = nextIndex
ww = df_2[['DayNo', 'y']]
ee = ww['DayNo'].tolist()
yy = ww['y'].tolist()
rr = ee[::-1]
# print len(ww.index.tolist())
IndexList.append((ww.index.tolist()))
x = map(fun, rr)
#print np.vstack(x[0])
ValueList.append(np.array(x[0]))
cc = df_2[['x', 'y']]
# ddr = cc.reset_index(level=None, drop=True, inplace=False, col_level=0, col_fill='').to_json(orient='records')
ddr = cc.to_json(orient='records')
WeekList.append(ddr)
WeekSum.append(cc['y'].sum())
fg = pk.DataFrame({"x": WeakString(len(WeekSum)), "y": WeekSum})
LG = fg.to_json(orient='records')
print np.column_stack(ValueList)
#print (IndexList)
print (IndexList[:])
@app.route("/getdata", methods=['POST'])
def chart():
print WeekList
print LG
return jsonify(WL=WeekList, WS=LG)
@app.route("/")
def hello():
return render_template('more.html')
if __name__ == "__main__":
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment