示例#1
0
 public static function rewind()
 {
     self::$_position = 0;
 }
				<span style="background-color:<?php 
    echo $color;
    ?>
; <?php 
    echo $square;
    ?>
"></span>
				Competitor Product: <b><?php 
    echo getProductsTitle($prodId);
    ?>
</b><br>
			</div>
		</div><?php 
    if (isset($comparison_data[$prodId])) {
        $competitor_map_id = $competitor_map[$prodId]['id'];
        $competitor_map_color = Color_handler::get_next($color_index[$competitor_map_id])->get_hex();
        ?>

		<div class="search-result" rel="<?php 
        echo $competitor_map_id;
        ?>
" style="float:left; width:<?php 
        echo $brandWidth;
        ?>
%;">
			<div style="margin-bottom:10px;" class="product_save">
				<span style="background-color:<?php 
        echo $competitor_map_color;
        ?>
; <?php 
        echo $square;
示例#3
0
 protected function generateGraphImage($finalData, $hourflag, $title = 'Sticky Charts', $x_axis_format = 'date')
 {
     $path = $this->config->item('csv_upload_path');
     if (!empty($finalData['data'])) {
         $DataSet = new pData();
         $in = 0;
         foreach ($finalData['data'] as $seriesData) {
             $in++;
             $seriesIndex = 'Serie' . $in;
             $DataSet->AddPoint($seriesData['data'], $seriesIndex);
             $DataSet->SetSerieName($seriesData['name'], $seriesIndex);
             $DataSet->AddSerie($seriesIndex);
         }
         $xAxisArray = array();
         $in++;
         $seriesIndex = 'Serie' . $in;
         $catCount = count($finalData['cat']);
         if ($catCount <= 10) {
             $DataSet->SetXAxisFormat($x_axis_format);
         }
         foreach ($finalData['cat'] as $catD) {
             if ($catCount > 10) {
                 $xAxisArray[] = '';
             } else {
                 $xAxisArray[] = strtotime($catD);
             }
         }
         $DataSet->SetYAxisFormat("number");
         $DataSet->AddPoint($xAxisArray, $seriesIndex);
         $DataSet->SetAbsciseLabelSerie($seriesIndex);
         $DataSet->SetYAxisName($finalData['y_title']);
         $DataSet->SetXAxisName($finalData['x_title']);
         // Initialise the graph
         $Test = new pChart(985, 458);
         $Test->drawBackground(247, 226, 180);
         $Test->setFontProperties(APPPATH . '3rdparty/pchart/Fonts/tahoma.ttf', 8);
         $Test->setGraphArea(40, 30, 950, 400);
         $Test->drawGraphArea(109, 110, 114, false);
         $Test->drawGrid(4, false, 0, 0, 0, 50);
         $Test->setFontProperties(APPPATH . '3rdparty/pchart/Fonts/tahoma.ttf', 6);
         // Draw the line graph
         if ($title == 'Violation Report') {
             //!$hourflag &&
             $sCount = count($finalData['data']);
             if ($sCount > 0) {
                 for ($m = 0; $m < $sCount; $m++) {
                     $color = Color_handler::get_next($m);
                     $rgb = $color->get_rgb();
                     $Test->setColorPalette($m, $rgb['r'], $rgb['g'], $rgb['b']);
                 }
             }
             $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 0, 0, 0, TRUE, 0, 0, TRUE);
             $Test->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription());
         } else {
             $sCount = count($finalData['data']);
             if ($sCount > 0) {
                 for ($m = 0; $m < $sCount; $m++) {
                     $color = Color_handler::get_next($m % 3);
                     $rgb = $color->get_rgb();
                     $Test->setColorPalette($m, $rgb['r'], $rgb['g'], $rgb['b']);
                 }
             }
             $Test->setLineStyle(2);
             $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_START0, 0, 0, 0, TRUE, 0, 2);
             $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription());
             $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 2);
         }
         // Finish the graph
         $Test->setFontProperties(APPPATH . '3rdparty/pchart/Fonts/tahoma.ttf', 8);
         $Test->setFontProperties(APPPATH . '3rdparty/pchart/Fonts/tahoma.ttf', 10);
         $imgName = uniqid('graph_') . '.png';
         $Test->Render($path . $imgName);
         return upload_to_amazon_graphImage($imgName, $path);
     }
 }
