-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
43 lines (30 loc) · 1011 Bytes
/
utils.py
File metadata and controls
43 lines (30 loc) · 1011 Bytes
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
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import os
from config import app
def uploadData(file, loc, file_name):
if not os.path.exists(loc):
os.makedirs(loc)
new_file_path = os.path.join(loc, file_name)
if os.path.exists(new_file_path):
os.remove(new_file_path)
file.seek(0)
file.save(new_file_path)
relative_path = os.path.relpath(new_file_path, start='static').replace(os.path.sep,'/')
return relative_path
def plot_graph(data,file_name):
labels, values = zip(*data)
plt.bar(labels,values)
plt.xlabel("Song Titles")
plt.ylabel("Total Streams")
plt.title('Top 10 Songs based on total streams')
loc = app.config['DASHBOARD']
if not os.path.exists(loc):
os.makedirs(loc)
new_file_path = os.path.join(loc, file_name)
if os.path.exists(new_file_path):
os.remove(new_file_path)
plt.savefig(new_file_path)
plt.close()
return new_file_path.replace(os.path.sep,'/')