/** * report getTable action allows to get a graph data for a specific report. * * @action getTable * @param KalturaReportType $reportType * @param KalturaReportInputFilter $reportInputFilter * @param KalturaFilterPager $pager * @param KalturaReportType $reportType * @param string $order * @param string $objectIds - one ID or more (separated by ',') of specific objects to query * @return KalturaReportTable */ function getTableAction($reportType, KalturaReportInputFilter $reportInputFilter, KalturaFilterPager $pager, $order = null, $objectIds = null) { $reportTable = new KalturaReportTable(); list($header, $data, $totalCount) = myReportsMgr::getTable($this->getPartnerId(), $reportType, $reportInputFilter->toReportsInputFilter(), $pager->pageSize, $pager->pageIndex, $order, $objectIds); $reportTable->fromReportTable($header, $data, $totalCount); return $reportTable; }
public function execute() { $this->forceSystemAuthentication(); $this->partners_stat = array(); $start = microtime(true); $this->from_date = $this->getP("from_date"); $this->to_date = $this->getP("to_date", date("Y-m-d", time())); $this->days = $this->getP("days", 7); $this->data = array(); $totals = array(); $header = ""; if ($this->days) { $timeStamp = strtotime($this->to_date); $timeStamp -= 24 * 60 * 60 * ($this->days - 1); // because it's inclusive-inclusive - reduce one day $this->from_date = date("Y-m-d", $timeStamp); } if ($this->getP("go")) { $input_filter = new reportsInputFilter(); $input_filter->from_date = strtotime($this->from_date); $input_filter->to_date = strtotime($this->to_date); list($header, $data, $totalCount) = myReportsMgr::getTable(null, "system/system_generic_partner_billing", $input_filter, "", 300, null, null); $this->data = $data; // create total summary line /* $i=0; foreach ($this->data[0] as $columns ) { $totals[$i] = $i<1 ? "TOTAL" : 0 ; $i++; } foreach ( $this->data as $line ) { $i=0; foreach ( $line as $val ) { if ( is_numeric ($val ) ) @$totals[$i]+=$val; $i++; } } */ } $this->data[] = $totals; $this->header = $header; $end = microtime(true); $this->go = $this->getP("go"); $this->bench = $end - $start; $this->format = $this->getP("format", "row"); }
public function execute() { $this->forceSystemAuthentication(); $this->partners_stat = array(); $start = microtime(true); $file_path = dirname(__FILE__) . "/../data/viewPartnersData.txt"; $partner_groups = new partnerGroups($file_path); $this->partner_group_list = $partner_groups->partner_group_list; $group_rest = new partnerGroup(); $group_rest->setName("_rest"); $this->partner_group_list[] = $group_rest; $this->from_date = $this->getP("from_date"); $this->to_date = $this->getP("to_date", date("Y-m-d", time())); $this->days = $this->getP("days", 7); if ($this->days) { $timeStamp = strtotime($this->to_date); $timeStamp -= 24 * 60 * 60 * ($this->days - 1); // because it's inclusive-inclusive - reduce one day $this->from_date = date("Y-m-d", $timeStamp); } $input_filter = new reportsInputFilter(); $input_filter->from_date = strtotime($this->from_date); $input_filter->to_date = strtotime($this->to_date); list($header, $data, $totalCount) = myReportsMgr::getTable(null, myReportsMgr::REPORT_TYPE_SYSTEM_GENERIC_PARTNER_TYPE, $input_filter, "", 300, null, null); $this->data = $data; // create total summary line $totals = array(); $i = 0; foreach ($this->data[0] as $columns) { $totals[$i] = $i < 3 ? "TOTAL" : 0; $i++; } foreach ($this->data as $line) { $i = 0; foreach ($line as $val) { if (is_numeric($val)) { @($totals[$i] += $val); } $i++; } } $this->data[] = $totals; $this->header = $header; $end = microtime(true); $this->go = $this->getP("go"); $this->bench = $end - $start; $this->format = $this->getP("format", "row"); }
public function execute() { ini_set("memory_limit", "256M"); ini_set("max_execution_time", "240"); $this->forceSystemAuthentication(); $start = microtime(true); $this->from_date = $this->getP("from_date"); $this->to_date = $this->getP("to_date", date("Y-m-d", time())); $this->days = $this->getP("days", 7); $page = $this->getP("page", 1); if ($page < 1) { $page = 1; } $this->page = $page; if ($this->days) { $timeStamp = strtotime($this->to_date); $timeStamp -= 24 * 60 * 60 * ($this->days - 1); // because it's inclusive-inclusive - reduce one day $this->from_date = date("Y-m-d", $timeStamp); } $this->new_first = $this->getP("new_first", null); if ($this->new_first == "false") { $this->new_first = false; } $this->package_list = array("all" => "1=1", "paying" => "dim_partner.partner_package>1", "kaltura_signup" => "dim_partner.partner_type_id=1 AND dim_partner.partner_package=1", "other" => "dim_partner.partner_type_id=1 AND dim_partner.partner_package=2", "wiki" => "dim_partner.partner_type_id=1 AND dim_partner.partner_package=100", "wordpress" => "dim_partner.partner_type_id=1 AND dim_partner.partner_package=101", "drupal" => "dim_partner.partner_type_id=1 AND dim_partner.partner_package=102", "mind_touch" => "dim_partner.partner_type_id=1 AND dim_partner.partner_package=103", "moodle" => "dim_partner.partner_type_id=1 AND dim_partner.partner_package=104", "kaltura_ce" => "dim_partner.partner_type_id=1 AND dim_partner.partner_package=105"); $updated_at = null; $this->selected_package = $this->getP("pkg", "paying"); $input_filter = new reportsInputFilter(); if ($this->selected_package) { $criteria = @$this->package_list[$this->selected_package]; $input_filter->extra_map = array("{PARTNER_PACKAGE_CRITERIA}" => $criteria); } $input_filter->from_date = strtotime($this->from_date); $input_filter->to_date = strtotime($this->to_date); $data = $header = null; $this->go = $this->getP("go"); if ($this->go) { list($header, $data, $totalCount) = myReportsMgr::getTable(null, myReportsMgr::REPORT_TYPE_SYSTEM_GENERIC_PARTNER, $input_filter, self::MAX_PAGE_SIZE, $this->page, null, null); } if ($data) { $this->partners_stat = $data; $this->data = $data; } $this->header = $header; $this->updated_at = $updated_at; $end = microtime(true); $this->bench = $end - $start; }
/** * deprecated - use collectPartnerStatisticsFromDWH instead */ public static function collectPartnerUsageFromDWH($partner, $partnerPackage, $report_date, $data_for_graph = false) { // reset values: $totalStorage = 0; $totalTraffic = 0; $totalUsage = 0; $reportFilter = new reportsInputFilter(); $reportFilter->from_day = str_replace('-', '', $report_date); list($header, $data) = myReportsMgr::getTable($partner->getId(), myReportsMgr::REPORT_TYPE_PARTNER_BANDWIDTH_USAGE, $reportFilter, 10000, 1, "", null); $avg_continuous_aggr_storage_mb_key = array_search('avg_continuous_aggr_storage_mb', $header); $sum_partner_bandwidth_kb_key = array_search('sum_partner_bandwidth_kb', $header); // according to $partnerPackage['id'], decide which row to take (last date, or full rollup row) if ($partnerPackage['id'] == 1) { // $res[count($res)-1] => specific partner rollup, relevant for free partner $relevant_row = count($data) - 1; } else { // $res[count($res)-1] => specific partner rollup, relevant for free partner // $res[count($res)-2] => specific partner, last month, relevant for paying partner $relevant_row = count($data) - 2; } $totalStorage = $data[$relevant_row][$avg_continuous_aggr_storage_mb_key]; // MB $totalTraffic = $data[$relevant_row][$sum_partner_bandwidth_kb_key]; // KB $totalUsage = $totalStorage * 1024 + $totalTraffic; // (MB*1024 => KB) + KB return array($totalStorage, $totalUsage, $totalTraffic); }
/** * report getTable action allows to get a graph data for a specific report. * * @action getTable * @param KalturaReportType $reportType * @param KalturaReportInputFilter $reportInputFilter * @param KalturaFilterPager $pager * @param KalturaReportType $reportType * @param string $order * @param string $objectIds - one ID or more (separated by ',') of specific objects to query * @return KalturaReportTable */ public function getTableAction($reportType, KalturaReportInputFilter $reportInputFilter, KalturaFilterPager $pager, $order = null, $objectIds = null) { if ($reportType == KalturaReportType::PARTNER_USAGE || $reportType == KalturaReportType::VAR_USAGE) { $objectIds = $this->validateObjectsAreAllowedPartners($objectIds); } $reportTable = new KalturaReportTable(); list($header, $data, $totalCount) = myReportsMgr::getTable($this->getPartnerId(), $reportType, $reportInputFilter->toReportsInputFilter(), $pager->pageSize, $pager->pageIndex, $order, $objectIds); $reportTable->fromReportTable($header, $data, $totalCount); return $reportTable; }
/** * @action getUsage * @param KalturaSystemPartnerUsageFilter $filter * @param KalturaFilterPager $pager * @return KalturaSystemPartnerUsageListResponse */ public function getUsageAction(KalturaPartnerFilter $partnerFilter = null, KalturaSystemPartnerUsageFilter $usageFilter = null, KalturaFilterPager $pager = null) { if (is_null($partnerFilter)) { $partnerFilter = new KalturaPartnerFilter(); } if (is_null($usageFilter)) { $usageFilter = new KalturaSystemPartnerUsageFilter(); $usageFilter->fromDate = time() - 60 * 60 * 24 * 30; // last 30 days $usageFilter->toDate = time(); } if (is_null($pager)) { $pager = new KalturaFilterPager(); } $partnerFilterDb = new partnerFilter(); $partnerFilter->toObject($partnerFilterDb); $partnerFilterDb->set('_gt_id', 0); // total count $c = new Criteria(); $partnerFilterDb->attachToCriteria($c); $totalCount = PartnerPeer::doCount($c); // filter partners criteria $pager->attachToCriteria($c); $c->addAscendingOrderByColumn(PartnerPeer::ID); // select partners $partners = PartnerPeer::doSelect($c); $partnerIds = array(); foreach ($partners as &$partner) { $partnerIds[] = $partner->getId(); } $items = array(); if (!count($partnerIds)) { // no partners fit the filter - don't fetch data $totalCount = 0; // the items are set to an empty KalturaSystemPartnerUsageArray } else { $inputFilter = new reportsInputFilter(); $inputFilter->from_date = $usageFilter->fromDate; $inputFilter->to_date = $usageFilter->toDate; list($reportHeader, $reportData, $totalCountNoNeeded) = myReportsMgr::getTable(null, myReportsMgr::REPORT_TYPE_ADMIN_CONSOLE, $inputFilter, $pager->pageSize, 0, null, implode(",", $partnerIds)); $unsortedItems = array(); foreach ($reportData as $line) { $item = KalturaSystemPartnerUsageItem::fromString($reportHeader, $line); if ($item) { $unsortedItems[$item->partnerId] = $item; } } // create the items in the order of the partnerIds and create some dummy for ones that don't exist foreach ($partnerIds as $partnerId) { if (isset($unsortedItems[$partnerId])) { $items[] = $unsortedItems[$partnerId]; } else { // if no item for partner - get its details from the db $items[] = KalturaSystemPartnerUsageItem::fromPartner(PartnerPeer::retrieveByPK($partnerId)); } } } $response = new KalturaSystemPartnerUsageListResponse(); $response->totalCount = $totalCount; $response->objects = $items; return $response; }
/** * Function which calulates partner usage of a group of a VAR's sub-publishers * * @action getPartnerUsage * @param KalturaPartnerFilter $partnerFilter * @param KalturaReportInputFilter $usageFilter * @param KalturaFilterPager $pager * @return KalturaPartnerUsageListResponse * @throws KalturaVarConsoleErrors::MAX_SUB_PUBLISHERS_EXCEEDED */ public function getPartnerUsageAction(KalturaPartnerFilter $partnerFilter = null, KalturaReportInputFilter $usageFilter = null, KalturaFilterPager $pager = null) { if (is_null($partnerFilter)) { $partnerFilter = new KalturaPartnerFilter(); } if (is_null($usageFilter)) { $usageFilter = new KalturaReportInputFilter(); $usageFilter->fromDate = time() - 60 * 60 * 24 * 30; // last 30 days $usageFilter->toDate = time(); } else { //The first time the filter is sent, it it sent with 0 as fromDate if (!$usageFilter->fromDate) { $usageFilter->fromDate = time() - 60 * 60 * 24 * 30; } if (!$usageFilter->interval) { $usageFilter->interval = KalturaReportInterval::MONTHS; } } if (is_null($pager)) { $pager = new KalturaFilterPager(); } //Create a propel filter for the partner $partnerFilterDb = new partnerFilter(); $partnerFilter->toObject($partnerFilterDb); //add filter to criteria $c = PartnerPeer::getDefaultCriteria(); $partnerFilterDb->attachToCriteria($c); $partnersCount = PartnerPeer::doCount($c); if ($partnersCount > self::MAX_SUB_PUBLISHERS) { throw new KalturaAPIException(KalturaVarConsoleErrors::MAX_SUB_PUBLISHERS_EXCEEDED); } $partners = PartnerPeer::doSelect($c); $partnerIds = array(); foreach ($partners as &$partner) { $partnerIds[] = $partner->getId(); } // add pager to criteria $pager->attachToCriteria($c); $c->addAscendingOrderByColumn(PartnerPeer::ID); // select partners $items = array(); $inputFilter = new reportsInputFilter(); $inputFilter->from_date = $usageFilter->fromDate; $inputFilter->to_date = $usageFilter->toDate; $inputFilter->from_day = date("Ymd", $usageFilter->fromDate); $inputFilter->to_day = date("Ymd", $usageFilter->toDate); $inputFilter->timeZoneOffset = $usageFilter->timeZoneOffset; $inputFilter->interval = $usageFilter->interval; if (!count($partnerIds)) { $total = new KalturaVarPartnerUsageTotalItem(); // no partners fit the filter - don't fetch data $totalCount = 0; // the items are set to an empty KalturaSystemPartnerUsageArray } else { $totalCount = 0; $orderBy = ($inputFilter->interval == reportInterval::MONTHS ? "+month_id" : "+date_id") . ",+partner_id"; list($reportHeader, $reportData, $totalCount) = myReportsMgr::getTable(null, myReportsMgr::REPORT_TYPE_VAR_USAGE, $inputFilter, $pager->pageSize, $pager->pageIndex, $orderBy, implode(",", $partnerIds)); foreach ($reportData as $line) { $item = new KalturaVarPartnerUsageItem(); $item->fromString($reportHeader, $line); if ($item) { $items[] = $item; } } list($reportHeader, $reportData) = myReportsMgr::getTotal(null, myReportsMgr::REPORT_TYPE_PARTNER_USAGE, $inputFilter, implode(",", $partnerIds)); $total = new KalturaVarPartnerUsageTotalItem(); $total->fromString($reportHeader, $reportData); list($peakStoragereportHeader, $peakStoragereportData) = myReportsMgr::getTotal(null, myReportsMgr::REPORT_TYPE_PEAK_STORAGE, $inputFilter, implode(",", $partnerIds)); if ($peakStoragereportData[0]) { $total->peakStorage = ceil(@$peakStoragereportData[0]); } } $response = new KalturaPartnerUsageListResponse(); //Sort according to dateId and partnerId uasort($items, array($this, 'sortByDate')); $response->total = $total; $response->totalCount = $totalCount; $response->objects = $items; return $response; }