test_class.file: jtstoolkit/src/test/java/ec/tstoolkit/timeseries/simplets/chainlinking/AnnualOverlapTest.java
test_class.identifier: AnnualOverlapTest
test_case.body: @Test
      public void testAnnualOverlap() {
          double[] qa = new double[]{56.4, 62.4, 65.7, 66.5, 67.4, 69.4, 71.5, 73.7, 76, 78.3, 80.6, 83.1, 85.5, 88.2, 90.8, 93.5};
          double[] qb = new double[]{57.6, 58, 59, 61.4, 57.6, 57.1, 56.5, 55.8, 55.4, 54.8, 54.2, 53.6, 53.2, 52.7, 52.1, 52};
          double[] pa = new double[]{6.2, 6.5, 7.6, 7.7, 6.1, 5.7, 5.3, 5, 4.5, 4.3, 3.8, 3.5, 3.4, 3.1, 2.8, 2.7};
          double[] pb = new double[]{5.4, 5.6, 6.2, 6.8, 8.0, 8.6, 9.4, 10.0, 10.7, 11.5, 11.7, 12.1, 12.5, 13, 13.8, 14.7};
          
          TsData QAq = new TsData(TsFrequency.Quarterly, 1997, 0, qa, true);
          TsData QBq = new TsData(TsFrequency.Quarterly, 1997, 0, qb, true);
          TsData PAq = new TsData(TsFrequency.Quarterly, 1997, 0, pa, true);
          TsData PBq = new TsData(TsFrequency.Quarterly, 1997, 0, pb, true);
          
          AnnualOverlap o = new AnnualOverlap();
          o.setRefYear(1997);
          
          o.addProduct("Product A", QAq, PAq);
          o.addProduct("Product B", QBq, PBq);
          
          o.process();
      }
