00001
00002
00003
00004
00005 #include <cassert>
00006 #include <ostream>
00007 #if BOOST_VERSION >= 103400
00008
00009 #include <boost/foreach.hpp>
00010 #endif // BOOST_VERSION >= 103400
00011
00012 #include <stdair/basic/BasConst_BomDisplay.hpp>
00013 #include <stdair/bom/BomManager.hpp>
00014 #include <stdair/bom/BomRoot.hpp>
00015 #include <stdair/bom/Inventory.hpp>
00016 #include <stdair/bom/FlightDate.hpp>
00017 #include <stdair/bom/LegDate.hpp>
00018 #include <stdair/bom/SegmentDate.hpp>
00019 #include <stdair/bom/LegCabin.hpp>
00020 #include <stdair/bom/SegmentCabin.hpp>
00021 #include <stdair/bom/FareFamily.hpp>
00022 #include <stdair/bom/BookingClass.hpp>
00023 #include <stdair/bom/Bucket.hpp>
00024 #include <stdair/bom/BomJSONExport.hpp>
00025
00026 namespace stdair {
00027
00028
00029 void BomJSONExport::jsonExport (std::ostream& oStream,
00030 const FlightDate& iFlightDate) {
00031
00032
00033 bpt::ptree pt;
00034
00035 #if BOOST_VERSION >= 104100
00036
00039 const AirlineCode_T& lAirlineCode = iFlightDate.getAirlineCode();
00040 const FlightNumber_T& lFlightNumber = iFlightDate.getFlightNumber();
00041 const Date_T& lFlightDateDate = iFlightDate.getDepartureDate();
00042
00043
00044 pt.put ("flight_date.airline_code", lAirlineCode);
00045
00046
00047 pt.put ("flight_date.flight_number", lFlightNumber);
00048
00049
00050 const std::string& lDepartureDateStr =
00051 boost::gregorian::to_simple_string (lFlightDateDate);
00052 pt.put ("flight_date.departure_date", lDepartureDateStr);
00053 #endif // BOOST_VERSION >= 104100
00054
00055
00056 jsonLegDateExport (pt, iFlightDate);
00057
00058
00059 jsonLegCabinExport (pt, iFlightDate);
00060
00061
00062 jsonBucketExport (pt, iFlightDate);
00063
00064
00065 jsonSegmentDateExport (pt, iFlightDate);
00066
00067
00068 jsonSegmentCabinExport (pt, iFlightDate);
00069
00070
00071 jsonFareFamilyExport (pt, iFlightDate);
00072
00073
00074 jsonBookingClassExport (pt, iFlightDate);
00075
00076 #if BOOST_VERSION >= 104100
00077
00078 write_json (oStream, pt);
00079 #endif // BOOST_VERSION >= 104100
00080 }
00081
00082
00083 void BomJSONExport::jsonLegDateExport (bpt::ptree& ioPropertyTree,
00084 const FlightDate& iFlightDate) {
00089
00090 if (BomManager::hasList<LegDate> (iFlightDate) == false) {
00091 return;
00092 }
00093
00094
00095 const LegDateList_T& lLegDateList =
00096 BomManager::getList<LegDate> (iFlightDate);
00097 for (LegDateList_T::const_iterator itLD = lLegDateList.begin();
00098 itLD != lLegDateList.end(); ++itLD) {
00099 const LegDate* lLD_ptr = *itLD;
00100 assert (lLD_ptr != NULL);
00101
00102 #if BOOST_VERSION >= 104100
00103
00104
00105 bpt::ptree lLegDateArray;
00106
00107
00108 lLegDateArray.put ("BoardPoint", lLD_ptr->getBoardingPoint());
00109
00110 lLegDateArray.put ("OffPoint", lLD_ptr->getOffPoint());
00111
00112 lLegDateArray.put ("BoardDate", lLD_ptr->getBoardingDate());
00113
00114 lLegDateArray.put ("OffDate", lLD_ptr->getOffDate());
00115
00116 lLegDateArray.put ("BoardTime", lLD_ptr->getBoardingTime());
00117
00118 lLegDateArray.put ("OffTime", lLD_ptr->getOffTime());
00119
00120 lLegDateArray.put ("Elapsed", lLD_ptr->getElapsedTime());
00121
00122 lLegDateArray.put ("Date_Offset", lLD_ptr->getDateOffset());
00123
00124 lLegDateArray.put ("Time_Offset", lLD_ptr->getTimeOffset());
00125
00126 lLegDateArray.put ("Distance", lLD_ptr->getDistance());
00127
00128 lLegDateArray.put ("Capacity", lLD_ptr->getCapacity());
00129
00130
00131 std::ostringstream oStream;
00132 oStream << "flight_date.leg_" << lLD_ptr->getBoardingPoint();
00133 ioPropertyTree.put_child(oStream.str(),lLegDateArray);
00134
00135 #endif // BOOST_VERSION >= 104100
00136 }
00137 }
00138
00139
00140 void BomJSONExport::jsonLegCabinExport (bpt::ptree& ioPropertyTree,
00141 const FlightDate& iFlightDate) {
00146
00147 if (BomManager::hasList<LegDate> (iFlightDate) == false) {
00148 return;
00149 }
00150
00151 const LegDateList_T& lLegDateList =
00152 BomManager::getList<LegDate> (iFlightDate);
00153 for (LegDateList_T::const_iterator itLD = lLegDateList.begin();
00154 itLD != lLegDateList.end(); ++itLD) {
00155 const LegDate* lLD_ptr = *itLD;
00156 assert (lLD_ptr != NULL);
00157
00158
00159 const LegCabinList_T& lLegCabinList =
00160 BomManager::getList<LegCabin> (*lLD_ptr);
00161 for (LegCabinList_T::const_iterator itLC = lLegCabinList.begin();
00162 itLC != lLegCabinList.end(); ++itLC) {
00163 const LegCabin* lLC_ptr = *itLC;
00164 assert (lLC_ptr != NULL);
00165
00166 #if BOOST_VERSION >= 104100
00167
00168
00169 bpt::ptree lLegCabinArray;
00170
00171
00172 lLegCabinArray.put ("OffedCAP", lLC_ptr->getOfferedCapacity());
00173
00174 lLegCabinArray.put ("PhyCAP", lLC_ptr->getPhysicalCapacity());
00175
00176 lLegCabinArray.put ("RgdADJ", lLC_ptr->getRegradeAdjustment());
00177
00178 lLegCabinArray.put ("AU", lLC_ptr->getAuthorizationLevel());
00179
00180 lLegCabinArray.put ("UPR", lLC_ptr->getUPR());
00181
00182 lLegCabinArray.put ("SS", lLC_ptr->getSoldSeat());
00183
00184 lLegCabinArray.put ("Staff", lLC_ptr->getStaffNbOfSeats());
00185
00186 lLegCabinArray.put ("WL", lLC_ptr->getWLNbOfSeats());
00187
00188 lLegCabinArray.put ("Group", lLC_ptr->getGroupNbOfSeats());
00189
00190 lLegCabinArray.put ("CommSpace", lLC_ptr->getCommittedSpace());
00191
00192 lLegCabinArray.put ("AvPool", lLC_ptr->getAvailabilityPool());
00193
00194 lLegCabinArray.put ("Avl", lLC_ptr->getAvailability());
00195
00196 lLegCabinArray.put ("NAV", lLC_ptr->getNetAvailability());
00197
00198 lLegCabinArray.put ("GAV", lLC_ptr->getGrossAvailability());
00199
00200 lLegCabinArray.put ("ACP", lLC_ptr->getAvgCancellationPercentage());
00201
00202 lLegCabinArray.put ("ETB", lLC_ptr->getETB());
00203
00204 lLegCabinArray.put ("BidPrice", lLC_ptr->getCurrentBidPrice());
00205
00206
00207 std::ostringstream oStream;
00208 oStream << "flight_date"
00209 << ".leg_" << lLD_ptr->getBoardingPoint()
00210 << ".cabin_" << lLC_ptr->toString();
00211 ioPropertyTree.put_child (oStream.str(), lLegCabinArray);
00212
00213 #endif // BOOST_VERSION >= 104100
00214 }
00215 }
00216 }
00217
00218
00219 void BomJSONExport::jsonBucketExport (bpt::ptree& ioPropertyTree,
00220 const FlightDate& iFlightDate) {
00225
00226 if (BomManager::hasList<LegDate> (iFlightDate) == false) {
00227 return;
00228 }
00229
00230
00231 const LegDateList_T& lLegDateList =
00232 BomManager::getList<LegDate> (iFlightDate);
00233 for (LegDateList_T::const_iterator itLD = lLegDateList.begin();
00234 itLD != lLegDateList.end(); ++itLD) {
00235 const LegDate* lLD_ptr = *itLD;
00236 assert (lLD_ptr != NULL);
00237
00238
00239 const LegCabinList_T& lLegCabinList =
00240 BomManager::getList<LegCabin> (*lLD_ptr);
00241 for (LegCabinList_T::const_iterator itLC = lLegCabinList.begin();
00242 itLC != lLegCabinList.end(); ++itLC) {
00243 const LegCabin* lLC_ptr = *itLC;
00244 assert (lLC_ptr != NULL);
00245
00246
00247 if (BomManager::hasList<Bucket> (*lLC_ptr) == false) {
00248 return;
00249 }
00250
00251
00252 const BucketList_T& lBucketList = BomManager::getList<Bucket> (*lLC_ptr);
00253 for (BucketList_T::const_iterator itBuck = lBucketList.begin();
00254 itBuck != lBucketList.end(); ++itBuck) {
00255 const Bucket* lBucket_ptr = *itBuck;
00256 assert (lBucket_ptr != NULL);
00257
00258 #if BOOST_VERSION >= 104100
00259
00260
00261 bpt::ptree lLegBucketArray;
00262
00263
00264 lLegBucketArray.put ("Yield", lBucket_ptr->getYieldRangeUpperValue());
00265
00266 lLegBucketArray.put ("SI", lBucket_ptr->getSeatIndex());
00267
00268 lLegBucketArray.put ("SS", lBucket_ptr->getSoldSeats());
00269
00270 lLegBucketArray.put ("AV", lBucket_ptr->getAvailability());
00271
00272
00273 std::ostringstream oStream;
00274 oStream << "flight_date"
00275 << ".leg_" << lLD_ptr->getBoardingPoint()
00276 << ".cabin_" << lLC_ptr->toString()
00277 << ".bucket_" << lBucket_ptr->toString();
00278 ioPropertyTree.put_child (oStream.str(),lLegBucketArray);
00279
00280 #endif // BOOST_VERSION >= 104100
00281 }
00282 }
00283 }
00284 }
00285
00286
00287 void BomJSONExport::jsonSegmentDateExport (bpt::ptree& ioPropertyTree,
00288 const FlightDate& iFlightDate) {
00289
00294
00295 if (BomManager::hasList<SegmentDate> (iFlightDate) == false) {
00296 return;
00297 }
00298
00299
00300 unsigned short idx = 0;
00301 const SegmentDateList_T& lSegmentDateList =
00302 BomManager::getList<SegmentDate> (iFlightDate);
00303 for (SegmentDateList_T::const_iterator itSD = lSegmentDateList.begin();
00304 itSD != lSegmentDateList.end(); ++itSD, ++idx) {
00305 const SegmentDate* lSD_ptr = *itSD;
00306 assert (lSD_ptr != NULL);
00307
00308 #if BOOST_VERSION >= 104100
00309
00310
00311 bpt::ptree lSegmentDateArray;
00312
00313
00314 lSegmentDateArray.put ("BoardPoint", lSD_ptr->getBoardingPoint());
00315
00316 lSegmentDateArray.put ("OffPoint", lSD_ptr->getOffPoint());
00317
00318 lSegmentDateArray.put ("BoardDate", lSD_ptr->getBoardingDate());
00319
00320 lSegmentDateArray.put ("OffDate", lSD_ptr->getOffDate());
00321
00322 lSegmentDateArray.put ("BoardTime", lSD_ptr->getBoardingTime());
00323
00324 lSegmentDateArray.put ("OffTime", lSD_ptr->getOffTime());
00325
00326 lSegmentDateArray.put ("Elapsed", lSD_ptr->getElapsedTime());
00327
00328 lSegmentDateArray.put ("Date_Offset", lSD_ptr->getDateOffset());
00329
00330 lSegmentDateArray.put ("Time_Offset", lSD_ptr->getTimeOffset());
00331
00332 lSegmentDateArray.put ("Distance", lSD_ptr->getDistance());
00333
00334
00335 std::ostringstream oStream;
00336 oStream << "flight_date.segment_" << lSD_ptr->getBoardingPoint()
00337 << "_" << lSD_ptr->getOffPoint();
00338 ioPropertyTree.put_child(oStream.str(),lSegmentDateArray);
00339
00340 #endif // BOOST_VERSION >= 104100
00341 }
00342 }
00343
00344
00345 void BomJSONExport::jsonSegmentCabinExport (bpt::ptree& ioPropertyTree,
00346 const FlightDate& iFlightDate) {
00350 }
00351
00352
00353 void BomJSONExport::jsonFareFamilyExport (bpt::ptree& ioPropertyTree,
00354 const FlightDate& iFlightDate) {
00359
00360 if (BomManager::hasList<SegmentDate> (iFlightDate) == false) {
00361 return;
00362 }
00363
00364
00365 unsigned short idx = 0;
00366 const SegmentDateList_T& lSegmentDateList =
00367 BomManager::getList<SegmentDate> (iFlightDate);
00368 for (SegmentDateList_T::const_iterator itSD = lSegmentDateList.begin();
00369 itSD != lSegmentDateList.end(); ++itSD, ++idx) {
00370 const SegmentDate* lSD_ptr = *itSD;
00371 assert (lSD_ptr != NULL);
00372
00373
00374 const SegmentCabinList_T& lSegmentCabinList =
00375 BomManager::getList<SegmentCabin> (*lSD_ptr);
00376 for (SegmentCabinList_T::const_iterator itSC = lSegmentCabinList.begin();
00377 itSC != lSegmentCabinList.end(); ++itSC) {
00378 const SegmentCabin* lSC_ptr = *itSC;
00379 assert (lSC_ptr != NULL);
00380
00381
00382 if (BomManager::hasList<FareFamily> (*lSC_ptr) == false) {
00383 continue;
00384 }
00385
00386
00387 unsigned short ffIdx = 0;
00388 const FareFamilyList_T& lFareFamilyList =
00389 BomManager::getList<FareFamily> (*lSC_ptr);
00390 for (FareFamilyList_T::const_iterator itFF = lFareFamilyList.begin();
00391 itFF != lFareFamilyList.end(); ++itFF, ++ffIdx) {
00392 const FareFamily* lFF_ptr = *itFF;
00393 assert (lFF_ptr != NULL);
00394
00395 #if BOOST_VERSION >= 104100
00396
00397 bpt::ptree lFFArray;
00398
00399
00400 lFFArray.put ("cabin",lSC_ptr->toString());
00401
00402 lFFArray.put ("code", lFF_ptr->getFamilyCode());
00403
00404 lFFArray.put ("MIN", lSC_ptr->getMIN());
00405
00406 lFFArray.put ("UPR", lSC_ptr->getUPR());
00407
00408 lFFArray.put ("CommSpace", lSC_ptr->getCommittedSpace());
00409
00410 lFFArray.put ("AvPool", lSC_ptr->getAvailabilityPool());
00411
00412 lFFArray.put ("BP", lSC_ptr->getCurrentBidPrice());
00413
00414 std::ostringstream oStream;
00415 oStream << "flight_date.segment_" << lSD_ptr->getBoardingPoint()
00416 << "_" << lSD_ptr->getOffPoint()
00417 << ".fare_family_" << lFF_ptr->toString();
00418 ioPropertyTree.put_child (oStream.str(), lFFArray);
00419 #endif // BOOST_VERSION >= 104100
00420 }
00421 }
00422 }
00423 }
00424
00425
00426 void BomJSONExport::jsonBookingClassExport (bpt::ptree& ioPropertyTree,
00427 const BookingClass& iBookingClass,
00428 const std::string& iLeadingString) {
00435 std::ostringstream oStream;
00436 oStream << iLeadingString;
00437 oStream << ".class_" << iBookingClass.toString();
00438
00439 #if BOOST_VERSION >= 104100
00440
00441 bpt::ptree lBookingClassArray;
00442
00443
00444 lBookingClassArray.put ("Subclass", iBookingClass.getSubclassCode());
00445
00446 std::ostringstream oAUProtStr;
00447 oAUProtStr << iBookingClass.getAuthorizationLevel()
00448 << " (" << iBookingClass.getProtection()
00449 << ") ";
00450 lBookingClassArray.put ("MIN/AU (Prot)", oAUProtStr.str());
00451
00452 lBookingClassArray.put ("Nego", iBookingClass.getNegotiatedSpace());
00453
00454 lBookingClassArray.put ("NS%", iBookingClass.getNoShowPercentage());
00455
00456 lBookingClassArray.put ("OB%", iBookingClass.getCancellationPercentage());
00457
00458 lBookingClassArray.put ("Bkgs", iBookingClass.getNbOfBookings());
00459
00460 lBookingClassArray.put ("GrpBks (pdg)", iBookingClass.getNbOfGroupBookings());
00461
00462 lBookingClassArray.put ("StfBkgs", iBookingClass.getNbOfStaffBookings());
00463
00464 lBookingClassArray.put ("WLBkgs", iBookingClass.getNbOfWLBookings());
00465
00466 lBookingClassArray.put ("ETB", iBookingClass.getETB());
00467
00468 lBookingClassArray.put ("ClassAvl", iBookingClass.getNetClassAvailability());
00469
00470 lBookingClassArray.put ("SegAvl", iBookingClass.getSegmentAvailability());
00471
00472 lBookingClassArray.put ("RevAvl", iBookingClass.getNetRevenueAvailability());
00473
00474
00475 ioPropertyTree.put_child (oStream.str(), lBookingClassArray);
00476
00477 #endif // BOOST_VERSION >= 104100
00478 }
00479
00480
00481 void BomJSONExport::jsonBookingClassExport (bpt::ptree& ioPropertyTree,
00482 const FlightDate& iFlightDate) {
00483
00484 if (BomManager::hasList<SegmentDate> (iFlightDate) == false) {
00485 return;
00486 }
00487
00488
00489 const SegmentDateList_T& lSegmentDateList =
00490 BomManager::getList<SegmentDate> (iFlightDate);
00491 for (SegmentDateList_T::const_iterator itSD = lSegmentDateList.begin();
00492 itSD != lSegmentDateList.end(); ++itSD) {
00493 const SegmentDate* lSD_ptr = *itSD;
00494 assert (lSD_ptr != NULL);
00495
00496
00497 std::ostringstream oLeadingStr;
00498
00499 oLeadingStr << "flight_date.segment_" << lSD_ptr->getBoardingPoint()
00500 << "_" << lSD_ptr->getOffPoint();
00501
00502
00503 const SegmentCabinList_T& lSegmentCabinList =
00504 BomManager::getList<SegmentCabin> (*lSD_ptr);
00505 for (SegmentCabinList_T::const_iterator itSC = lSegmentCabinList.begin();
00506 itSC != lSegmentCabinList.end(); ++itSC) {
00507 const SegmentCabin* lSC_ptr = *itSC;
00508 assert (lSC_ptr != NULL);
00509
00510
00511 if (BomManager::hasList<FareFamily> (*lSC_ptr) == true) {
00512
00513
00514 const FareFamilyList_T& lFareFamilyList =
00515 BomManager::getList<FareFamily> (*lSC_ptr);
00516 for (FareFamilyList_T::const_iterator itFF = lFareFamilyList.begin();
00517 itFF != lFareFamilyList.end(); ++itFF) {
00518 const FareFamily* lFF_ptr = *itFF;
00519 assert (lFF_ptr != NULL);
00520
00521 oLeadingStr << ".fare_family_" << lFF_ptr->toString();
00522
00523
00524 const BookingClassList_T& lBookingClassList =
00525 BomManager::getList<BookingClass> (*lFF_ptr);
00526 for (BookingClassList_T::const_iterator itBC =
00527 lBookingClassList.begin();
00528 itBC != lBookingClassList.end(); ++itBC) {
00529 const BookingClass* lBC_ptr = *itBC;
00530 assert (lBC_ptr != NULL);
00531
00532
00533 jsonBookingClassExport (ioPropertyTree, *lBC_ptr,
00534 oLeadingStr.str());
00535 }
00536 }
00537 } else {
00538
00539
00540
00541 FamilyCode_T lDefaultFamilyCode ("NoFF");
00542 oLeadingStr << ".fare_family_" << lDefaultFamilyCode ;
00543
00544
00545 const BookingClassList_T& lBookingClassList =
00546 BomManager::getList<BookingClass> (*lSC_ptr);
00547 for (BookingClassList_T::const_iterator itBC =
00548 lBookingClassList.begin();
00549 itBC != lBookingClassList.end(); ++itBC) {
00550 const BookingClass* lBC_ptr = *itBC;
00551 assert (lBC_ptr != NULL);
00552
00553
00554 jsonBookingClassExport (ioPropertyTree, *lBC_ptr, oLeadingStr.str());
00555 }
00556 }
00557 }
00558 }
00559 }
00560 }