Beispiel #1
0
 /**
  * Overview reporting:
  *
  * @param Integer $reportId
  * @return object $data
  **/
 public function report_overview($reportId = false)
 {
     $CI =& get_instance();
     $CI->load->model('crawl_data_m');
     // tell the view this is the pricing overview report
     $this->_data['report_name'] = 'Pricing Overview';
     $this->_data['report_type'] = 'pricingoverview';
     $this->_data['file_name'] = str_replace(' ', '_', 'Pricing Overview ' . date('Y-m-d'));
     if ($reportId) {
         $this->_set_defaults($reportId);
     }
     $this->_data['number_of_merchants'] = getNumberOfMerchants($this->store_id, $this->crawl_range['from'], $this->crawl_range['to']);
     $this->_data['last_tracked_arr'] = $CI->Report->last_tracked_image($this->crawl_range['from']);
     $this->_data['last_tracked_date'] = trackingDateFormat($this->crawl_range['from']);
     // calculate the overview statistics
     $this->_data['products_monitored'] = $CI->Product->getProductsMonitoredCount($this->store_id);
     $this->_data['total_violations'] = $CI->Violator->countViolatedProducts($this->store_id);
     $this->_data['marketplace_products'] = array();
     $this->_data['market_violations'] = array();
     /*
     $markets = array_keys(get_market_lookup(TRUE,TRUE));
     
     foreach ($markets as $market)
     {
     	$crawl_info = ! empty($this->last_crawl[$market]) ? $this->last_crawl[$market] : FALSE;
     	
     	// using global crawl time - change by Christophe on 9/2/2015 
     	$crawl_info = TRUE;
     	
     	if ($crawl_info)
     	{
     		//$from = $crawl_info->start_datetime;
     		//$to = $crawl_info->end_datetime;
     
     	  // change by Christophe on 9/2/2015  
             //$from = $CI->Violator->crawlStart;
             //$to = $CI->Violator->crawlEnd;
             
             if ($CI->config->item('environment') == 'local')
             {
                 $from = '2015-08-01 00:00:00';
                 $to = '2015-08-02 00:00:00';
             }
             else
             {
                 $from = date('Y-m-d H:i:s', strtotime('-24 hours'));
                 $to = date('Y-m-d H:i:s');
             } 
     	            
     		$marketplace_products = $CI->MProducts->getCountByMarketplace($this->store_id, $market, $from, $to);
     						
     		if (!empty($marketplace_products))
     		{
                 $this->_data['marketplace_products'][] = $marketplace_products[0];
                 
                 $market_violations = $CI->Violator->getViolatedMarkets($this->store_id, '', $market, $from, $to);
                 //$market_violations = $CI->Violator->getMarketViolations($this->store_id, '', $market);
                 					
                 $this->_data['market_violations'][$market] = $market_violations[$market];
     		}			
     	}
     }
     */
     /*		
     		//for saving reports - not necessary to provide info for overview
     		$this->_data['report_where'] = array('report_type' => 'pricingoverview');
     		$this->_data['gData'] = array(
     			'type'       => 'pie',
     			'width'      => '220',
     			'height'     => '150',
     			'googleData' => array(
     				array('State','Count'),
     				array('Non Violation', (int)max($this->_data['products_monitored'] - $this->_data['total_violations'], 0)),
     				array('Violation', (int)$this->_data['total_violations'])
     			)
     		);
     
     		// separate marketplaces from retailers
     		$this->_data['marketplaces'] = array();
     		$this->_data['retailers'] = array();
     		$this->_data['violatedMarketplaces'] = array();
     		$this->_data['violatedRetailers'] = array();
     		
     		for ($i = 0, $n = count($this->_data['marketplace_products']); $i < $n; $i++) 
     		{
     			$name = $this->_data['marketplace_products'][$i]['marketplace'];
     			
     			if ($this->_data['marketplace_products'][$i]['is_retailer'] === '1') 
     			{
     				$merchant = $CI->MProducts->getMerchantDetailsByMarketplace($name);
     				
     				if (isset($merchant[0]['id'])) 
     				{
     					$this->_data['marketplace_products'][$i] = array_merge($this->_data['marketplace_products'][$i], $merchant[0]);
     					$this->_data['retailers'][] = $this->_data['marketplace_products'][$i];
     					
     					if ( ! empty($this->_data['market_violations'][$name]))
     					{
     						$this->_data['violatedRetailers'][$name] = TRUE;
     					}
     				}
     			}
     			else 
     			{
     				$this->_data['marketplaces'][] = $this->_data['marketplace_products'][$i];
     				
     				if ( ! empty($this->_data['market_violations'][$name]))
     				{
     					$this->_data['violatedMarketplaces'][$name] = TRUE;
     				}
     			}
     		}
     		
     		usort($this->_data['marketplaces'], function($a, $b) 
     		{
     			return strtolower($a['marketplace']) > strtolower($b['marketplace']);
     		});
     		
     		usort($this->_data['retailers'], function($a, $b) 
     		{
     			return strtolower($a['marketplace']) > strtolower($b['marketplace']);
     		});
     
     		$this->_data['totalMarketplaces'] = count($this->_data['marketplaces']);
     		$this->_data['totalRetailers'] = count($this->_data['retailers']);
     */
     return $this->_data;
 }
