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 547988b
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 13 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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0"?>
<measure>
<schema_version>3.1</schema_version>
<name>alfalfa_metadata</name>
<uid>870213d3-36a2-4da2-9a04-c377a37fd4fe</uid>
<version_id>6f08ed47-aa1b-407f-a9c8-bbd58fbfaba7</version_id>
<version_modified>2023-12-05T20:31:10Z</version_modified>
<xml_checksum>70995EFB</xml_checksum>
<class_name>AlfalfaMetadata</class_name>
<display_name>Alfalfa Metadata</display_name>
<description>Generate metadata report for Alfalfa</description>
<modeler_description>Generate metadata report for Alfalfa</modeler_description>
<arguments />
<outputs />
<provenances />
<tags>
<tag>HVAC.HVAC Controls</tag>
</tags>
<attributes>
<attribute>
<name>Measure Type</name>
<value>EnergyPlusMeasure</value>
<datatype>string</datatype>
</attribute>
</attributes>
<files>
<file>
<version>
<software_program>OpenStudio</software_program>
<identifier>3.1.0</identifier>
<min_compatible>3.1.0</min_compatible>
</version>
<filename>measure.rb</filename>
<filetype>rb</filetype>
<usage_type>script</usage_type>
<checksum>901131AC</checksum>
</file>
</files>
</measure>
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 547988b

Please sign in to comment.