Skip to main content

Burnout

Just couldn't get much done today. Wasn't very focused, lots of distractions. Holiday season is starting to kick in as the family returns home.

I fixed some bugs with Buzz Scanner. The basic problem is Google Charts only allows a maximum URL length, so you cannot pass infinite amounts of data in to graph.

The solution: a method to add all adjacent units of data together:
3,6,3,8,9,6,3,4,5,0,6 becomes 9,11,15,7,5,6 (if it's odd, just leaves last one)

It expects data already in the URL format for Google Charts API in the chd field.

Sample expected input:
t:0|18,10,15,7|0|14,13,14,14
Sample expected output:
t:0|28,22|0|27,28

The PHP code:

function mergeData($dataString){
    $chdTempArray = explode("|",$dataString);
    for($c=0;$c<count($chdTempArray);$c++){
        if($c%2==1){
            $merge = explode(",",$chdTempArray[$c]);
            $c2=0;
            $newMerge = "";
            while($c2<count($merge)){
                if($c2+1!=count($merge)){
                    $newMerge .= ($merge[$c2]+$merge[$c2+1]).",";
                    $c2=$c2+2;
                }
                else{//if it's odd number of units
                    $newMerge .= $merge[$c2].",";
                    $c2=$c2+2;
                }
            }
            $newMerge=substr($newMerge,0,-1);//remove last comma
            $chdTempArray[$c]=$newMerge;

        }
    }
    $dataString = implode("|",$chdTempArray);
    
    return $dataString;
}