Skip to content

Commit

Permalink
Fast run updates
Browse files Browse the repository at this point in the history
- Add: --fast-run logic to more methods.
- Add: config.py: Initialized with constants to use for controlling --fast-run.
  • Loading branch information
joeflack4 committed Nov 11, 2024
1 parent 6f08c08 commit 5858d3b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/comp_loinc/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Additional internal configuration"""
FAST_RUN_N_TERMS = 5000
FAST_RUN_N_PARTS = 100

29 changes: 26 additions & 3 deletions src/comp_loinc/loinc_builder_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from linkml_runtime.linkml_model import ClassDefinition, SlotDefinition, Annotation

from comp_loinc import Runtime
from comp_loinc.config import FAST_RUN_N_PARTS, FAST_RUN_N_TERMS
from comp_loinc.datamodel import (
LoincPart,
LoincPartId,
Expand Down Expand Up @@ -121,7 +122,7 @@ def loinc_terms_all(
count = 0
for node in self.runtime.graph.get_nodes(LoincNodeType.LoincTerm):
count += 1
if self.configuration.fast_run and count > 5000:
if self.configuration.fast_run and count > FAST_RUN_N_TERMS:
break
if count % 1000 == 0:
logger.info(f"Finished {count}")
Expand Down Expand Up @@ -161,8 +162,8 @@ def loinc_parts_all(

count = 0
for node in self.runtime.graph.get_nodes(LoincNodeType.LoincPart):
count = count + 1
if self.configuration.fast_run and count > 100:
count += 1
if self.configuration.fast_run and count > FAST_RUN_N_PARTS:
break
status = node.get_property(LoincPartProps.status)
if active_only and status != "ACTIVE":
Expand Down Expand Up @@ -197,8 +198,12 @@ def entity_labels(self):
loinc_tree_loader.load_method_tree()
loinc_tree_loader.load_document_tree()

count = 0
loinc_term: LoincTerm
for loinc_term in self.runtime.current_module.get_entities_of_type(LoincTerm):
count += 1
if self.configuration.fast_run and count > FAST_RUN_N_TERMS:
break
node = self.runtime.graph.get_node_by_code(
type_=LoincNodeType.LoincTerm, code=loinc_term.id
)
Expand Down Expand Up @@ -253,8 +258,12 @@ def entity_annotations(self):
loinc_tree_loader.load_method_tree()
loinc_tree_loader.load_document_tree()

count = 0
loinc_term: LoincTerm
for loinc_term in self.runtime.current_module.get_entities_of_type(LoincTerm):
count += 1
if self.configuration.fast_run and count > FAST_RUN_N_TERMS:
break
node = self.runtime.graph.get_node_by_code(
type_=LoincNodeType.LoincTerm, code=loinc_term.id
)
Expand Down Expand Up @@ -364,7 +373,11 @@ def loinc_part_hierarchy_all(self):
loinc_tree_loader.load_method_tree()
loinc_tree_loader.load_document_tree()

count = 0
for child_part_node in graph.get_nodes(type_=LoincNodeType.LoincPart):
count += 1
if self.configuration.fast_run and count > FAST_RUN_N_PARTS:
break
child_part_number = child_part_node.get_property(
type_=LoincPartProps.part_number
)
Expand Down Expand Up @@ -406,10 +419,14 @@ def loinc_term_primary_def(self):
loinc_loader = LoincLoader(graph=graph, configuration=self.configuration)
loinc_loader.load_accessory_files__part_file__loinc_part_link_primary_csv()

count = 0
loinc_term: LoincTerm
for loinc_term in self.runtime.current_module.get_entities_of_type(
entity_class=LoincTerm
):
count += 1
if self.configuration.fast_run and count > FAST_RUN_N_TERMS:
break
loinc_term_id = loinc_term.id
loinc_term_node = self.runtime.graph.get_node_by_code(
type_=LoincNodeType.LoincTerm, code=loinc_term_id
Expand Down Expand Up @@ -510,10 +527,14 @@ def loinc_term_supplementary_def(self):
loinc_loader = LoincLoader(graph=graph, configuration=self.configuration)
loinc_loader.load_accessory_files__part_file__loinc_part_link_supplementary_csv()

count = 0
loinc_term: LoincTerm
for loinc_term in self.runtime.current_module.get_entities_of_type(
entity_class=LoincTerm
):
count += 1
if self.configuration.fast_run and count > FAST_RUN_N_TERMS:
break
loinc_term_id = loinc_term.id
loinc_term_node = self.runtime.graph.get_node_by_code(
type_=LoincNodeType.LoincTerm, code=loinc_term_id
Expand Down Expand Up @@ -618,6 +639,8 @@ def loinc_term_class_roots(self):
entity_class=LoincTerm
):
count += 1
if self.configuration.fast_run and count > FAST_RUN_N_TERMS:
break
if count % 1000 == 0:
logger.info(f"Finished {count}")
loinc_term_node = self.runtime.graph.get_node_by_code(
Expand Down
3 changes: 2 additions & 1 deletion src/comp_loinc/snomed_builder_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import typing as t

from comp_loinc import Runtime
from comp_loinc.config import FAST_RUN_N_PARTS
from comp_loinc.datamodel import SnomedConcept
from loinclib import (
Configuration,
Expand Down Expand Up @@ -50,7 +51,7 @@ def loinc_part_mapping_instances(self):
count = 0
for part in self.runtime.graph.get_nodes(type_=LoincNodeType.LoincPart):
count = count + 1
if self.configuration.fast_run and count > 100:
if self.configuration.fast_run and count > FAST_RUN_N_PARTS:
break
for edge in part.get_all_out_edges():
if edge.edge_type.type_ is SnomedEdges.maps_to:
Expand Down

0 comments on commit 5858d3b

Please sign in to comment.