JpGraph: Beispiel: GanttBar: Hits durch Suchmaschinen
geschrieben von Julian Hofmann am 23. Dezember 2008 - zuletzt aktualisiert am 5. August 2013
<?PHP function sBrowser($stext) { if (strpos($stext, "Googlebot") > 0) return (0); if (strpos($stext, "oogle-Sitemaps") > 0) return (0); if (strpos($stext, "Yahoo!") > 0) return (1); if (strpos($stext, "snbot") > 0) return (2); return(FALSE); } $suche = "2008-11-17"; $suchmaschinen = array( array("Google", "#00B00C"), array("Yahoo", "#0095FF"), array("MSN", "#E15600") ); list($jahr, $monat, $tag) = explode("-", $suche); $kw = date("W", strtotime($suche)); for ($z = 0; $z < count($suchmaschinen); $z++) $suMa[$z][] = 0; $monate = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); $handle = fopen("access_log2", "r"); while (!feof($handle)) { $zeile = fgets($handle, 4096); $gBrowser = explode("\"", $zeile); if (strstr($gBrowser[1], "?")) { $p = explode(" ", $zeile); if ($jahr == substr($p[3], 8, 4)) { $datum = ((substr($p[3], 8, 4))."-" .(array_search(substr($p[3], 4, 3), $monate) + 1) ."-{$p[3][1]}{$p[3][2]} ".(substr($p[3], 13, 8))); $ts = strtotime($datum); if ($kw == (date("W", $ts))) { if (($t = sBrowser($gBrowser[count($gBrowser) - 2])) >= 0) if (($suMa[$t][(count($suMa[$t])) - 1]) <> $ts) $suMa[$t][] = $ts; } } } } fclose ($handle); $ts_beginn = strtotime($suche); $ts_ende = strtotime($suche) + (60 * 60 * 24 * 7); for ($s = $ts_beginn; $s <= $ts_ende; $s = $s + (15 * 60)) { $e = $s + (15 * 60); foreach ($suMa as $index => $content) foreach ($content as $id => $timestamp) if (($timestamp >= $s) && ($timestamp < $e)) { if (($suMaShort[$index][(count($suMaShort[$index]) - 1)]) <> $s) $suMaShort[$index][] = $s; unset($suMa[$index][$id]); } } foreach ($suMaShort as $i => $ts) foreach ($ts as $t) { $daten[] = array($i, (($k[$i] == NULL) ? array($suchmaschinen[$i][0], (string) (number_format( (count($suMaShort[$i]) * (15 * 60) / 3600), 0, ",", ".")." h"), (string) count($suMaShort[$i])) : ""), date("Y-m-d H:i:s", $t), date("Y-m-d H:i:s", ($t + (15 * 60)))); $k[$i] = 1; } $graph = new GanttGraph(); $graph->SetMarginColor("#EBEBEB"); $graph->SetColor("white"); $graph->scale->hour->SetBackgroundColor("lightyellow:1.5"); $graph->scale->hour->SetFont(FF_VERDANA, FS_BOLD, 6); $graph->scale->day->SetBackgroundColor("lightyellow:1.5"); $graph->scale->day->SetFont(FF_VERDANA, FS_BOLD, 7); $graph->title->Set("Hits von Suchmaschinen im 15-Minuten Takt (KW {$jahr}/{$kw})"); $graph->title->SetFont(FF_VERDANA,FS_BOLD, 9); $graph->title->SetMargin(8); $graph->title->SetColor("black"); $graph->ShowHeaders(GANTT_HDAY | GANTT_HHOUR); $graph->scale->week->SetStyle(WEEKSTYLE_FIRSTDAY); $graph->scale->week->SetFont(FF_VERDANA); $graph->scale->hour->SetIntervall(4); $graph->scale->hour->SetStyle(HOURSTYLE_HM24); $graph->scale->day->SetStyle(DAYSTYLE_SHORTDAYDATE3); $graph->hgrid->Show(); $graph->hgrid->SetRowFillColor("darkblue@0.9"); $graph->scale->actinfo->SetColTitles( array("Such-\nmaschine", "\nDauer", "H\344ufig-\nkeit"), array(70, 50, 50)); $graph->scale->actinfo->SetBackgroundColor("green:0.5@0.5"); $graph->scale->actinfo->SetFont(FF_VERDANA, FS_BOLD, 6); $graph->scale->actinfo->vgrid->SetStyle("solid"); $graph->scale->actinfo->vgrid->SetColor("gray"); for ($i = 0; $i < count($daten); $i++) { $bar = new GanttBar($daten[$i][0], $daten[$i][1], $daten[$i][2], $daten[$i][3], "", 10); $bar->SetPattern(GANTT_SOLID, $suchmaschinen[($daten[$i][0])][1]); $bar->SetFillColor($suchmaschinen[($daten[$i][0])][1]); $bar->SetColor($suchmaschinen[($daten[$i][0])][1]); $graph->Add($bar); } $graph->Stroke("include/tmp/jpgraph/JpGraph_GanttSuchmaschinen.png"); ?>