def get_session_item_count(sessionID): if sessionID == "0": print("SessionID: 0") session_data = dbh.get_all_items() else: session_data = dbh.get_session_data(sessionID) # Count items of types items = {"Nikotin": 0, "Annat": 0} for item in session_data: itemType = item[0] if itemType not in items.keys(): items[itemType] = 1 else: items[itemType] += 1 print(items) return(items)
def download_with_filename(sessionID, filename): """ To download the whole dataset as a csv file If sessionID is given, should return only specific session data otherwise returns full Item database. """ if int(sessionID) > 0: items = dbh.get_session_data(sessionID) else: items = dbh.get_all_items() # Prepare csv file columns = [["type", "latitude", "longitude", "datetime", "sessionID"]] csvList = columns + items with open(THIS_FOLDER + "/tempfile.csv", "w") as f: writer = csv.writer(f) writer.writerows(csvList) filepath = THIS_FOLDER + "/tempfile.csv" return send_file(filepath, attachment_filename=filename, as_attachment=True)
def get_data(): items = dbh.get_all_items() return json.dumps(items)
def get_session_items(sessionID): if sessionID == 0: session_data = dbh.get_all_items() else: session_data = dbh.get_session_data(sessionID) return json.dumps(session_data)