public static function getReportChart($reportid, $chartType) { global $log, $adb; $oReportRun = new ReportRun($reportid); $groupBy = $oReportRun->getGroupingList($reportid); foreach ($groupBy as $key => $value) { // $groupByConditon = explode(" ",$value); //$groupByNew = explode("'",$groupByConditon[0]); list($tablename, $colname, $module_field, $fieldname, $single) = explode(":", $key); list($module, $field) = explode("_", $module_field); $fieldDetails = $key; break; } $queryReports = self::getCustomReportsQuery($reportid); $queryResult = $adb->pquery($queryReports, array()); //ChartUtils::generateChartDataFromReports($queryResult, strtolower($groupByNew[1])); if ($chartType == 'horizontalbarchart') { $Chart = ChartUtils::getReportBarChart($queryResult, strtolower($module_field), $fieldDetails, $reportid); } else { if ($chartType == 'verticalbarchart') { $Chart = ChartUtils::getReportBarChart($queryResult, strtolower($module_field), $fieldDetails, $reportid, 'vertical'); } else { if ($chartType == 'piechart') { $Chart = ChartUtils::getReportPieChart($queryResult, strtolower($module_field), $fieldDetails, $reportid); } } } return $Chart; }
public static function getTopActivitiesData($domain, $fromDate, $toDate, $aggregation, $limit = 10, $dealId = null) { $col = MongoUtils::getCollection('analytics.activities'); $keys = array("url" => 1); $cond = array("date" => array('$gte' => new MongoDate(strtotime($fromDate)), '$lte' => new MongoDate(strtotime($toDate)))); if (is_array($domain)) { $cond['host'] = array('$in' => $domain); } else { $cond['host'] = $domain; } if ($dealId) { $dealId = intval($dealId); $cond['d_id'] = $dealId; } else { $cond['d_id'] = array('$exists' => false); } $initial = array("total" => 0, "pos" => 0, "neg" => 0, "contacts" => 0, "clickbacks" => 0, "distribution" => 0, "title" => ''); $reduce = "function(doc, out){ " . "out.total+=1;" . "out.pos+=doc.pos==true ? 1 : 0;" . "out.neg+=doc.pos==false ? 1 : 0;" . "for(oi in doc.oi) {" . "out.contacts+=isNaN(doc.oi[oi].cnt) ? 0 : doc.oi[oi].cnt;" . "}" . "if(doc.cb!=undefined && doc.cb!=null) {" . "out.clickbacks+=1;" . "}" . "if(doc.title!=undefined && doc.title!=null) {" . "out.title = doc.title;" . "}" . "}"; $g = $col->group($keys, $initial, $reduce, array("condition" => $cond)); $totalTotals = 0; for ($i = 0; $i < count($g['retval']); $i++) { $totalTotals += $g['retval'][$i]['total']; } for ($i = 0; $i < count($g['retval']); $i++) { $g['retval'][$i]['distribution'] = round($totalTotals == 0 ? 0 : $g['retval'][$i]['total'] / $totalTotals * 100, 2); } $data = array(); $data['data'] = ChartUtils::sortArrayByTotals($g['retval'], $limit); foreach ($data['data'] as $key => $item) { $data['data'][$key]['pis'] = array('total' => 0, 'cb' => 123, 'yiid' => 0); $pis = MongoUtils::getPisDataForUrl($item['url'], $fromDate, $toDate, $dealId); $data['data'][$key]['pis'] = $pis; } $data['filter'] = MongoUtils::getFilter($domain, $fromDate, $toDate); return $data; }
if (!empty($groupBy)) { foreach ($groupBy as $key => $value) { //$groupByConditon = explode(" ",$value); //$groupByNew = explode("'",$groupByConditon[0]); list($tablename, $colname, $module_field, $fieldname, $single) = explode(":", $key); list($module, $field) = explode("_", $module_field); $fieldDetails = $key; break; } //$groupByField = $oReportRun->GetFirstSortByField($reportid); $queryReports = CustomReportUtils::getCustomReportsQuery($Report_ID, $filtersql); $queryResult = $adb->pquery($queryReports, array()); //ChartUtils::generateChartDataFromReports($queryResult, strtolower($groupByNew[1])); if ($adb->num_rows($queryResult)) { $pieChart = ChartUtils::getReportPieChart($queryResult, strtolower($module_field), $fieldDetails, $reportid); $barChart = ChartUtils::getReportBarChart($queryResult, strtolower($module_field), $fieldDetails, $reportid); $list_report_form->assign("PIECHART", $pieChart); $list_report_form->assign("BARCHART", $barChart); } else { $showCharts = false; } } else { $showCharts = false; } $list_report_form->assign("SHOWCHARTS", $showCharts); } //Monolithic Changes Ends // Performance Optimization: Direct output of the report result if ($_REQUEST['submode'] == 'generateReport' && empty($advft_criteria)) { $filtersql = ''; }
public static function getReportPieChart($queryResult, $groupbyField, $fieldDetails, $reportid) { global $theme; $PieChartDetails = self::generateChartDataFromReports($queryResult, $groupbyField, $fieldDetails, $reportid); $groupbyFields = $PieChartDetails['xaxisData']; $yaxisArray = $PieChartDetails['yaxisData']; $targerLinks = $PieChartDetails['targetLink']; $charttype = 'vertical'; if ($theme == "softed") { $font_color = "#212473"; } else { $font_color = "#000000"; } if (!empty($PieChartDetails['error'])) { return $PieChartDetails['error']; } else { $pieChart = ChartUtils::getPieChart($groupbyFields, $yaxisArray, '', '350', '300', $charttype, false, $targerLinks, $font_color); return $pieChart; } }
public static function getActivitiesForAllServices($rawData, $services) { $temp = array(); // Initializing the Data arrays for the chart foreach ($services as $service) { $temp[$service . '_likes'] = array(); $temp[$service . '_dislikes'] = array(); } // Sort data by date $rawData['data'] = ChartUtils::sortArrayByDate($rawData['data']); // Converting data into a chart usable format foreach ($rawData['data'] as $data) { foreach ($services as $service) { if (array_key_exists($service, $data)) { array_push($temp[$service . '_likes'], $data[$service]['likes']); array_push($temp[$service . '_dislikes'], $data[$service]['dislikes']); } else { array_push($temp[$service . '_likes'], 0); array_push($temp[$service . '_dislikes'], 0); } } } return $temp; }
function getChartLineRangeViewsData($rawData, $community = 'all') { $res = array(); $services = array('facebook', 'twitter', 'linkedin', 'google'); $res['clickbacks'] = array(); $res['views'] = array(); $temp = array(); // Initializing the Data arrays for the chart foreach ($services as $service) { $temp[$service . '_contacts'] = array(); $temp[$service . '_clickbacks'] = array(); } // Sort data by date $rawData['data'] = ChartUtils::sortArrayByDate($rawData['data']); // Converting data into a chart usable format foreach ($rawData['data'] as $data) { $cb = 0; foreach ($services as $service) { if (array_key_exists($service, $data)) { array_push($temp[$service . '_contacts'], $data[$service]['contacts']); array_push($temp[$service . '_clickbacks'], $data[$service]['clickbacks']); $cb += $data[$service]['clickbacks']; } else { array_push($temp[$service . '_contacts'], 0); array_push($temp[$service . '_clickbacks'], 0); } } //array_push($res['clickbacks'], $cb); } for ($i = 0; $i < count($temp['facebook_contacts']); $i++) { $res['views'][$i] = 0; if ($community == 'all') { $res['views'][$i] += $temp['facebook_contacts'][$i] + $temp['twitter_contacts'][$i] + $temp['google_contacts'][$i] + $temp['linkedin_contacts'][$i]; } else { $res['views'][$i] += $temp[$community . '_contacts'][$i]; } $res['clickbacks'][$i] = 0; if ($community == 'all') { $res['clickbacks'][$i] += $temp['facebook_clickbacks'][$i] + $temp['twitter_clickbacks'][$i] + $temp['google_clickbacks'][$i] + $temp['linkedin_clickbacks'][$i]; } else { $res['clickbacks'][$i] += $temp[$community . '_clickbacks'][$i]; } } // Addding some metadata from the filter like categories, range, etc. $metadata = ChartUtils::addFilterData($res, $rawData['filter']); $res['startdate'] = $metadata['startdate']; return json_encode($res); }