Ich möchte eine Anzahl von Monaten in Daten auftreten, lesen Sie aus einer CSV, wo Daten im Format TT/MM/JJJJ eingegeben werden. $all
ist ein Array dieser Daten. Ich zeichne den Fortschritt der Studenten in einem akademischen Jahr auf, das im September beginnt und im Juli endet. Ein Datum repräsentiert eine Schülerleistung. Ich brauche die Zählung zu sein kumulativ - ein Datum im September auch in allen folgenden Monaten gezählt werden sollte, usw. ich das dann mit einem Google-Diagramms wie diese erstellen:Keeping eine kumulierte Anzahl von Monaten
Ich habe den folgenden Arbeits Code das fühlt sich sehr umständlich an. Ich habe das Gefühl, dass ich etwas vermisse, das einen viel prägnanteren Weg zur Lösung meines Problems ermöglichen würde.
Gibt es gemeinsame Lösungen für die Arbeit mit Daten auf diese Weise? Kannst du eine breitere Lektüre vorschlagen?
foreach ($all as $y) {
$month = substr($y,3, 2);
switch ($month) {
case '09':
$sep++;$oct++;$nov++;$dec++;$jan++;$feb++;$mar++;$apr++;$may++;$jun++;$jul++;
break;
case '10':
$oct++;$nov++;$dec++;$jan++;$feb++;$mar++;$apr++;$may++;$jun++;$jul++;
break;
case '11':
$nov++;$dec++;$jan++;$feb++;$mar++;$apr++;$may++;$jun++;$jul++;
break;
case '12':
$dec++;$jan++;$feb++;$mar++;$apr++;$may++;$jun++;$jul++;
break;
case '01':
$jan++;$feb++;$mar++;$apr++;$may++;$jun++;$jul++;
break;
case '02':
$feb++;$mar++;$apr++;$may++;$jun++;$jul++;
break;
case '03':
$mar++;$apr++;$may++;$jun++;$jul++;
break;
case '04':
$apr++;$may++;$jun++;$jul++;
break;
case '05':
$may++;$jun++;$jul++;
break;
case '06':
$jun++;$jul++;
break;
case '07':
$jul++;
break;
default:
$jul++;
}
}
//All months initially set to 1 to help with scaling issues.
//Work out percentage of all achievements completed
$NOW = date("n");
switch($NOW) {
case '9':
if ($sep != 1) {
$sep = round(($sep-1)/$total*100);
}
$oct="null";$nov="null";$dec="null";$jan="null";$feb="null";$mar="null";$apr="null";$may="null";$jun="null";$jul="null";
break;
case '10':
if ($oct != 1) {
$sep = round(($sep-1)/$total*100);
$oct = round(($oct-1)/$total*100);
}
$nov="null";$dec="null";$jan="null";$feb="null";$mar="null";$apr="null";$may="null";$jun="null";$jul="null";
break;
case '11':
if ($nov != 1) {
$sep = round(($sep-1)/$total*100);
$oct = round(($oct-1)/$total*100);
$nov = round(($nov-1)/$total*100);
}
$dec="null";$jan="null";$feb="null";$mar="null";$apr="null";$may="null";$jun="null";$jul="null";
break;
case '12':
if ($dec != 1) {
$sep = round(($sep-1)/$total*100);
$oct = round(($oct-1)/$total*100);
$nov = round(($nov-1)/$total*100);
$dec = round(($dec-1)/$total*100);
}
$jan="null";$feb="null";$mar="null";$apr="null";$may="null";$jun="null";$jul="null";
break;
case '1':
if ($jan != 1) {
$sep = round(($sep-1)/$total*100);
$oct = round(($oct-1)/$total*100);
$nov = round(($nov-1)/$total*100);
$dec = round(($dec-1)/$total*100);
$jan = round(($jan-1)/$total*100);
}
$feb="null";$mar="null";$apr="null";$may="null";$jun="null";$jul="null";
break;
case '2':
if ($feb != 1) {
$sep = round(($sep-1)/$total*100);
$oct = round(($oct-1)/$total*100);
$nov = round(($nov-1)/$total*100);
$dec = round(($dec-1)/$total*100);
$jan = round(($jan-1)/$total*100);
$feb = round(($feb-1)/$total*100);
}
$mar="null";$apr="null";$may="null";$jun="null";$jul="null";
break;
case '3':
if ($mar != 1) {
$sep = round(($sep-1)/$total*100);
$oct = round(($oct-1)/$total*100);
$nov = round(($nov-1)/$total*100);
$dec = round(($dec-1)/$total*100);
$jan = round(($jan-1)/$total*100);
$feb = round(($feb-1)/$total*100);
$mar = round(($mar-1)/$total*100);
}
$apr="null";$may="null";$jun="null";$jul="null";
break;
case '4':
if ($apr != 1) {
$sep = round(($sep-1)/$total*100);
$oct = round(($oct-1)/$total*100);
$nov = round(($nov-1)/$total*100);
$dec = round(($dec-1)/$total*100);
$jan = round(($jan-1)/$total*100);
$feb = round(($feb-1)/$total*100);
$mar = round(($mar-1)/$total*100);
$apr = round(($apr-1)/$total*100);
}
$may="null";$jun="null";$jul="null";
break;
case '5':
if ($may != 1) {
$sep = round(($sep-1)/$total*100);
$oct = round(($oct-1)/$total*100);
$nov = round(($nov-1)/$total*100);
$dec = round(($dec-1)/$total*100);
$jan = round(($jan-1)/$total*100);
$feb = round(($feb-1)/$total*100);
$mar = round(($mar-1)/$total*100);
$apr = round(($apr-1)/$total*100);
$may = round(($may-1)/$total*100);
}
$jun="null";$jul="null";
break;
case '6':
if ($jun != 1) {
$sep = round(($sep-1)/$total*100);
$oct = round(($oct-1)/$total*100);
$nov = round(($nov-1)/$total*100);
$dec = round(($dec-1)/$total*100);
$jan = round(($jan-1)/$total*100);
$feb = round(($feb-1)/$total*100);
$mar = round(($mar-1)/$total*100);
$apr = round(($apr-1)/$total*100);
$may = round(($may-1)/$total*100);
$jun = round(($jun-1)/$total*100);
}
$jul="null";
break;
case '7':
if ($jul != 1) {
$sep = round(($sep-1)/$total*100);
$oct = round(($oct-1)/$total*100);
$nov = round(($nov-1)/$total*100);
$dec = round(($dec-1)/$total*100);
$jan = round(($jan-1)/$total*100);
$feb = round(($feb-1)/$total*100);
$mar = round(($mar-1)/$total*100);
$apr = round(($apr-1)/$total*100);
$may = round(($may-1)/$total*100);
$jun = round(($jun-1)/$total*100);
$jul = round(($jul-1)/$total*100);
}
break;
case '8':
if ($jul != 1) {
$sep = round(($sep-1)/$total*100);
$oct = round(($oct-1)/$total*100);
$nov = round(($nov-1)/$total*100);
$dec = round(($dec-1)/$total*100);
$jan = round(($jan-1)/$total*100);
$feb = round(($feb-1)/$total*100);
$mar = round(($mar-1)/$total*100);
$apr = round(($apr-1)/$total*100);
$may = round(($may-1)/$total*100);
$jun = round(($jun-1)/$total*100);
$jul = round(($jul-1)/$total*100);
}
break;
default:
echo " ";
}