3 #include <boost/property_tree/xml_parser.hpp> 4 #include <boost/property_tree/ptree.hpp> 5 #include <boost/property_tree/json_parser.hpp> 6 #include <boost/filesystem.hpp> 20 using boost::property_tree::ptree;
21 using boost::property_tree::write_json;
27 using std::stringstream;
35 m_sim_day(0), m_file_name(file_name), m_pop_file_name(pop_file_name), m_facility_file_name(facility_file_name) {
46 boost::filesystem::create_directory(boost::filesystem::path(
m_file_dir));
52 if (!boost::filesystem::exists(boost::filesystem::path(
m_file_dir))) {
53 boost::filesystem::create_directory(boost::filesystem::path(
m_file_dir));
57 if (!boost::filesystem::exists(boost::filesystem::path(
m_pop_file_dir))) {
58 boost::filesystem::create_directory(boost::filesystem::path(
m_pop_file_dir));
71 ss << setfill(
'0') << setw(5) <<
m_sim_day;
73 csv_file.open(file_name.c_str());
76 csv_file <<
"id,size,infected,infected_percent,lat,lon,type" << endl;
93 size_t size = cluster.
getSize();
98 double ratio = (infected_count == 0 ? -1 : (
double) infected_count / size);
101 csv_file << cluster.
getId() <<
',' <<
103 infected_count <<
',' <<
111 map<GeoCoordinate, vector<unsigned int>> aggregation_mapping;
113 for (
unsigned int i = 1; i < households.size(); i++) {
114 aggregation_mapping[households[i].getLocation()].push_back(i);
117 for (
auto entry : aggregation_mapping) {
123 ofstream& csv_file)
const {
125 unsigned int id = households[indices[0]].getId();
127 string cluster_type =
toString(households[indices[0]].getClusterType());
129 unsigned int total_size = 0;
130 unsigned int total_infected = 0;
131 for (
auto index : indices) {
132 total_size += households[index].getSize();
133 total_infected += households[index].getInfectedCount();
135 double ratio = (total_infected == 0 ? -1 : (
double) total_infected / total_size);
137 csv_file <<
id <<
',' <<
139 total_infected <<
',' <<
143 cluster_type <<
"\n";
184 ptree cluster_geometry;
185 ptree cluster_properties;
187 cluster_geometry.put(
"type",
"Point");
195 coordinates.push_back(std::make_pair(
"", lon));
196 coordinates.push_back(std::make_pair(
"", lat));
197 cluster_geometry.add_child(
"coordinates", coordinates);
199 size_t id = cluster.
getId();
200 size_t size = cluster.
getSize();
202 double ratio = (size == 0 ? 0 : (
double) infected_count / size);
203 if (infected_count == 0) {
208 cluster_properties.put(
"id",
id);
209 cluster_properties.put(
"size", size);
210 cluster_properties.put(
"infected", infected_count);
211 cluster_properties.put(
"infected_percent", ratio);
212 cluster_properties.put(
"type", cluster_type);
214 return std::make_pair(cluster_geometry, cluster_properties);
217 #define SET_CLUSTER_SURFACE(cluster_type) \ 219 surface = ClusterCalculator<cluster_type>::calculateSurface(local_sim); \ 220 if (surface == 0.0) \ 221 densities.put(toString(cluster_type), 0.0); \ 223 densities.put(toString(cluster_type), double(pop_count) / surface); \ 226 #define SET_CLUSTER_MAP(cluster_type) \ 228 ptree specific_cluster_map; \ 229 auto cluster_map = ClusterCalculator<cluster_type>::getClusterMap(local_sim); \ 230 for (auto it = cluster_map.begin(); it != cluster_map.end(); ++it) { \ 231 if (it->first != 0) { \ 232 specific_cluster_map.put(to_string(it->first), it->second); \ 235 cluster_sizes.add_child(toString(cluster_type), specific_cluster_map); \ 240 ss << setfill(
'0') << setw(5) <<
m_sim_day;
257 pop_data.add_child(
"densities", densities);
262 for (
auto it = age_map.begin(); it != age_map.end(); ++it) {
263 ages.put(to_string(it->first), it->second);
266 pop_data.add_child(
"age_map", ages);
277 pop_data.add_child(
"cluster_sizes", cluster_sizes);
280 write_json(file_name.c_str(), pop_data);
288 total += cluster.getSize();
295 map<uint, uint> result;
298 for (
const auto& person: cluster.getMembers()) {
299 if (result.find(person.first->getAge()) == result.end()) {
300 result[person.first->getAge()] = 0;
302 ++result[person.first->getAge()];
315 for (
const auto& facility: district.m_transportations_facilities) {
316 ptree facility_config;
317 facility_config.put(
"city", district.getName());
318 facility_config.put(
"name", facility.first);
319 facility_config.put(
"location.lat", district.getLocation().m_latitude);
320 facility_config.put(
"location.lon", district.getLocation().m_longitude);
321 facility_config.put(
"influence", facility.second.getInfluence());
322 facility_config.put(
"passengers_today", facility.second.m_deque.front());
323 facility_config.put(
"passengers_x_days", facility.second.getScore());
324 facility_config.put(
"x_days", facility.second.m_deque.size());
326 children.push_back(make_pair(
"", facility_config));
330 result.add_child(
"facilities", children);
333 ss << setfill(
'0') << setw(5) <<
m_sim_day;
335 write_json(file_name.c_str(), result);
const std::vector< Cluster > & getPrimaryCommunities() const
GeoCoordinate getLocation() const
Return the geo coordinates (latitude-longitude) of the cluster.
Interface for install directory queries.
string toString(ClusterType c)
Converts a ClusterType value to corresponding name.
double getPopCount(const Simulator &local_sim) const
#define SET_CLUSTER_SURFACE(cluster_type)
void saveClustersCSV(const Simulator &sim) const
Saves cluster information for Households (aggregated), Primary Communities and Secondary Communities...
ClusterType getClusterType() const
Return the type of this cluster.
std::size_t getInfectedCount() const
Return the amount of infected people in this cluster.
#define SET_CLUSTER_MAP(cluster_type)
Time Dependent Person DataType.
void saveClustersJSON(const Simulator &sim) const
pair< ptree, ptree > getClusterJSON(const Cluster &cluster) const
void saveTransportationFacilities(const Simulator &local_sim) const
ClusterSaver(string file_name, string pop_file_name, string facility_file_name, string output_dir)
map< uint, uint > getAgeMap(const Simulator &local_sim) const
void saveClusterGroup(const vector< Cluster > &households, const vector< uint > indices, ofstream &csv_file) const
Saves an aggregated cluster. The clusters that need to be aggregated are given by the indices...
std::size_t getSize() const
Return number of persons in this cluster.
string m_facility_file_dir
const std::vector< Cluster > & getSchoolClusters() const
Definition of ClusterType.
Main class that contains and direct the virtual world.
std::size_t getId() const
Get the ID of this cluster.
const std::vector< Cluster > & getWorkClusters() const
const std::vector< Cluster > & getSecondaryCommunities() const
void savePopDataJSON(const Simulator &local_sim) const
string m_facility_file_name
Represents a location for social contacts, an group of people.
void saveClusterCSV(const Cluster &cluster, ofstream &csv_file) const
Saves a single cluster.
const std::vector< Cluster > & getHouseholds() const
void saveAggrClustersCSV(const vector< Cluster > &households, ofstream &csv_file) const
Aggregates the vector of given clusters according to their GeoLocation, and saves them...
const std::vector< District > & getDistricts() const