Skip to content

Commit

Permalink
Add default values to missing json entries
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkStar1997 committed Aug 5, 2023
1 parent 3412214 commit f8b789c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions simulation/src/avg_plot_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ void AveragePlotHandler::add_record(const FBuffer& avg_world_instance,
for (const auto& [key, value] : current_organism_json.items()) {
organism_json[key].emplace_back(value);
}

// add 0s to empty entries
const flatbuffers::TypeTable* type_table =
Ecosystem::OrganismTypeTable();
for (size_t i = 0; i < type_table->num_elems; i++) {
if (type_table->type_codes[i].base_type ==
flatbuffers::ET_FLOAT ||
type_table->type_codes[i].base_type ==
flatbuffers::ET_UINT) {
if (current_organism_json.find(type_table->names[i]) ==
current_organism_json.end()) {
organism_json[type_table->names[i]].emplace_back(0);
}
}
}
}
auto& population_json = species_json["organism"];
for (const auto& [key, value] :
Expand Down
2 changes: 1 addition & 1 deletion simulation/src/stat_fetcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ FBuffer create_avg_world(const flatbuffers::DetachedBuffer &world_buffer) {
auto asleep = species->organism()->Get(0)->asleep(); // dummy
auto monitor = species->organism()->Get(0)->monitor(); // dummy

std::vector<uint8_t> chromosome_vec; // dummy
std::vector<uint8_t> chromosome_vec; // dummy
auto chromosome = new_builder.CreateVector(chromosome_vec.data(),
chromosome_vec.size());

Expand Down

0 comments on commit f8b789c

Please sign in to comment.