def get_tab4_data(): # External is 1 based, internal is 0 based per_page = int(get_arg("per_page", "2")) per_page = max(2, min(999, per_page)) page = int(get_arg("page", "1")) page = max(0, page - 1) start = page * per_page execute(""" SELECT site, issue, is_resolved FROM ( SELECT * FROM tab4 ORDER BY row_id DESC LIMIT {p},{pp} ) sub ORDER BY row_id DESC; """.format(p=start, pp=per_page)) rows = fetch_all() execute("SELECT COUNT(*) FROM tab4 ORDER BY row_id") count = (fetch_all() or [[0]])[0][0] pages = ceil(count / per_page) return dict(page_count=pages, current_page=page + 1, per_page=per_page, data=rows)
def get_tab4_data(): # External is 1 based, internal is 0 based per_page = int(get_arg("per_page", "15")) per_page = max(2, min(999, per_page)) page = int(get_arg("page", "1")) page = max(0, page - 1) start = page * per_page con = connect(**connection_params) cur = con.cursor() try: cur.execute(""" SELECT site, issue, is_resolved FROM ( SELECT * FROM tab4 ORDER BY row_id DESC LIMIT {p},{pp} ) sub ORDER BY row_id DESC; """.format(p=start, pp=per_page)) rows = cur.fetchall() cur.execute("SELECT COUNT(*) FROM tab4 ORDER BY row_id") count = (cur.fetchall() or [[0]])[0][0] pages = ceil(count / per_page) finally: cur.close() con.close() return dict(page_count=pages, current_page=page+1, per_page=per_page, data=rows)
def get_tab4_data(): # External is 1 based, internal is 0 based per_page = int(get_arg("per_page", "15")) per_page = max(2, min(999, per_page)) page = int(get_arg("page", "1")) page = max(0, page - 1) start = page * per_page con = connect(**connection_params) cur = con.cursor() try: cur.execute(""" SELECT site, issue, is_resolved FROM ( SELECT * FROM tab4 ORDER BY row_id DESC LIMIT {p},{pp} ) sub ORDER BY row_id DESC; """.format(p=start, pp=per_page)) rows = cur.fetchall() cur.execute("SELECT COUNT(*) FROM tab4 ORDER BY row_id") count = (cur.fetchall() or [[0]])[0][0] pages = ceil(count / per_page) finally: cur.close() con.close() return dict(page_count=pages, current_page=page + 1, per_page=per_page, data=rows)
def get_tab_data(tab): if tab == "tab1_a": parent_id = get_arg("parent_id") data_nodes = True if get_arg("data_nodes") == "true" else False data_nodes_q = "AND data_available BETWEEN 1 and 2" if data_nodes else "" try: parent_id = 0 if parent_id == "#" else int(parent_id) execute(""" SELECT ontology_id,parent_id,ontology_name, data_available FROM tab1_a WHERE parent_id=%s {dn};""".format(dn=data_nodes_q), parent_id) data = [] data_d = dict() ids = [] for ontology_id, parent_id, ontology_name, data_available in fetch_iter(): ids.append(ontology_id) item = dict( id=ontology_id, parent="#" if parent_id == 0 else parent_id, text=ontology_name, children=False, ) if data_available == 1: item["li_attr"] = {"class": "li_darkblue",} elif data_available == 2 and not data_nodes: item["li_attr"] = {"class": "li_darkgreen",} data.append(item) data_d[ontology_id] = item # Check if has children if data: query = "SELECT DISTINCT parent_id FROM tab1_a WHERE " + " OR ".join(("parent_id=%s" % (i,) for i in ids)) + ";" execute(query) for i, in fetch_iter(): data_d[i]["children"] = True return Response(json.dumps(data).encode("utf8"), 200, mimetype="application/json") except ValueError: pass except TypeError: pass elif tab == "tab1_b": try: ontology_id = int(get_arg("ontology_id")) min_year = int(get_arg("min_year") or "2000") max_year = int(get_arg("may_year") or "2050") execute(""" SELECT * FROM tab1_b WHERE ontology_id=%s AND (year BETWEEN %s AND %s);""", ontology_id, min_year, max_year) return get_csv(["query_run_timestamp", "ontology_id", "Year", "UCLA", "UCI", "UCSF", "UCSD", "UCD"], cur) except ValueError: pass return None
def home(): tag = helpers.get_arg(request.args.get('tag'), 'untagged') page = int(helpers.get_arg(request.args.get('page'), 1)) count = int( helpers.get_arg(request.args.get('count'), settings.items_per_page)) itms = items.get_items() num_pages = items.get_num_pages(itms, count, tag='untagged') labels_json = items.get_page(items.get_tag(itms, tag), page, count) return render_template('custom/index.html', labels_json=labels_json, num_pages=num_pages, page_num=page)
def all(): page = int(helpers.get_arg(request.args.get('page'), 1)) count = int( helpers.get_arg(request.args.get('count'), settings.items_per_page)) itms = items.get_items() num_pages = items.get_num_pages(itms, count) labels_json = items.get_page(itms, page, count) return render_template('custom/index.html', labels_json=labels_json, num_pages=num_pages, page_num=page)
def get_tab_data(tab): cur = db.cursor() if tab == "tab1_a": parent_id = get_arg("parent_id") try: parent_id = 0 if parent_id == "#" else int(parent_id) cur.execute(""" SELECT ontology_id,parent_id,ontology_name FROM tab1_a WHERE parent_id=%s""", [parent_id]) # WHERE parent_id=%s data = [] for ontology_id, parent_id, ontology_name in cur.fetchall(): data.append( dict(id=ontology_id, parent="#" if parent_id == 0 else parent_id, text=ontology_name, children=True)) #data.append(dict(id=9999999,text="placeholder", parent=ontology_id)) return Response(json.dumps(data).encode("utf8"), 200, mimetype="application/json") except ValueError: pass except TypeError: pass elif tab == "tab1_b": try: ontology_id = int(get_arg("ontology_id")) min_year = int(get_arg("min_year") or "2005") max_year = int(get_arg("may_year") or "2016") cur.execute( """ SELECT * FROM tab1_b WHERE ontology_id=%s AND (year BETWEEN %s AND %s)""", [ontology_id, min_year, max_year]) return get_csv([ "query_run_timestamp", "ontology_id", "Year", "UCLA", "UCI", "UCSF", "UCSD", "UCD" ], cur.fetchall()) except ValueError: pass elif tab == "tab1_c": cur.execute("SELECT * FROM tab1_c") return get_csv(["ontology_id", "hospital", "comments"], cur.fetchall()) cur.close() return None
def update_comment(): comment_id = get_arg("comment_id") is_public = get_arg("is_public") if not comment_id.isdigit(): return Response(json.dumps(dict( result="error", error_message="Invalid comment_id format, must be numeric" ))) if not is_public.isdigit(): return Response(json.dumps(dict( result="error", error_message="Invalid is_public format, must be numeric" ))) update_comment_visibility(comment_id, is_public) return Response(json.dumps(dict(result="success")))
def update_comment(): comment_id = get_arg("comment_id") is_public = get_arg("is_public") if not comment_id.isdigit(): return Response( json.dumps( dict(result="error", error_message= "Invalid comment_id format, must be numeric"))) if not is_public.isdigit(): return Response( json.dumps( dict(result="error", error_message= "Invalid is_public format, must be numeric"))) update_comment_visibility(comment_id, is_public) return Response(json.dumps(dict(result="success")))
def get_tab_data(tab): cur = db.cursor() if tab == "tab1_a": parent_id = get_arg("parent_id") try: parent_id = 0 if parent_id == "#" else int(parent_id) cur.execute(""" SELECT ontology_id,parent_id,ontology_name FROM tab1_a WHERE parent_id=%s""", [parent_id]) # WHERE parent_id=%s data = [] for ontology_id, parent_id, ontology_name in cur.fetchall(): data.append(dict( id=ontology_id, parent="#" if parent_id == 0 else parent_id, text=ontology_name, children=True )) #data.append(dict(id=9999999,text="placeholder", parent=ontology_id)) return Response(json.dumps(data).encode("utf8"), 200, mimetype="application/json") except ValueError: pass except TypeError: pass elif tab == "tab1_b": try: ontology_id = int(get_arg("ontology_id")) min_year = int(get_arg("min_year") or "2005") max_year = int(get_arg("may_year") or "2016") cur.execute(""" SELECT * FROM tab1_b WHERE ontology_id=%s AND (year BETWEEN %s AND %s)""", [ontology_id, min_year, max_year]) return get_csv(["query_run_timestamp", "ontology_id", "Year", "UCLA", "UCI", "UCSF", "UCSD", "UCD"], cur.fetchall()) except ValueError: pass elif tab == "tab1_c": cur.execute("SELECT * FROM tab1_c") return get_csv(["ontology_id", "hospital", "comments"], cur.fetchall()) cur.close() return None
def get_tab4_data(): # External is 1 based, internal is 0 based per_page = int(get_arg("per_page", "2")) per_page = max(2, min(999, per_page)) page = int(get_arg("page", "1")) page = max(0, page - 1) start = page * per_page execute(""" SELECT site, issue, is_resolved FROM ( SELECT * FROM tab4 ORDER BY row_id DESC LIMIT {p},{pp} ) sub ORDER BY row_id DESC; """.format(p=start, pp=per_page)) rows = fetch_all() execute("SELECT COUNT(*) FROM tab4 ORDER BY row_id") count = (fetch_all() or [[0]])[0][0] pages = ceil(count / per_page) return dict(page_count=pages, current_page=page+1, per_page=per_page, data=rows)
def get_tab_data(tab): if tab == "tab1_a": parent_id = get_arg("parent_id") data_nodes = True if get_arg("data_nodes") == "true" else False data_nodes_q = "AND data_available BETWEEN 1 and 2" if data_nodes else "" try: parent_id = 0 if parent_id == "#" else int(parent_id) execute( """ SELECT ontology_id,parent_id,ontology_name, data_available FROM tab1_a WHERE parent_id=%s {dn};""".format(dn=data_nodes_q), parent_id) data = [] data_d = dict() ids = [] for ontology_id, parent_id, ontology_name, data_available in fetch_iter( ): ids.append(ontology_id) item = dict( id=ontology_id, parent="#" if parent_id == 0 else parent_id, text=ontology_name, children=False, ) if data_available == 1: item["li_attr"] = { "class": "li_darkblue", } elif data_available == 2 and not data_nodes: item["li_attr"] = { "class": "li_darkgreen", } data.append(item) data_d[ontology_id] = item # Check if has children if data: query = "SELECT DISTINCT parent_id FROM tab1_a WHERE " + " OR ".join( ("parent_id=%s" % (i, ) for i in ids)) + ";" execute(query) for i, in fetch_iter(): data_d[i]["children"] = True return Response(json.dumps(data).encode("utf8"), 200, mimetype="application/json") except ValueError: pass except TypeError: pass elif tab == "tab1_b": try: ontology_id = int(get_arg("ontology_id")) min_year = int(get_arg("min_year") or "2000") max_year = int(get_arg("may_year") or "2050") execute( """ SELECT * FROM tab1_b WHERE ontology_id=%s AND (year BETWEEN %s AND %s);""", ontology_id, min_year, max_year) return get_csv([ "query_run_timestamp", "ontology_id", "Year", "UCLA", "UCI", "UCSF", "UCSD", "UCD" ], cur) except ValueError: pass return None
def get_tab_data(tab): con = connect(**connection_params) cur = con.cursor() try: if tab == "tab1_a": parent_id = get_arg("parent_id") data_nodes = True if get_arg("data_nodes") == "true" else False data_nodes_q = "AND data_available BETWEEN 1 and 2" if data_nodes else "" try: parent_id = 0 if parent_id == "#" else int(parent_id) cur.execute(""" SELECT ontology_id,parent_id,ontology_name, data_available FROM tab1_a WHERE parent_id=%s {dn};""".format(dn=data_nodes_q), [parent_id]) data = [] data_d = dict() ids = [] for ontology_id, parent_id, ontology_name, data_available in cur: ids.append(ontology_id) item = dict( id=ontology_id, parent="#" if parent_id == 0 else parent_id, text=ontology_name, children=False, ) if data_available == 1: item["li_attr"] = {"class": "li_darkblue",} elif data_available == 2 and not data_nodes: item["li_attr"] = {"class": "li_darkgreen",} else: item["li_attr"] = {"class": "li_black",} data.append(item) data_d[ontology_id] = item # Check if has children if data: query = "SELECT DISTINCT parent_id FROM tab1_a WHERE " + " OR ".join(("parent_id=%s" % (i,) for i in ids)) + ";" cur.execute(query) for i, in cur: data_d[i]["children"] = True return Response(json.dumps(data).encode("utf8"), 200, mimetype="application/json") except ValueError: pass except TypeError as ex: pass elif tab == "tab1_b": try: ontology_id = int(get_arg("ontology_id")) min_year = int(get_arg("min_year") or "2000") max_year = int(get_arg("may_year") or "9999") cur.execute(""" SELECT query_run_timestamp,ontology_id,year,ucla,uci,ucsf,ucsd,ucd FROM tab1_b WHERE ontology_id=%s AND (year BETWEEN %s AND %s);""", [ontology_id, min_year, max_year]) data = [] header = "query_run_timestamp,ontology_id,year,ucla,uci,ucsf,ucsd,ucd".split(",") for row in cur: item = dict() for i,name in enumerate(header): item[name] = row[i] data.append(item) data = { "result": "success", "data": data } return data except ValueError: pass elif tab == "tab2_raw": try: year = int(get_arg("year", "")) month = int(get_arg("month", "")) day = int(get_arg("day", "")) except ValueError: return {"result": "error", "error_message": "Invalid parameter type", "code":"400"} if not year or not month or not day: return start = datetime(year, month, day) end = datetime(year, month, day+1) cur.execute(""" SELECT path,timestamp,ucla,uci,ucd,ucsf,ucsd FROM dashdb.tab2_raw WHERE timestamp BETWEEN %s AND %s;""", [start.isoformat(), end.isoformat()]) data = [] for path,timestamp,ucla,uci,ucd,ucsf,ucsd in cur: item = dict( path=path, timestamp=timestamp, ucla=ucla, uci=uci, ucd=ucd, ucsf=ucsf, ucsd=ucsd ) data.append(item) data = dict( result="success", data = data ) return data else: return dict(result="error", error_message="Specified data api not found", code=404) finally: cur.close() con.close() return dict(result="error", error_message="Unknown error", code=500)
def get_tab_data(tab): con = connect(**connection_params) cur = con.cursor() try: if tab == "tab1_a": parent_id = get_arg("parent_id") data_nodes = True if get_arg("data_nodes") == "true" else False data_nodes_q = "AND data_available BETWEEN 1 and 2" if data_nodes else "" try: parent_id = 0 if parent_id == "#" else int(parent_id) cur.execute( """ SELECT ontology_id,parent_id,ontology_name, data_available FROM tab1_a WHERE parent_id=%s {dn};""".format(dn=data_nodes_q), [parent_id]) data = [] data_d = dict() ids = [] for ontology_id, parent_id, ontology_name, data_available in cur: ids.append(ontology_id) item = dict( id=ontology_id, parent="#" if parent_id == 0 else parent_id, text=ontology_name, children=False, ) if data_available == 1: item["li_attr"] = { "class": "li_darkblue", } elif data_available == 2 and not data_nodes: item["li_attr"] = { "class": "li_darkgreen", } else: item["li_attr"] = { "class": "li_black", } data.append(item) data_d[ontology_id] = item # Check if has children if data: query = "SELECT DISTINCT parent_id FROM tab1_a WHERE " + " OR ".join( ("parent_id=%s" % (i, ) for i in ids)) + ";" cur.execute(query) for i, in cur: data_d[i]["children"] = True return Response(json.dumps(data).encode("utf8"), 200, mimetype="application/json") except ValueError: pass except TypeError as ex: pass elif tab == "tab1_b": try: ontology_id = int(get_arg("ontology_id")) min_year = int(get_arg("min_year") or "2000") max_year = int(get_arg("may_year") or "9999") cur.execute( """ SELECT query_run_timestamp,ontology_id,year,ucla,uci,ucsf,ucsd,ucd FROM tab1_b WHERE ontology_id=%s AND (year BETWEEN %s AND %s);""", [ontology_id, min_year, max_year]) data = [] header = "query_run_timestamp,ontology_id,year,ucla,uci,ucsf,ucsd,ucd".split( ",") for row in cur: item = dict() for i, name in enumerate(header): item[name] = row[i] data.append(item) data = {"result": "success", "data": data} return data except ValueError: pass elif tab == "tab2_raw": try: year = int(get_arg("year", "")) month = int(get_arg("month", "")) day = int(get_arg("day", "")) except ValueError: return { "result": "error", "error_message": "Invalid parameter type", "code": "400" } if not year or not month or not day: return start = datetime(year, month, day) end = datetime(year, month, day + 1) cur.execute( """ SELECT path,timestamp,ucla,uci,ucd,ucsf,ucsd FROM dashdb.tab2_raw WHERE timestamp BETWEEN %s AND %s;""", [start.isoformat(), end.isoformat()]) data = [] for path, timestamp, ucla, uci, ucd, ucsf, ucsd in cur: item = dict(path=path, timestamp=timestamp, ucla=ucla, uci=uci, ucd=ucd, ucsf=ucsf, ucsd=ucsd) data.append(item) data = dict(result="success", data=data) return data else: return dict(result="error", error_message="Specified data api not found", code=404) finally: cur.close() con.close() return dict(result="error", error_message="Unknown error", code=500)