Skip to content

Commit

Permalink
Enhanced data capturing
Browse files Browse the repository at this point in the history
Enhanced MySQL query for checking for what dates need data added to the
database.
  • Loading branch information
PromInc committed Aug 28, 2015
1 parent 7a77759 commit 74f8a47
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
2 changes: 0 additions & 2 deletions data-capture.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
</div>

<?php
//$domains = array("www.luggagepros.com/");

$domains = $mysql->getSettings("sites_google", "1");

foreach( $domains as $domain => $values ) {
Expand Down
27 changes: 17 additions & 10 deletions inc/code/dataCapture.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,43 @@ class DataCapture
public function checkNeededDataGoogleSearchAnalytics($website) {
$core = new Core(); //Load core
$mysql = new MySQL(); //Load MySQL

$now = $core->now();

/* Identify date range */
$dateStartOffset = self::GOOGLE_SEARCH_ANALYTICS_MAX_DATE_OFFSET+self::GOOGLE_SEARCH_ANALYTICS_MAX_DAYS;
$dateStart = date('Y-m-d', strtotime('-'.$dateStartOffset.' days', $now));
$dateEnd = date('Y-m-d', strtotime('-'.self::GOOGLE_SEARCH_ANALYTICS_MAX_DATE_OFFSET.' days', $now));


/* Query database for dates with data */
$query = "SELECT COUNT( DISTINCT date ) AS record, date FROM ".MySQL::DB_TABLE_SEARCH_ANALYTICS." WHERE domain LIKE '".$website."' AND date >= '".$dateStart."' AND date <= '".$dateEnd."' GROUP BY date";
$result = $mysql->query( $query );

/* Create array from database response */
$datesWithData = array();
foreach( $result as $row ) {
array_push( $datesWithData, $row['date'] );
}

/* Get date rante */
$dates = $core->getDateRangeArray( $dateStart, $dateEnd );

/* Loop through dates, removing those with data */
foreach( $dates as $index => $date ) {
/* $numRows = $mysql->numRows( 'search_queries_table', array('date'=>$date,'domain'=>$website,'search_engine'=>'google') ); */
$numRows = $mysql->numRows( MySQL::DB_TABLE_SEARCH_ANALYTICS, array('date'=>$date,'domain'=>$website,'search_engine'=>'google') );
if( $numRows > 0 ) {
if( in_array( $date, $datesWithData ) ) {
unset( $dates[ $index ] );
}
}



/* Reindex dates array */
$dates = array_values($dates);

$returnArray = array(
'dateStart' => $dateStart,
'dateEnd' => $dateEnd,
'datesWithNoData' => $dates
);


return $returnArray;
}

Expand Down
13 changes: 13 additions & 0 deletions inc/code/mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ public function query( $query ) {
}


/**
* Query Database
*
* @param $query String SQL formated query
*
* @returns Array Assosiative array of response
*/
public function queryArray( $query ) {
$result = self::query( $query );
return $result->fetch_array();
}


/**
* Get Number of Rows
*
Expand Down

0 comments on commit 74f8a47

Please sign in to comment.