diff --git a/modules/newhorizons/util/instrumenttimesparser.cpp b/modules/newhorizons/util/instrumenttimesparser.cpp index b7bae64493..32d57a7333 100644 --- a/modules/newhorizons/util/instrumenttimesparser.cpp +++ b/modules/newhorizons/util/instrumenttimesparser.cpp @@ -29,10 +29,11 @@ #include #include #include +#include #include #include #include - +#include #include namespace { @@ -46,16 +47,46 @@ namespace openspace { InstrumentTimesParser::InstrumentTimesParser( const std::string& name, const std::string& sequenceSource, - ghoul::Dictionary& parserDict) + ghoul::Dictionary& inputDict) : _name(name) , _fileName(sequenceSource) - , _pattern("\".+\" \".+\"") + , _pattern("\"(.{23})\" \"(.{23})\"") + , _target("") { + ghoul::Dictionary target; + if (inputDict.getValue("Target", target)) { + target.getValue("Body", _target); + } + ghoul::Dictionary instruments; + ghoul_assert(inputDict.getValue("Instruments", instruments), "Must define instruments"); + + _detectorType = "CAMERA"; //default value + + + + for (const auto& instrumentKey : instruments.keys()) { + ghoul::Dictionary instrumentDict; + instruments.getValue(instrumentKey, instrumentDict); + + _fileTranslation[instrumentKey] = Decoder::createFromDictionary(instrumentDict, "Instrument"); + + ghoul::Dictionary files; + if (instrumentDict.getValue("Files", files)) { + for (int i = 0; i < files.size(); i++) { + std::string id = std::to_string(i+1); // lua index starts at 1 + std::string filename; + if (files.getValue(id, filename)) { + _instrumentFiles[instrumentKey].push_back(filename); + } + } + } + } } + bool InstrumentTimesParser::create() { auto imageComparer = [](const Image &a, const Image &b)->bool{ return a.startTime < b.startTime; @@ -64,9 +95,7 @@ bool InstrumentTimesParser::create() { const std::pair &b)->bool{ return a.first < b.first; }; - std::string previousTarget; - std::string lblName = ""; - + using RawPath = ghoul::filesystem::Directory::RawPath; ghoul::filesystem::Directory sequenceDir(_fileName, RawPath::Yes); if (!FileSys.directoryExists(sequenceDir)) { @@ -77,8 +106,52 @@ bool InstrumentTimesParser::create() { using Recursive = ghoul::filesystem::Directory::Recursive; using Sort = ghoul::filesystem::Directory::Sort; std::vector sequencePaths = sequenceDir.read(Recursive::Yes, Sort::No); + + for (auto it = _instrumentFiles.begin(); it != _instrumentFiles.end(); it++) { + std::string instrumentID = it->first; + for (std::string filename: it->second) { + std::string filepath = FileSys.pathByAppendingComponent(sequenceDir.path(), filename); + + // Read file into string + std::ifstream in(filepath); + std::string line; + std::smatch matches; + while (std::getline(in, line)) { + if (std::regex_match(line, matches, _pattern)) { + ghoul_assert(matches.size() == 3, "Bad event data formatting. Must have regex 3 matches (source string, start time, stop time)."); + std::string start = matches[1].str(); + std::string stop = matches[2].str(); + + TimeRange timeRange; + timeRange._min = SpiceManager::ref().ephemerisTimeFromDate(start); + timeRange._max = SpiceManager::ref().ephemerisTimeFromDate(stop); + + _instrumentTimes.push_back({ instrumentID, timeRange }); + _targetTimes.push_back({ timeRange._min, _target }); + _captureProgression.push_back(timeRange._min); + + Image image; + image.startTime = timeRange._min; + image.stopTime = timeRange._max; + image.path = filepath; + image.activeInstruments.push_back(instrumentID); + image.target = _target; + image.projected = false; + + _subsetMap[_target]._subset.push_back(image); + _subsetMap[_target]._range.setRange(image.startTime); + } + } + } + } + + + std::stable_sort(_captureProgression.begin(), _captureProgression.end()); + //std::stable_sort(_instrumentTimes.begin(), _instrumentTimes.end()); + std::stable_sort(_targetTimes.begin(), _targetTimes.end(), targetComparer); + sendPlaybookInformation(PlaybookIdentifierName); return true; } diff --git a/modules/newhorizons/util/instrumenttimesparser.h b/modules/newhorizons/util/instrumenttimesparser.h index 112f07a94b..4674cc73c3 100644 --- a/modules/newhorizons/util/instrumenttimesparser.h +++ b/modules/newhorizons/util/instrumenttimesparser.h @@ -45,13 +45,17 @@ public: bool create() override; + //virtual std::map getTranslation() override; + // temporary need to figure this out - std::map getTranslation(){ return _fileTranslation; }; + std::map getTranslation(){ return _fileTranslation; }; private: std::regex _pattern; + std::map> _instrumentFiles; + std::string _name; std::string _fileName; std::string _spacecraft; @@ -59,8 +63,6 @@ private: std::vector _specsOfInterest; std::string _target; - std::string _instrumentID; - std::string _instrumentHostID; std::string _detectorType; std::string _sequenceID; bool _badDecoding;