示例#4
0
 /**
  * Pre process the data to use in google charts
  *
  * @param array $data
  * @param array $report_where
  * @param String $chartType
  * @return array
  */
 public function prepGoogleData($data, $report_where, $chartType)
 {
     if (empty($data)) {
         $data = array();
     }
     $store_id = get_instance()->store_id;
     //define chart type, colors come from global config
     //use productId as indexes for data=>result keys
     $googleData = array('type' => '', 'date' => array('start' => time(), 'end' => time()), 'data' => array('size' => 0));
     $marketColors = $this->config->item('market_colors');
     $prepData = array();
     switch ($chartType) {
         case 'scatter':
             /* example price array - only take what we need for the google data
             		array('price' => '17.59', 'retail' => '30.85', 'wholesale' => '17.56', 'map' => '21.6', 'count' => '1', 'upc' => '658010113403', 'title' => 'GARDEN OF LIFE 100% Organic Extra Virgin Coconut Oil 32 fl.oz', 'marketplace' => 'Shopping.com', 'url' => 'http://www.allstarhealth.com/de_p_ref/21115/DT21115/GARDEN_OF_LIFE_100Percent_Organic_Extra_Virgin_Coconut_Oil.htm', 'dt' => '1340074876', 'prod_id' => '391', 'timestamp' => '1340074876', 'hash_key' => 'AllStarHealth#658010113403', 'merchant' => 'AllStarHealth', 'original_name' => 'AllStarHealth', 'merchant_id' => '9183', 'date' => '06/18/2012 20:01:16')*/
             //scatterchart
             $c = 0;
             $googleData['type'] = 'scatter';
             //we can't have the start & end be the same for the scatter chart
             $googleData['date']['start'] = $report_where['date_from'];
             $googleData['date']['end'] = $report_where['date_to'] == $report_where['date_from'] ? $report_where['date_from'] + 86400 : $report_where['date_to'];
             $googleData['date']['earliest'] = time();
             $googleData['data']['size'] = sizeof($data);
             $num_outliers = 0;
             foreach ($data as $prodId => $prodData) {
                 // create the prepData and calculate average on pass 1
                 $avg = 0;
                 for ($i = 0, $n = sizeof($prodData); $i < $n; $i++) {
                     $price = (double) $prodData[$i]['price'];
                     $map = (double) $prodData[$i]['map'];
                     $violation = $price < $map;
                     $avg += $price;
                     $prepData[$prodId][] = array('price' => $price, 'map' => $map, 'marketplace' => $prodData[$i]['marketplace'], 'merchant' => getMerchantName($prodData[$i]['merchant_id']), 'merchant_id' => $prodData[$i]['merchant_id'], 'timestamp' => $prodData[$i]['timestamp'], 'violation' => $violation);
                     //reset earliest date if necessary
                     if ($prodData[$i]['timestamp'] < $googleData['date']['earliest']) {
                         $googleData['date']['earliest'] = $prodData[$i]['timestamp'];
                     }
                 }
                 // Calculate standard deviation on pass 2
                 $avg = $n > 0 ? round($avg / $n, 2) : 0;
                 $sd = 0;
                 for ($i = 0; $i < $n; $i++) {
                     $sd += pow($prepData[$prodId][$i]['price'] - $avg, 2);
                 }
                 $sd = $n > 0 ? round(sqrt($sd / $n), 2) : round(sqrt($sd), 2);
                 // find outliers on pass 3
                 $thresh = 3 * $sd;
                 $outliers = array();
                 for ($i = 0; $i < $n; $i++) {
                     if (abs($prepData[$prodId][$i]['price'] - $avg) > $thresh) {
                         $outliers[] = $i;
                         $num_outliers++;
                     }
                 }
                 // build data column
                 $productInfo = getProductUPCByID($prodId, $this->ci->store_id);
                 $mapPrice = getPricingHistory($productInfo['upc_code'], $this->ci->store_id, 'price_floor', $googleData['date']['start'], $googleData['date']['end']);
                 $retailPrice = getPricingHistory($productInfo['upc_code'], $this->ci->store_id, 'retail_price', $googleData['date']['start'], $googleData['date']['end']);
                 $wholeSalePrice = getPricingHistory($productInfo['upc_code'], $this->ci->store_id, 'wholesale_price', $googleData['date']['start'], $googleData['date']['end']);
                 $Color = Color_handler::get_next();
                 $color_info = array('hex' => $Color->get_hex(), 'string' => $Color->get_string());
                 $this->ci->data->colors[] = $color_info;
                 $googleData['data']['columns'][$prodId] = array('type' => 'number', 'color' => $color_info, 'name' => getProductsTitle($prodId), 'pricing' => array('map' => $mapPrice, 'retail' => $retailPrice, 'wholesale' => $wholeSalePrice), 'stats' => array('avg' => $avg, 'sd' => $sd, 'thresh' => $thresh, 'outliers' => $outliers));
                 $c++;
             }
             $googleData['data']['outliers'] = $num_outliers;
             $googleData['data']['result'] = $prepData;
             break;
         case 'line':
         default:
             /* example price array - only take what we need for the google data
             			array(391 => array(0 => array("marketplace" => "amazon", "upc" => "658010113403", "price" => "30.20", "wholesale" => array(0 => array("start" => "0000-00-00 00:00:00", "stamp" => 1340631116, "price" => 17.56)), "retail" => array(0 => array("start" => "0000-00-00 00:00:00", "stamp" => 1340631116, "price" => 30.85)), "map" => array(0 => array("start" => "0000-00-00 00:00:00", "stamp" => 1340631116, "price" => 21.6)), "dt" => 1340089200, "prod_id" => "391"))) */
             $googleData['type'] = 'line';
             $googleData['date']['start'] = $report_where['date_from'];
             $googleData['date']['end'] = $report_where['date_to'];
             $size = $c = 0;
             foreach ($data as $prodId => $data) {
                 $marketColorArray = array();
                 $upc = getProductsUPC($prodId);
                 $marketColorArray[$c] = array();
                 $Color = Color_handler::get_next();
                 $color_info = array('hex' => $Color->get_hex(), 'string' => $Color->get_string());
                 $this->ci->data->colors[] = $color_info;
                 $googleData['data']['columns'][$prodId] = array('type' => 'number', 'color' => $color_info, 'name' => getProductsTitle($prodId), 'pricing' => array('map' => getPricingHistory($upc, $store_id, 'price_floor', $report_where['date_from'], $report_where['date_to']), 'retail' => getPricingHistory($upc, $store_id, 'retail_price', $report_where['date_from'], $report_where['date_to']), 'wholesale' => getPricingHistory($upc, $store_id, 'wholesale_price', $report_where['date_from'], $report_where['date_to'])));
                 foreach ($data as $market => $pricing) {
                     $size++;
                     $marketColorArray['market'][$market] = isset($marketColors[$market]) ? $marketColors[$market] : stringToColorCode($market);
                     foreach ($pricing as $priceArr) {
                         $prepData[$prodId][$market][] = array('upc' => $priceArr['upc'], 'price' => (double) $priceArr['price'], 'dt' => $priceArr['dt'], 'date' => date('Y-m-d', $priceArr['dt']));
                     }
                 }
                 array_push($googleData['data']['columns'][$prodId]['color'], $marketColorArray['market']);
                 $c++;
             }
             $googleData['data']['size'] = $size;
             $googleData['data']['result'] = $prepData;
             break;
     }
     if ($googleData['data']['size'] == 0) {
         $googleData['type'] = "empty";
     }
     //echo "googs<br>\n";
     //var_dump($googleData);exit;
     return $googleData;
 }
