diff --git a/data/assets/testwsa/pfss_io.asset b/data/assets/testwsa/pfss_io.asset index c982364b76..3d03c3b3c1 100755 --- a/data/assets/testwsa/pfss_io.asset +++ b/data/assets/testwsa/pfss_io.asset @@ -23,7 +23,7 @@ local fieldlines = { ColorTableRanges = { { -0.6, 0.6 }, }, - LoadAtRuntime = false, + LoadAtRuntime = true, ScaleToMeters = 1.0, SecondsBefore = 24*60*60, SecondsAfter = 24*60*60, diff --git a/data/assets/testwsa/pfss_io_25.asset b/data/assets/testwsa/pfss_io_25.asset index ad1f7f1a81..6ce0b01c87 100755 --- a/data/assets/testwsa/pfss_io_25.asset +++ b/data/assets/testwsa/pfss_io_25.asset @@ -23,7 +23,7 @@ local fieldlines = { ColorTableRanges = { { -0.6, 0.6 }, }, - LoadAtRuntime = false, + LoadAtRuntime = true, ScaleToMeters = 1.0, SecondsBefore = 24*60*60, SecondsAfter = 24*60*60, diff --git a/data/assets/testwsa/pfss_oi.asset b/data/assets/testwsa/pfss_oi.asset index 4e7ddf956a..56de4ee9e2 100755 --- a/data/assets/testwsa/pfss_oi.asset +++ b/data/assets/testwsa/pfss_oi.asset @@ -23,7 +23,7 @@ local fieldlines = { ColorTableRanges = { { -0.6, 0.6 }, }, - LoadAtRuntime = false, + LoadAtRuntime = true, ScaleToMeters = 1.0, SecondsBefore = 24*60*60, SecondsAfter = 24*60*60, @@ -31,7 +31,7 @@ local fieldlines = { Color = { Uniform = {0.725, 0.1, 0, 1} }, - ColoringMethod = "Quantity", + ColoringMethod = "Quantity" }, GUI = { Path = "/Solar System/Heliosphere", diff --git a/data/assets/testwsa/pfss_oi_25.asset b/data/assets/testwsa/pfss_oi_25.asset index 1437a203de..af07aaed7a 100755 --- a/data/assets/testwsa/pfss_oi_25.asset +++ b/data/assets/testwsa/pfss_oi_25.asset @@ -23,7 +23,7 @@ local fieldlines = { ColorTableRanges = { { -0.6, 0.6 }, }, - LoadAtRuntime = false, + LoadAtRuntime = true, ScaleToMeters = 1.0, SecondsBefore = 24*60*60, SecondsAfter = 24*60*60, diff --git a/data/assets/testwsa/pfss_oi_540.asset b/data/assets/testwsa/pfss_oi_540.asset index e35ffa9ceb..7974bf1a21 100644 --- a/data/assets/testwsa/pfss_oi_540.asset +++ b/data/assets/testwsa/pfss_oi_540.asset @@ -19,7 +19,7 @@ local fieldlines = { { 0, 1000000 }, { 100, 2000 } }, - LoadAtRuntime = false, + LoadAtRuntime = true, ScaleToMeters = 1.0, SecondsBefore = 24*60*60, SecondsAfter = 24*60*60, diff --git a/data/assets/testwsa/pfss_oi_boundary.asset b/data/assets/testwsa/pfss_oi_boundary.asset index 9999cb6422..ecf430b3e7 100644 --- a/data/assets/testwsa/pfss_oi_boundary.asset +++ b/data/assets/testwsa/pfss_oi_boundary.asset @@ -23,7 +23,7 @@ local fieldlines = { ColorTableRanges = { { -0.6, 0.6 }, }, - LoadAtRuntime = false, + LoadAtRuntime = true, ScaleToMeters = 1.0, SecondsBefore = 24*60*60, SecondsAfter = 24*60*60, diff --git a/data/assets/testwsa/scs_oi.asset b/data/assets/testwsa/scs_oi.asset index 62b5d7d42f..a75a5711e4 100755 --- a/data/assets/testwsa/scs_oi.asset +++ b/data/assets/testwsa/scs_oi.asset @@ -23,7 +23,7 @@ local fieldlines = { ColorTableRanges = { { -0.02, 0.02 }, }, - LoadAtRuntime = false, + LoadAtRuntime = true, ScaleToMeters = 1.0, SecondsBefore = 24*60*60, SecondsAfter = 24*60*60, diff --git a/data/assets/testwsa/scs_oi_25.asset b/data/assets/testwsa/scs_oi_25.asset index ce6c635520..29546d8d57 100755 --- a/data/assets/testwsa/scs_oi_25.asset +++ b/data/assets/testwsa/scs_oi_25.asset @@ -23,7 +23,7 @@ local fieldlines = { ColorTableRanges = { { -0.02, 0.02 }, }, - LoadAtRuntime = false, + LoadAtRuntime = true, ScaleToMeters = 1.0, SecondsBefore = 24*60*60, SecondsAfter = 24*60*60, diff --git a/data/assets/testwsa/scs_oi_540.asset b/data/assets/testwsa/scs_oi_540.asset index af1af3c225..acc77e0741 100644 --- a/data/assets/testwsa/scs_oi_540.asset +++ b/data/assets/testwsa/scs_oi_540.asset @@ -19,7 +19,7 @@ local fieldlines = { { 0, 1000000 }, { 100, 2000 } }, - LoadAtRuntime = false, + LoadAtRuntime = true, ScaleToMeters = 1.0, SecondsBefore = 24*60*60, SecondsAfter = 24*60*60, diff --git a/data/assets/testwsa/scs_oi_boundary.asset b/data/assets/testwsa/scs_oi_boundary.asset index 2a6a6de903..e1e76d3fae 100644 --- a/data/assets/testwsa/scs_oi_boundary.asset +++ b/data/assets/testwsa/scs_oi_boundary.asset @@ -23,7 +23,7 @@ local fieldlines = { ColorTableRanges = { { -0.02, 0.02 }, }, - LoadAtRuntime = false, + LoadAtRuntime = true, ScaleToMeters = 1.0, SecondsBefore = 24*60*60, SecondsAfter = 24*60*60, diff --git a/modules/fieldlinessequence/rendering/renderablefieldlinessequence.cpp b/modules/fieldlinessequence/rendering/renderablefieldlinessequence.cpp index 78ec022b2b..762532cdad 100644 --- a/modules/fieldlinessequence/rendering/renderablefieldlinessequence.cpp +++ b/modules/fieldlinessequence/rendering/renderablefieldlinessequence.cpp @@ -1196,11 +1196,8 @@ void RenderableFieldlinesSequence::update(const UpdateData& data) { computeSequenceEndTime(); } - const bool isInInterval = (currentTime >= _startTimes[0]) && (currentTime < _sequenceEndTime); - - // Check if current time in OpenSpace is within sequence interval if (isInInterval) { diff --git a/modules/fieldlinessequence/util/webfieldlinesmanager.cpp b/modules/fieldlinessequence/util/webfieldlinesmanager.cpp index 8ca01b697d..ce97b1d8ef 100644 --- a/modules/fieldlinessequence/util/webfieldlinesmanager.cpp +++ b/modules/fieldlinessequence/util/webfieldlinesmanager.cpp @@ -40,45 +40,44 @@ namespace { namespace openspace{ - WebFieldlinesManager::WebFieldlinesManager(std::string identifier, std::string fieldLineModelType): - _flsType(fieldLineModelType) - { - _syncDir = initializeSyncDirectory(identifier); - - std::string testTime; - triggerTimeInt2String(610056000, testTime); - - int testInt; - triggerTimeString2Int(testTime, testInt); + WebFieldlinesManager::WebFieldlinesManager(std::string syncDir){ + // change to parameter + _syncDir = "/Users/shuy/Offline-dokument/OpenSpace/Spaceweather/OpenSpace/data/assets/testwsa/fl_pfss_io_25"; + _flsType = "PfssIo"; + _downloadMargin = 3; + _timeTriggerDelta = 7200; + getAvailableTriggertimes(); + setInitialSet(global::timeManager.time().j2000Seconds()); + LERROR("WebFieldlinesManager initialized"); - + } - // For testing purposes - void WebFieldlinesManager::downloadFieldlines(std::vector& _sourceFile, std::vector& _startTimes, size_t& _nStates){ + // dowload files specified in _filestodownload + // I'm thinking we can replace the parameters with pointers to the lists that will be + // initialized in the constuctor instead + void WebFieldlinesManager::downloadFieldlines(std::vector& _sourceFiles, std::vector& _startTimes, size_t& _nStates){ LERROR("starting download"); - for (auto& tt : _availableTriggertimes){ + for (int index : _filesToDownload){ - downloadOsfls(tt); - - //add the timetrigger at the right place in the list - std::string sub = tt.substr(6, 23); - int temp; - triggerTimeString2Int(sub,temp); - double timetriggernumber = temp; - - int i = 0; - while(timetriggernumber > _startTimes[i]){ - if( i == _startTimes.size()) break; + std::string filename = _availableTriggertimes[index].second; + double timetrigger = _availableTriggertimes[index].first; + + // download fieldlines file + std::string destPath = downloadOsfls(filename); + + //add the timetrigger at the right place in the list + int i = 0; + while(timetrigger > _startTimes[i]){ + if( i == static_cast(_nStates)) break; else i++; - } - _sourceFile.insert(_sourceFile.begin() + i, _syncDir + '/' + tt.substr(6)); - _startTimes.insert(_startTimes.begin() + i, timetriggernumber); + _sourceFiles.insert(_sourceFiles.begin() + i, destPath); + _startTimes.insert(_startTimes.begin() + i, timetrigger); _nStates += 1; } } @@ -109,11 +108,25 @@ namespace openspace{ // --------------------------- PRIVATE FUNCTIONS --------------------------- // - void WebFieldlinesManager::update(){ - + // this function aint done + void WebFieldlinesManager::update(std::vector startTimes, int activeTriggerTimeIndex){ + // check how many are left until fieldlinessequence runs out - add direction information later + double nextTheroticalTimeTrigger; + double eps = 100; + if(activeTriggerTimeIndex == startTimes.size()-1){ + // if it's at the last index, definetily start some downloading + return; + } + for (int i = activeTriggerTimeIndex; i < startTimes.size(); i++){ + nextTheroticalTimeTrigger = startTimes[i] +_timeTriggerDelta; + if(startTimes[i + 1] > (nextTheroticalTimeTrigger + eps)){ + // do some downloading + } + + } } - void WebFieldlinesManager::downloadOsfls(std::string triggertime){ + std::string WebFieldlinesManager::downloadOsfls(std::string triggertime){ std::string url = "http://localhost:3000/WSA/" + triggertime; std::string destinationpath = absPath(_syncDir + '/' + triggertime.substr(6)); AsyncHttpFileDownload ashd = AsyncHttpFileDownload(url, destinationpath, HttpFileDownload::Overwrite::Yes); @@ -127,6 +140,7 @@ namespace openspace{ if(ashd.hasFailed() == true ){ LERROR("failed: " + destinationpath); } + return destinationpath; } // Make sure that the sync directory exists @@ -152,23 +166,41 @@ namespace openspace{ opt.requestTimeoutSeconds = 0; mmryDld.download(opt); - // Put the results in a string and remove [ ] + // Put the results in a string std::string s; std::transform(mmryDld.downloadedData().begin(), mmryDld.downloadedData().end(), std::back_inserter(s), [](char c) { return c; }); parseTriggerTimesList(s); + + // sort ascending by trigger time + std::sort(_availableTriggertimes.begin(), _availableTriggertimes.end()); } void WebFieldlinesManager::setInitialSet(double openSpaceTime){ + int openspaceindex = -1; + do openspaceindex++; + while (openSpaceTime > _availableTriggertimes[openspaceindex].first); + + int startInd = openspaceindex - _downloadMargin; + int endInd = openspaceindex + _downloadMargin; + + if(startInd < 0) startInd = 0; + if(endInd >= _availableTriggertimes.size()) + endInd = _availableTriggertimes.size()-1; + + for(int i = startInd; i <= endInd; i++) + _filesToDownload.push_back(i); } + // TODO void WebFieldlinesManager::downloadInitialSequence(std::vector triggertimes){ } + // TODO void WebFieldlinesManager::updateStartTimes(){ } @@ -177,25 +209,27 @@ namespace openspace{ // Turn into stringstream to parse the comma-delimited string into vector std::stringstream ss(s); char c; - std::string substr; + std::string sub; while(ss >> c) { if (c == '[' || c == ']' || c == '"' ) continue; else if (c == ','){ - _availableTriggertimes.push_back(substr); - substr.clear(); + double tt = triggerTimeString2Int(sub.substr(6, 23)); + _availableTriggertimes.push_back(std::make_pair(tt, sub)); + sub.clear(); } - else substr += c; + else sub += c; } - _availableTriggertimes.push_back(substr); + double tt = triggerTimeString2Int(sub.substr(6, 23)); + _availableTriggertimes.push_back(std::make_pair(tt, sub)); } - void WebFieldlinesManager::triggerTimeString2Int(std::string s, int& i){ + int WebFieldlinesManager::triggerTimeString2Int(std::string s){ s.replace(13, 1, ":"); s.replace(16, 1, ":"); Time time = Time(); time.setTime(s); - i = static_cast (time.j2000Seconds() - 69.185013294); + return static_cast (time.j2000Seconds() - 69.185013294); } void WebFieldlinesManager::triggerTimeInt2String(int i, std::string& s){ diff --git a/modules/fieldlinessequence/util/webfieldlinesmanager.h b/modules/fieldlinessequence/util/webfieldlinesmanager.h index c1fe5cd9cc..5fc2ca670a 100644 --- a/modules/fieldlinessequence/util/webfieldlinesmanager.h +++ b/modules/fieldlinessequence/util/webfieldlinesmanager.h @@ -32,13 +32,12 @@ namespace openspace { class WebFieldlinesManager{ public: - WebFieldlinesManager() = default; - // Constructor - WebFieldlinesManager(std::string identifier, std::string fieldLineModelType); - - // For testing purposes - void downloadFieldlines(std::vector& _sourceFile, std::vector& _startTimes, size_t& _nStates); + WebFieldlinesManager() = default; + WebFieldlinesManager(std::string syncDir); + + // download files specified in _filestodownload + void downloadFieldlines(std::vector& _sourceFiles, std::vector& _startTimes, size_t& _nStates); //---------------- OPERATORS ------------------------- // @@ -52,28 +51,33 @@ public: private: - + // Directory for saving this specific typ of field line, named by the identifier std::string _syncDir; // What model is this field line derived from, may come to be the same as the identifier std::string _flsType; + int _downloadMargin; + + // How long between the timesteps? + double _timeTriggerDelta; + // List of all triggertimes(field lines states) available for download - // ***turn into ints later*** - std::vector _availableTriggertimes; + std::vector> _availableTriggertimes; + + // Indices for what fieldlines to download + std::vector _filesToDownload; // Function to run in FieldLinesSequence's update loop - void update(); + void update(std::vector startTimes, int activeTriggerTimeIndex); // Download one file, given what model type and triggertime in J2000 // ***turn into ints later*** - void downloadOsfls(std::string triggertime); - - // Checks if there is a sync directory for one specific set of field lines - // If not creates one and returns the string to that directory - std::string initializeSyncDirectory(std::string identifier); + std::string downloadOsfls(std::string triggertime); + std::string initializeSyncDirectory(std::string identifier); + // Get list of all triggertimes(field lines states) available form the server void getAvailableTriggertimes(); @@ -91,8 +95,8 @@ private: // Parse the data from http request void parseTriggerTimesList(std::string s); - // some temporary functions to translate the filenames to ints - void triggerTimeString2Int(std::string s, int& d); + // some temporary functions to translate the filenames to ints (doubles?) + int triggerTimeString2Int(std::string s); void triggerTimeInt2String(int d, std::string& s); };