def videos_list(): if request.method == 'POST': # We are only expecting the URL and Directory data = request.json vid_url = data["data"]["attributes"]["url"] vid_dir = data["data"]["attributes"]["directory"] if vid_url == None: return mod_response({'error': 'URL not specified'}, 400) if vid_dir == None: vid_dir = "" # Create the Video row & object rowId = create_row(vid_url, "", "Pending", "Placed in Queue", vid_dir, "") newVid = Video(rowId, vid_url, "", "Pending", "Placed in Queue", vid_dir, "") # Pass this video object to the Queue q.put(newVid) return mod_response({'data': newVid.toJson()}, 201) else: data = { 'data': [ Video(row[0], row[1], row[2], row[3], row[4], row[5], row[6]).toJson() for row in get_all_rows() ] } return mod_response(data, 200)
def get_fever_events_measurements(start_date: int, end_date: int): conn = db.create_connection(db.DB_FILE) with conn: rows = db.get_all_rows(conn, db.TABLE_NAME) events_list = [] event_dict = {} for row in rows: timestamp = int(row[0]) value = row[1] event = row[2] if timestamp > end_date: break # we asume that the data is sorted inside db as it should be if timestamp < start_date: continue # we asume that the data is sorted inside db as it should be if event == FEVER_START and not event_dict: event_dict = { "event_start": timestamp, "event_stop": 0, "measurements": [{ "timestamp": timestamp, "value": value }] } elif event == FEVER_START and event_dict: event_dict['event_stop'] = timestamp event_dict['measurements'].append({ "timestamp": timestamp, "value": value }) elif event == FEVER_END: if event_dict['event_stop'] == 0: event_dict['event_stop'] = timestamp event_dict['measurements'].append({ "timestamp": timestamp, "value": value }) events_list.append(event_dict) event_dict = {} elif event_dict: event_dict['measurements'].append({ "timestamp": timestamp, "value": value }) return events_list
def get_raw_temp_measurements(start_date: int, end_date: int): conn = db.create_connection(db.DB_FILE) with conn: rows = db.get_all_rows(conn, db.TABLE_NAME) m = [] for row in rows: timestamp = int(row[0]) value = row[1] if timestamp > end_date: break # we asume that the data is sorted inside db as it should be if timestamp < start_date: continue # we asume that the data is sorted inside db as it should be m.append({"timestamp": timestamp, "value": value}) return m
def get_aggregated_temp_measurements(start_date: int, end_date: int, aggregation_type: str, operator_type: str): conn = db.create_connection(db.DB_FILE) with conn: rows = db.get_all_rows(conn, db.TABLE_NAME) rows_iter = iter(rows) m = [] while True: try: row = next(rows_iter) timestamp = int(row[0]) value = row[1] start_timestamp = timestamp if aggregation_type == 'HOURLY': end_timestamp = timestamp + 36000 elif aggregation_type == 'DAILY': end_timestamp = timestamp + (3600 * 24) aggregation_list = [value] while timestamp < end_timestamp: try: row = next(rows_iter) timestamp = int(row[0]) value = row[1] aggregation_list.append(value) except StopIteration: break value = apply_operation(aggregation_list, operator_type) m.append({"timestamp": start_timestamp, "value": value}) except StopIteration: break return m
def service_health(): rows = get_all_rows() if len(rows) != None: return mod_response({'data': 'Service is healthy'}, 200) else: return mod_response({'error': 'Service is unhealthy'}, 500)
def startup(q): rows = get_all_rows() for row in rows: if row[3] == 'Pending' or row[3] == 'Processing': q.put(Video(row[0], row[1], row[2], row[3], row[4], row[5], row[6]))