MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / toJSON

Function toJSON

src/epjson/epJSONTranslator.cpp:328–493  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

326}
327
328Json::Value toJSON(const openstudio::IdfFile& idf, const openstudio::path& schemaPath) {
329
330 openstudio::path schemaToLoad = schemaPath;
331 if (schemaToLoad.empty()) {
332 schemaToLoad = defaultSchemaPath(idf.iddFileType());
333 if (schemaToLoad.empty()) {
334 return Json::Value::null;
335 }
336 }
337
338 std::map<std::string, int> type_counts;
339
340 Json::Value result;
341
342 std::map<std::pair<std::string, std::string>, std::pair<std::string, bool>> group_names;
343 std::map<std::string, std::string> field_names;
344
345 Json::Value schema = loadJSON(schemaToLoad);
346 if (schema.isNull()) {
347 LOG_FREE(LogLevel::Error, "epJSONTranslator", "Schema is invalid at path=" << schemaToLoad);
348 return Json::Value::null;
349 }
350
351 result["Version"]["Version 1"]["version_identifier"] = fmt::format("{}.{}", idf.version().major(), idf.version().minor());
352
353 for (const auto& obj : idf.objects()) {
354 if (obj.iddObject().type().value() == openstudio::IddObjectType::CommentOnly) {
355 // we aren't translating comments it seems
356 continue;
357 }
358
359 const auto& type_description = obj.iddObject().type().valueDescription();
360
361 const auto& name = obj.name();
362 const auto& defaultedName = obj.nameString(true);
363
364 auto& json_group = result[type_description];
365
366 const bool is_fluid_properties_name = type_description.find("FluidProperties:Name") != std::string::npos;
367 const bool is_lcc_use_price_escalation = type_description.find("LifeCycleCost:UsePriceEscalation") != std::string::npos;
368
369 const auto& usable_json_object_name = [&]() {
370 if (name && !is_fluid_properties_name) {
371 return *name;
372 } else {
373 if (!defaultedName.empty() && !is_fluid_properties_name) {
374 return defaultedName;
375 } else {
376 return fmt::format("{} {}", type_description, ++type_counts[type_description]);
377 }
378 }
379 }();
380
381 auto& json_object = json_group[usable_json_object_name];
382 json_object = Json::Value(Json::objectValue);
383
384 if (name) {
385 if (is_fluid_properties_name) {

Callers 15

toJSONStringFunction · 0.85
TEST_FFunction · 0.85
toJSONStringMethod · 0.85
toJSONStringMethod · 0.85
toJSONStringMethod · 0.85
toJSONStringMethod · 0.85
toJSONStringMethod · 0.85
toJSONStringMethod · 0.85
toJSONStringMethod · 0.85
stringMethod · 0.85
stringMethod · 0.85

Calls 15

defaultSchemaPathFunction · 0.85
loadJSONFunction · 0.85
fixupEnumerationValueFunction · 0.85
getGroupNameFunction · 0.85
getFieldNameFunction · 0.85
isNullMethod · 0.80
majorMethod · 0.80
minorMethod · 0.80
iddObjectMethod · 0.80
valueDescriptionMethod · 0.80
nameStringMethod · 0.80

Tested by 2

TEST_FFunction · 0.68