Really struggling to understand how the php code builds these tables.
My php & html knowledge is near zilch. (Other programming like PIC32 Basic Ok).
Trying to see where they yearly figures are generated so I can change some averages to totals.
Rainfall in particular, Id' like monthly totals not daily averages and probably do the same thing with EVT as it's sort of relevant to rain.
I sort of get that the yearly summaries are generated with the 879-1028 line mark in betel_readDayfile.php, but that's about as close as I can get.
Code: Select all
// START year avg table
$tablelayout .= " <table id='avgTable' style = 'display:".($show_year_averages ? "table" : "none").";'>\n";
$tablelayout .= "<tr>\n";
$tablelayout .= '<th style="width: 80px;">'.($dataSet == 'winddir' ? $translit[$dayfileLang]['dom'] : $translit[$dayfileLang]['avg']).'</th>';
$tablelayout .= '<th>'.$translit[$dayfileLang]['mn'][0].'</th><th>'.$translit[$dayfileLang]['mn'][1].'</th><th>'.$translit[$dayfileLang]['mn'][2].'</th><th>'.$translit[$dayfileLang]['mn'][3].'</th><th>'.$translit[$dayfileLang]['mn'][4].'</th><th>'.$translit[$dayfileLang]['mn'][5].'</th><th>'.$translit[$dayfileLang]['mn'][6].'</th><th>'.$translit[$dayfileLang]['mn'][7].'</th><th>'.$translit[$dayfileLang]['mn'][8].'</th><th>'.$translit[$dayfileLang]['mn'][9].'</th><th>'.$translit[$dayfileLang]['mn'][10].'</th><th>'.$translit[$dayfileLang]['mn'][11].'</th>';
$tablelayout .= "</tr>\n";
$bert = count($type_year) -1;
$alltime = array(1 => array(), 2 => array(), 3 => array(), 4 => array(), 5 => array(), 6 => array(), 7 => array(), 8 => array(), 9 => array(), 10 => array(), 11 => array(), 12 => array());
$bg_alltime = array(1 => array(), 2 => array(), 3 => array(), 4 => array(), 5 => array(), 6 => array(), 7 => array(), 8 => array(), 9 => array(), 10 => array(), 11 => array(), 12 => array());
if($dataSet == 'winddir') {
for($zz = 1; $zz <= 12; $zz++){
$alltime[$zz] = array( 0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0);
}
}
$shortMon = array();
for ($d = $bert; $d >= 0; $d--) { // latest year first
$shortMon[$d] = array();
$tablelayout .= '<tr>';
$tablelayout .= '<th>'.$type_year[$d].'</th>';
for ($m = 1; $m <= 12; $m++) {
$shortMon[$d][$m] = false;
$windd = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0); // twitch fix
$tablelayout .= '<td';
$thisValue = '';
$part2 = '';
if(isset($type_data[$type_year[$d]]) && array_key_exists($m, $type_data[$type_year[$d]])) {
$turd = array();
$bg_turd = array(); // hmm ... it's not going to be that simple !!!
foreach($type_data[$type_year[$d]][$m] as $k => $v){
if($v <> ''){ // only take account of non null entries
if($dataSet == 'winddir'){
if($v[0] >0 && $v[1] >0) $windd[round($v[0] / 45)]++ ; // increment wind dir count
$v = '';
}
if(is_array($v)){ // we are dealing with something that needs calculating
$thisValue = $v;
formatOP(); // only want to use 'native' result
$thisValue = ''; // reset
$part2 = ''; // reset
$turd[] = $native;
} else { // 'normal' single piece of data
$turd[] = $v; // a 'normal' single data entry
if($dataSet == "HoursSun" && $run_sun) {
$bg_y = $type_year[$d];
$bg_when = mktime(0,0,0, $m, $k, $bg_y);
$bg_turd[] = maxsunhours($bg_when);
}
}
}
}
if($turd){
if($dataSet == 'winddir'){
$workMax = max($windd); // find highest occurrence
$found = false;
foreach($windd as $k => $v){
$alltime[$m][$k] += $v;
if($found !== true && $v == $workMax){ // see if number of occurrences = max
$thisValue = ($k == 0 ? 44 : $k * 45); // sort of put back into a degree range
$found = true; // only looking for first (clockwise) event
}
}
} else { // everything that really needs averages
$thisValue = array_sum($turd) / count($turd);
$thatvalue = "";
if($dataSet == 'HoursSun' && $run_sun){
$bg_value = round(array_sum($bg_turd) / count($bg_turd), 1);
$sunAvailable = $bg_value;
}
}
}
if($thisValue || $thisValue == 0){
if($dataSet != 'winddir') $alltime[$m][] = $thisValue;
if($dataSet == 'HoursSun' && $run_sun) $bg_alltime[$m][] = $bg_value; // ### NEW bargraph stuff
formatOP();
$short = (count($turd) < cal_days_in_month(CAL_GREGORIAN, $m, $type_year[$d]) ? "* " : "");
if(count($turd) < cal_days_in_month(CAL_GREGORIAN, $m, $type_year[$d])) $shortMon[$d][$m] = true ;
$tablelayout .= " class=\"datacell2\"".$part2.">".($dataSet != 'HoursSun' ? $short : '').$thisValue."</td>";
}else {
$tablelayout .= ' class="nondate"> </td>';
}
}else{
$tablelayout .= ' class="nondate"> </td>';
}
} // END month walk
$tablelayout .= "</tr>\n";
} // END year walk
// now do overall month averages
$tablelayout .= '<tr>';
$tablelayout .= '<th class="topborder">'.($dataSet == 'winddir' ? $translit[$dayfileLang]['dom'] : $translit[$dayfileLang]['avg']).'</th>';
for ($m = 1; $m <= 12; $m++) {
$tablelayout .= '<td';
$thisValue = '';
$part2 = '';
if(isset($alltime[$m])) {
if($dataSet == 'winddir'){
$workMax = max($alltime[$m]);
foreach($alltime[$m] as $k => $v){
if($v == $workMax){ // see if number of occurences = max
$thisValue = ($k == 0 ? 44 : $k * 45); // sort of put back into a degree range
break; // only looking for first (clockwise) event
}
}
} else {
if(is_array($alltime[$m])) {
if(count($alltime[$m]) != 0) $thisValue = array_sum($alltime[$m]) / count($alltime[$m]);
}
}
if($thisValue){
if($dataSet == 'HoursSun' && $run_sun){
if(is_array($bg_alltime[$m])) {
if(count($bg_alltime[$m]) != 0) $bg_value = round(array_sum($bg_alltime[$m]) / count($bg_alltime[$m]), 1);
$sunAvailable = $bg_value;
}
}
formatOP();
$short = "";
for ($d = $bert; $d >= 0; $d--) { // latest year first (not important)
if($shortMon[$d][$m]){
$short = "* ";
break;
}
}
$tablelayout .= " class=\"datacell2 topborder\"".$part2.">".($dataSet != 'HoursSun' ? $short : '').$thisValue."</td>";
}else {
$tablelayout .= ' class="nondate topborder"> </td>';
}
}else{
$tablelayout .= ' class="nondate topborder"> </td>';
}
} // END month walk
$tablelayout .= "</tr>\n";
// END overall year averages
$tablelayout .= " </table>\n </div>\n";
// END year averages table
And how I'd make it apply to only the Rainfall & EVT pages.
Thanks
Phil