mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-25 05:29:41 -06:00
Merge remote-tracking branch 'origin/thesis/2019/spaceweather-stream' into thesis/2019/spaceweather-stream
This commit is contained in:
@@ -1188,7 +1188,7 @@ namespace openspace {
|
||||
}
|
||||
|
||||
void RenderableFieldlinesSequence::initializeWebManager() {
|
||||
_webFieldlinesManager.initializeWebFieldlinesManager(_identifier, _nStates, _sourceFiles, _startTimes);
|
||||
_webFieldlinesManager.initializeWebFieldlinesManager(_identifier,_dynWebContentUrl, _nStates, _sourceFiles, _startTimes);
|
||||
}
|
||||
|
||||
void RenderableFieldlinesSequence::update(const UpdateData& data) {
|
||||
|
||||
@@ -42,14 +42,13 @@ namespace {
|
||||
namespace openspace{
|
||||
|
||||
// --------------------------- PUBLIC FUNCTIONS --------------------------- //
|
||||
void WebFieldlinesManager::initializeWebFieldlinesManager(std::string identifier, size_t& _nStates, std::vector<std::string>& _sourceFiles,
|
||||
void WebFieldlinesManager::initializeWebFieldlinesManager(std::string identifier, std::string url, size_t& _nStates, std::vector<std::string>& _sourceFiles,
|
||||
std::vector<double>& _startTimes)
|
||||
{
|
||||
// Initialize the sliding window
|
||||
_webFieldlinesWindow = WebFieldlinesWindow(_syncDir, "http://localhost:3000/", _sourceFiles, _startTimes, _nStates, convertIdentifierToID(identifier));
|
||||
|
||||
LINFO("WebFieldlinesManager initialized " + identifier);
|
||||
_webFieldlinesWindow = WebFieldlinesWindow(_syncDir, url, _sourceFiles, _startTimes, _nStates, convertIdentifierToID(identifier));
|
||||
|
||||
LTRACE("WebFieldlinesManager initialized " + identifier);
|
||||
}
|
||||
|
||||
bool WebFieldlinesManager::isConnected() {
|
||||
@@ -77,8 +76,7 @@ namespace openspace{
|
||||
// the start latest line
|
||||
// this could be used to test the connection too
|
||||
void WebFieldlinesManager::preDownload(std::string dUrl){
|
||||
// Download a dataset that we know exists, hopefully the API could send the latest entry of that dataset
|
||||
// TODO(Axel): Change this endpoint to be dynamic for each dataset
|
||||
|
||||
int ID = std::stoi(dUrl.substr(dUrl.size() - 4));
|
||||
std::string type = "";
|
||||
switch (ID)
|
||||
@@ -95,22 +93,26 @@ namespace openspace{
|
||||
case 1179:
|
||||
type = "trace_pfss_outtoin";
|
||||
break;
|
||||
case 1180:
|
||||
type = "WSA_OUT";
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO(Axel): Change this endpoint to be dynamic for each dataset
|
||||
std::string url = "https://iswa.ccmc.gsfc.nasa.gov/iswa_data_tree/model/solar/WSA4.5/WSA4.5_fieldlines/" + type + "/2017/09/2017-09-28T00-23-22.000.osfls";
|
||||
std::string destinationpath = absPath(_syncDir + ghoul::filesystem::FileSystem::PathSeparator + "2017-09-28T00-23-22.000.osfls"); // what the downloaded filename is to be
|
||||
|
||||
/* For experimentation with suntexturemanager */
|
||||
if (ID == 1180) {
|
||||
url = "https://iswa.ccmc.gsfc.nasa.gov/iswa_data_tree/model/solar/WSA4.5/" + type + "/2017/09/wsa_201709280023R000_gong.fits";
|
||||
destinationpath = absPath(_syncDir + ghoul::filesystem::FileSystem::PathSeparator + "wsa_201709280023R000_gong.fits"); // what the downloaded filename is to be
|
||||
}
|
||||
/* End of experiment */
|
||||
|
||||
AsyncHttpFileDownload ashd = AsyncHttpFileDownload(url, destinationpath, HttpFileDownload::Overwrite::Yes);
|
||||
HttpRequest::RequestOptions opt = {};
|
||||
opt.requestTimeoutSeconds = 0;
|
||||
ashd.start(opt);
|
||||
ashd.wait();
|
||||
if(ashd.hasSucceeded() == true ){
|
||||
LERROR("succeeeded: " + destinationpath);
|
||||
}
|
||||
if(ashd.hasFailed() == true ){
|
||||
LERROR("failed: " + destinationpath);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
// To replace the constructor, takes the identifier of the field line, is used for storing the field lines mainly
|
||||
// Also takes a second parameter containing the name of the field line model used.
|
||||
// These may in the future be the same.
|
||||
void initializeWebFieldlinesManager(std::string identifier, size_t& _nStates, std::vector<std::string>& _sourceFiles, std::vector<double>& _startTimes);
|
||||
void initializeWebFieldlinesManager(std::string identifier, std::string url, size_t& _nStates, std::vector<std::string>& _sourceFiles, std::vector<double>& _startTimes);
|
||||
|
||||
// Returns true or false, wether a successful connection to the field line-providing server has been establish
|
||||
bool isConnected();
|
||||
|
||||
@@ -102,8 +102,7 @@ namespace openspace{
|
||||
/* Release the worker for execution,
|
||||
Pick up a timestep to request for download,
|
||||
Check if that timestep is already on disk,
|
||||
repeat until a proper timestep to download is found, and start download,
|
||||
(( Maybe alert Root RenderableFieldlinesSequence that it may udpates _sourceFiles/_startTimes?)) */
|
||||
repeated until a proper timestep to download is found, and start download */
|
||||
void WebFieldlinesWindow::executeDownloadWorker(){
|
||||
_worker.downloadWindow(_window.triggerTimes);
|
||||
_worker.updateRFSSourceFiles(*rfs_sourceFiles);
|
||||
@@ -111,21 +110,16 @@ namespace openspace{
|
||||
|
||||
void WebFieldlinesWindow::newWindow(double time){
|
||||
// Find where in the list we are
|
||||
int index = _nAvailableWeb-1;
|
||||
while(true){
|
||||
if(time > (_triggerTimesWeb[index].first)) break;
|
||||
index--;
|
||||
}
|
||||
auto it = std::find_if(_triggerTimesWeb.rbegin(), _triggerTimesWeb.rend(), [time](auto element) {
|
||||
if (time > element.first) return true;
|
||||
});
|
||||
|
||||
const int index = static_cast<int>(std::distance(it, _triggerTimesWeb.rend())) - 1;
|
||||
|
||||
// Should do the same as above?
|
||||
//std::find_if(_triggerTimesWeb.rbegin(), _triggerTimesWeb.rend(), [time](auto it) {
|
||||
// if (time > it.first)
|
||||
// return true;
|
||||
//})
|
||||
|
||||
// Make a window around that area
|
||||
_window.triggerTimes.clear();
|
||||
_window.nTriggerTimes = 0;
|
||||
// This should be safe, because in the manager, it is checked wether the current position is within
|
||||
// the boundaries with respect to back & forward width
|
||||
for(int i = index - _window.backWidth; i <= index + _window.forwardWidth; i++){
|
||||
if(i < 0) i = 0;
|
||||
_window.triggerTimes.push_back(std::make_pair(_triggerTimesWeb[i].first, _triggerTimesWeb[i].second));
|
||||
@@ -146,7 +140,7 @@ namespace openspace{
|
||||
|
||||
void WebFieldlinesWindow::getNewTriggerTimesWebList(double time){
|
||||
|
||||
_worker.getRangeOfAvailableTriggerTimes(time, time, _triggerTimesWeb, _apiID);
|
||||
_worker.getRangeOfAvailableTriggerTimes(time, time, _triggerTimesWeb);
|
||||
_nAvailableWeb = static_cast<int>(_triggerTimesWeb.size());
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,8 @@ namespace openspace{
|
||||
// CONSTRUCTOR
|
||||
WebFieldlinesWorker::WebFieldlinesWorker(std::string syncDir, std::string serverUrl)
|
||||
: _syncDir(syncDir), _serverUrl(serverUrl) {
|
||||
_endpointSingleDownload = _serverUrl + "WSA/fieldline/"; // should be set by argument to be more general [DEPRICATED FOR NOW, DO WE NEED THIS?]
|
||||
// Maybe to be used
|
||||
_endpointSingleDownload = _serverUrl; // should be set by argument to be more general [DEPRICATED FOR NOW, DO WE NEED THIS?]
|
||||
}
|
||||
|
||||
// Destructor, deleting all files that were downloaded during the run.
|
||||
@@ -58,11 +59,10 @@ namespace openspace{
|
||||
FileSys.deleteFile(it);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// PUBLIC FUNCTIONS
|
||||
void WebFieldlinesWorker::getRangeOfAvailableTriggerTimes(double start, double end, std::vector<std::pair<double, std::string>> &_triggerTimesWeb, int id){
|
||||
void WebFieldlinesWorker::getRangeOfAvailableTriggerTimes(double startTime, double endTime, std::vector<std::pair<double, std::string>> &_triggerTimesWeb){
|
||||
|
||||
if (global::timeManager.time().j2000Seconds() < acceptableToStartRequestingAgain.first || global::timeManager.time().j2000Seconds() > acceptableToStartRequestingAgain.second) {
|
||||
_noEmptyResponses = true;
|
||||
@@ -73,7 +73,7 @@ namespace openspace{
|
||||
auto time = global::timeManager.time().ISO8601();
|
||||
Time maxTime;
|
||||
Time minTime;
|
||||
const int timeSpann = 86400; // The timespann we would like to request (in seconds) [ 1 day = 86400, 1 week = 604800 ]
|
||||
const int timeSpann = 2*86400; // The timespann we would like to request (in seconds) [ 1 day = 86400, 1 week = 604800 ]
|
||||
const std::string dataID = "dataID";
|
||||
const std::string files = "files";
|
||||
std::string stringResult;
|
||||
@@ -85,7 +85,7 @@ namespace openspace{
|
||||
maxTime.advanceTime(timeSpann);
|
||||
minTime.advanceTime(-timeSpann);
|
||||
|
||||
std::string url = "https://iswa.gsfc.nasa.gov/IswaSystemWebApp/FilesInRangeServlet?dataID=" + std::to_string(id) + "&time.min=" + minTime.ISO8601() + "&time.max=" + maxTime.ISO8601();
|
||||
std::string url = _serverUrl + "&time.min=" + minTime.ISO8601() + "&time.max=" + maxTime.ISO8601();
|
||||
SyncHttpMemoryDownload mmryDld = SyncHttpMemoryDownload(url);
|
||||
HttpRequest::RequestOptions opt = {};
|
||||
opt.requestTimeoutSeconds = 0;
|
||||
@@ -118,26 +118,24 @@ namespace openspace{
|
||||
if (_strikes % 2 == 0){ // We have got 2 strikes, no more requests for you, Mr.Sir.
|
||||
_noEmptyResponses = false;
|
||||
acceptableToStartRequestingAgain = std::make_pair(minTime.j2000Seconds(), maxTime.j2000Seconds());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Download all files in the current window
|
||||
// This function starts in the middle of the window and proceeds to download all future timesteps,
|
||||
// then steps backwards from the middle
|
||||
//TODO(Axel): Different behaviour depending on direction the user is moving in.
|
||||
//TODO(Axel): Different behaviour depending on direction the user is moving in, might be wanted?
|
||||
void WebFieldlinesWorker::downloadWindow(std::vector<std::pair<double, std::string>> triggerTimes) {
|
||||
|
||||
// Limit the number of concurrent downloads
|
||||
|
||||
// Want to use std::find_if to break the for_each
|
||||
// Helper variables
|
||||
int middle = triggerTimes.size() / 2;
|
||||
bool downloaded = false;
|
||||
bool oneUpdate = false;
|
||||
|
||||
// May be interesting to keep something like this, if it will be possible to use a list of
|
||||
// AsyncHttpFileDownloads
|
||||
|
||||
/*if (auto index = std::find_if(_downloadList.begin(), _downloadList.end(), [](auto element) {
|
||||
return element.first->hasSucceeded();
|
||||
}); index != _downloadList.end()) {
|
||||
@@ -147,6 +145,7 @@ namespace openspace{
|
||||
_downloadList.erase(index);
|
||||
}
|
||||
else { */
|
||||
|
||||
if (_downloading && _downloading->hasSucceeded() && _newWindow) {
|
||||
_downloading->wait();
|
||||
addToDownloadedList(_latestDownload);
|
||||
@@ -171,7 +170,7 @@ namespace openspace{
|
||||
|
||||
// Backwards
|
||||
if (!downloaded) {
|
||||
std::for_each(triggerTimes.rbegin(), triggerTimes.rend(), [this, &downloaded](auto it) {
|
||||
std::for_each(triggerTimes.rbegin() + middle, triggerTimes.rend(), [this, &downloaded](auto it) {
|
||||
if (!downloaded && !fileIsOnDisk(it.first)) {
|
||||
downloadOsfls(it);
|
||||
downloaded = true;
|
||||
@@ -179,7 +178,6 @@ namespace openspace{
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ((!downloaded && !_doneUpdating && _newWindow && _readyToDownload) || oneUpdate) {
|
||||
@@ -189,7 +187,6 @@ namespace openspace{
|
||||
_newWindow = false;
|
||||
oneUpdate = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Updates the list of available sourcefiles, owned by renderablefieldlinessequence.
|
||||
@@ -228,8 +225,7 @@ namespace openspace{
|
||||
|
||||
}
|
||||
|
||||
bool WebFieldlinesWorker::windowIsComplete()
|
||||
{
|
||||
bool WebFieldlinesWorker::windowIsComplete(){
|
||||
return _doneUpdating;
|
||||
}
|
||||
|
||||
@@ -237,8 +233,7 @@ namespace openspace{
|
||||
_doneUpdating = false;
|
||||
}
|
||||
|
||||
void WebFieldlinesWorker::newWindowToDownload()
|
||||
{
|
||||
void WebFieldlinesWorker::newWindowToDownload(){
|
||||
_newWindow = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
|
||||
WebFieldlinesWorker(std::string syncDir, std::string serverUrl);
|
||||
|
||||
void getRangeOfAvailableTriggerTimes(double start, double end, std::vector<std::pair<double, std::string>>& _triggerTimesWeb, int id);
|
||||
void getRangeOfAvailableTriggerTimes(double startTime, double endTime, std::vector<std::pair<double, std::string>>& _triggerTimesWeb);
|
||||
|
||||
// Sets the third index in _triggerTimesWeb to whether it is on disk already or not
|
||||
// If it's on disk, get the index of the corresponding triggertime in _triggerTimesOnDisk
|
||||
|
||||
Reference in New Issue
Block a user