test_case.class_method_signature: AnnualOverlapTest.testAnnualOverlap()
test_case.full_signature: @Test public void testAnnualOverlap()
test_case.identifier: testAnnualOverlap
test_case.invocations: setRefYear addProduct addProduct process
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testAnnualOverlap()
focal_class.declarator: TOTAL_VALUES = "totalvalues"
focal_class.modifier: public static final
focal_class.original_string: public static final String TOTAL_VALUES = "totalvalues";
focal_class.type: String
focal_class.var_name: TOTAL_VALUES
focal_class.declarator: VALUES_PREVIOUS_PRICE = "valuesPreviousYearPrice"
focal_class.modifier: public static final
focal_class.original_string: public static final String VALUES_PREVIOUS_PRICE = "valuesPreviousYearPrice";
focal_class.type: String
focal_class.var_name: VALUES_PREVIOUS_PRICE
focal_class.declarator: CHAIN_LINKED_INDEXES = "percPreviousYearPrice"
focal_class.modifier: public static final
focal_class.original_string: public static final String CHAIN_LINKED_INDEXES = "percPreviousYearPrice";
focal_class.type: String
focal_class.var_name: CHAIN_LINKED_INDEXES
focal_class.declarator: REF_YEAR = "refYear"
focal_class.modifier: public static final
focal_class.original_string: public static final String REF_YEAR = "refYear";
focal_class.type: String
focal_class.var_name: REF_YEAR
focal_class.file: jtstoolkit/src/main/java/ec/tstoolkit/timeseries/simplets/chainlinking/AnnualOverlap.java
focal_class.identifier: AnnualOverlap
focal_class.class_method_signature: AnnualOverlap.process()
focal_class.full_signature: @Override public void process()
focal_class.identifier: process
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void process()
focal_class.class_method_signature: AnnualOverlap.findSmallestDomain()
focal_class.full_signature: private TsDomain findSmallestDomain()
focal_class.identifier: findSmallestDomain
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: TsDomain
focal_class.signature: TsDomain findSmallestDomain()
focal_class.class_method_signature: AnnualOverlap.intersectAllDomains(TsDomain ref)
focal_class.full_signature: private TsDomain intersectAllDomains(TsDomain ref)
focal_class.identifier: intersectAllDomains
focal_class.modifiers: private
focal_class.parameters: (TsDomain ref)
focal_class.return: TsDomain
focal_class.signature: TsDomain intersectAllDomains(TsDomain ref)
focal_class.class_method_signature: AnnualOverlap.cloneInputList()
focal_class.full_signature: private ArrayList<Product> cloneInputList()
focal_class.identifier: cloneInputList
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: ArrayList<Product>
focal_class.signature: ArrayList<Product> cloneInputList()
focal_class.class_method_signature: AnnualOverlap.calculateMissingData()
focal_class.full_signature: private void calculateMissingData()
focal_class.identifier: calculateMissingData
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void calculateMissingData()
focal_class.superclass: extends AChainLinking
focal_method.body: @Override
      public void process() {
          if (input == null || input.isEmpty()) {
              results = null;
              return;
          }
  
          results = new InformationSet();
          
          // Calculate the 3rd missing Ts
          calculateMissingData();
  
          // Find the intersection domain between all series
          TsDomain intersection = intersectAllDomains(findSmallestDomain());
          if (intersection.getLength() == 0) {
              throw new IllegalArgumentException("The common domain is empty");
          }
  
          if (refYear == - 1 || intersection.getStart().getYear() > refYear
                  || intersection.getEnd().getYear() < refYear) {
              refYear = intersection.getStart().getYear();
          }
  
          results.add(REF_YEAR, refYear);
  
          // Then, drop everything before the reference year (-1 quarter each iteration)
          while (intersection.getStart().getYear() < refYear) {
              intersection = intersection.drop(1, 0);
          }
  
          // Create the list of domain fitted products, we keep original list unchanged
          List<Product> prds = cloneInputList();
  
          for (int i = 0; i < prds.size(); i++) {
              prds.get(i).setQuantities(prds.get(i).getQuantities().fittoDomain(intersection));
              prds.get(i).setPrice(prds.get(i).getPrice().fittoDomain(intersection));
              prds.get(i).setValue(prds.get(i).getValue().fittoDomain(intersection));
          }
  
          List<TsData> allPricesY = new ArrayList<>();
          for (int i = 0; i < prds.size(); i++) {
              allPricesY.add(prds.get(i).getPrice().changeFrequency(TsFrequency.Yearly, TsAggregationType.Average, true));
          }
  
          //-------------------------------------------------------------------
          // Create list of first year dropped quantities
          List<TsData> allQuantitiesQ = new ArrayList<>();
          for (int i = 0; i < prds.size(); i++) {
              TsData ts = prds.get(i).getQuantities();
              ts = ts.update(ts.changeFrequency(TsFrequency.Quarterly, TsAggregationType.Sum, true));
              ts = ts.drop(4, 0);
              allQuantitiesQ.add(ts);
          }
  
          // Calculate total value TsData (column Total at current prices)        
          TsData totalValueQ = prds.get(0).getValue();
          for (int i = 1; i < prds.size(); i++) {
              totalValueQ = TsData.add(totalValueQ, prds.get(i).getValue());
          }
  
          results.add(TOTAL_VALUES, totalValueQ);
  
          TsData totalValueY = totalValueQ.changeFrequency(TsFrequency.Yearly, TsAggregationType.Sum, true);
          totalValueQ = totalValueQ.drop(4, 0);
  
          // Iterates through the years for computing the series at the price of previous year
          TsData Qq = new TsData(totalValueQ.getDomain());
          YearIterator yq = new YearIterator(Qq);
          List<YearIterator> iterators = new ArrayList<>();
          for (int i = 0; i < allQuantitiesQ.size(); i++) {
              iterators.add(new YearIterator(allQuantitiesQ.get(i)));
          }
          while (yq.hasMoreElements()) {
              TsDataBlock qcur = yq.nextElement();
              List<TsDataBlock> dataBlocks = new ArrayList<>();
              for (int i = 0; i < prds.size(); i++) {
                  dataBlocks.add(iterators.get(i).nextElement());
              }
              TsPeriod prev = TsPeriod.year(qcur.start.getYear() - 1);
  
              qcur.data.setAY(allPricesY.get(0).get(prev), dataBlocks.get(0).data);
              for (int i = 1; i < dataBlocks.size(); i++) {
                  qcur.data.addAY(allPricesY.get(i).get(prev), dataBlocks.get(i).data);
              }
          }
  
          // In Qq I have values of each quarter computed with the price of previous year
          results.set(VALUES_PREVIOUS_PRICE, Qq.clone());
  
          //---------------------------------------------------------------
          // STEP 3. Chain the indexes.
          double idx = 100;
          int ifreq = Qq.getFrequency().intValue();
          yq.reset();
  
          while (yq.hasMoreElements()) {
              TsDataBlock qcur = yq.nextElement();
              TsPeriod prev = TsPeriod.year(qcur.start.getYear() - 1);
              double val0 = totalValueY.get(prev);
              double val1 = qcur.data.sum();
              qcur.data.mul(idx / (val0 / ifreq));
              idx *= val1 / val0;
          }
          // In Qq I have % of chain linked indexes
          results.set(CHAIN_LINKED_INDEXES, Qq);
      }
focal_method.class_method_signature: AnnualOverlap.process()
focal_method.full_signature: @Override public void process()
focal_method.identifier: process
focal_method.invocations: isEmpty calculateMissingData intersectAllDomains findSmallestDomain getLength getYear getStart getYear getEnd getYear getStart add getYear getStart drop cloneInputList size setQuantities get fittoDomain getQuantities get setPrice get fittoDomain getPrice get setValue get fittoDomain getValue get size add changeFrequency getPrice get size getQuantities get update changeFrequency drop add getValue get size add getValue get add changeFrequency drop getDomain size add get hasMoreElements nextElement size add nextElement get year getYear setAY get get get size addAY get get get set clone intValue getFrequency reset hasMoreElements nextElement year getYear get sum mul set
focal_method.modifiers: @Override public
focal_method.parameters: ()
focal_method.return: void
focal_method.signature: void process()