-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
118 lines (96 loc) · 2.96 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
###############################################
# Import Dependencies
###############################################
from flask import Flask, render_template, jsonify, request
from os import environ
import json
import os
from config import CSV_FILE_URL
import pandas as pd
###############################################
# Flask Setup & Access Environ Variables
###############################################
# Creating new application of the flask module
app = Flask(__name__)
csv_file_path = environ.get('CSV_FILE_PATH') or CSV_FILE_URL
###############################################
# Flask Routes
###############################################
# route to fetch page data
@app.route('/fetchpagedata/<pageNumber>')
def fetchpagedata(pageNumber):
# setting number of rows per page
nPerPage = 100
# finding first row number for current page
skipCount = ( ( int(pageNumber) - 1 ) * nPerPage ) + 1 if (int(pageNumber) > 0) else 1
header_list = ["Time",
"V1",
"V2",
"V3",
"V4",
"V5",
"V6",
"V7",
"V8",
"V9",
"V10",
"V11",
"V12",
"V13",
"V14",
"V15",
"V16",
"V17",
"V18",
"V19",
"V20",
"V21",
"V22",
"V23",
"V24",
"V25",
"V26",
"V27",
"V28",
"Amount",
"Class"]
# Fetch data from database
df = pd.read_csv(csv_file_path,
delimiter = ',',
names = header_list,
skiprows = skipCount,
nrows = nPerPage)
# Convert dataframe to array of dictionary
data = df.to_dict('records')
return jsonify(data)
# Routes that will render html templates
@app.route('/')
def index():
return render_template('index.html')
@app.route('/navbar')
def navbar():
return render_template('navbar.html')
@app.route('/footer')
def footer():
return render_template('footer.html')
@app.route('/data')
def data():
return render_template('data.html')
@app.route('/research')
def research():
return render_template('research.html')
@app.route('/predictions')
def predictions():
return render_template('predictions.html')
@app.route('/conclusions')
def conclusions():
return render_template('conclusions.html')
@app.route('/about')
def about():
return render_template('about.html')
###############################################
# Run the Flask Application
###############################################
# Spin-up the Flask Application
if __name__ == "__main__":
app.run(debug=True)