Finished making dashboards

This commit is contained in:
2021-12-04 20:47:43 +00:00
parent 85460b7192
commit 9fa515cf9b
5 changed files with 278 additions and 27 deletions

View File

@ -3,13 +3,12 @@ import pathlib
from json import dump, loads
from datetime import datetime, timedelta
from glob import glob
from flask.json import jsonify
from main import app
from random import shuffle
from werkzeug.utils import secure_filename
from main import app, db
from .security.database import decrypt_find_one
def check_data_folder_exists():
if not os.path.exists(app.config['DATA_FILE_DIRECTORY']):
pathlib.Path(app.config['DATA_FILE_DIRECTORY']).mkdir(parents='True', exist_ok='True')
@ -199,4 +198,23 @@ def get_time_options():
('90', '1 hour 30 minutes'),
('120', '2 hours')
]
return time_options
return time_options
def get_datasets():
files = glob(os.path.join(app.config["DATA_FILE_DIRECTORY"],'*.json'))
data = []
if files:
for file in files:
filename = file.rsplit('/')[-1]
with open(file) as _file:
load = loads(_file.read())
_author = load['meta']['author']
author = decrypt_find_one(db.users, {'_id': _author})['username']
data_element = {
'filename': filename,
'timestamp': datetime.strptime(load['meta']['timestamp'], '%Y-%m-%d %H%M%S'),
'author': author,
'use': len(load['meta']['tests'])
}
data.append(data_element)
return data