Skip to content

Commit

Permalink
- Big refactor of graph stuff.
Browse files Browse the repository at this point in the history
  - It should be more correct now
  - I think it's slower
  - The first two tests succeed now, but:
  - With lots of concepts (e.g., 20,000), it takes forever and the whole
    backend won't respond while it's processing
    - The problem isn't in connect_nodes anymore, it's in all_paths when
      it's looking for simple paths to root. Those paths can get long
      and there can be a lot of them. Maybe a strategy of looking for
      predecessors would work?
  - It needs a lot more inline documentation
- I may have fixed the duplicate test thing by putting the loop through
  tests inside the loop through environments rather than other way
  around.
  • Loading branch information
Sigfried committed Nov 28, 2023
1 parent 232ef3c commit 8b7c2a9
Show file tree
Hide file tree
Showing 12 changed files with 393 additions and 101 deletions.
3 changes: 3 additions & 0 deletions .run/backend.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<module name="TermHub" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYDEVD_USE_CYTHON" value="NO" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="true" />
Expand Down
2 changes: 1 addition & 1 deletion backend/api_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async def start_rpt(self, request: Request, params: Dict):
if len(v) > 20:
# change any params with len > 20 to just log the len
rpt_params[k + '_len'] = len(v)
elif k == 'codeset_ids' or k == 'id':
elif k in ['codeset_ids', 'id', ]:
# put codeset_ids in a separate column (is this going to be helpful?)
codeset_ids = v

Expand Down
4 changes: 2 additions & 2 deletions backend/db/ddl-19-apirun_groups.jinja.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ WITH RankedGroups AS (
SELECT
*,
ROW_NUMBER() OVER (PARTITION BY api_call_group_id ORDER BY timestamp::timestamp DESC) AS rn
FROM
public.api_runs
FROM public.api_runs
WHERE api_call_group_id IS NOT NULL
)
SELECT
host,
Expand Down
22 changes: 15 additions & 7 deletions backend/db/ddl-20-concept_graph.jinja.sql
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
DROP TABLE IF EXISTS concept_graph CASCADE;

CREATE TABLE IF NOT EXISTS concept_graph AS (
SELECT ancestor_concept_id AS source_id, descendant_concept_id AS target_id
SELECT ancestor_concept_id AS source_id,
-- 'Child of' AS relationship_id,
descendant_concept_id AS target_id
FROM concept_ancestor
WHERE min_levels_of_separation = 1
/*
UNION
SELECT concept_id_1, concept_id_2
SELECT concept_id_1,
relationship_id,
concept_id_2
FROM concept_relationship
WHERE relationship_id = 'Is a'
WHERE relationship_id IN ('Is a', 'Replaces')
*/
);

CREATE INDEX cg_idx1 ON concept_graph(source_id);

CREATE INDEX cg_idx2 ON concept_graph(target_id);

/*
# load_csv(con, 'relationship', 'dataset', schema='n3c')
# rels = sql_query(con, f"""
Expand Down Expand Up @@ -38,7 +49,4 @@ CREATE TABLE IF NOT EXISTS concept_graph AS (
) y
"""
*/

CREATE INDEX cg_idx1 ON concept_graph(source_id);

CREATE INDEX cg_idx2 ON concept_graph(target_id);
SELECT 1; -- in case ending on a comment breaks the ddl parser
Loading

0 comments on commit 8b7c2a9

Please sign in to comment.