10
10
send_from_directory , url_for , session )
11
11
12
12
app = Flask (__name__ )
13
- app .secret_key = os .urandom (24 )
13
+ # app.secret_key = os.urandom(24)
14
14
15
- conn = pymssql .connect (host = 'bonjour.database.windows.net' ,user = 'zander' ,password = 'KB24ts1989' ,database = 'Mavs' )
16
- cur = conn .cursor ()
15
+ # conn = pymssql.connect(host='bonjour.database.windows.net' ,user='zander' ,password = 'KB24ts1989',database='Mavs')
16
+ # cur = conn.cursor()
17
17
#================================================================================================
18
18
# # Create a blob client using the local simulator
19
19
# try:
@@ -36,128 +36,128 @@ def index():
36
36
return render_template ('index.html' )
37
37
38
38
39
- @app .route ('/test' )
40
- def test ():
41
- SQL_QUERY = """
42
- SELECT
43
- TOP 5 c.CustomerID,
44
- c.CompanyName,
45
- COUNT(soh.SalesOrderID) AS OrderCount
46
- FROM
47
- SalesLT.Customer AS c
48
- LEFT OUTER JOIN SalesLT.SalesOrderHeader AS soh ON c.CustomerID = soh.CustomerID
49
- GROUP BY
50
- c.CustomerID,
51
- c.CompanyName
52
- ORDER BY
53
- OrderCount DESC;
54
- """
55
- cur .execute (SQL_QUERY )
56
- data = cur .fetchall ()
57
- print ('Request for test page received' )
58
- return render_template ('test.html' , data = data )
59
-
60
-
61
- @app .route ('/assignment1' )
62
- def assignment1 ():
63
- data_file_path = os .path .join (app .root_path , 'static' , 'data' , 'people.csv' )
64
- data = pd .read_csv (data_file_path )
65
- print ('Request for assignment1 page received' )
66
-
67
- return render_template ('assignment1.html' , contain_content = False , table_content = list (data .values .tolist ()), titles = data .columns .values )
68
-
69
-
70
- @app .route ('/assignment2' )
71
- def assignment2 ():
39
+ # @app.route('/test')
40
+ # def test():
41
+ # SQL_QUERY = """
42
+ # SELECT
43
+ # TOP 5 c.CustomerID,
44
+ # c.CompanyName,
45
+ # COUNT(soh.SalesOrderID) AS OrderCount
46
+ # FROM
47
+ # SalesLT.Customer AS c
48
+ # LEFT OUTER JOIN SalesLT.SalesOrderHeader AS soh ON c.CustomerID = soh.CustomerID
49
+ # GROUP BY
50
+ # c.CustomerID,
51
+ # c.CompanyName
52
+ # ORDER BY
53
+ # OrderCount DESC;
54
+ # """
55
+ # cur.execute(SQL_QUERY)
56
+ # data = cur.fetchall()
57
+ # print('Request for test page received')
58
+ # return render_template('test.html', data=data)
59
+
60
+
61
+ # @app.route('/assignment1')
62
+ # def assignment1():
63
+ # data_file_path = os.path.join(app.root_path, 'static', 'data', 'people.csv')
64
+ # data = pd.read_csv(data_file_path)
65
+ # print('Request for assignment1 page received')
66
+
67
+ # return render_template('assignment1.html', contain_content=False, table_content=list(data.values.tolist()), titles=data.columns.values)
68
+
69
+
70
+ # @app.route('/assignment2')
71
+ # def assignment2():
72
72
73
- print ('Request for assignment1 page received' )
74
- data = None
75
- headers = None
76
- return render_template ('assignment2.html' , contain_content = False , table_content = data , titles = headers )
77
-
78
-
79
- @app .route ('/a1-upload' , methods = ['POST' ])
80
- def upload ():
81
- if request .method == 'POST' :
82
- f = request .files ['file' ]
83
- file_path = os .path .join (app .root_path , 'uploads' , f .filename )
84
- session ['file_path' ] = file_path
85
- f .save (file_path )
86
-
87
- data = pd .read_csv (file_path )
88
-
89
- for idx , (_ , row ) in enumerate (data .iterrows ()):
90
- sql_query = f"INSERT INTO dbo.Quiz1 VALUES ('{ idx } ', "
91
- for element in row :
92
- if pd .isna (element ):
93
- element = 'NULL'
94
- sql_query += f"{ element } ,"
95
- else :
96
- sql_query += f"'{ element } ',"
97
- sql_query = sql_query [:- 1 ] + ");"
98
- print (sql_query )
99
- cur .execute (sql_query )
100
-
101
- conn .commit ()
102
- return render_template ('assignment1.html' , contain_content = False , table_content = list (data .values .tolist ()), titles = data .columns .values )
103
-
104
-
105
- @app .route ('/a1-searchbyname' , methods = ['POST' , 'GET' ])
106
- def a1_searchbyname ():
107
- name = request .form .get ('queryName' )
108
- data_file_path = session .get ('file_path' )
109
- data = pd .read_csv (data_file_path )
110
- query_data = data .loc [data ['name' ] == name ]
111
- print (name , query_data )
112
- for col in query_data .columns :
113
- query_data [col ].fillna (f"no { col } available" , inplace = True )
114
- return render_template ('assignment1.html' , contain_content = True , table_content = list (query_data .values .tolist ()), titles = query_data .columns .values )
115
-
116
- @app .route ('/a1-searchbycostrange' , methods = ['POST' , 'GET' ])
117
- def a1_searchbycostrange ():
118
- min_cost = request .form .get ('minCost' )
119
- max_cost = request .form .get ('maxCost' )
120
- data_file_path = session .get ('file_path' )
121
- data = pd .read_csv (data_file_path )
122
- query_data = data .loc [(data ['cost' ].astype (float ) >= int (min_cost )) & (data ['cost' ].astype (float ) <= int (max_cost ))]
123
- print (min_cost , max_cost , query_data )
124
- for col in query_data .columns :
125
- query_data [col ].fillna (f"no { col } available" , inplace = True )
126
- return render_template ('assignment1.html' , contain_content = True , table_content = list (query_data .values .tolist ()), titles = query_data .columns .values )
127
-
128
-
129
- @app .route ('/a2-searchbymag' , methods = ['POST' , 'GET' ])
130
- def a2_searchbymag ():
131
- min_mag = request .form .get ('minMag' )
132
- max_mag = request .form .get ('maxMag' )
133
- back_day = request .form .get ('backDay' )
73
+ # print('Request for assignment1 page received')
74
+ # data = None
75
+ # headers = None
76
+ # return render_template('assignment2.html', contain_content=False, table_content=data, titles=headers)
77
+
78
+
79
+ # @app.route('/a1-upload', methods = ['POST'])
80
+ # def upload():
81
+ # if request.method == 'POST':
82
+ # f = request.files['file']
83
+ # file_path = os.path.join(app.root_path, 'uploads', f.filename)
84
+ # session['file_path'] = file_path
85
+ # f.save(file_path)
86
+
87
+ # data = pd.read_csv(file_path)
88
+
89
+ # for idx, (_, row) in enumerate(data.iterrows()):
90
+ # sql_query = f"INSERT INTO dbo.Quiz1 VALUES ('{idx}', "
91
+ # for element in row:
92
+ # if pd.isna(element):
93
+ # element = 'NULL'
94
+ # sql_query += f"{element},"
95
+ # else:
96
+ # sql_query += f"'{element}',"
97
+ # sql_query = sql_query[:-1] + ");"
98
+ # print(sql_query)
99
+ # cur.execute(sql_query)
100
+
101
+ # conn.commit()
102
+ # return render_template('assignment1.html', contain_content=False, table_content=list(data.values.tolist()), titles=data.columns.values)
103
+
104
+
105
+ # @app.route('/a1-searchbyname', methods = ['POST', 'GET'])
106
+ # def a1_searchbyname():
107
+ # name = request.form.get('queryName')
108
+ # data_file_path = session.get('file_path')
109
+ # data = pd.read_csv(data_file_path)
110
+ # query_data = data.loc[data['name'] == name]
111
+ # print(name, query_data)
112
+ # for col in query_data.columns:
113
+ # query_data[col].fillna(f"no {col} available", inplace=True)
114
+ # return render_template('assignment1.html', contain_content=True, table_content=list(query_data.values.tolist()), titles=query_data.columns.values)
115
+
116
+ # @app.route('/a1-searchbycostrange', methods = ['POST', 'GET'])
117
+ # def a1_searchbycostrange():
118
+ # min_cost = request.form.get('minCost')
119
+ # max_cost = request.form.get('maxCost')
120
+ # data_file_path = session.get('file_path')
121
+ # data = pd.read_csv(data_file_path)
122
+ # query_data = data.loc[(data['cost'].astype(float) >= int(min_cost)) & (data['cost'].astype(float) <= int(max_cost))]
123
+ # print(min_cost, max_cost, query_data)
124
+ # for col in query_data.columns:
125
+ # query_data[col].fillna(f"no {col} available", inplace=True)
126
+ # return render_template('assignment1.html', contain_content=True, table_content=list(query_data.values.tolist()), titles=query_data.columns.values)
127
+
128
+
129
+ # @app.route('/a2-searchbymag', methods = ['POST', 'GET'])
130
+ # def a2_searchbymag():
131
+ # min_mag = request.form.get('minMag')
132
+ # max_mag = request.form.get('maxMag')
133
+ # back_day = request.form.get('backDay')
134
134
135
- # query header from database
136
- SQL_QUERY_TITLE = """select COLUMN_NAME
137
- from INFORMATION_SCHEMA.COLUMNS
138
- where TABLE_NAME='earthquakes';"""
139
- cur .execute (SQL_QUERY_TITLE )
140
- headers = cur .fetchall ()
135
+ # # query header from database
136
+ # SQL_QUERY_TITLE = """select COLUMN_NAME
137
+ # from INFORMATION_SCHEMA.COLUMNS
138
+ # where TABLE_NAME='earthquakes';"""
139
+ # cur.execute(SQL_QUERY_TITLE)
140
+ # headers = cur.fetchall()
141
141
142
- # query data from database
143
- # Get today's datetime
144
- today = datetime .datetime .now ()
145
-
146
- # Modify the query to query for the latest back_day data
147
- SQL_QUERY = f"""
148
- SELECT
149
- *
150
- FROM
151
- ass1.earthquakes
152
- WHERE
153
- mag >= { min_mag } AND mag <= { max_mag } AND time >= DATEADD(day, -{ back_day } , GETDATE());
154
- """
155
- cur .execute (SQL_QUERY )
156
- data = cur .fetchall ()
157
- print (type (headers ))
158
- print (type (data ))
159
-
160
- return render_template ('assignment2.html' , contain_content = True , table_content = data , titles = headers )
142
+ # # query data from database
143
+ # # Get today's datetime
144
+ # today = datetime.datetime.now()
145
+
146
+ # # Modify the query to query for the latest back_day data
147
+ # SQL_QUERY = f"""
148
+ # SELECT
149
+ # *
150
+ # FROM
151
+ # ass1.earthquakes
152
+ # WHERE
153
+ # mag >= {min_mag} AND mag <= {max_mag} AND time >= DATEADD(day, -{back_day}, GETDATE());
154
+ # """
155
+ # cur.execute(SQL_QUERY)
156
+ # data = cur.fetchall()
157
+ # print(type(headers))
158
+ # print(type(data))
159
+
160
+ # return render_template('assignment2.html', contain_content=True, table_content=data, titles=headers)
161
161
162
162
163
163
@app .route ('/favicon.ico' )
0 commit comments