Jump to content

This function won't work!?


rofl90

Recommended Posts

This function outputs what it shouldn't. It should output That it worked, instead it outputs that it doesn't.

 

Output:

2008-06-07 00:00:00

2008-06-08 00:00:00

Notice: Undefined offset: 3 in /opt/local/share/httpd/charlie/wib_3.3/macdaddy/includes/database_helper.php on line 279

 

Catchable fatal error: Object of class DatabaseHelper could not be converted to string in /opt/local/share/httpd/charlie/wib_3.3/macdaddy/includes/activity.php on line 297

 

What's outputting it:

 

<?php
error_reporting(E_ALL);
define('LOGIN_TYPE', 'PUBLIC');
require "header.php";

if($activity->spikeDay()) {
echo "It was matched, in a real situation we'd of emailed etc already!";
}
else {
echo "Damni, it wasn't sent..and it should of";
}

?>

 

function spikeDay(){
		global $dbh;
		$starttime = $this->getStamp("last_day");
		$endtime = $this->getStamp("day");

		$starttime = strtotime($starttime);
		$endtime = strtotime($endtime);

		$starttime = strtotime("-1 month, -2 days", $starttime);
		$endtime = strtotime("-1 month, -2 days", $endtime);
		$starttime = date("Y-m-d H:i:s", $starttime);
		$endtime = date("Y-m-d H:i:s", $endtime);
		echo $starttime . "<br />" . $endtime;
		$testingSQL = $this->dbh->query("SELECT * FROM ".LOGGING_DB.".`spike` WHERE `intervalTime` = 'day'", 'execute', __LINE__, __FILE__);
		while($spikeDayQL = $this->$dbh->getArray($testingSQL, __LINE__, __FILE__)) {
			if($spikeDayQL['conditionType'] == "PercentageChange") {


				$n = array();
				for ($i=0; $i<7; $i++) {
				    $new[date('m-d', strtotime("+$i days", $starttime))] = 0;         // create empty array for time period
				}

				$sqly = "SELECT DATE_FORMAT(stamp, '%m-%d%') , `count` 
						FROM ".LOGGING_DB.".`activityDay` 
						WHERE `line` = '{$spikeDayQL['monitor']}' 
				    		AND `stamp` BETWEEN '$starttime' AND '$endtime' ";
				$res = mysql_query($sqly) or die (mysql_error());
				while (list($k, $count) = mysql_fetch_row($res)) {
					$new[$k] += $count;
				}
				$theLeast = 99999999999999;
				$theMost  = 0;
				foreach($new as $newa => $newb) {
					$theMost  = max($newb, $theMost);
					$theLeast = min($newb, $theLeast);
				}
				if($theMost == $theLeast) $changePercentage = 0;
				//the formula to calculate what the percentage of the extremes are (changes between)
				$thePercentage = (($theMost - $theLeast) / $theLeast) * 100;

				($thePercentage > 0) ? $isPos = true : $isPos = false;
				 return ($isPos) ? (($thePercentage >= $spikeDayQL['changeBy']) ? true : false) : (($thePercentage >= $spikeDayQL['changeBy']) ? false : true);

				}
				elseif($spikeDayQL['conditionType'] == "WhenLineReaches") {
					 $sqly = "SELECT * 
						FROM ".LOGGING_DB.".`activityDay` 
						WHERE `line` = '{$spikeDayQL['monitor']}' 
				    		AND `stamp` BETWEEN '$starttime' AND '$endtime' AND `count` >= {$spikeDayQL['changeBy']}";
							echo $sqly;
					$countSpikes = mysql_query($sqly);
					return (mysql_num_rows($countSpikes) >= 1) ? true : false;
					echo mysql_num_rows($countSpikes);
					echo "yo!";
				}
				elseif($spikeDayQL['conditionType'] == "WhenLineDropsBelow") {
					 $sqly = "SELECT * 
						FROM ".LOGGING_DB.".`activityDay` 
						WHERE `line` = '{$spikeDayQL['monitor']}' 
				    		AND `stamp` BETWEEN '$starttime' AND '$endtime' AND `count` < {$spikeDayQL['changeBy']}";
					$countSpikes = mysql_query($sqly);
					return (mysql_num_rows($countSpikes) >= 1) ? true : false;
				}

			}

Link to comment
Share on other sites

Yes, I did.

 

the function checks for a spike in activity, eg it checks logs for the last 6 days and gets the min and max, calculates the percentage  of change then checks if the percentage is big enough to trigger an spike alert. this could also be "drops below" and "reaches" which are self-explanatory. the whole array thing in the percentage part just creates rows with "1" in if they dont exist as 0 is an infinite percentage if it is relative.

Link to comment
Share on other sites

Offset error, database handler... gut instinct is telling me it's this line:

 

while (list($k, $count) = mysql_fetch_row($res)) {
$new[$k] += $count;[b] <-- HERE[/b]
}

 

Try using:

 

while ($row = mysql_fetch_row($res)) {
$new[$row['theDate']] += $row['count'];
}

 

And in the SELECT query, change the fields to:

DATE_FORMAT(stamp, '%m-%d%') as theDate, `count` 

Link to comment
Share on other sites

public function query($query, $location='')

{

$query=trim($query);

 

// Grab the first word from a query which is assumed to be the query type (ie select insert delete update etc...)

$explosion=explode(' ', strtolower(trim(str_replace('(','',$query))));

$explosion=array_shift($explosion);

$query_type = (strtolower($explosion) == 'select') ? 'query':'execute';

$pieces = explode(' ', $location);

$this->_query($query, $query_type, $pieces[0], $pieces[3]); {{{{{{MEEEEEEEEEEE}}}}}

return true;

}

 

 

If you were referring to  the other:

 

function spikeDay(){

global $dbh;

$starttime = $this->getStamp("last_day");

$endtime = $this->getStamp("day");

 

$starttime = strtotime($starttime);

$endtime = strtotime($endtime);

 

$starttime = strtotime("-1 month, -2 days", $starttime);

$endtime = strtotime("-1 month, -2 days", $endtime);

$starttime = date("Y-m-d H:i:s", $starttime);

$endtime = date("Y-m-d H:i:s", $endtime);

echo $starttime . "<br />" . $endtime;

$testingSQL = $this->dbh->query("SELECT * FROM ".LOGGING_DB.".`spike` WHERE `intervalTime` = 'day'", 'execute', __LINE__, __FILE__);

while($spikeDayQL = $this->$dbh->getArray($testingSQL, __LINE__, __FILE__)) { {{{MEEE}}}

if($spikeDayQL['conditionType'] == "PercentageChange") {

 

 

$n = array();

for ($i=0; $i<7; $i++) {

    $new[date('m-d', strtotime("+$i days", $starttime))] = 0;        // create empty array for time period

}

 

$sqly = "DATE_FORMAT(stamp, '%m-%d%') as theDate, `count` 

FROM ".LOGGING_DB.".`activityDay`

WHERE `line` = '{$spikeDayQL['monitor']}'

    AND `stamp` BETWEEN '$starttime' AND '$endtime' ";

$res = mysql_query($sqly) or die (mysql_error());

while ($row = mysql_fetch_row($res)) {

$new[$row['theDate']] += $row['count'];

}

$theLeast = 99999999999999;

$theMost  = 0;

foreach($new as $newa => $newb) {

$theMost  = max($newb, $theMost);

$theLeast = min($newb, $theLeast);

}

if($theMost == $theLeast) $changePercentage = 0;

//the formula to calculate what the percentage of the extremes are (changes between)

$thePercentage = (($theMost - $theLeast) / $theLeast) * 100;

 

($thePercentage > 0) ? $isPos = true : $isPos = false;

return ($isPos) ? (($thePercentage >= $spikeDayQL['changeBy']) ? true : false) : (($thePercentage >= $spikeDayQL['changeBy']) ? false : true);

 

}

elseif($spikeDayQL['conditionType'] == "WhenLineReaches") {

$sqly = "SELECT *

FROM ".LOGGING_DB.".`activityDay`

WHERE `line` = '{$spikeDayQL['monitor']}'

    AND `stamp` BETWEEN '$starttime' AND '$endtime' AND `count` >= {$spikeDayQL['changeBy']}";

echo $sqly;

$countSpikes = mysql_query($sqly);

return (mysql_num_rows($countSpikes) >= 1) ? true : false;

echo mysql_num_rows($countSpikes);

echo "yo!";

}

elseif($spikeDayQL['conditionType'] == "WhenLineDropsBelow") {

$sqly = "SELECT *

FROM ".LOGGING_DB.".`activityDay`

WHERE `line` = '{$spikeDayQL['monitor']}'

    AND `stamp` BETWEEN '$starttime' AND '$endtime' AND `count` < {$spikeDayQL['changeBy']}";

$countSpikes = mysql_query($sqly);

return (mysql_num_rows($countSpikes) >= 1) ? true : false;

}

 

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.