Skip to content

Commit

Permalink
migrate names from Sites to Runs to remove need for Sites
Browse files Browse the repository at this point in the history
  • Loading branch information
TShapinsky committed Dec 5, 2023
1 parent 975b785 commit a5391c0
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 14 deletions.
4 changes: 2 additions & 2 deletions alfalfa_web/components/Sites/Sites.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down Expand Up @@ -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));
}
};
Expand Down
11 changes: 1 addition & 10 deletions alfalfa_web/server/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,17 @@ 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,
uploadTimestamp: run.created,
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) {
Expand Down
16 changes: 15 additions & 1 deletion alfalfa_worker/jobs/openstudio/create_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ def exec(self):
# run workflow
check_output(['openstudio', '--gem_path', '/var/lib/gems/2.7.0', 'run', '-m', '-w', str(submitted_osw_path)])

self.logger.info('Loading Building Metadata')
metadata_json_path = submitted_workflow_path / 'reports' / 'alfalfa_metadata_report_metadata.json'
if metadata_json_path.exists():
self.load_metadata(metadata_json_path)
else:
self.logger.info('Could not find Alfalfa Metadata Report')

self.logger.info('Generating variables from measure reports')
self.variables = Variables(self.run)
self.variables.load_reports()
Expand Down Expand Up @@ -109,6 +116,13 @@ def cleanup(self) -> None:
super().cleanup()
self.set_run_status(RunStatus.READY)

def load_metadata(self, metadata_json: Path):
with open(metadata_json) as fp:
metadata_dict = json.load(fp)
if 'building_name' in metadata_dict:
self.run.name = metadata_dict['building_name']
self.run.save()

def insert_os_tags(self, points_json_path, mapping_json_path):
"""
Make unique ids and replace site_id. Upload to mongo and filestore.
Expand Down Expand Up @@ -140,4 +154,4 @@ def insert_os_tags(self, points_json_path, mapping_json_path):
json.dump(mapping_json, fp)

# add points to database
self.run_manager.add_site_to_mongo(points_json, self.run)
# self.run_manager.add_site_to_mongo(points_json, self.run)
7 changes: 7 additions & 0 deletions alfalfa_worker/jobs/openstudio/lib/workflow/workflow.osw
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions alfalfa_worker/lib/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion alfalfa_worker/lib/run_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a5391c0

Please sign in to comment.