Awkward time processing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is hideous, can anyone think of a more novel approach?

What I have is an array of values and timestamps:

17 15:31
16 15:32
27 15:33
14 15:34
11 15:35

now for a day I should have 1440 entries but there could be spotty
results, no data from say 11:59 -> 13:00.
What I need is to sum the values for each hour interval.

Because the results could be spotty I figured I would need to use a
lookup table so that I could zero out any empty hours (this is going
to be graphed)

So I have this:

loop through the set above and do

$hour = explode(":", $row[0]);
$comp[] = $hour[0] . "||" . $row[1];

$c00 = $c01 = $c02 = $c03 = $c04 .... = 0;

for ($a = 0; $a < sizeof($comp); ++ $a) {
    list($h,$c) = explode("||", $comp[$a]);

    switch ($h) {
        case 00: $c00 += $c; break;
        case 01: $c01+= $c; break;
        case 02: $c02 += $c; break;
        case 03: $c03 += $c; break;
        case 04: $c04 += $c; break;
        .....
    }
}

Works but wow is it ugly..

Thoughts?

-- 
Paul Halliday
http://www.pintumbler.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux