18 #include "geopop/ContactCenter.h" 23 #include <boost/lexical_cast.hpp> 24 #include <boost/property_tree/json_parser.hpp> 41 boost::property_tree::ptree root;
44 }
catch (runtime_error&) {
45 throw Exception(
"Problem parsing JSON file, check whether empty or invalid JSON.");
49 auto people = root.get_child(
"persons");
51 for (
auto it = people.begin(); it != people.end(); it++) {
52 auto person =
ParsePerson(it->second.get_child(
""));
55 auto locations = root.get_child(
"locations");
57 for (
auto it = locations.begin(); it != locations.end(); it++) {
58 shared_ptr<Location> loc;
60 geoGrid.AddLocation(move(loc));
70 const auto id = boost::lexical_cast<
unsigned int>(location.get<
string>(
"id"));
71 const auto name = location.get<
string>(
"name");
72 const auto province = boost::lexical_cast<
unsigned int>(location.get<
string>(
"province"));
73 const auto population = boost::lexical_cast<
unsigned int>(location.get<
string>(
"population"));
74 const auto coordinate =
ParseCoordinate(location.get_child(
"coordinate"));
76 auto result = make_shared<Location>(id, province, coordinate, name, population);
77 auto contactCenters = location.get_child(
"contactCenters");
79 for (
auto it = contactCenters.begin(); it != contactCenters.end(); it++) {
81 result->AddCenter(center);
84 if (location.count(
"commutes")) {
85 boost::property_tree::ptree commutes = location.get_child(
"commutes");
86 for (
auto it = commutes.begin(); it != commutes.end(); it++) {
87 const auto to = boost::lexical_cast<
unsigned int>(it->first);
88 const auto amount = boost::lexical_cast<
double>(it->second.data());
98 const auto longitude = boost::lexical_cast<
double>(coordinate.get<
string>(
"longitude"));
99 const auto latitude = boost::lexical_cast<
double>(coordinate.get<
string>(
"latitude"));
100 return {longitude, latitude};
105 const auto type = contactCenter.get<
string>(
"type");
106 const auto id = boost::lexical_cast<
unsigned int>(contactCenter.get<
string>(
"id"));
109 if (type ==
ToString(Id::K12School)) {
110 typeId = Id::K12School;
111 }
else if (type ==
ToString(Id::College)) {
112 typeId = Id::College;
113 }
else if (type ==
ToString(Id::Household)) {
114 typeId = Id::Household;
115 }
else if (type ==
ToString(Id::PrimaryCommunity)) {
116 typeId = Id::PrimaryCommunity;
117 }
else if (type ==
ToString(Id::SecondaryCommunity)) {
118 typeId = Id::SecondaryCommunity;
119 }
else if (type ==
ToString(Id::Workplace)) {
120 typeId = Id::Workplace;
122 throw Exception(
"No such ContactCenter type: " + type);
124 auto result = make_shared<ContactCenter>(id, typeId);
125 auto contactPools = contactCenter.get_child(
"pools");
127 for (
auto it = contactPools.begin(); it != contactPools.end(); it++) {
129 result->RegisterPool(pool);
139 auto people = contactPool.get_child(
"people");
141 for (
auto it = people.begin(); it != people.end(); it++) {
142 auto person_id = boost::lexical_cast<
unsigned int>(it->second.get<
string>(
""));
143 if (
m_people.count(person_id) == 0) {
144 throw Exception(
"No such person: " + to_string(person_id));
146 result->AddMember(
m_people[person_id]);
154 const auto id = boost::lexical_cast<
unsigned int>(person.get<
string>(
"id"));
155 const auto age = boost::lexical_cast<
unsigned int>(person.get<
string>(
"age"));
156 const auto hhId = boost::lexical_cast<
unsigned int>(person.get<
string>(
"Household"));
157 const auto ksId = boost::lexical_cast<
unsigned int>(person.get<
string>(
"K12School"));
158 const auto coId = boost::lexical_cast<
unsigned int>(person.get<
string>(
"College"));
159 const auto wpId = boost::lexical_cast<
unsigned int>(person.get<
string>(
"Workplace"));
160 const auto pcId = boost::lexical_cast<
unsigned int>(person.get<
string>(
"PrimaryCommunity"));
161 const auto scId = boost::lexical_cast<
unsigned int>(person.get<
string>(
"SecondaryCommunity"));
void Read() override
Actually perform the read and return the GeoGrid.
std::shared_ptr< ContactCenter > ParseContactCenter(boost::property_tree::ptree &contactCenter)
Create a ContactCenter based on the information stored in the provided boost property tree...
Id
Enumerates the ContactPool types.
void AddCommutes(GeoGrid &geoGrid)
Add the commutes that were found to their respective Locations symmetrically.
A group of Persons that potentially have contacts with one another.
Utilities for the project.
string ToString(Id l)
Converts a LogMode value to corresponding name.
stride::Population * m_population
Population to use in the GeoGrid may be nullptr.
geopop::GeoGrid & RefGeoGrid()
Reference the GeoGrid associated with this population (may be a nullptr).
Basic exception class: needed to prevent clang-tidy warning "thrown exception type is not nothrow cop...
ContactPoolSys & RefPoolSys()
Reference the ContactPoolSys of the Population.
Key Data structure: container for (a) all individuals in the population (b) the ContactPoolSys wchich...
Coordinate ParseCoordinate(boost::property_tree::ptree &coordinate)
Create a Coordinate based on the information stored in the provided boost property tree...
Namespace for the geographic and demograhic classes.
std::vector< std::tuple< unsigned int, unsigned int, double > > m_commutes
Person * CreatePerson(unsigned int id, double age, unsigned int householdId, unsigned int k12SchoolId, unsigned int collegeId, unsigned int workId, unsigned int primaryCommunityId, unsigned int secondaryCommunityId)
Create Person in the population.
std::unique_ptr< std::istream > m_inputStream
File to read.
An abstract base class for creating a GeoGrid that was read from a file, can be implemented using mul...
boost::geometry::model::point< double, 2, boost::geometry::cs::geographic< boost::geometry::degree >> Coordinate
Header file for the core Population class.
GeoGridJSONReader(std::unique_ptr< std::istream > inputStream, stride::Population *pop)
Construct the GeoGridJSONReader with the istream which contains the JSON.
std::map< unsigned int, stride::Person * > m_people
< Store the persons (id->person) that were found while loping over the ContactPools.
ContactPool * CreateContactPool(ContactType::Id typeId)
Create a new contact pool of a given type.
std::shared_ptr< Location > ParseLocation(boost::property_tree::ptree &location)
Create a Location based on the information stored in the provided boost property tree.
Store and handle person data.
Namespace for the simulator and related classes.
stride::Person * ParsePerson(boost::property_tree::ptree &person)
Create a Person based on the information stored in the provided boost property tree.
stride::ContactPool * ParseContactPool(boost::property_tree::ptree &contactPool, stride::ContactType::Id typeId)
Create a ContactCenter based on the information stored in the provided boost property tree...
Namespace to manage types of ContactPool.