diff --git a/data/assets/scene/solarsystem/planets/earth/aurorasaurus/main.asset b/data/assets/scene/solarsystem/planets/earth/aurorasaurus/main.asset index 86618254fe..361a2b776c 100644 --- a/data/assets/scene/solarsystem/planets/earth/aurorasaurus/main.asset +++ b/data/assets/scene/solarsystem/planets/earth/aurorasaurus/main.asset @@ -50,9 +50,9 @@ asset.require("./may2024assets/rendermodeTest/22") ]] asset.require("./actions") --asset.require("./auroraImage") --asset.require("./ovalGeojson") -asset.require("./ovalLayer") +--asset.require("./ovalLayer") -asset.require("./northernViewline") -asset.require("./southernViewline") +--asset.require("./northernViewline") +--asset.require("./southernViewline") --asset.require("./mission") ---asset.require("./storm") \ No newline at end of file +asset.require("./storm") \ No newline at end of file diff --git a/data/assets/scene/solarsystem/planets/earth/aurorasaurus/storm.asset b/data/assets/scene/solarsystem/planets/earth/aurorasaurus/storm.asset index dfbe7ad714..f30168b3c9 100644 --- a/data/assets/scene/solarsystem/planets/earth/aurorasaurus/storm.asset +++ b/data/assets/scene/solarsystem/planets/earth/aurorasaurus/storm.asset @@ -42,14 +42,15 @@ local marker = { } asset.onInitialize(function() - openspace.addScreenSpaceRenderable(marker) + --openspace.addScreenSpaceRenderable(marker) openspace.addScreenSpaceRenderable(Dashboard) + openspace.setPropertyValueSingle("ScreenSpace.ScreenSpaceKPindex.CartesianPosition", {-0.630000,0.380000,-2.310000}) openspace.setPropertyValueSingle("ScreenSpace.ScreenSpaceKPindex.Size", {0.000000,0.000000,640.000000,320.000000}) end) asset.onDeinitialize(function() - openspace.removeScreenSpaceRenderable(marker) + --openspace.removeScreenSpaceRenderable(marker) openspace.addScreenSpaceRenderable(Dashboard) end) diff --git a/modules/base/dashboard/dashboarditemtext.cpp b/modules/base/dashboard/dashboarditemtext.cpp index ddf52a4ed2..39fc982f7f 100644 --- a/modules/base/dashboard/dashboarditemtext.cpp +++ b/modules/base/dashboard/dashboarditemtext.cpp @@ -27,12 +27,24 @@ #include #include #include +#include #include #include #include #include #include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + namespace { constexpr openspace::properties::Property::PropertyInfo TextInfo = { "Text", @@ -57,6 +69,24 @@ documentation::Documentation DashboardItemText::Documentation() { ); } +void DashboardItemText::loadDataFromJson(const std::string& filePath) { + std::ifstream file(filePath); + if (!file.is_open()) { + throw std::runtime_error("Unable to open JSON file: " + filePath); + } + + nlohmann::json jsonData; + file >> jsonData; + + _data.clear(); + + for (const auto& item : jsonData["data"]) { + std::string time = item[0].get(); + double value = item[1].get(); + _data[time] = value; + } +} + DashboardItemText::DashboardItemText(const ghoul::Dictionary& dictionary) : DashboardTextItem(dictionary) , _text(TextInfo, "") @@ -64,11 +94,50 @@ DashboardItemText::DashboardItemText(const ghoul::Dictionary& dictionary) const Parameters p = codegen::bake(dictionary); _text = p.text.value_or(_text); addProperty(_text); + + loadDataFromJson("C:/Users/alundkvi/Documents/work/OpenSpace/user/data/assets/aurorasaurus/KPjson/data.json"); } +std::string formatTimeForData(std::string_view timeStr) { + std::string formattedTime(timeStr); + + // Convert to the format YYYY-MM-DDTHH:MM:00Z + std::replace(formattedTime.begin(), formattedTime.end(), 'T', ' '); + std::replace(formattedTime.begin(), formattedTime.end(), '.', ' '); // Remove milliseconds + + std::tm tm = {}; + std::istringstream ss(formattedTime); + ss >> std::get_time(&tm, "%Y %b %d %H:%M:%S"); + + std::ostringstream oss; + oss << std::put_time(&tm, "%Y-%m-%dT%H:%M:00Z"); + return oss.str(); +} + +double DashboardItemText::getValueForCurrentTime() const { + std::string_view currentTimeStr = global::timeManager->time().UTC(); + std::string formattedTime = formatTimeForData(currentTimeStr); + + // Check if the formatted time exists in the data + auto it = _data.find(formattedTime); + if (it != _data.end()) { + // Exact match found, update last value + _lastValue = it->second; + return _lastValue; + } + + // If no exact match is found, return the last value + return _lastValue; +} + + void DashboardItemText::render(glm::vec2& penPosition) { ZoneScoped; + double value = getValueForCurrentTime(); + + _text = "KP Index: " + std::to_string(value); + penPosition.y -= _font->height(); RenderFont(*_font, penPosition, _text.value()); } diff --git a/modules/base/dashboard/dashboarditemtext.h b/modules/base/dashboard/dashboarditemtext.h index ef11a0cca1..70babc06c2 100644 --- a/modules/base/dashboard/dashboarditemtext.h +++ b/modules/base/dashboard/dashboarditemtext.h @@ -29,6 +29,21 @@ #include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + namespace openspace { namespace documentation { struct Documentation; } @@ -46,6 +61,12 @@ public: private: properties::StringProperty _text; + std::unordered_map _data; + + mutable double _lastValue = 0.0; + + void loadDataFromJson(const std::string& filePath); + double getValueForCurrentTime() const; }; } // namespace openspace