From a98f0769bc8e12764e31909b51393f61fa196cb9 Mon Sep 17 00:00:00 2001 From: Walter Hupfeld Date: Tue, 10 Oct 2023 11:04:06 +0200 Subject: [PATCH] refine --- lib/attributes.php | 12 ++++++ statistics/gemeinde_detail.php | 71 +++++++++++++++++---------------- statistics/include.php | 72 +++++++++++++++------------------- 3 files changed, 78 insertions(+), 77 deletions(-) diff --git a/lib/attributes.php b/lib/attributes.php index b660abe..24b4c17 100644 --- a/lib/attributes.php +++ b/lib/attributes.php @@ -83,6 +83,18 @@ $arrTopic = array ( 5 => "Lkw-Verkehr" ); +$arrBeteiligte = array ( + "rad" => "Fahrräder", + "pkw" => "PKW", + "fuss" => "Fussgänger", + "krad" => "Krafträder", + "lkw" => "LKW", + "sonstiges" => "Sonstiges", + "gleich" => "Alleinunfälle und Unfälle mit geicher Fahrzeugart" +); + + + $arrMarkerType = array ( 0=>"infoMarker", 1=>"pedestrianMarker", diff --git a/statistics/gemeinde_detail.php b/statistics/gemeinde_detail.php index 5fcf7b6..e97a3ef 100644 --- a/statistics/gemeinde_detail.php +++ b/statistics/gemeinde_detail.php @@ -19,35 +19,18 @@ $strName=$row['Name']; $numFlaeche=$row['Flaeche']; $numPopulation=$row['Einwohner']; - } + $numRegbez=$row['UREGBEZ']; + $numKreis=$row['UKREIS']; + $numGemeinde=$row['UGEMEINDE']; + } else {exit;} $strLocation=" AND ULAND=$numLand AND UREGBEZ=$numRegbez AND UKREIS=$numKreis AND UGEMEINDE=$numGemeinde "; + $resultUnfallzahlen = get_unfallzahlen($numJahr,$strLocation); + $resultUnfallart = get_unfallart($numJahr,$strLocation); + $resultUnfalltyp = get_unfalltyp($numJahr,$strLocation); + $resultBeteiligte = get_beteiligte($numJahr,$strLocation); + $numGesamt=0; - //Unfallzahlen - - $strWhat=" SUM(UKATEGORIE=1) as Tote, - SUM(UKATEGORIE=2) as Schwerverletzte, - SUM(UKATEGORIE=3) as Leichtverletzte, - COUNT(*) as gesamt"; - $strWhere= " IstRad=1 "; - $strSQL="SELECT $strWhat FROM data - WHERE $strWhere - AND ULAND=:land AND UREGBEZ=:regbez AND UKREIS=:kreis - AND UGEMEINDE=:gemeinde AND UJAHR=:jahr"; - - $result= $db->prepare($strSQL); - $result->bindParam(":land",$numLand); - $result->bindParam(":regbez",$numRegbez); - $result->bindParam(":kreis",$numKreis); - $result->bindParam(":gemeinde",$numGemeinde); - $result->bindParam(":jahr",$numJahr); - $result->execute(); - if ($row = $result->fetch(PDO::FETCH_ASSOC)) { - $numTote=$row['Tote']; - $numSchwerverletzte=$row['Schwerverletzte']; - $numLeichtverletzte=$row['Leichtverletzte']; - $numGesamt=$row['gesamt']; - } ?> @@ -105,9 +88,14 @@
- - - + "; print_r($resultUnfallzahlen);echo ""; + $numGesamt=0; + foreach ($resultUnfallzahlen as $row) { + echo "\n"; + $numGesamt+=$row['anz']; + } + ?>
Unfall mit Getöteten
Unfall mit Schwerverletztem
Unfall mit Leichtverletztem
".$arrCategory[$row['UKATEGORIE']]."".$row['anz']."
Gesamt
@@ -122,14 +110,17 @@
- -

Unfallbeteiligte

+ + // DEBUG: echo "
"; print_r($resultBeteiligte);echo "
"; + foreach ($resultBeteiligte as $key => $numCount) { + echo "\n"; + } + ?> +
".$arrBeteiligte[$key]."".$numCount."
@@ -137,18 +128,26 @@

Unfalltyp

+ \n"; + } ?> +
".$arrUnfalltyp[$row['UTYP1']]."".$row['anz']."