Beispiel #2
0
 /**
  * Violations by retailers.
  * 
  * @author Christophe
  */
 public function violations_by_retailers_old($id = false)
 {
     // Tell the view this is the violation overview report
     $this->data->my = 'violationOverview';
     $this->data->report_name = 'Violation Overview';
     $this->data->file_name = str_replace(' ', '_', 'Violations Overview ' . date('m-d-Y'));
     //if($id) $this->data->report_id = base64_decode(urldecode($id));
     if ($id) {
         $this->data->report_id = $id;
     }
     // Get the last crawl data
     $this->data->last_crawl = $this->crawl_data_m->last_crawl();
     $this->crawl_range = $this->crawl_data_m->last_crawl_range();
     $this->data->crawl_range = $this->crawl_range;
     $this->data->number_of_merchants = getNumberOfMerchants($this->store_id, $this->crawl_range['from'], $this->crawl_range['to']);
     $this->data->last_tracked_arr = $this->Report->last_tracked_image($this->crawl_range['from']);
     $this->data->last_tracked_date = trackingDateFormat($this->crawl_range['from']);
     // Get market/merchant/product violations
     $this->data->priceViolators = $this->_countPriceViolations();
     $this->data->totalPriceViolators = count($this->data->priceViolators);
     $this->data->violatedProducts = $this->Violator->getViolatedProducts($this->store_id);
     loadPricePoints($this->data->violatedProducts, strtotime($this->crawl_range['from']));
     // Calculate the overview statistics
     $this->data->products_monitored = $this->Product->getProductsMonitoredCount($this->store_id);
     $this->data->total_violations = count($this->data->violatedProducts);
     $this->data->marketplace_products = array();
     $this->data->market_violations = array();
     $markets = $this->Market->get_marketplaces_by_storeid_using_categories($this->store_id);
     //var_dump($markets); exit();
     foreach ($markets as $market) {
         $market = $market['name'];
         $crawl_info = !empty($this->data->last_crawl[$market]) ? $this->data->last_crawl[$market] : FALSE;
         //var_dump($crawl_info);
         // local env debug
         if ($this->config->item('environment') == 'local') {
             $crawl_info = TRUE;
         }
         if ($crawl_info) {
             // local env debug
             if ($this->config->item('environment') == 'local') {
                 $from = $this->data->crawl_start = $this->Violator->crawlStart;
                 $to = $this->data->crawl_end = $this->Violator->crawlEnd;
             } else {
                 $from = $this->crawl_range['from'];
                 $to = $this->crawl_range['to'];
                 //$from = $crawl_info->start_datetime;
                 //$to = $crawl_info->end_datetime;
             }
             $marketplace_products = $this->merchant_products_m->getCountByMarketplace($this->store_id, $market, $from, $to, 1);
             //print_r($marketplace_products);
             if (!empty($marketplace_products)) {
                 //$market_violations = $this->Violator->getViolatedMarkets($this->store_id, '', $market, $from, $to); // this is retarded
                 //print_r($market_violations);
                 $this->data->marketplace_products[] = $marketplace_products[0];
                 //$this->data->market_violations[$market] = $market_violations[$market];
                 $this->data->market_violations[$market] = $marketplace_products[0]['violated_products'];
             }
         }
     }
     //var_dump($this->data->marketplace_products); exit();
     $this->data->marketplaces = array();
     $this->data->retailers = array();
     $this->data->violatedMarketplaces = array();
     $this->data->violatedRetailers = array();
     for ($i = 0, $n = count($this->data->marketplace_products); $i < $n; $i++) {
         $name = $this->data->marketplace_products[$i]['marketplace'];
         if ($this->data->marketplace_products[$i]['is_retailer'] === '1') {
             $merchant = $this->merchant_products_m->getMerchantDetailsByMarketplace($this->data->marketplace_products[$i]['marketplace']);
             if (isset($merchant[0]['id'])) {
                 $this->data->marketplace_products[$i] = array_merge($this->data->marketplace_products[$i], $merchant[0]);
                 $this->data->retailers[] = $this->data->marketplace_products[$i];
                 if (!empty($this->data->market_violations[$name])) {
                     $this->data->violatedRetailers[$name] = TRUE;
                 }
             }
         } else {
             $this->data->marketplaces[] = $this->data->marketplace_products[$i];
             if (!empty($this->data->market_violations[$name])) {
                 $this->data->violatedMarketplaces[$name] = TRUE;
             }
         }
     }
     //$this->data->crawl_start = $this->Violator->crawlStart;
     //$this->data->crawl_end = $this->Violator->crawlEnd;
 }