<?php

$style = 'style="border: 1px solid #E7E6E5;height: 20px;padding: 2px 0 0 10px;text-align: left;vertical-align: top;"';
$j = 0;
foreach ($Data as $prodId => $productData) {
    $color = Color_handler::get_next($j++)->get_hex();
    ?>
	<div style="margin-bottom:10px;">
		<span class="squareKey" style="background-color:<?php 
    echo $color . '; ' . $square;
    ?>
"></span>
		<b><?php 
    echo getProductsTitle($prodId);
    ?>
</b><br>
	</div>
	<?php 
    if (!empty($marketplacesExist[$prodId])) {
        ?>
	<table border="0" bordercolor="#CCCCCC" cellpadding="3" cellspacing="0" width="100%" style=" border-collapse: collapse; background:#fff; font-family:Arial, Helvetica, sans-serif; font-size:12px">
		<thead>
			<tr style="background:#E7E7E8; height:30px; color:#000; vertical-align: top">
				<th width="200" align="left" <?php 
        echo $style;
        ?>
>Marketplace</th>
				<th width="160" align="left" <?php 
        echo $style;
        ?>
>Date</th>
示例#6
0
 /**
  * Load the color class and a color manager.
  * Default colors can be specified in config['report_colors'].
  * Once the default colors are depleted they are randomly generated.
  */
 private function _init_color_handler()
 {
     require_once APPPATH . 'libraries/color_handler.php';
     $colors = $this->config->item('report_colors') ? $this->config->item('report_colors') : array();
     Color_handler::init($colors);
 }
示例#7
0
 /**
  *
  * function productViolationGraph
  *
  * @param <array>     $data
  *
  *
  */
 public static function productViolationGraph($gData, $request_info)
 {
     $graph_data = $gData['violations'];
     $series = array();
     $i = 0;
     $cat = createDateRangeArray($request_info['fromDate'], $request_info['toDate']);
     $cat = array_unique($cat);
     $tempArray = array();
     sort($cat);
     foreach ($graph_data as $key => $dArr) {
         $priceD1 = array();
         $priceD2 = array();
         $priceD3 = array();
         $k = 1;
         foreach ($cat as $ckey => $cval) {
             if (!isset($dArr[$cval])) {
                 unset($cat[$ckey]);
             } else {
                 if (!in_array($cat[$ckey], $tempArray)) {
                     $tempArray[] = $cat[$ckey];
                 }
                 $priceD1[] = isset($dArr[$cval]['amazon']) ? $dArr[$cval]['amazon'] : 0;
                 $priceD2[] = isset($dArr[$cval]['google']) ? $dArr[$cval]['google'] : 0;
                 $priceD3[] = isset($dArr[$cval]['Shopping.com']) ? $dArr[$cval]['Shopping.com'] : 0;
             }
         }
         if (in_array('all', $request_info['api_type'])) {
             $series[] = array('name' => getProductsTitle($key, 'Amazon'), 'data' => $priceD1, 'color' => Color_handler::get_next(0)->get_hex(), 'id' => $key);
             $series[] = array('name' => getProductsTitle($key, 'Google'), 'data' => $priceD2, 'color' => Color_handler::get_next(1)->get_hex(), 'id' => $key);
             $series[] = array('name' => getProductsTitle($key, 'Shopping.com'), 'data' => $priceD3, 'color' => Color_handler::get_next(2)->get_hex(), 'id' => $key);
         } else {
             if (in_array('Amazon', $request_info['api_type']) || in_array('amazon', $request_info['api_type'])) {
                 $series[] = array('name' => getProductsTitle($key, 'Amazon'), 'data' => $priceD1, 'color' => Color_handler::get_next(0)->get_hex(), 'id' => $key);
             }
             if (in_array('Google', $request_info['api_type']) || in_array('google', $request_info['api_type'])) {
                 $series[] = array('name' => getProductsTitle($key, 'Google'), 'data' => $priceD2, 'color' => Color_handler::get_next(1)->get_hex(), 'id' => $key);
             }
             if (in_array('Shopping.com', $request_info['api_type']) || in_array('shopping.com', $request_info['api_type']) || in_array('Shopping', $request_info['api_type']) || in_array('shopping', $request_info['api_type'])) {
                 $series[] = array('name' => getProductsTitle($key, 'Shoping.com'), 'data' => $priceD3, 'color' => Color_handler::get_next(2)->get_hex(), 'id' => $key);
             }
         }
         $i++;
     }
     $cat = $tempArray;
     foreach ($cat as $val) {
         $mcat[] = date('n/j', strtotime($val));
     }
     $cat = $mcat;
     if (count($cat) > 10) {
         foreach ($cat as $ind => &$val) {
             $val = ' ';
         }
     }
     $fArray = array('data' => $series, 'y_title' => 'Violations', 'x_title' => 'Date', 'cat' => $cat, 'type' => 'column');
     /* For Google Charts */
     $googledataColorArray = array();
     $googleDataArray = array();
     $googleDataArray[0][] = 'Date';
     $maxValue = 0;
     $prCount = count($graph_data);
     $keys = array_keys($graph_data);
     for ($prcounter = 0; $prcounter < $prCount; $prcounter++) {
         $color = Color_handler::get_next($prcounter)->get_hex();
         if (in_array('all', $request_info['api_type'])) {
             $googleDataArray[0][] = 'Amazon: ' . getProductsTitle($keys[$prcounter]);
             $googleDataArray[0][] = 'Google:' . getProductsTitle($keys[$prcounter]);
             $googleDataArray[0][] = 'Shopping.com:' . getProductsTitle($keys[$prcounter]);
             $googledataColorArray[] = $color;
             $googledataColorArray[] = $color;
             $googledataColorArray[] = $color;
         } else {
             if (in_array('Amazon', $request_info['api_type']) || in_array('amazon', $request_info['api_type'])) {
                 $googleDataArray[0][] = 'Amazon: ' . getProductsTitle($keys[$prcounter]);
                 $googledataColorArray[] = $color;
             }
             if (in_array('Google', $request_info['api_type']) || in_array('google', $request_info['api_type'])) {
                 $googleDataArray[0][] = 'Google:' . getProductsTitle($keys[$prcounter]);
                 $googledataColorArray[] = $color;
             }
             if (in_array('Shopping.com', $request_info['api_type']) || in_array('shopping.com', $request_info['api_type']) || in_array('Shopping', $request_info['api_type']) || in_array('shopping', $request_info['api_type'])) {
                 $googleDataArray[0][] = 'Shopping.com:' . getProductsTitle($keys[$prcounter]);
                 $googledataColorArray[] = $color;
             }
         }
     }
     foreach ($cat as $keyCat => $vCat) {
         $googleDataArray[$keyCat + 1][] = $vCat;
         foreach ($series as $seriesKey => $seriesData) {
             $valueForDisplay = isset($seriesData['data'][$keyCat]) ? $seriesData['data'][$keyCat] : 0;
             $googleDataArray[$keyCat + 1][] = $valueForDisplay;
             if ($valueForDisplay > $maxValue) {
                 $maxValue = $valueForDisplay;
             }
         }
     }
     $fArray['googleData'] = $googleDataArray;
     $fArray['googleDataColors'] = $googledataColorArray;
     $fArray['maxValue'] = $maxValue;
     /* END FOR Google Charts */
     return $fArray;
 }