Skip to content

Commit

Permalink
Generate policy json file and display in GUI (#265)
Browse files Browse the repository at this point in the history
* Generate policy json file and display in GUI

* Fix json serialization error
  • Loading branch information
mreveil authored Sep 2, 2021
1 parent ca59aa0 commit f7abcfc
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 28 deletions.
11 changes: 11 additions & 0 deletions citam/engine/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,17 @@ def run_simulation(inputs: dict):
LOG.info("Extracting stats...")
my_model.save_outputs(work_directory)

# Write policy.json
policy = {}
del inputs["output_directory"]
policy["facility_name"] = inputs["facility_name"]
policy["general"] = inputs
policy["meetings"] = my_model.meetings_policy_params
policy["scheduling"] = my_model.scheduling_rules
policy["traffic"] = inputs["traffic_policy"]
with open(os.path.join(work_directory, "policy.json"), "w") as outfile:
json.dump(policy, outfile)

if upload_results and upload_location is not None:
LOG.info("Uploading results to server...")
cwd = os.getcwd()
Expand Down
2 changes: 2 additions & 0 deletions citamjs/src/components/Overview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,14 @@ export default {
.get("/list") //get list of policies, simulations, facilities
.then((response) => {
this.policyList = response.data.map((list) => list);
console.log("Policy list is: ", this.policyList);
this.$store.commit("setPolicyList", this.policyList);
return axios.all(response.data.map((x) => axios.get(`/${x.RunID}`)));
})
.then((runResponse) => {
// eslint-disable-next-line no-unused-vars
this.runList = runResponse.map((run) => run.data);
console.log("Run List: ", this.runList);
return axios.all(
runResponse.map((x) => axios.get(`/${x.data.RunID}/statistics`))
);
Expand Down
75 changes: 47 additions & 28 deletions citamjs/src/components/Policies.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
href="#"
@click="getPolicyDetails(policy.policyHash, id)"
>
{{ policy.policyHash }}
{{ policy.simulationName }}
</a>
</li>
</ul>
Expand Down Expand Up @@ -71,13 +71,13 @@
<div class="col">
<span>Total Steps</span>
<div class="polValue">
{{ policyDetails.general.daylength }}
{{ policyDetails.general.total_timesteps }}
</div>
</div>
<div class="col">
<span>Total Hours</span>
<div class="polValue">
{{ policyDetails.general.daylength / 3600 }}
{{ policyDetails.general.total_timesteps / 3600 }}
</div>
</div>
<div class="col"></div>
Expand All @@ -89,7 +89,7 @@
<div class="col">
<span>Number of Agents</span>
<div class="polValue">
{{ policyDetails.general.NumberOfEmployees }}
{{ policyDetails.general.n_agents }}
</div>
</div>
<div class="col"></div>
Expand All @@ -102,7 +102,13 @@
<div class="col">
<span>Distance (Meters)</span>
<div class="polValue">
{{ policyDetails.general.contact_distance }}
{{
Math.round(
(policyDetails.general.contact_distance +
Number.EPSILON) *
100
) / 100
}}
</div>
</div>
<div class="col"></div>
Expand All @@ -123,7 +129,7 @@
</div>
</div>
<div class="col">
<span>Shift Start time</span>
<span>Shift Start Timestep</span>
<div
class="polValue"
v-for="(shift, id) in policyDetails.general.shifts"
Expand All @@ -133,13 +139,13 @@
</div>
</div>
<div class="col">
<span>Percent of agents assigned to shift</span>
<span>Percent of Agents Assigned to Shift</span>
<div
class="polValue"
v-for="(shift, id) in policyDetails.general.shifts"
:key="id"
>
{{ shift.percent_workforce }}
{{ shift.percent_agents * 100 }}%
</div>
</div>
</div>
Expand All @@ -155,7 +161,7 @@
future, the possibility will be given to manually add specific
meetings that always take place (e.g. classroom instructions).
</div>
<div>
<div v-if="policyDetails.meetings">
<span class="headingFont">MEETING DURATION</span>
<div class="row polSubSection">
<div class="col">
Expand Down Expand Up @@ -216,6 +222,7 @@
<div class="col"></div>
</div>
</div>
<div v-else>No meetings in this simulation.</div>
</div>
<div class="polHeading">SCHEDULING POLICY</div>
<div class="polPanel">
Expand Down Expand Up @@ -282,7 +289,8 @@
<div class="polPanel">
<div class="polDesc">
A traffic policy is made of list of circulation rules where each
rule is as follows:
rule will apply to specific hallways (or aisles) and will dictate
the direciton of agent traffic in that space.
</div>
<div class="row polSubSection">
<div class="col">
Expand All @@ -296,7 +304,7 @@
</div>
</div>
<div class="col">
<span>Aisle SSegment Id</span>
<span>Aisle Segment Id</span>
<div
class="polValue"
v-for="(traffic, id) in policyDetails.traffic"
Expand Down Expand Up @@ -385,32 +393,43 @@ export default {
(item) => item.facilityName == this.selectedFacility
).policies,
};
console.log("Policy name: ", this.polName);
console.log("Policy data: ", this.policyData);
if (_.isEmpty(this.polName)) {
this.selectedPolicyData.policyInfo = this.policyData.policies[0];
axios
.get(`/${this.selectedPolicyData.policyInfo.simulationRuns[0].runID}/policy`) //get policy info with any of the simid
.then((response) => {
this.policyDetails = response.data;
return response.data;
})
.catch((error) => {
console.log(error.response)
alert('No policy data found, please check if policy.json file exists')
});
.get(
`/${this.selectedPolicyData.policyInfo.simulationRuns[0].runID}/policy`
) //get policy info with any of the simid
.then((response) => {
console.log("We have the policy: ", response.data);
this.policyDetails = response.data;
return response.data;
})
.catch((error) => {
console.log(error.response);
alert(
"No policy data found, please check if policy.json file exists"
);
});
} else {
this.selectedPolicyData.policyInfo = this.policyData.policies.find(
(item) => item.policyHash == this.polName
);
axios
.get(`/${this.selectedPolicyData.policyInfo.simulationRuns[0].runID}/policy`) //get policy info with any of the simid
.then((response) => {
this.policyDetails = response.data;
return response.data;
})
.get(
`/${this.selectedPolicyData.policyInfo.simulationRuns[0].runID}/policy`
) //get policy info with any of the simid
.then((response) => {
this.policyDetails = response.data;
return response.data;
})
.catch((error) => {
console.log(error.response)
alert('No policy data found, please check if policy.json file exists')
});
console.log(error.response);
alert(
"No policy data found, please check if policy.json file exists"
);
});
this.polIndex = this.policyData.policies.findIndex(
(item) => item.policyHash == this.polName
);
Expand Down

0 comments on commit f7abcfc

Please sign in to comment.