Commit 5b3872335c7f0ecc7dfe125bfb697550b33ae4b6

Authored by Vincent Cephirins
1 parent c03f1231

RM7926 - Evol - Choix du format du temps dans les catalogues et TT

src/Common/OutputFormatTime.hh
... ... @@ -20,8 +20,8 @@ enum OutputFormatTime {
20 20 FORMAT_OUTPUT_TIME_DD, ///< DD_server style
21 21 FORMAT_OUTPUT_TIME_ISO, ///< ISO STYLE AAAA-MM-JJTHH:MM:ss.msd
22 22 FORMAT_OUTPUT_TIME_DOUBLE, ///< in second; stating from 1970
23   - FORMAT_OUTPUT_TIME_SPACES, /// < YYYY MM DD hh mm ss
24   - FORMAT_OUTPUT_TIME_MS, /// < Double with milliseconds
  23 + FORMAT_OUTPUT_TIME_SPACES, /// < YYYY MM DD hh mm ss
  24 + FORMAT_OUTPUT_TIME_MS, /// < Double with milliseconds
25 25 };
26 26  
27 27 static std::map<OutputFormatTime,std::string> ouputFormatTimeToStr = {
... ...
src/ParamOutputImpl/Download/FileWriterASCIIAbstract.cc
... ... @@ -536,13 +536,13 @@ bool FileWriterASCIIAbstract::writeTimeData(std::string paramId, double data, Ou
536 536 (*crtFile) << getDataFillCharacter() << getDataFillCharacter();
537 537 TimeUtil::double2DD_TimeDate(data, *crtFile);
538 538 break;
539   - case FORMAT_OUTPUT_TIME_SPACES:
540   - TimeUtil:: formatTimeDateWithSpaces(data, *crtFile);
541   - break;
542   - case FORMAT_OUTPUT_TIME_MS:
  539 + case FORMAT_OUTPUT_TIME_SPACES:
  540 + TimeUtil:: formatTimeDateWithSpaces(data, *crtFile);
  541 + break;
  542 + case FORMAT_OUTPUT_TIME_MS:
543 543 //one fill character to preserve tests validation
544 544 (*crtFile) << getDataFillCharacter() << std::scientific << std::setprecision(12) << data;
545   - break;
  545 + break;
546 546 case FORMAT_OUTPUT_TIME_DOUBLE:
547 547 default:
548 548 //one fill character to preserve tests validation
... ...
src/TTConversion/TTConversionLauncher.cc
... ... @@ -7,6 +7,11 @@
7 7  
8 8 #include <iostream>
9 9 #include <cstring>
  10 +
  11 +// Common include modules
  12 +#include "OutputFormatTime.hh"
  13 +
  14 +
10 15 #include "TimeTableCatalogFactory.hh"
11 16 #include "Application.hh"
12 17 #include <log4cxx/logger.h>
... ... @@ -21,7 +26,8 @@ log4cxx::LoggerPtr _logger(
21 26 * Shows help on std::cout.
22 27 */
23 28 void help() {
24   - std::cout << "Use : ttConversion InputFileName InputFileFormat OutputDir OutputFileName OutputFileFormat" << std::endl;
  29 + std::cout << "Use : ttConversion InputFileName InputFileFormat OutputDir OutputFileName OutputFileFormat [OutputTimeFormat]" << std::endl;
  30 + std::cout << " OutputTimeFormat with values: ISO (default), DD, DOUBLE, SPACES or MS" << std::endl;
25 31 }
26 32  
27 33  
... ... @@ -36,7 +42,19 @@ int ttConversion(int argc, char *argv[], AMDA::helpers::Properties&amp; /*properties
36 42 return -1;
37 43 }
38 44  
39   - TimeTableCatalog::TimeTable ttMgr;
  45 + // Default value for time format (Option)
  46 + AMDA::OutputFormatTime timeFormat = AMDA::OutputFormatTime::FORMAT_OUTPUT_TIME_ISO;
  47 + if (argc >= 7) {
  48 + // Map time enum between php and C++
  49 + // See Request/TTRequestImpl/TTRequestDataClass.php and AMDA_Kernel/src/Common/OutputFormatTime.hh
  50 + const string pTimeFormat = argv[6];
  51 + if (pTimeFormat.compare("DD") == 0) timeFormat = AMDA::OutputFormatTime::FORMAT_OUTPUT_TIME_DD;
  52 + else if (pTimeFormat.compare("DOUBLE") == 0) timeFormat = AMDA::OutputFormatTime::FORMAT_OUTPUT_TIME_DOUBLE;
  53 + else if (pTimeFormat.compare("SPACES") == 0) timeFormat = AMDA::OutputFormatTime::FORMAT_OUTPUT_TIME_SPACES;
  54 + else if (pTimeFormat.compare("MS") == 0) timeFormat = AMDA::OutputFormatTime::FORMAT_OUTPUT_TIME_MS;
  55 + }
  56 +
  57 + TimeTableCatalog::TimeTable ttMgr(timeFormat);
40 58  
41 59 ttMgr.convert(std::string(argv[1]), std::string(argv[2]), std::string(argv[3]), std::string(argv[4]), std::string(argv[5]));
42 60  
... ...
src/TimeTableCatalog/AsciiWriter.cc
... ... @@ -99,9 +99,9 @@ void AsciiWriter::writeIntervals(const TimeTable&amp; pTT, std::ostream&amp; pOut) {
99 99 ParameterDescriptionList pdl = pTT.getParameterDescritptions();
100 100  
101 101 for (TimeInterval interval : pTT.getIntervals()) {
102   - writeISOTime(interval._startTime, pTT._timeFormat, pOut);
  102 + writeTimeData(interval._startTime, pTT._extTimeFormat, pOut);
103 103 pOut << AsciiData::SEPARATOR;
104   - writeISOTime(interval._stopTime, pTT._timeFormat, pOut);
  104 + writeTimeData(interval._stopTime, pTT._extTimeFormat, pOut);
105 105  
106 106 // If the TT has a parameter description list, write parameter data
107 107 if (pdl.empty() == false) {
... ...
src/TimeTableCatalog/CMakeLists.txt
... ... @@ -3,6 +3,7 @@ PROJECT(TimeTableCatalog)
3 3  
4 4 include_directories(
5 5 ${DDCLIENTINCLUDE_DIR}
  6 + ${CMAKE_HOME_DIRECTORY}/src/Common/
6 7 ${CMAKE_HOME_DIRECTORY}/src/TimeUtil/
7 8 ${LIBXML2_INCLUDE_DIR}
8 9 ${LOG4CXX_INCLUDE_DIR}
... ...
src/TimeTableCatalog/InternalXMLWriter.cc
... ... @@ -142,12 +142,12 @@ void InternalXMLWriter::writeIntervals(const TimeTable&amp; pTT, xmlTextWriterPtr&amp; p
142 142  
143 143 // -- write "start" tag
144 144 std::ostringstream osstart;
145   - writeISOTime(interval._startTime, pTT._timeFormat, osstart);
  145 + writeTimeData(interval._startTime, pTT._extTimeFormat, osstart);
146 146 writeElement(pTT, pWriter, InternalXMLData::ELEM_START, osstart.str());
147 147  
148 148 // -- write "stop" tag
149 149 std::ostringstream osstop;
150   - writeISOTime(interval._stopTime, pTT._timeFormat, osstop);
  150 + writeTimeData(interval._stopTime, pTT._extTimeFormat, osstop);
151 151 writeElement(pTT, pWriter, InternalXMLData::ELEM_STOP, osstop.str());
152 152  
153 153 // If the TT has a parameter description list, write parameter data
... ...
src/TimeTableCatalog/TimeTable.cc
... ... @@ -23,11 +23,15 @@ log4cxx::LoggerPtr TimeTable::_logger(
23 23 log4cxx::Logger::getLogger("AMDA-Kernel.TimeTable"));
24 24  
25 25 TimeTable::TimeTable() :
26   - _creationDate(0), _timeFormat(TimeTable::TIME_FORMAT::UNKNOWN){
  26 + _creationDate(0), _timeFormat(TimeTable::TIME_FORMAT::UNKNOWN), _extTimeFormat(AMDA::OutputFormatTime::FORMAT_OUTPUT_TIME_ISO) {
27 27 }
28 28  
29 29 TimeTable::TimeTable(TIME_FORMAT pFormat) :
30   - _creationDate(0), _timeFormat(pFormat) {
  30 + _creationDate(0), _timeFormat(pFormat), _extTimeFormat(AMDA::OutputFormatTime::FORMAT_OUTPUT_TIME_ISO) {
  31 +}
  32 +
  33 +TimeTable::TimeTable(AMDA::OutputFormatTime pFormat) :
  34 + _creationDate(0), _timeFormat(TimeTable::TIME_FORMAT::UNKNOWN), _extTimeFormat(pFormat) {
31 35 }
32 36  
33 37 TimeTable::~TimeTable() {
... ... @@ -222,6 +226,7 @@ void TimeTable::clear() {
222 226 _creationDate = -1;
223 227 _history = std::string();
224 228 _timeFormat = TIME_FORMAT::UNKNOWN;
  229 + _extTimeFormat = AMDA::OutputFormatTime::FORMAT_OUTPUT_TIME_ISO;
225 230 }
226 231  
227 232 /**
... ...
src/TimeTableCatalog/TimeTable.hh
... ... @@ -12,6 +12,9 @@
12 12 #include <vector>
13 13 #include <memory>
14 14  
  15 +// Common include modules
  16 +#include "OutputFormatTime.hh"
  17 +
15 18 #include "TimeInterval.hh"
16 19 #include "ParameterDescription.hh"
17 20 #include "log4cxx/logger.h"
... ... @@ -41,6 +44,7 @@ public:
41 44  
42 45 TimeTable();
43 46 TimeTable(TIME_FORMAT pFormat);
  47 + TimeTable(AMDA::OutputFormatTime pFormat);
44 48 ~TimeTable();
45 49  
46 50 /**
... ... @@ -85,7 +89,7 @@ public:
85 89 * Reads a time table and writes it into another format.
86 90 */
87 91 void convert(const std::string& pInPath, const std::string& pInType,
88   - const std::string& pOutPath, const std::string& pName, const std::string& pOutType);
  92 + const std::string& pOutPath, const std::string& pName, const std::string& pOutType);
89 93  
90 94 /**
91 95 * Unset current TT.
... ... @@ -163,6 +167,11 @@ public:
163 167 */
164 168 TIME_FORMAT _timeFormat;
165 169  
  170 + /**
  171 + * TT creation date and interval dates extented format
  172 + */
  173 + AMDA::OutputFormatTime _extTimeFormat;
  174 +
166 175 protected:
167 176  
168 177 /**
... ...
src/TimeTableCatalog/TimeTableCatalogUtil.cc
... ... @@ -8,13 +8,14 @@
8 8 #include <boost/algorithm/string.hpp>
9 9 #include <boost/algorithm/string/predicate.hpp>
10 10 #include <boost/lexical_cast.hpp>
  11 +#include <sstream>
  12 +#include <iomanip>
  13 +#include <time.h>
11 14  
  15 +// Self include modules
12 16 #include "TimeTableCatalogUtil.hh"
13 17 #include "TimeUtil.hh"
14 18 #include "DD_time.hh"
15   -#include <sstream>
16   -#include <iomanip>
17   -#include <time.h>
18 19  
19 20 namespace TimeTableCatalog {
20 21  
... ... @@ -245,6 +246,38 @@ void writeISOTime(const double pTime, const TimeTable::TIME_FORMAT pFormat,
245 246 }
246 247 }
247 248  
  249 +void writeTimeData(const double pTime, const AMDA::OutputFormatTime pFormat, std::ostream& pOut)
  250 +{
  251 + if (pTime == -1) {
  252 + return;
  253 + }
  254 +
  255 + std::ostringstream os;
  256 + switch (pFormat)
  257 + {
  258 + case AMDA::OutputFormatTime::FORMAT_OUTPUT_TIME_ISO:
  259 + AMDA::TimeUtil::formatTimeDateInIso(pTime, os);
  260 + pOut << os.str();
  261 + break;
  262 + case AMDA::OutputFormatTime::FORMAT_OUTPUT_TIME_DD:
  263 + AMDA::TimeUtil::double2DD_TimeDate(pTime, pOut);
  264 + pOut << os.str();
  265 + break;
  266 + case AMDA::OutputFormatTime::FORMAT_OUTPUT_TIME_SPACES:
  267 + AMDA::TimeUtil:: formatTimeDateWithSpaces(pTime, pOut);
  268 + pOut << os.str();
  269 + break;
  270 + case AMDA::OutputFormatTime::FORMAT_OUTPUT_TIME_MS:
  271 + pOut << std::scientific << std::setprecision(12) << pTime;
  272 + break;
  273 + case AMDA::OutputFormatTime::FORMAT_OUTPUT_TIME_DOUBLE:
  274 + default:
  275 + pOut << std::scientific << std::setprecision(9) <<(double)(int) pTime;
  276 + break;
  277 + }
  278 +
  279 +}
  280 +
248 281 // ----------------- EXTERN --------------------------
249 282  
250 283 bool contains(const std::string & pline, const std::string & pkeyword,
... ...
src/TimeTableCatalog/TimeTableCatalogUtil.hh
... ... @@ -33,10 +33,15 @@ double readISOTime(const std::string&amp; ptime,
33 33 const TimeTable::TIME_FORMAT pformat);
34 34  
35 35 /**
36   - * Writes an ISO time to a given stream qith a given format.
  36 + * Writes an ISO time to a given stream with a given format.
37 37 */
38   -void writeISOTime(const double ptime, const TimeTable::TIME_FORMAT pformat,
39   - std::ostream& pOut);
  38 +void writeISOTime(const double pTime, const TimeTable::TIME_FORMAT pFormat, std::ostream& pOut);
  39 +
  40 +/**
  41 + * Writes an time into a stream with a given format.
  42 + */
  43 +void writeTimeData(const double pTime, const AMDA::OutputFormatTime pFormat, std::ostream& pOut);
  44 +
40 45  
41 46 /**
42 47 * Checks a line contains or not a metadata keyword.
... ...
src/TimeTableCatalog/VOTableWriter.cc
... ... @@ -198,12 +198,12 @@ void VOTableWriter::writeVOTable(const TimeTable&amp; pTT,
198 198  
199 199 // -- write "TD" tag for start date
200 200 std::ostringstream osstart;
201   - writeISOTime(interval._startTime, pTT._timeFormat, osstart);
  201 + writeTimeData(interval._startTime, pTT._extTimeFormat, osstart);
202 202 writeElement(pTT, pWriter, VOTableData::TD_TAG, osstart.str());
203 203  
204 204 // -- write "TD" tag for stop date
205 205 std::ostringstream osstop;
206   - writeISOTime(interval._stopTime, pTT._timeFormat, osstop);
  206 + writeTimeData(interval._stopTime, pTT._extTimeFormat, osstop);
207 207 writeElement(pTT, pWriter, VOTableData::TD_TAG, osstop.str());
208 208  
209 209 // Write parameter values if defined (Catalog ONLY)
... ...
test/DD_Client/CSlimFixtures/CMakeLists.txt
... ... @@ -5,6 +5,7 @@ find_package(CSlim REQUIRED)
5 5 include_directories(
6 6 ${CSLIMINCLUDE_DIRS}
7 7 ${Boost_INCLUDE_DIR}
  8 + ${CMAKE_HOME_DIRECTORY}/src/Common/
8 9 ${CMAKE_HOME_DIRECTORY}/src/TimeTableCatalog/
9 10 ${LOG4CXX_INCLUDE_DIR}
10 11 )
... ...