Skip to content

Commit

Permalink
- Made sequence for generating group numbers for api logger, and search
Browse files Browse the repository at this point in the history
  and comparison pages will log all their calls using the same
  api_call_group_id.
- Expanded to include all 'Is a' relationships from concept_relationship
  table in addition to concept_ancestor where min separation = 1 already
  included.
- No longer need an undirected version of the graph
- Totally redid subgraph generation and now downloading indented concept
  list instead of constructing it on the front end based on creating a
  front-end graph based on subgraph edges from backend. Seems to work,
  but collapse is broken now...maybe other stuff too.
  • Loading branch information
Sigfried committed Nov 13, 2023
1 parent d0a3d81 commit 9f6f82b
Show file tree
Hide file tree
Showing 10 changed files with 426 additions and 276 deletions.
2 changes: 2 additions & 0 deletions backend/api_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ async def start_rpt(self, request: Request, params: Dict):

rpt['schema'] = get_schema_name()

rpt['api_call_group_id'] = int(request.query_params.get('api_call_group_id'))

rpt_params = {}
for k,v in params.items():
if type(v) == list:
Expand Down
50 changes: 50 additions & 0 deletions backend/db/ddl-19-apirun_groups.jinja.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
-- View: apiruns_grouped ------------------------------------------------------------------------------------
DROP TABLE IF EXISTS public.api_runs CASCADE;

CREATE TABLE IF NOT EXISTS public.api_runs (
api_call_group_id integer,
host text,
client text,
schema text not null,
api_call text not null,
codeset_ids integer[],
params text,
timestamp text not null,
result text,
process_seconds float
--date text,
--note text
);

DROP SEQUENCE IF EXISTS api_call_group_id_seq;

CREATE SEQUENCE api_call_group_id_seq START 10001;

CREATE OR REPLACE VIEW public.apiruns_grouped AS (
WITH RankedGroups AS (
SELECT
*,
ROW_NUMBER() OVER (PARTITION BY api_call_group_id ORDER BY timestamp::timestamp DESC) AS rn
FROM
public.api_runs
)
SELECT
host,
client,
schema,
api_call_group_id,
/*
codeset_ids,
params,
*/
ARRAY_AGG(api_call) AS api_calls,
MIN(timestamp::timestamp) as group_start_time,
MAX(timestamp::timestamp) as group_end_time,
(MAX(timestamp::timestamp) - MIN(timestamp::timestamp)) +
CASE WHEN MAX(rn) = 1 THEN MAX(process_seconds) * INTERVAL '1 second' ELSE INTERVAL '0 seconds' END as duration_seconds
FROM
RankedGroups
GROUP BY
api_call_group_id, host, client, schema /* , api_call, codeset_ids, params*/
ORDER BY api_call_group_id desc -- group_start_time DESC, client
);
60 changes: 0 additions & 60 deletions backend/db/ddl-19-apirun_groups.sql

This file was deleted.

15 changes: 1 addition & 14 deletions backend/db/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,6 @@
success_datetime timestamp with time zone,
comment text);"""

DDL_API_LOG = """CREATE TABLE IF NOT EXISTS public.api_runs (
host text,
client text,
schema text not null,
api_call text not null,
codeset_ids integer[],
params text,
timestamp text not null,
result text,
process_seconds float
--date text,
--note text
);"""

DDL_CSET_COMPARE = """CREATE TABLE IF NOT EXISTS public.codeset_comparison (
fetch_time text,
orig_codeset_id integer,
Expand All @@ -92,6 +78,7 @@ def create_database(con: Connection, schema: str):
run_sql(con2, DDL_COUNTS)
run_sql(con2, DDL_COUNTS_RUNS)
run_sql(con2, DDL_FETCH_AUDIT)
run_sql(con2, DDL_CSET_COMPARE)
run_sql(con, f'CREATE SCHEMA IF NOT EXISTS {schema};')


Expand Down
9 changes: 8 additions & 1 deletion backend/routes/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,8 +777,15 @@ def generate_n3c_comparison_rpt():
'rpt': json.dumps(rpt)})


@router.get("/next-api-call-group-id")
def next_api_call_group_id() -> int:
with get_db_connection():
id = sql_query_single_col(get_db_connection(), "SELECT nextval('api_call_group_id_seq')")[0]
return id


from backend.utils import pdump
if __name__ == '__main__':
# n3c_comparison_rpt()
generate_n3c_comparison_rpt()
# generate_n3c_comparison_rpt()
pass
Loading

0 comments on commit 9f6f82b

Please sign in to comment.