From: Paul Halliday on
I have been starting at this problem blankly for a couple hours now.
Hopefully someone can help.

I have a query that returns an event count grouped by hour:

timestamp:
Array ( [0] => 2010-09-08 03 [1] => 2010-09-08 04 [2] => 2010-09-08 05
[3] => 2010-09-08 06 [4] => 2010-09-08 07 [5] => 2010-09-08 08 [6] =>
2010-09-08 09 [7] => 2010-09-08 10 [8] => 2010-09-08 11 [9] =>
2010-09-08 12 [10] => 2010-09-08 13 [11] => 2010-09-08 14 [12] =>
2010-09-08 15 [13] => 2010-09-08 16 ) 24

event count:
Array ( [0] => 1731 [1] => 885 [2] => 544 [3] => 668 [4] => 748 [5] =>
754 [6] => 933 [7] => 2422 [8] => 6713 [9] => 31925 [10] => 18827 [11]
=> 16743 [12] => 16875 [13] => 11775 )

Lets say that coming into this, I knew that the query spanned 36 hours
and started at 01:00. How can I manipulate the resulting array to
contain the missing time stamps and a value of 0.

The effect I am shooting for looks like this:

http://www.pintumbler.org/example.png

So 0 - > 23 will be static and I just walk through the array and
populate those. If we hit 23, start a new row and continue. The matrix
will always be the same though.

I think I know what needs to happen, I just cant come up with the logic.

Any push in the right direction would be appreciated.
--
Paul Halliday
Ideation | Individualization | Learner | Achiever | Analytical
http://www.pintumbler.org
From: chris h on
Paul,

How are you matching the records in the "event count" array to the ones in
the timestamp array?

Is it safe to say that:
"$timestamp[ $i ]" corresponds to "$eventCount[ $i ]"?

If so, you could just iterate through the timestamp array; on each iteration
create a record in a new array that holds the timestamp and whatever the
corresponding eventCount record is. Something like:

--------------------------------
$newTimeArray = array();

foreach ($timestamps as $i => $singleTimestamp) {

$newTimeArray[ $i ] = array(
'timestamp' => $singleTimestamp,
'count' => $eventCounts[ $i ]
);

}
--------------------------------

Now if "$timestamp[ $i ]" does NOT correspond to "$eventCount[ $i ]" then I
think we'll need you to explain how that relationship works, unless I missed
something :)


Chris.


On Wed, Sep 8, 2010 at 1:02 PM, Paul Halliday <paul.halliday(a)gmail.com>wrote:

> I have been starting at this problem blankly for a couple hours now.
> Hopefully someone can help.
>
> I have a query that returns an event count grouped by hour:
>
> timestamp:
> Array ( [0] => 2010-09-08 03 [1] => 2010-09-08 04 [2] => 2010-09-08 05
> [3] => 2010-09-08 06 [4] => 2010-09-08 07 [5] => 2010-09-08 08 [6] =>
> 2010-09-08 09 [7] => 2010-09-08 10 [8] => 2010-09-08 11 [9] =>
> 2010-09-08 12 [10] => 2010-09-08 13 [11] => 2010-09-08 14 [12] =>
> 2010-09-08 15 [13] => 2010-09-08 16 ) 24
>
> event count:
> Array ( [0] => 1731 [1] => 885 [2] => 544 [3] => 668 [4] => 748 [5] =>
> 754 [6] => 933 [7] => 2422 [8] => 6713 [9] => 31925 [10] => 18827 [11]
> => 16743 [12] => 16875 [13] => 11775 )
>
> Lets say that coming into this, I knew that the query spanned 36 hours
> and started at 01:00. How can I manipulate the resulting array to
> contain the missing time stamps and a value of 0.
>
> The effect I am shooting for looks like this:
>
> http://www.pintumbler.org/example.png
>
> So 0 - > 23 will be static and I just walk through the array and
> populate those. If we hit 23, start a new row and continue. The matrix
> will always be the same though.
>
> I think I know what needs to happen, I just cant come up with the logic.
>
> Any push in the right direction would be appreciated.
> --
> Paul Halliday
> Ideation | Individualization | Learner | Achiever | Analytical
> http://www.pintumbler.org
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>