phpmedo

From: Peter (BOUGHTONP)21 Feb 2016 22:56
To: ANT_THOMAS 2 of 23

Seems like a convoluted way to do whatever this is, but yeah, here's a simple way to generate that - all untested and may contain stupid bugs because I've got a headache, but here you go...

First build the array of weeks:

    $marking = [ strtotime('sunday') * 1000 ];
    for ( var $i = 1 ; $i <= 52 ; $i++ )
        $marking[i] = strtotime((-1*$i).' week sunday') * 1000;

Then re-map each one into the desired format (use a better function name):

    function convert_to_my_format( $CurMarking )
    {
        return "{ xaxis: { from: ".($CurMarking+10000000).", to: ".($CurMarking-96400000)." }, color: \"#F3F3ED\" }";
    }

    $markings = array_map( "convert_to_my_format" , $marking );

Finally convert that array into a comma-delimited string:

    $markings = implode( "," , $markings );
From: ANT_THOMAS21 Feb 2016 23:40
To: Peter (BOUGHTONP) 3 of 23
Thanks BP. I'll give that a go tomorrow.
From: ANT_THOMAS22 Feb 2016 11:09
To: Peter (BOUGHTONP) 4 of 23
Right, we're close!

If I include the var in the 2nd line I get a 500 server error.

With it removed it outputs the 52nd and final part of the array but not the full array, I've checked by changing the 52 to another number.
 
Code: 
   for ( $i = 1 ; $i <= 52 ; $i++ )
        $marking[i] = strtotime((-1*$i).' week sunday') * 1000;

   function convert_to_markings( $CurMarking )
    {
        return "{ xaxis: { from: ".($CurMarking).", to: ".($CurMarking-96400000)." }, color: \"#F3F3ED\" }";
    }

    $markings = array_map( "convert_to_markings" , $marking );

    $markings = implode( "," , $markings );
Output from that is
 
Code: 
{ xaxis: { from: 1425168000000, to: 1425071600000 }, color: "#F3F3ED" }

Please help Peter!
From: Chris (CHRISSS)22 Feb 2016 19:30
To: ANT_THOMAS 5 of 23
There's a missing $ in the for loop code. $marking[i] should be $marking[$i]

Dunno if that will fix it though.
From: ANT_THOMAS22 Feb 2016 19:34
To: Chris (CHRISSS) 6 of 23
I have literally just spotted that, working now :D
From: Chris (CHRISSS)22 Feb 2016 20:07
To: ANT_THOMAS 7 of 23
Good timing :D Glad it's working.
From: ANT_THOMAS22 Feb 2016 22:05
To: Chris (CHRISSS) 8 of 23
It nicely highlights the weekends on my electricity usage chart.
From: Peter (BOUGHTONP)22 Feb 2016 22:16
To: Chris (CHRISSS) 9 of 23
Bah! Damn PHP and its stupid dollars.
From: Chris (CHRISSS)22 Feb 2016 23:58
To: ANT_THOMAS 10 of 23
Is that from the camera you have pointing at your electric meter?
From: Chris (CHRISSS)23 Feb 2016 00:00
To: Peter (BOUGHTONP) 11 of 23
Who puts dollar symbols in front of variable names? :(
From: CHYRON (DSMITHHFX)23 Feb 2016 01:07
To: Chris (CHRISSS) 12 of 23
jquery. Well, in front of selectors.
EDITED: 23 Feb 2016 01:07 by DSMITHHFX
From: ANT_THOMAS23 Feb 2016 09:40
To: Chris (CHRISSS) 13 of 23
That's the one.

I was originally just putting it in a spreadsheet and trawling through a load of readings every week or so (never got OCR working).

But now I've got it all in a MySQL database where I've got a little form that checks the last row in the database, then checks the date and displays the image for the next reading I need to enter, once entered it calculates the usage that day and the cost that day and adds them to the database. Data stored is - date, total meter reading, daily usage, cost. When it's up to date it tells me there's nothing more to add.

 
 
EDITED: 23 Feb 2016 09:54 by ANT_THOMAS
Attachments:
From: ANT_THOMAS23 Feb 2016 09:51
To: ANT_THOMAS 14 of 23
The last 12 Weeks

Attachments:
From: Peter (BOUGHTONP)23 Feb 2016 22:40
To: Chris (CHRISSS) 15 of 23
Idiots who blindly copy bits of shell script into a toy language without really knowing what they're doing, and then come up with lame justifications of why they shouldn't fix the nonsense when everyone uses the damned thing. Probably.
From: Peter (BOUGHTONP)23 Feb 2016 22:42
To: CHYRON (DSMITHHFX) 16 of 23
A perfect example!

...of an idiot who doesn't know what things are. :S

Hmm, bit harsh? Maybe just a dunce. (hug)

jQuery neither prefixes variable names not puts dollars in front of selectors. It aliases itself as $, and as a function it can have arguments, the first of which can be a selector, though it also can be other things, and also has various methods attached to the function's object itself.

Which is not to say it isn't a bit dumb, but it is at least more convenient than typing case sensitive jQuery, though even that isn't as $durbrained $as $bloody $_PHP.

From: Peter (BOUGHTONP)23 Feb 2016 22:50
To: ANT_THOMAS 17 of 23
It seems cost is just half of usage - or does that change?
From: ANT_THOMAS24 Feb 2016 09:36
To: Peter (BOUGHTONP) 18 of 23
Cost is calculated based on a standing daily rate + (units used * unit rate)
From: koswix24 Feb 2016 09:45
To: Peter (BOUGHTONP) 19 of 23
I've been wondering about that lately. Linux is, in theory, a much more secure OS than windows. But how many Linux users consist of people like me that spend days at a time running commands and scripts they find down the back of the internet trying to make bits of software work without any real clue of wtf they are actually doing? 
From: ANT_THOMAS24 Feb 2016 10:09
To: koswix 20 of 23
Depending on your level of knowledge, running a command is less of an issue because you can see what you're inputting (and hopefully have some idea what it does, but often not), running scripts though is a different issue since I doubt most people check every line.

Could have a format c: in there somewhere.
From: CHYRON (DSMITHHFX)24 Feb 2016 10:48
To: Peter (BOUGHTONP) 21 of 23
It does stuff. With dollar signs. I get dollars from it. Your fragile ego gets a wee boost. Win, win, win.