Skip to content

Commit

Permalink
Finally
Browse files Browse the repository at this point in the history
  • Loading branch information
mseng10 committed Feb 16, 2025
1 parent 43faddf commit 7d1aa6e
Show file tree
Hide file tree
Showing 17 changed files with 410 additions and 437 deletions.
15 changes: 13 additions & 2 deletions server/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
logger = setup_logger(__name__, logging.DEBUG)

# Probably abstract this out to a Role class and have this be in the master role class
discover_systems() # Maybe put this into the installable?
# Maybe put this into the installable?
discover_systems()

# Create Flask app
app = Flask(__name__)
Expand Down Expand Up @@ -62,7 +63,7 @@ def get_meta():
logger.info("Received request to query the meta")

meta = {
# "alert_count": db.plant_alerts.count_documents({"deprecated": False}),
"alert_count": Table.ALERT.count({"deprecated": False}),
"todo_count": Table.TODO.count({"deprecated": False})
}

Expand All @@ -86,6 +87,16 @@ def get_notebook():
# Serve the HTML
return body

# Print details of the running endpoints
for rule in app.url_map.iter_rules():
methods = ','.join(sorted(rule.methods))
arguments = ','.join(sorted(rule.arguments))
logger.debug(f"Endpoint: {rule.endpoint}")
logger.debug(f" URL: {rule}")
logger.debug(f" Methods: {methods}")
logger.debug(f" Arguments: {arguments}")
logger.debug("---")

scheduler = APScheduler()
scheduler.init_app(app)
scheduler.start()
Expand Down
25 changes: 11 additions & 14 deletions server/app/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
# Create a logger for this specific module
logger = setup_logger(__name__, logging.DEBUG)

def create_model(model_path: str, model_class: Type[FlexibleModel]):
def create_model(model_path: str, table: Table):
"""
Create the provided model from the data path.
"""
table: Table = model_class.table

logger.info(f"Beginning to create model {table.value}")

Expand All @@ -33,13 +32,11 @@ def create_model(model_path: str, model_class: Type[FlexibleModel]):

# Load models from CSV and insert them
# Doing this way to create null values in the db in the event some fields get updated
models = model_class.from_csv(model_path)
documents = [model.to_dict() for model in models]

if documents:
for doc in documents:
models: List[FlexibleModel] = table.model_class.from_csv(model_path)
if models:
for doc in models:
table.create(doc)
logger.info(f"Successfully created {len(documents)} documents for {table.value}")
logger.info(f"Successfully created {len(models)} documents for {table.value}")
else:
logger.error(f"No documents to create for {table.value}")

Expand All @@ -49,11 +46,11 @@ def create_all_models():
"""
logger.info("Beginning to create models.")

models_to_create: List[Tuple[str, Type[FlexibleModel]]] = [
("data/installable/soils/soils.csv", Soil),
("data/installable/plants/genus_types.csv", PlantGenusType),
("data/installable/plants/genera.csv", PlantGenus),
("data/installable/plants/species.csv", PlantSpecies),
models_to_create: List[Tuple[str, Table]] = [
("data/installable/soils/soils.csv", Table.SOIL),
("data/installable/plants/genus_types.csv", Table.GENUS_TYPE),
("data/installable/plants/genera.csv", Table.GENUS),
("data/installable/plants/species.csv", Table.SPECIES),
]

for model_path, model_class in models_to_create:
Expand All @@ -70,4 +67,4 @@ def install():
logger.info("Installation complete")

if __name__ == "__main__":
install()
install()
Loading

0 comments on commit 7d1aa6e

Please sign in to comment.