public function valueTv(Request\ValueTv $request)
 {
     $result = new Response\ValueTv();
     $this->_logger->info("'TV Value' calculation is started.");
     $reqGetPeriod = new PeriodGetForDependentCalcRequest();
     $reqGetPeriod->setBaseCalcTypeCode(Cfg::CODE_TYPE_CALC_COMPRESS_FOR_PTC);
     $reqGetPeriod->setDependentCalcTypeCode(Cfg::CODE_TYPE_CALC_VALUE_TV);
     $respGetPeriod = $this->_callPeriod->getForDependentCalc($reqGetPeriod);
     if ($respGetPeriod->isSucceed()) {
         $def = $this->_manTrans->begin();
         try {
             /* working vars */
             $thisPeriodData = $respGetPeriod->getDependentPeriodData();
             $thisPeriodId = $thisPeriodData[Period::ATTR_ID];
             $thisCalcData = $respGetPeriod->getDependentCalcData();
             $thisCalcId = $thisCalcData[Calculation::ATTR_ID];
             $basePeriodData = $respGetPeriod->getBasePeriodData();
             $baseDsBegin = $basePeriodData->getDstampBegin();
             $baseDsEnd = $basePeriodData->getDstampEnd();
             $baseCalcData = $respGetPeriod->getBaseCalcData();
             $baseCalcId = $baseCalcData->getId();
             /* calculation itself */
             $this->_logger->info("Processing period #{$thisPeriodId} ({$baseDsBegin}-{$baseDsEnd})");
             /* get compressed data by calculation ID */
             $compressPtc = $this->_subDb->getCompressedPtcData($baseCalcId);
             $updates = $this->_subCalc->valueTv($compressPtc);
             $this->_subDb->saveValueTv($updates, $baseCalcId);
             $this->_subDb->markCalcComplete($thisCalcId);
             $this->_manTrans->commit($def);
             $result->markSucceed();
             $result->setPeriodId($thisPeriodId);
             $result->setCalcId($thisCalcId);
         } finally {
             $this->_manTrans->end($def);
         }
     }
     $this->_logMemoryUsage();
     $this->_logger->info("'TV Value' calculation is completed.");
     return $result;
 }
 public function test_valueTv()
 {
     /** === Test Data === */
     $COMPRESSION = [1 => [PtcCompress::ATTR_CUSTOMER_ID => 1, PtcCompress::ATTR_PARENT_ID => 1, PtcCompress::ATTR_PV => 325], 2 => [PtcCompress::ATTR_CUSTOMER_ID => 2, PtcCompress::ATTR_PARENT_ID => 1, PtcCompress::ATTR_PV => 300], 3 => [PtcCompress::ATTR_CUSTOMER_ID => 3, PtcCompress::ATTR_PARENT_ID => 1, PtcCompress::ATTR_PV => 700]];
     /** === Mocks === */
     $mLogger = $this->_mockLogger();
     $mToolbox = $this->_mockToolbox();
     $mCallDownlineSnap = $this->_mockFor('\\Praxigento\\Downline\\Service\\ISnap');
     /**
      * Prepare request and perform call.
      */
     /** @var  $sub Calc */
     $sub = new Calc($mLogger, $mToolbox, $mCallDownlineSnap);
     $data = $sub->valueTv($COMPRESSION);
     $this->assertTrue(is_array($data));
 }