. .

JpGraph: Beispiel: LinePlot: Statistik des entstandenen Traffics

 

<?PHP
    function sBrowser($stext) {
        if (strpos($stext, "Googlebot") > 0)
            return (2);
        if (strpos($stext, "oogle-Sitemaps") > 0)
            return (2);
        if (strpos($stext, "Yahoo!") > 0)
            return (2);
        if (strpos($stext, "snbot") > 0)
            return (2);

        if (strpos($stext, "Safari") > 0)
            return (1);
        if (strpos($stext, "Firefox") > 0)
            return (1);
        if (strpos($stext, "MSIE") > 0)
            return (1);
        if (strpos($stext, "pera/") > 0)
            return (1);
        if (strpos($stext, "BonEcho") > 0)
            return (1);
        if (strpos($stext, "ozilla") > 0)
            return (1);

        return (NULL);
    }

    $Monat = "Nov/2008";
    $lMonat = "Oct/2008";

    $monate = array("Jan", "Feb", "Mar", "Apr", "May", "Jun",
        "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    $WochenTage = array("So", "Mo", "Di", "Mi", "Do", "Fr", "Sa");

    $handle = fopen("access_log", "r");
    while (!feof($handle)) {
        $zeile = fgets($handle, 4096);

        $gBrowser = explode("\"", $zeile);
        if (($a = strpos($gBrowser[0], $Monat))
            || ($v = strpos($gBrowser[0], $lMonat))) {
            if ($t = sBrowser($gBrowser[count($gBrowser) - 2])) {
                $p = explode(" ", $zeile);

                $datum = ((substr($p[3], 8, 4))."-"
                    .(array_search(substr($p[3], 4, 3), $monate) + 1)
                    ."-{$p[3][1]}{$p[3][2]}");
                $ts = strtotime($datum);

                $p = explode(" ", $gBrowser[2]);

                if ($a <> FALSE)
                    $summe[$ts][$t] += ((int) ($p[2]) / 1024 / 1024);
                elseif ($v <> FALSE)
                    $summeVormonat[$ts] += ((int) ($p[2]) / 1024 / 1024);
    }    }    }
    fclose ($handle);

    foreach ($summe as $ts => $va) {
        $gesamt[] = (array_sum($va));
        $summe_normal[] = ($va[1]);
        $summe_bots[] = ($va[2]);
        $legende[] = $WochenTage[date("w", $ts)]."\n".date("d", $ts).".";
    }
    foreach ($summeVormonat as $va)
        $summeVm[] = $va;
    if (($diff = (count($summeVm) - count($legende))) > 0)
        for ($d = 1; $d <= $diff; $d++)
            $legende[] = " \n".((count($legende)) + $d).".";

    $ds_v = array_sum($summeVm) / count($summeVm);
    $ds_a = array_sum($gesamt) / count($gesamt);

    $graph = new Graph(600, 400, "auto");
    $graph->img->SetMargin(40, 20, 40, 135);
    $graph->SetScale("textlin");
    $graph->SetMarginColor("#EBEBEB");
    $graph->title->Set("Entstandener Traffic im Monat November");
    $graph->title->SetFont(FF_VERDANA, FS_BOLD, 9);
    $graph->title->SetMargin(8);
    $graph->title->SetColor("black");

    $bplot1 = new BarPlot($summe_normal);
    $bplot1->SetFillColor("orange@0.4");

    $bplot2 = new BarPlot($summe_bots);
    $bplot2->SetFillColor("blue@0.4");

    $gbplot1 = new AccBarPlot(array($bplot1, $bplot2));

    $lineplot1 = new LinePlot($summeVm);
    $lineplot1->SetWeight(1);
    $lineplot1->SetFillColor("red@0.9");
    $lineplot1->SetColor("red@0.6");
 
    $lineplot2 = new LinePlot($gesamt);
    $lineplot2->SetWeight(0);
    $lineplot2->value->Show();
    $lineplot2->value->SetFont(FF_FONT0, FS_BOLD);
    $lineplot2->value->SetColor("black");
    $lineplot2->value->SetFormat("%d");

    $line1 = new PlotLine(HORIZONTAL, $ds_v, "#0D6D00@0.5", 1);
    $line2 = new PlotLine(HORIZONTAL, $ds_a, "#FFC800@0.5", 1);

    $graph->xaxis->SetFont(FF_VERDANA, FS_BOLD, 7);
    $graph->yaxis->SetFont(FF_VERDANA, FS_BOLD, 7);

    $graph->yaxis->SetLabelMargin(12);
    $graph->xaxis->SetLabelMargin(12);
    $graph->yaxis->HideZeroLabel(); 

    $graph->xaxis->SetTickLabels($legende);
    $graph->xaxis->HideTicks(true, true); 
    $graph->yaxis->scale->SetGrace(7);

    $graph->xgrid->Show(false, false);
    $graph->ygrid->Show(true, false);
    $graph->ygrid->SetColor("lightblue");
    $graph->ygrid->SetFill(true, "#EFEFEF@0.6", "#BBCCFF@0.6");
    $graph->ygrid->SetLineStyle("dashed");
    $graph->ygrid->SetWeight(1); 

    $lineplot1->SetLegend("Traffic in MB des Vormonats\n");
    $bplot1->SetLegend("Traffic in MB durch normale Clients\n");
    $bplot2->SetLegend("Traffic in MB durch Such-Engines\n");
    $line1->SetLegend("durchschn. Traffic in MB Vormonat\n");
    $line2->SetLegend("durchschn. Traffic in MB\n");

    $graph->legend->Pos(0.5, 0.97, "center", "bottom");
    $graph->legend->SetLayout(LEGEND_VERT);
    $graph->legend->SetColor("darkblue");
    $graph->legend->SetFont(FF_VERDANA, FS_BOLD, 7);
    $graph->legend->SetFillColor("white");
    $graph->legend->SetShadow(FALSE);

    $graph->Add($line1);
    $graph->Add($line2);
    $graph->Add($lineplot1);
    $graph->Add($lineplot2);
    $graph->Add($gbplot1);

    $graph->Stroke("include/tmp/jpgraph/JpGraph_TrafficMonat.png");

?>

Hinterlasse eine Antwort

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *

Du kannst folgende HTML-Tags benutzen: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>