Beispiel #3
0
 private function _prep_pricing_overview()
 {
     $this->data->my = 'pricingOverview';
     $this->data->report_chart = 'na';
     // Get the last crawl data
     $this->data->last_crawl = $this->crawl_data_m->last_crawl();
     $this->crawl_range = $this->crawl_data_m->last_crawl_range();
     $this->data->number_of_merchants = getNumberOfMerchants($this->report_info->store_id, $this->crawl_range['from'], $this->crawl_range['to']);
     $this->data->last_tracked_arr = $this->Report->last_tracked_image($this->crawl_range['from']);
     $this->data->last_tracked_date = trackingDateFormat($this->crawl_range['from']);
     // Calculate the overview statistics
     $this->data->products_monitored = $this->Product->getProductsMonitoredCount($this->report_info->store_id);
     $this->data->total_violations = $this->Violator->countViolatedProducts($this->report_info->store_id);
     $this->data->marketplace_products = array();
     $this->data->market_violations = array();
     $markets = array_keys(get_market_lookup(TRUE));
     foreach ($markets as $market) {
         $crawl_info = !empty($this->data->last_crawl[$market]) ? $this->data->last_crawl[$market] : FALSE;
         if ($crawl_info) {
             $from = $crawl_info->start_datetime;
             $to = $crawl_info->end_datetime;
             $marketplace_products = $this->merchant_products_m->getCountByMarketplace($this->report_info->store_id, $market, $from, $to);
             if (!empty($marketplace_products)) {
                 $market_violations = $this->Violator->getViolatedMarkets($this->report_info->store_id, '', $market, $from, $to);
                 $this->data->marketplace_products[] = $marketplace_products[0];
                 $this->data->market_violations[$market] = $market_violations[$market];
             }
         }
     }
     $this->data->request_info = array('fromDate' => strtotime($this->crawl_range['from']), 'toDate' => strtotime($this->crawl_range['to']), 'time_frame' => 1, 'product_ids' => array());
     $this->data->gData = array('type' => 'pie', 'width' => '220', 'height' => '150', 'googleData' => array(array('State', 'Count'), array('Non Violation', (int) max($this->data->products_monitored - $this->data->total_violations, 0)), array('Violation', (int) $this->data->total_violations)));
     // Separate marketplaces from retailers
     $this->data->marketplaces = array();
     $this->data->retailers = array();
     $this->data->violatedMarketplaces = array();
     $this->data->violatedRetailers = array();
     for ($i = 0, $n = count($this->data->marketplace_products); $i < $n; $i++) {
         $name = $this->data->marketplace_products[$i]['marketplace'];
         if ($this->data->marketplace_products[$i]['is_retailer'] === '1') {
             $merchant = $this->merchant_products_m->getMerchantDetailsByMarketplace($name);
             if (isset($merchant[0]['id'])) {
                 $this->data->marketplace_products[$i] = array_merge($this->data->marketplace_products[$i], $merchant[0]);
                 $this->data->retailers[] = $this->data->marketplace_products[$i];
                 if (!empty($this->data->market_violations[$name])) {
                     $this->data->violatedRetailers[$name] = TRUE;
                 }
             }
         } else {
             $this->data->marketplaces[] = $this->data->marketplace_products[$i];
             if (!empty($this->data->market_violations[$name])) {
                 $this->data->violatedMarketplaces[$name] = TRUE;
             }
         }
     }
     $this->data->Data->retailers = $this->data->retailers;
     $this->data->Data->marketplaces = $this->data->marketplaces;
     //print_r($this->data); exit;
 }
