8 #include <stdair/basic/BasConst_Inventory.hpp>
9 #include <stdair/bom/BomRetriever.hpp>
10 #include <stdair/bom/BomManager.hpp>
11 #include <stdair/bom/SegmentDate.hpp>
12 #include <stdair/bom/SegmentCabin.hpp>
13 #include <stdair/bom/FareFamily.hpp>
14 #include <stdair/bom/BookingClass.hpp>
15 #include <stdair/bom/SegmentSnapshotTable.hpp>
16 #include <stdair/service/Logger.hpp>
28 const stdair::DateTime_T& iSnapshotTime) {
31 const stdair::SegmentCabinIndexMap_T& lSegmentCabinIndexMap =
32 ioSegmentSnapshotTable.getSegmentCabinIndexMap();
33 for (stdair::SegmentCabinIndexMap_T::const_iterator itSCIdx =
34 lSegmentCabinIndexMap.begin();
35 itSCIdx != lSegmentCabinIndexMap.end(); ++itSCIdx) {
36 const stdair::SegmentCabin* lSC_ptr = itSCIdx->first;
37 assert (lSC_ptr != NULL);
38 const stdair::SegmentDataID_T& lSCIdx = itSCIdx->second;
40 const stdair::Date_T& lSnapshotDate = iSnapshotTime.date();
44 const stdair::SegmentDate& lSegmentDate =
45 stdair::BomManager::getParent<stdair::SegmentDate> (*lSC_ptr);
46 const stdair::Date_T& lDepartureDate = lSegmentDate.getBoardingDate();
47 const stdair::DateOffset_T lDateOffset = lDepartureDate - lSnapshotDate;
48 const stdair::DTD_T lDTD = lDateOffset.days() + 1;
50 if (lDTD >= 0 && lDTD <= stdair::DEFAULT_MAX_DTD) {
52 takeSnapshots (ioSegmentSnapshotTable, lDTD, *lSC_ptr, lSCIdx);
53 registerProductAndPriceOrientedBookings (ioSegmentSnapshotTable,
54 lDTD, *lSC_ptr, lSCIdx);
61 takeSnapshots (stdair::SegmentSnapshotTable& ioSegmentSnapshotTable,
62 const stdair::DTD_T& iDTD,
63 const stdair::SegmentCabin& iSegmentCabin,
64 const stdair::SegmentDataID_T iSegmentCabinIdx) {
67 stdair::SegmentCabinDTDSnapshotView_T lBookingView = ioSegmentSnapshotTable.
68 getSegmentCabinDTDBookingSnapshotView (iSegmentCabinIdx,
69 iSegmentCabinIdx, iDTD);
70 stdair::SegmentCabinDTDSnapshotView_T lCancellationView = ioSegmentSnapshotTable.
71 getSegmentCabinDTDCancellationSnapshotView (iSegmentCabinIdx,
72 iSegmentCabinIdx, iDTD);
73 stdair::SegmentCabinDTDSnapshotView_T lAvailabilityView = ioSegmentSnapshotTable.
74 getSegmentCabinDTDAvailabilitySnapshotView (iSegmentCabinIdx,
75 iSegmentCabinIdx, iDTD);
78 std::ostringstream lSCMapKey;
79 lSCMapKey << stdair::DEFAULT_SEGMENT_CABIN_VALUE_TYPE
80 << iSegmentCabin.describeKey();
81 const stdair::ClassIndex_T& lCabinIdx =
82 ioSegmentSnapshotTable.getClassIndex (lSCMapKey.str());
83 lAvailabilityView[lCabinIdx] = iSegmentCabin.getAvailabilityPool();
84 lBookingView[lCabinIdx] = iSegmentCabin.getCommittedSpace();
88 const stdair::BookingClassList_T& lBCList =
89 stdair::BomManager::getList<stdair::BookingClass> (iSegmentCabin);
90 for (stdair::BookingClassList_T::const_iterator itBC = lBCList.begin();
91 itBC != lBCList.end(); ++itBC) {
92 const stdair::BookingClass* lBookingClass_ptr = *itBC;
93 assert (lBookingClass_ptr != NULL);
96 const stdair::ClassIndex_T& lIdx =
97 ioSegmentSnapshotTable.getClassIndex (lBookingClass_ptr->describeKey());
107 lBookingView[lIdx]=lBookingClass_ptr->getNbOfBookings();
108 lCancellationView[lIdx] =
109 lBookingClass_ptr->getNbOfCancellations();
110 lAvailabilityView[lIdx] =
111 lBookingClass_ptr->getSegmentAvailability();
116 void SegmentSnapshotTableHelper::registerProductAndPriceOrientedBookings
117 (stdair::SegmentSnapshotTable& ioSegmentSnapshotTable,
const stdair::DTD_T& iDTD,
118 const stdair::SegmentCabin& iSegmentCabin,
119 const stdair::SegmentDataID_T iSegmentCabinIdx) {
122 stdair::SegmentCabinDTDRangeSnapshotView_T lRangeBookingView =
123 ioSegmentSnapshotTable.getSegmentCabinDTDRangeBookingSnapshotView (iSegmentCabinIdx, iSegmentCabinIdx, iDTD, iDTD + 1);
124 stdair::SegmentCabinDTDRangeSnapshotView_T lRangeCancellationView =
125 ioSegmentSnapshotTable.getSegmentCabinDTDRangeCancellationSnapshotView (iSegmentCabinIdx, iSegmentCabinIdx, iDTD, iDTD + 1);
126 stdair::SegmentCabinDTDSnapshotView_T lProductOrientedGrossBookingView =
127 ioSegmentSnapshotTable.getSegmentCabinDTDProductOrientedGrossBookingSnapshotView (iSegmentCabinIdx, iSegmentCabinIdx, iDTD);
128 stdair::SegmentCabinDTDSnapshotView_T lPriceOrientedGrossBookingView =
129 ioSegmentSnapshotTable.getSegmentCabinDTDPriceOrientedGrossBookingSnapshotView (iSegmentCabinIdx, iSegmentCabinIdx, iDTD);
130 stdair::SegmentCabinDTDSnapshotView_T lProductOrientedNetBookingView =
131 ioSegmentSnapshotTable.getSegmentCabinDTDProductOrientedNetBookingSnapshotView (iSegmentCabinIdx, iSegmentCabinIdx, iDTD);
132 stdair::SegmentCabinDTDSnapshotView_T lPriceOrientedNetBookingView =
133 ioSegmentSnapshotTable.getSegmentCabinDTDPriceOrientedNetBookingSnapshotView (iSegmentCabinIdx, iSegmentCabinIdx, iDTD);
137 const stdair::BookingClassList_T& lBCList =
138 stdair::BomManager::getList<stdair::BookingClass> (iSegmentCabin);
139 stdair::BookingClassList_T::const_iterator iterBC = lBCList.begin();
140 assert (iterBC != lBCList.end());
141 stdair::BookingClass* lLowestClass_ptr = *iterBC;
142 assert (lLowestClass_ptr != NULL);
143 stdair::Yield_T lLowestYield = lLowestClass_ptr->getYield();
144 for (; iterBC != lBCList.end(); iterBC++) {
145 const stdair::BookingClass* lBookingClass_ptr = *iterBC;
146 assert (lBookingClass_ptr != NULL);
147 const stdair::Yield_T& lYield = lBookingClass_ptr->getYield();
148 if (lYield < lLowestYield) {
149 lLowestYield = lYield;
150 lLowestClass_ptr = *iterBC;
153 assert (lLowestClass_ptr != NULL);
156 const stdair::ClassIndex_T& lClassIdx =
157 ioSegmentSnapshotTable.getClassIndex (lLowestClass_ptr->describeKey());
160 const stdair::NbOfBookings_T lNbOfNetBkgs =
161 lRangeBookingView[lClassIdx][0] - lRangeBookingView[lClassIdx][1];
162 const stdair::NbOfCancellations_T lNbOfCx =
163 lRangeCancellationView[lClassIdx][0]-lRangeCancellationView[lClassIdx][1];
164 const stdair::NbOfBookings_T lNbOfGrossBkgs = lNbOfNetBkgs + lNbOfCx;
167 lPriceOrientedGrossBookingView[lClassIdx] = lNbOfGrossBkgs;
168 lPriceOrientedNetBookingView[lClassIdx] = lNbOfNetBkgs;
171 bool noLowerClassAvl =
true;
172 if (lLowestClass_ptr->getSegmentAvailability() >= 1.0) {
173 noLowerClassAvl =
false;
177 stdair::BookingClassList_T::const_reverse_iterator itBC = lBCList.rbegin();
178 for (; itBC != lBCList.rend(); itBC++) {
179 const stdair::BookingClass* lBookingClass_ptr = *itBC;
180 assert (lBookingClass_ptr != NULL);
183 const stdair::Yield_T& lYield = lBookingClass_ptr->getYield();
184 assert (lYield >= lLowestYield);
185 if (lYield > lLowestYield) {
188 const stdair::ClassIndex_T& lIdx =
189 ioSegmentSnapshotTable.getClassIndex (lBookingClass_ptr->describeKey());
192 const stdair::NbOfBookings_T lNetBkgs =
193 lRangeBookingView[lIdx][0] - lRangeBookingView[lIdx][1];
194 const stdair::NbOfCancellations_T lCx =
195 lRangeCancellationView[lIdx][0] - lRangeCancellationView[lIdx][1];
196 const stdair::NbOfBookings_T lGrossBkgs = lNetBkgs + lCx;
201 if (noLowerClassAvl ==
false) {
202 lProductOrientedGrossBookingView[lIdx] = lGrossBkgs;
203 lProductOrientedNetBookingView[lIdx] = lNetBkgs;
205 lPriceOrientedGrossBookingView[lIdx] = lGrossBkgs;
206 lPriceOrientedNetBookingView[lIdx] = lNetBkgs;
208 if (lBookingClass_ptr->getSegmentAvailability() >= 1.0) {
209 noLowerClassAvl =
false;