Exemplo n.º 1
0
 /**
  * Get usage statistics for a partner
  * Calculation is done according to partner's package
  *
  * Additional data returned is a graph points of streaming usage in a timeframe
  * The resolution can be "days" or "months"
  *
  * @link http://docs.kaltura.org/api/partner/usage
  * @action getUsage
  * @param int $year
  * @param int $month
  * @param string $resolution accepted values are "days" or "months"
  * @return KalturaPartnerUsage
  * 
  * @throws APIErrors::UNKNOWN_PARTNER_ID
  */
 function getUsageAction($year = '', $month = 1, $resolution = "days")
 {
     $dbPartner = PartnerPeer::retrieveByPK($this->getPartnerId());
     if (!$dbPartner) {
         throw new KalturaAPIException(APIErrors::UNKNOWN_PARTNER_ID, $this->getPartnerId());
     }
     $packages = new PartnerPackages();
     $partnerUsage = new KalturaPartnerUsage();
     $partnerPackage = $packages->getPackageDetails($dbPartner->getPartnerPackage());
     $report_date = dateUtils::todayOffset(-3);
     list($totalStorage, $totalUsage, $totalTraffic) = myPartnerUtils::collectPartnerUsageFromDWH($dbPartner, $partnerPackage, $report_date);
     $partnerUsage->hostingGB = round($totalStorage / 1024, 2);
     // from MB to GB
     $totalUsageGB = round($totalUsage / 1024 / 1024, 2);
     // from KB to GB
     if ($partnerPackage) {
         $partnerUsage->Percent = round($totalUsageGB / $partnerPackage['cycle_bw'] * 100, 2);
         $partnerUsage->packageBW = $partnerPackage['cycle_bw'];
     }
     $partnerUsage->usageGB = $totalUsageGB;
     $partnerUsage->reachedLimitDate = $dbPartner->getUsageLimitWarning();
     if ($year != '' && is_int($year)) {
         $graph_lines = myPartnerUtils::getPartnerUsageGraph($year, $month, $dbPartner, $resolution);
         // currently we provide only one line, output as a string.
         // in the future this could be extended to something like KalturaGraphLines object
         $partnerUsage->usageGraph = $graph_lines['line'];
     }
     return $partnerUsage;
 }
 /**
  * Get usage statistics for a partner
  * Calculation is done according to partner's package
  *
  * Additional data returned is a graph points of streaming usage in a timeframe
  * The resolution can be "days" or "months"
  *
  * @link http://docs.kaltura.org/api/partner/usage
  * @action getUsage
  * @param int $year
  * @param int $month
  * @param KalturaReportInterval $resolution
  * @return KalturaPartnerUsage
  * 
  * @throws APIErrors::UNKNOWN_PARTNER_ID
  * @deprecated use getStatistics instead
  */
 public function getUsageAction($year = '', $month = 1, $resolution = "days")
 {
     $dbPartner = PartnerPeer::retrieveByPK($this->getPartnerId());
     if (!$dbPartner) {
         throw new KalturaAPIException(APIErrors::UNKNOWN_PARTNER_ID, $this->getPartnerId());
     }
     $packages = new PartnerPackages();
     $partnerUsage = new KalturaPartnerUsage();
     $partnerPackage = $packages->getPackageDetails($dbPartner->getPartnerPackage());
     $report_date = date("Y-m-d", time());
     list($totalStorage, $totalUsage, $totalTraffic) = myPartnerUtils::collectPartnerUsageFromDWH($dbPartner, $partnerPackage, $report_date);
     $partnerUsage->hostingGB = round($totalStorage / 1024, 2);
     // from MB to GB
     $totalUsageGB = round($totalUsage / 1024 / 1024, 2);
     // from KB to GB
     if ($partnerPackage) {
         $partnerUsage->Percent = round($totalUsageGB / $partnerPackage['cycle_bw'] * 100, 2);
         $partnerUsage->packageBW = $partnerPackage['cycle_bw'];
     }
     $partnerUsage->usageGB = $totalUsageGB;
     $partnerUsage->reachedLimitDate = $dbPartner->getUsageLimitWarning();
     if ($year != '') {
         $startDate = gmmktime(0, 0, 0, $month, 1, $year);
         $endDate = gmmktime(0, 0, 0, $month, date('t', $startDate), $year);
         if ($resolution == reportInterval::MONTHS) {
             $startDate = gmmktime(0, 0, 0, 1, 1, $year);
             $endDate = gmmktime(0, 0, 0, 12, 31, $year);
             if (intval(date('Y')) == $year) {
                 $endDate = time();
             }
         }
         $usageGraph = myPartnerUtils::getPartnerUsageGraph($startDate, $endDate, $dbPartner, $resolution);
         // currently we provide only one line, output as a string.
         // in the future this could be extended to something like KalturaGraphLines object
         $partnerUsage->usageGraph = $usageGraph;
     }
     return $partnerUsage;
 }
 public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser)
 {
     // make sure the secret fits the one in the partner's table
     $partner = PartnerPeer::retrieveByPK($partner_id);
     if (!$partner) {
         // CANNOT be because we are already in the service. it would have fallen before...
         $this->addException(APIErrors::UNKNOWN_PARTNER_ID);
     }
     $packages = new PartnerPackages();
     $partnerPackage = $packages->getPackageDetails($partner->getPartnerPackage());
     $report_date = dateUtils::todayOffset(-3);
     list($totalStorage, $totalUsage, $totalTraffic) = myPartnerUtils::collectPartnerUsageFromDWH($partner, $partnerPackage, $report_date);
     $return['hostingGB'] = round($totalStorage / 1024, 2);
     // from MB to GB
     $totalUsageGB = round($totalUsage / 1024 / 1024, 2);
     // from KB to GB
     $return['Percent'] = round($totalUsageGB / $partnerPackage['cycle_bw'] * 100, 2);
     $return['package_bw'] = $partnerPackage['cycle_bw'];
     $return['GB'] = $totalUsageGB;
     $return['reached_limit_date'] = $partner->getUsageLimitWarning();
     /* total usage status */
     /*  --- ended total usage status --- */
     /* usage graph */
     $year = $this->getPM("year");
     $month = $this->getP("month");
     $resolution = $this->getP("resolution");
     $graph_points = myPartnerUtils::getPartnerUsageGraph($year, $month, $partner, $resolution);
     /* --- ended usage graph --- */
     $this->addMsg("usage", $return);
     if (isset($debug_data)) {
         $this->addDebug('debug_data', $debug_data);
     }
     $this->addMsg("graph", $graph_points);
     /*
     * ADD ATTRIBUTES TO GRAPH
     
     <graph caption=""
     bgcolor="0xffffff" 
     border="false" 
     bordercolor="0xffffa7" 
     customxaxis="true" 
     minimumx="0"  
     maximumx="10" 
     intervalx="1" 
     xaxisname="Time"
     xtype="Category" 
     dataunits="hours"
     customyaxis="false" 
     minimumy="0" 
     maximumy="100" 
     intervaly="10" 
     yaxisname=""
     showdatatips="true" 
     mousesensitivity="50" 
     datatipmode="multiple"
     gridlinesdirection="both"
     customgridlines="true" 
     lineshadow="false"
     horizontalstrokecolor="0xeeeeee" 
     horizontalstrokesize=".3" 
     horizontalfillcolor="0xffffff" 
     horizontalfillsize=".3" 
     horizontalstrokealpha="0.1"
     horizontalalternatefillcolor="0xffffff" 
     horizontalalternatefillsize=".3"
     verticalstrokecolor="0xcccccc" 
     verticalstrokesize=".5"  
     verticalstrokealpha="0.5"
     verticalfillcolor="0xffffff" 
     verticalfillsize=".3" 
     verticalalternatefillcolor="0xffffff"
     verticalalternatefillsize=".3">
     
     * 
     */
 }