Beispiel #4
0
 private function getStoreStatistics($store_id)
 {
     $storeData = array('report_name' => 'StickVision Overview', 'store_id' => $store_id);
     $storeData['number_of_merchants'] = getNumberOfMerchants($store_id);
     $lastTrackedTime = getTrackedTime($store_id);
     $storeData['last_tracked_date'] = trackingDateFormat($lastTrackedTime);
     $storeData['endTrackedTIme'] = getEndTrackTime($lastTrackedTime);
     $storeData['totalProducts'] = count($this->Product->getByStore($store_id));
     $request_info['fromDate'] = strtotime($lastTrackedTime);
     $request_info['toDate'] = strtotime($storeData['endTrackedTIme']);
     //$storeData 											= $this->Store->get_store_info($store_id);
     $storeData['total_violations'] = $this->Violator->countViolatedProducts($store_id);
     $notViolation = $storeData['totalProducts'] - $storeData['total_violations'];
     $notViolation = $notViolation < 0 ? 0 : $notViolation;
     $storeData['notViolation'] = $notViolation;
     $violationPercentage = 0;
     if ($storeData['totalProducts'] > 0) {
         $violationPercentage = number_format($storeData['total_violations'] / $storeData['totalProducts'] * 100, 2);
     }
     $remaing = number_format(100 - (double) $violationPercentage, 2);
     $violationPercentage = (double) $violationPercentage;
     $remaing = (double) $remaing;
     $gData = array($storeData['total_violations'] . ' In violations' => 0, $notViolation . ' Not In Violation' => $remaing);
     //,' Not In Violations'=>0	 //$notViolation
     //echo "$violationPercentage=======$remaing";
     if ($storeData['totalProducts'] > 0) {
         $gData[$storeData['total_violations'] . ' In violations'] = $violationPercentage;
         //In violation
         $gData[$notViolation . ' Not In Violation'] = $remaing;
         // $gData[$this->data->totalProducts.' products'] = $this->data->totalProducts;//$notViolation  $notViolation Not in violation
     }
     $googleDataArray = array();
     $googleDataArray[0] = array('State', 'Count');
     $googleDataArray[] = array('Non Violation', $notViolation);
     $googleDataArray[] = array('Violation', (int) $storeData['total_violations']);
     $gData['googleData'] = $googleDataArray;
     $gData['type'] = 'pie';
     $gData['width'] = '220';
     $gData['height'] = '150';
     $storeData['gData'] = $gData;
     // who's selling my products - marketplace data
     $storeData['marketplace_products'] = $this->merchant_products_m->getCountByMarketplace($store_id);
     // get violations count for each market
     $storeData['market_violations'] = $this->Violator->getViolatedMarkets($store_id);
     // get count for products monitored
     $storeData['products_monitored'] = $this->Product->getProductsMonitoredCount($store_id);
     return $storeData;
 }