Unfallart

+ + foreach ($resultUnfallart as $row) { + echo "\n"; + } + ?> +
".$arrUnfallart[$row['UART']]."".$row['anz']."
diff --git a/statistics/include.php b/statistics/include.php index 42db9ca..4f629ec 100644 --- a/statistics/include.php +++ b/statistics/include.php @@ -1,65 +1,55 @@ query($strSQL); + $arrResult = $result->fetchAll(PDO::FETCH_ASSOC); + return $arrResult; +} + + +function get_beteiligte($numYear,$strLocation) { global $db; - $numVehicle=1; $strSQL="SELECT sum(IstRad) as rad, sum(IstPKW) as pkw, sum(IstFuss) as fuss, sum(IstKrad) as krad, sum(IstGkfz) as lkw, - sum(IstSonstige) as sonstiges, - count(*) as summe + sum(IstSonstige) as sonstiges FROM data - WHERE istRad=1 AND UJAHR =".$strYear.$strLocation; + WHERE istRad=1 AND UJAHR =".$numYear.$strLocation; $result = $db->query($strSQL); + if ($row = $result->fetch(PDO::FETCH_ASSOC)) { $arrResult = $row; } - $strTable=""; - if ($row = $result->fetch(PDO::FETCH_ASSOC)) { - $strTable.=""; - $strTable.=""; - $strTable.=""; - $strTable.=""; - $strTable.="\n"; - $strTable.="\n"; - } $strSQL="SELECT count(*) as count FROM data - WHERE IstPKW=0 and IstFuss=0 and IstKrad=0 and IstGkfz=0 and IstSonstige=0".$strLocation; - - $result = $db->query($strSQL." AND UJAHR=".$strYear); + WHERE UJAHR=".$numYear." AND IstPKW=0 and IstFuss=0 and IstKrad=0 and IstGkfz=0 + and IstSonstige=0 ".$strLocation; + $result = $db->query($strSQL); if ($row = $result->fetch(PDO::FETCH_ASSOC)) { - $strTable.=""; - } - $strTable.="
Fahrräder".$row['rad']."
PKW".$row['pkw']."
Fussgänger".$row['fuss']."
Krafträder".$row['krad']."
LKW".$row['lkw']."
Sonstiges".$row['sonstiges']."
Alleinunfälle und Unfälle mit geicher Fahrzeugart".$row['count']."
"; - return $strTable; + $arrResult["gleich"]=$row['count']; + } + return $arrResult; } -function get_unfalltyp($strWhere,$strYear,$strLocation){ +function get_unfalltyp($numYear,$strLocation){ global $db; - global $arrUnfalltyp; - $numVehicle=1; - $strSQL="SELECT UTYP1, count(UTYP1) as anz FROM data WHERE istRad=1 AND UJAHR=".$strYear.$strLocation." GROUP BY UTYP1"; - $strTable=""; + $strSQL="SELECT UTYP1, count(UTYP1) as anz FROM data WHERE istRad=1 AND UJAHR=".$numYear.$strLocation." GROUP BY UTYP1"; $result = $db->query($strSQL); - while ($row = $result->fetch(PDO::FETCH_ASSOC)) { - $strTable.="\n"; - } - $strTable.="
".$arrUnfalltyp[$row['UTYP1']]."".$row['anz']."
"; - return $strTable; + $arrResult = $result->fetchAll(PDO::FETCH_ASSOC); + return $arrResult; } -function get_unfallart($strWhere,$strYear,$strLocation){ +function get_unfallart($numYear,$strLocation){ global $db; - global $arrUnfallart; - $numVehicle=1; - $strSQL="SELECT UART, count(UART) as anz FROM data WHERE istRad=1 AND UJAHR=".$strYear.$strLocation." GROUP BY UART"; - $strTable=""; + $strSQL="SELECT UART, count(UART) as anz FROM data WHERE istRad=1 AND UJAHR=".$numYear.$strLocation." GROUP BY UART"; $result = $db->query($strSQL); - while ($row = $result->fetch(PDO::FETCH_ASSOC)) { - $strTable.="\n"; - } - $strTable.="
".$arrUnfallart[$row['UART']]."".$row['anz']."
"; - return $strTable; + $arrResult = $result->fetchAll(PDO::FETCH_ASSOC); + return $arrResult; }