From 547988bfeeef26209eed49485c089a1528367640 Mon Sep 17 00:00:00 2001 From: TShapinsky Date: Tue, 5 Dec 2023 14:20:27 -0700 Subject: [PATCH] migrate names from Sites to Runs to remove need for Sites --- alfalfa_web/components/Sites/Sites.js | 4 +- alfalfa_web/server/api.js | 11 +--- .../measures/alfalfa_metadata/measure.rb | 54 +++++++++++++++++++ .../measures/alfalfa_metadata/measure.xml | 39 ++++++++++++++ .../jobs/openstudio/lib/workflow/workflow.osw | 7 +++ alfalfa_worker/lib/models.py | 1 + alfalfa_worker/lib/run_manager.py | 2 +- 7 files changed, 105 insertions(+), 13 deletions(-) create mode 100644 alfalfa_worker/jobs/openstudio/lib/workflow/measures/alfalfa_metadata/measure.rb create mode 100644 alfalfa_worker/jobs/openstudio/lib/workflow/measures/alfalfa_metadata/measure.xml diff --git a/alfalfa_web/components/Sites/Sites.js b/alfalfa_web/components/Sites/Sites.js index c90f8935..5c292256 100644 --- a/alfalfa_web/components/Sites/Sites.js +++ b/alfalfa_web/components/Sites/Sites.js @@ -22,7 +22,7 @@ export const Sites = () => { }; const fetchSites = async () => { - const { data: sites } = await ky("/api/v2/sites").json(); + const { data: sites } = await ky("/api/v2/runs").json(); setSites(sites); setLoading(false); }; @@ -109,7 +109,7 @@ export const Sites = () => { .map(({ id }) => id); for (const id of ids) { - location.href = `/api/v2/sites/${id}/download`; + location.href = `/api/v2/runs/${id}/download`; await new Promise((resolve) => setTimeout(resolve, 500)); } }; diff --git a/alfalfa_web/server/api.js b/alfalfa_web/server/api.js index 5072c1eb..9f49987d 100644 --- a/alfalfa_web/server/api.js +++ b/alfalfa_web/server/api.js @@ -61,11 +61,10 @@ class AlfalfaAPI { const run = await this.runs.findOne({ ref_id: siteRef }); if (run) { const model = await this.models.findOne({ _id: run.model }); - let site = await this.sites.findOne({ ref_id: siteRef }); const site_dict = { id: siteRef, - name: model.model_name, + name: run.name, status: run.status.toLowerCase(), datetime: "", simType: run.sim_type, @@ -73,14 +72,6 @@ class AlfalfaAPI { uploadPath: `uploads/${model.ref_id}/${model.model_name}`, errorLog: run.error_log }; - - if (site) { - const siteHash = await getHash(this.redis, siteRef); - site = mapHaystack(site); - - site_dict.name = site?.dis ?? site_dict.name; - site_dict.datetime = siteHash?.sim_time ?? ""; - } return site_dict; } } catch (e) { diff --git a/alfalfa_worker/jobs/openstudio/lib/workflow/measures/alfalfa_metadata/measure.rb b/alfalfa_worker/jobs/openstudio/lib/workflow/measures/alfalfa_metadata/measure.rb new file mode 100644 index 00000000..d2d6261f --- /dev/null +++ b/alfalfa_worker/jobs/openstudio/lib/workflow/measures/alfalfa_metadata/measure.rb @@ -0,0 +1,54 @@ +# start the measure +class AlfalfaMetadata < OpenStudio::Measure::EnergyPlusMeasure + + # human readable name + def name + # Measure name should be the title case of the class name. + return 'Alfalfa Metadata' + end + + # human readable description + def description + return 'Generate metadata report for Alfalfa' + end + + # human readable description of modeling approach + def modeler_description + return 'Generate metadata report for Alfalfa' + end + + # define the arguments that the user will input + def arguments(workspace) + args = OpenStudio::Measure::OSArgumentVector.new + + return args + end + + # define what happens when the measure is run + def run(workspace, runner, user_arguments) + super(workspace, runner, user_arguments) + + # use the built-in error checking + if !runner.validateUserArguments(arguments(workspace), user_arguments) + return false + end + + metadata_dict = {} + + buildings = workspace.getObjectsByType('Building'.to_IddObjectType) + buildings.each do |building| + metadata_dict['building_name'] = building.name.get + end + + File.open('./report_metadata.json', 'w') do |f| + JSON.dump(metadata_dict, f) + end + + runner.registerFinalCondition("Done") + + return true + end +end + +# register the measure to be used by the application +AlfalfaMetadata.new.registerWithApplication diff --git a/alfalfa_worker/jobs/openstudio/lib/workflow/measures/alfalfa_metadata/measure.xml b/alfalfa_worker/jobs/openstudio/lib/workflow/measures/alfalfa_metadata/measure.xml new file mode 100644 index 00000000..22818057 --- /dev/null +++ b/alfalfa_worker/jobs/openstudio/lib/workflow/measures/alfalfa_metadata/measure.xml @@ -0,0 +1,39 @@ + + + 3.1 + alfalfa_metadata + 870213d3-36a2-4da2-9a04-c377a37fd4fe + 6f08ed47-aa1b-407f-a9c8-bbd58fbfaba7 + 2023-12-05T20:31:10Z + 70995EFB + AlfalfaMetadata + Alfalfa Metadata + Generate metadata report for Alfalfa + Generate metadata report for Alfalfa + + + + + HVAC.HVAC Controls + + + + Measure Type + EnergyPlusMeasure + string + + + + + + OpenStudio + 3.1.0 + 3.1.0 + + measure.rb + rb + script + 901131AC + + + diff --git a/alfalfa_worker/jobs/openstudio/lib/workflow/workflow.osw b/alfalfa_worker/jobs/openstudio/lib/workflow/workflow.osw index 5b057c30..ec8b6f77 100644 --- a/alfalfa_worker/jobs/openstudio/lib/workflow/workflow.osw +++ b/alfalfa_worker/jobs/openstudio/lib/workflow/workflow.osw @@ -52,6 +52,13 @@ "name" : "Python", "description" : "Add python to IDF", "modeler_description" : "Add python script path to IDF" + }, + { + "arguments" : {}, + "measure_dir_name" : "alfalfa_metadata", + "name" : "Metadata", + "description" : "Generate metadata report for Alfalfa", + "modeler_description" : "Generate metadata report for Alfalfa" } ], "updated_at" : "20170606T230145Z", diff --git a/alfalfa_worker/lib/models.py b/alfalfa_worker/lib/models.py index 56270333..338c5d8a 100644 --- a/alfalfa_worker/lib/models.py +++ b/alfalfa_worker/lib/models.py @@ -514,6 +514,7 @@ def add_point(self, point: Point): # external ID used to track this object ref_id = StringField(default=uuid4_str, unique=True) + name = StringField(max_length=255) # The site is required but it only shows up after the haystack points # are extracted. diff --git a/alfalfa_worker/lib/run_manager.py b/alfalfa_worker/lib/run_manager.py index beeffac3..2aa86b5c 100644 --- a/alfalfa_worker/lib/run_manager.py +++ b/alfalfa_worker/lib/run_manager.py @@ -84,7 +84,7 @@ def create_run_from_model(self, model_id: str, sim_type=SimType.OPENSTUDIO, run_ file_path.unlink() else: shutil.copy(file_path, run_path) - run = Run(dir=run_path, model=model, ref_id=run_id, sim_type=sim_type) + run = Run(dir=run_path, model=model, ref_id=run_id, sim_type=sim_type, name=model_name) run.save() # self.register_run(run) return run