php-general Digest 3 Aug 2012 03:48:36 -0000 Issue 7907

Topics (messages 318614 through 318620):

Awkward time processing
        318614 by: Paul Halliday
        318615 by: Ashley Sheridan
        318616 by: Paul Halliday
        318617 by: Robert Williams
        318618 by: Paul Halliday

php safe mode no more?
        318619 by: D. Dante Lorenso

PHP 5.4.6RC1 Released for Testing!
        318620 by: Stas Malyshev

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
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/

--- End Message ---
--- Begin Message ---

Paul Halliday <paul.halli...@gmail.com> wrote:

>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

Where is the data coming from? I would presume an SQL database? If so, you 
could use a group by with a substring to get the counts you need. MySQL happily 
allows this to be done on date and datetime fields.

Thanks,
Ash
http://ashleysheridan.co.uk

--- End Message ---
--- Begin Message ---
On Thu, Aug 2, 2012 at 12:27 PM, Ashley Sheridan
<a...@ashleysheridan.co.uk> wrote:
>
>
> Paul Halliday <paul.halli...@gmail.com> wrote:
>
>>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
>
> Where is the data coming from? I would presume an SQL database? If so, you 
> could use a group by with a
substring to get the counts you need. MySQL happily allows this to be
done on date and datetime fields.

I am actually doing that already on the data coming in:

SELECT COUNT(signature) AS count,
SUBSTRING(CONVERT_TZ(timestamp,'+00:00','-03:00'),12,5) AS time..

as I am doing a minute breakdown as well. The query isn't cheap; about
half a second, so I was hoping to do my hourly consolidation in code
as I already have the data, instead of performing a second query.

--- End Message ---
--- Begin Message ---
On 8/2/12 05:51, "Paul Halliday" <paul.halli...@gmail.com> wrote:


>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.

I may be misinterpreting what you're asking, but what about something like
this:

$times = array(
        17 => '15:31',
        16 => '15:32',
        27 => '15:33',
        14 => '15:34',
        11 => '15:35',
        27 => '16:33',
        14 => '17:34',
        11 => '11:35',
        11 => '11:36',
);

$sums = array_fill(0, 24, 0);

foreach ($times as $value => $time) {
        $sums[substr($time, 0, 2)] += (integer)$value;
}

print_r($sums);

This produces:


/usr/bin/php /Volumes/Dev/Sites/playground/play4.php
Array
(
    [0] => 0
    [1] => 0
    [2] => 0
    [3] => 0
    [4] => 0
    [5] => 0
    [6] => 0
    [7] => 0
    [8] => 0
    [9] => 0
    [10] => 0
    [11] => 11
    [12] => 0
    [13] => 0
    [14] => 0
    [15] => 33
    [16] => 27
    [17] => 14
    [18] => 0
    [19] => 0
    [20] => 0
    [21] => 0
    [22] => 0
[23] => 0
)

Process finished with exit code 0



--
Robert E. Williams, Jr.
Associate Vice President of Software Development
Newtek Businesss Services, Inc. -- The Small Business Authority
https://www.newtekreferrals.com/rewjr
http://www.thesba.com/







Notice: This communication, including attachments, may contain information that 
is confidential. It constitutes non-public information intended to be conveyed 
only to the designated recipient(s). If the reader or recipient of this 
communication is not the intended recipient, an employee or agent of the 
intended recipient who is responsible for delivering it to the intended 
recipient, or if you believe that you have received this communication in 
error, please notify the sender immediately by return e-mail and promptly 
delete this e-mail, including attachments without reading or saving them in any 
manner. The unauthorized use, dissemination, distribution, or reproduction of 
this e-mail, including attachments, is prohibited and may be unlawful. If you 
have received this email in error, please notify us immediately by e-mail or 
telephone and delete the e-mail and the attachments (if any).

--- End Message ---
--- Begin Message ---
:)

Perfect! Thank you.

On Thu, Aug 2, 2012 at 1:25 PM, Robert Williams <rewilli...@thesba.com> wrote:
> On 8/2/12 05:51, "Paul Halliday" <paul.halli...@gmail.com> wrote:
>
>
>>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.
>
> I may be misinterpreting what you're asking, but what about something like
> this:
>
> $times = array(
>         17 => '15:31',
>         16 => '15:32',
>         27 => '15:33',
>         14 => '15:34',
>         11 => '15:35',
>         27 => '16:33',
>         14 => '17:34',
>         11 => '11:35',
>         11 => '11:36',
> );
>
> $sums = array_fill(0, 24, 0);
>
> foreach ($times as $value => $time) {
>         $sums[substr($time, 0, 2)] += (integer)$value;
> }
>
> print_r($sums);
>
> This produces:
>
>
> /usr/bin/php /Volumes/Dev/Sites/playground/play4.php
> Array
> (
>     [0] => 0
>     [1] => 0
>     [2] => 0
>     [3] => 0
>     [4] => 0
>     [5] => 0
>     [6] => 0
>     [7] => 0
>     [8] => 0
>     [9] => 0
>     [10] => 0
>     [11] => 11
>     [12] => 0
>     [13] => 0
>     [14] => 0
>     [15] => 33
>     [16] => 27
>     [17] => 14
>     [18] => 0
>     [19] => 0
>     [20] => 0
>     [21] => 0
>     [22] => 0
> [23] => 0
> )
>
> Process finished with exit code 0
>
>
>
> --
> Robert E. Williams, Jr.
> Associate Vice President of Software Development
> Newtek Businesss Services, Inc. -- The Small Business Authority
> https://www.newtekreferrals.com/rewjr
> http://www.thesba.com/
>
>
>
>
>
>
>
> Notice: This communication, including attachments, may contain information 
> that is confidential. It constitutes non-public information intended to be 
> conveyed only to the designated recipient(s). If the reader or recipient of 
> this communication is not the intended recipient, an employee or agent of the 
> intended recipient who is responsible for delivering it to the intended 
> recipient, or if you believe that you have received this communication in 
> error, please notify the sender immediately by return e-mail and promptly 
> delete this e-mail, including attachments without reading or saving them in 
> any manner. The unauthorized use, dissemination, distribution, or 
> reproduction of this e-mail, including attachments, is prohibited and may be 
> unlawful. If you have received this email in error, please notify us 
> immediately by e-mail or telephone and delete the e-mail and the attachments 
> (if any).
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--- End Message ---
--- Begin Message --- The school I work with wants to set up PHP and MySQL hosting for about 10,000 students.

I see that in 5.4, PHP safe-mode is being removed. How is it supposed to be done if not safe-mode?

Are all the hosting providers using suExec and running PHP as CGI or FastCGI? If I'm trying to do this the right way, what way is that? Anyone got link or pointers on what I need to learn?

-- Dante


--- End Message ---
--- Begin Message ---
Hi!

I've released PHP 5.4.6RC1 which can be found here:
    http://downloads.php.net/stas/
Windows binaries as always are at:
    http://windows.php.net/qa/

This is a regular bugfix release, the full list of issues fixed can be
found in the NEWS files. Please test and report if anything is broken.

If no critical issues is found in this RC, the final version will be
released in two weeks.

Regards,
    Stas Malyshev and David Soria Parra

--- End Message ---

Reply via email to