Commit d8c9f8e26d3fb8970df3c17fbffbcfb71ab0f931

Authored by Benjamin Renard
1 parent 86a9a37d

Improve intervals info in plot context

Showing 1 changed file with 114 additions and 105 deletions   Show diff stats
src/ParamOutputImpl/Plot/PanelPlotOutput.cc
@@ -2308,64 +2308,58 @@ namespace plot @@ -2308,64 +2308,58 @@ namespace plot
2308 if (!isStandalone()) 2308 if (!isStandalone())
2309 return; 2309 return;
2310 2310
2311 - writer.startElement("panel"); 2311 + writer.startElement("panel"); // OPENNODE panel
2312 _panel->writeContext(_pls, writer); 2312 _panel->writeContext(_pls, writer);
2313 2313
2314 - writer.startElement("parameters");  
2315 -  
2316 - for (ParameterAxesList::iterator it = _parameterAxesList.begin();  
2317 - it != _parameterAxesList.end(); ++it)  
2318 - {  
2319 - AMDA::Parameters::ParameterSPtr originalParam =  
2320 - _parameterManager.getParameter(it->_originalParamId);  
2321 -  
2322 - // Retrieve ParamInfo Manager  
2323 - ParamMgr *piMgr = ParamMgr::getInstance();  
2324 - ParamInfoSPtr paramInfo = piMgr->getParamInfoFromId(originalParam->getInfoId());  
2325 - std::string name = "";  
2326 - std::string shortname = "";  
2327 - std::string unit = "";  
2328 - if (paramInfo != nullptr) {  
2329 - name = paramInfo->getName();  
2330 - shortname = paramInfo->getShortName();  
2331 - unit = paramInfo->getUnits();  
2332 - }  
2333 -  
2334 - double resol = originalParam->getDataWriterTemplate()->getMinSampling();  
2335 - std::string resolstr = std::to_string(resol);  
2336 - writer.startElement("parameter");  
2337 - writer.addAttribute("id", originalParam->getId().c_str());  
2338 - writer.addAttribute("name", name.c_str());  
2339 - writer.addAttribute("shortname", shortname.c_str());  
2340 - writer.addAttribute("MinSampling", resolstr.c_str());  
2341 - writer.addAttribute("unit", unit.c_str());  
2342 - writer.endElement();  
2343 - }  
2344 - writer.endElement();  
2345 -  
2346 - if (!_parameterAxesList.empty()) 2314 + if (!_parameterAxesList.empty())
2347 { 2315 {
2348 - bool hasSpectro = false; 2316 + bool hasSpectro = false;
2349 bool hasSauvaud = false; 2317 bool hasSauvaud = false;
2350 - for (auto parameter : _parameterAxesList)  
2351 - {  
2352 - if (parameter.getSpectroProperties() != nullptr) 2318 +
  2319 + writer.startElement("parameters"); // OPENNODE parameters
  2320 +
  2321 +
  2322 + for (ParameterAxesList::iterator it = _parameterAxesList.begin();
  2323 + it != _parameterAxesList.end(); ++it)
  2324 + {
  2325 + AMDA::Parameters::ParameterSPtr originalParam =
  2326 + _parameterManager.getParameter(it->_originalParamId);
  2327 +
  2328 + // Retrieve ParamInfo Manager
  2329 + ParamMgr *piMgr = ParamMgr::getInstance();
  2330 + ParamInfoSPtr paramInfo = piMgr->getParamInfoFromId(originalParam->getInfoId());
  2331 + std::string name = "";
  2332 + std::string shortname = "";
  2333 + std::string unit = "";
  2334 + if (paramInfo != nullptr) {
  2335 + name = paramInfo->getName();
  2336 + shortname = paramInfo->getShortName();
  2337 + unit = paramInfo->getUnits();
  2338 + }
  2339 +
  2340 + double resol = originalParam->getDataWriterTemplate()->getMinSampling();
  2341 + std::string resolstr = std::to_string(resol);
  2342 + writer.startElement("parameter"); // OPENNODE parameter
  2343 + writer.addAttribute("id", originalParam->getId().c_str());
  2344 + writer.addAttribute("name", name.c_str());
  2345 + writer.addAttribute("shortname", shortname.c_str());
  2346 + writer.addAttribute("MinSampling", resolstr.c_str());
  2347 + writer.addAttribute("unit", unit.c_str());
  2348 +
  2349 + if (it->getSpectroProperties() != nullptr)
2353 { 2350 {
2354 hasSpectro = true; 2351 hasSpectro = true;
2355 - break;  
2356 } 2352 }
2357 - if (parameter.getSauvaudProperties() != nullptr) 2353 + if (it->getSauvaudProperties() != nullptr)
2358 { 2354 {
2359 hasSauvaud = true; 2355 hasSauvaud = true;
2360 - break;  
2361 } 2356 }
2362 - if (parameter.getIntervalsProperties() != nullptr) 2357 +
  2358 + if (it->getIntervalsProperties() != nullptr)
2363 { 2359 {
2364 - ParameterSPtr p = _parameterManager.getParameter(parameter._originalParamId);  
2365 - AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(p->getInfoId());  
2366 std::map<std::string, std::string> inputAdditionals = paramInfo->getAdditionInfo(); 2360 std::map<std::string, std::string> inputAdditionals = paramInfo->getAdditionInfo();
2367 std::string ttOrCatPath = inputAdditionals["TTCatToParamPath"]; 2361 std::string ttOrCatPath = inputAdditionals["TTCatToParamPath"];
2368 - std::string intervalColumnId = parameter.getIntervalsProperties()->getColumnId(); 2362 + std::string intervalColumnId = it->getIntervalsProperties()->getColumnId();
2369 2363
2370 // Load TT or Catalog 2364 // Load TT or Catalog
2371 std::string lReaderType = TimeTableCatalog::TimeTableCatalogFactory::getInstance().getReaderType(ttOrCatPath); 2365 std::string lReaderType = TimeTableCatalog::TimeTableCatalogFactory::getInstance().getReaderType(ttOrCatPath);
@@ -2373,80 +2367,95 @@ namespace plot @@ -2373,80 +2367,95 @@ namespace plot
2373 { 2367 {
2374 TimeTableCatalog::Catalog inputTTOrCat; 2368 TimeTableCatalog::Catalog inputTTOrCat;
2375 inputTTOrCat.read(ttOrCatPath, lReaderType); 2369 inputTTOrCat.read(ttOrCatPath, lReaderType);
2376 - for (std::vector<TimeTableCatalog::TimeInterval>::const_iterator it = inputTTOrCat.getIntervals().begin(); it != inputTTOrCat.getIntervals().end(); ++it) 2370 + bool isCatalog = !inputTTOrCat.getParameterDescriptions().empty();
  2371 + if (isCatalog) {
  2372 + writer.startElement("catalog"); // OPENNODE catalog
  2373 + }
  2374 + else {
  2375 + writer.startElement("timetable"); // OPENNODE catalog
  2376 + }
  2377 + writer.addAttribute("name", inputTTOrCat._name.c_str());
  2378 + writer.addAttribute("columnToShow", intervalColumnId.c_str());
  2379 + if (!inputTTOrCat.getParameterDescriptions().empty()) {
  2380 + writer.startElement("columns"); // OPENNODE columns
  2381 + for (auto &desc : inputTTOrCat.getParameterDescriptions()) {
  2382 + writer.startElement("column"); // OPENNODE column
  2383 + writer.addAttribute("id", desc.getId().c_str());
  2384 + writer.addAttribute("name", desc.getName().c_str());
  2385 + writer.addAttribute("size", desc.getSize().c_str());
  2386 + writer.addAttribute("unit", desc.getUnit().c_str());
  2387 + writer.addAttribute("description", desc.getDescription().c_str());
  2388 + writer.addAttribute("ucd", desc.getUcd().c_str());
  2389 + writer.addAttribute("utype", desc.getUtype().c_str());
  2390 + writer.endElement(); // CLOSENODE column
  2391 + }
  2392 + writer.endElement(); // CLOSENODE columns
  2393 + }
  2394 +
  2395 + writer.startElement("intervals"); // OPENNODE intervals
  2396 + for (std::vector<TimeTableCatalog::TimeInterval>::const_iterator it2 = inputTTOrCat.getIntervals().begin(); it2 != inputTTOrCat.getIntervals().end(); ++it2)
2377 { 2397 {
2378 double acceptedRatio = 0.005; // if the interval is too small, no more info given 2398 double acceptedRatio = 0.005; // if the interval is too small, no more info given
2379 double timeRatio = (currentTimeInterval->_stopTime - currentTimeInterval->_startTime) / _plotAreaBounds._width; 2399 double timeRatio = (currentTimeInterval->_stopTime - currentTimeInterval->_startTime) / _plotAreaBounds._width;
2380 2400
2381 std::map<std::string, std::vector<std::string>> data; 2401 std::map<std::string, std::vector<std::string>> data;
2382 - bool needTTWriter = false;  
2383 - bool needCatWriter = false;  
2384 - double startTime = it->_startTime;  
2385 - double stopTime = it->_stopTime;  
2386 -  
2387 - if (it->_startTime >= currentTimeInterval->_startTime && it->_stopTime <= currentTimeInterval->_stopTime) // inside the interval 2402 +
  2403 + double startTime = it2->_startTime;
  2404 + double stopTime = it2->_stopTime;
  2405 + if ((startTime < currentTimeInterval->_startTime && stopTime < currentTimeInterval->_startTime) ||
  2406 + (startTime > currentTimeInterval->_stopTime && stopTime > currentTimeInterval->_stopTime)) {
  2407 + //outside the request interval
  2408 + continue;
  2409 + }
  2410 + else if (it2->_startTime < currentTimeInterval->_startTime) {
  2411 + //partially inside the request interval
  2412 + startTime = currentTimeInterval->_startTime;
  2413 + }
  2414 + else if (it2->_stopTime > currentTimeInterval->_stopTime) {
  2415 + //partially inside the request interval
  2416 + stopTime = currentTimeInterval->_stopTime;
  2417 + }
  2418 +
  2419 + if (timeRatio * acceptedRatio < (stopTime - startTime) / _plotAreaBounds._width)
2388 { 2420 {
2389 - if (timeRatio * acceptedRatio < (stopTime - startTime) / _plotAreaBounds._width)  
2390 - {  
2391 - needTTWriter = true;  
2392 - data = it->getAllParameterData();  
2393 - if (data.size() > 0)  
2394 - needCatWriter = true;  
2395 - }  
2396 - }  
2397 - else if (it->_startTime <= currentTimeInterval->_startTime && it->_stopTime <= currentTimeInterval->_stopTime && it->_stopTime >= currentTimeInterval->_startTime) // begins before, ends inside  
2398 - {  
2399 - startTime = currentTimeInterval->_startTime;  
2400 - if (timeRatio * acceptedRatio < (stopTime - startTime) / _plotAreaBounds._width)  
2401 - {  
2402 - needTTWriter = true;  
2403 - data = it->getAllParameterData();  
2404 - if (data.size() > 0)  
2405 - needCatWriter = true;  
2406 - }  
2407 - }  
2408 - else if (it->_startTime >= currentTimeInterval->_startTime && it->_startTime <= currentTimeInterval->_stopTime && it->_stopTime >= currentTimeInterval->_stopTime) // begins inside, ends after  
2409 - {  
2410 - stopTime = currentTimeInterval->_stopTime;  
2411 - if (timeRatio * acceptedRatio < (stopTime - startTime) / _plotAreaBounds._width)  
2412 - {  
2413 - needTTWriter = true;  
2414 - data = it->getAllParameterData();  
2415 - if (data.size() > 0)  
2416 - needCatWriter = true;  
2417 - }  
2418 - } 2421 + writer.startElement("interval"); // OPENNODE interval
2419 2422
2420 - if (needTTWriter)  
2421 - {  
2422 - writer.startElement("intervals");  
2423 - writer.addAttribute("name", inputTTOrCat._name.c_str());  
2424 - writer.addAttribute("id", std::to_string(it->_index + 1).c_str());  
2425 - writer.addAttribute("startTime", std::to_string(startTime).c_str());  
2426 - writer.addAttribute("stopTime", std::to_string(stopTime).c_str());  
2427 - if (needCatWriter) 2423 + writer.addAttribute("id", std::to_string(it2->_index + 1).c_str());
  2424 + writer.addAttribute("startTime", std::to_string(it2->_startTime).c_str());
  2425 + writer.addAttribute("stopTime", std::to_string(it2->_stopTime).c_str());
  2426 + if (isCatalog)
2428 { 2427 {
2429 - std::string allParams = "";  
2430 - std::string selectedColValue = "";  
2431 - for (auto i : data) 2428 + for (auto i : it2->getAllParameterData())
2432 { 2429 {
2433 - if(i.first == intervalColumnId)  
2434 - selectedColValue = i.first+"|"+ i.second[0];  
2435 - allParams += i.second[0] + "|"; 2430 + writer.startElement("param"); // OPENNODE column
  2431 + writer.addAttribute("id", i.first.c_str());
  2432 + std::string val;
  2433 + for (auto v : i.second) {
  2434 + if (!val.empty()) {
  2435 + val += ", ";
  2436 + }
  2437 + val += v.c_str();
  2438 + }
  2439 + writer.addAttribute("val", val.c_str());
  2440 + writer.endElement(); // CLOSENODE column
2436 } 2441 }
2437 - if(allParams != "")  
2438 - writer.addAttribute("params", allParams.c_str());  
2439 - if(selectedColValue != "")  
2440 - writer.addAttribute("selectedColValue", selectedColValue.c_str());  
2441 } 2442 }
2442 - writer.endElement(); 2443 + writer.endElement(); // CLOSENODE interval
2443 } 2444 }
2444 } 2445 }
  2446 + writer.endElement(); // CLOSENODE intervals
  2447 +
  2448 + writer.endElement(); // CLOSENODE catalog or timetable
2445 } 2449 }
2446 } 2450 }
2447 - }  
2448 2451
2449 - writer.startElement("plotArea"); 2452 +
  2453 + writer.endElement(); // CLOSENODE parameter
  2454 + }
  2455 + writer.endElement(); // CLOSENODE parameters
  2456 +
  2457 +
  2458 + writer.startElement("plotArea"); // OPEN plotArea NODE
2450 if (_panel->_page->_orientation == PlotCommon::Orientation::PORTRAIT) 2459 if (_panel->_page->_orientation == PlotCommon::Orientation::PORTRAIT)
2451 { 2460 {
2452 writer.addAttribute("x", std::to_string(_plotAreaBounds._y * std::get<0>(_panel->_page->getSize())).c_str()); 2461 writer.addAttribute("x", std::to_string(_plotAreaBounds._y * std::get<0>(_panel->_page->getSize())).c_str());
@@ -2484,10 +2493,10 @@ namespace plot @@ -2484,10 +2493,10 @@ namespace plot
2484 } 2493 }
2485 } 2494 }
2486 2495
2487 - writer.endElement(); 2496 + writer.endElement(); // CLOSENODE plotArea
2488 } 2497 }
2489 2498
2490 - writer.endElement(); 2499 + writer.endElement(); // CLOSENODE panel
2491 } 2500 }
2492 2501
2493 /** 2502 /**