View Source - Hint, actually 'View the page source!'

======= SCRIPT CONTENTS BELOW HERE - VIEW THE PAGE SOURCE! ========

 (isset($SITE['uomTemp']) ? substr($SITE['uomTemp'], -1) : 'C'),
    'rain' => (isset($SITE['uomRain']) ? substr($SITE['uomRain'], 1) : 'mm'),
    'wind' => (isset($SITE['uomWind']) ? substr($SITE['uomWind'], 1) : 'mph'),
    'baro' => (isset($SITE['uomBaro']) ? substr($SITE['uomBaro'], 1) : 'hPa')
);

// language ........

$default_lang = 'en'; // 'look-up' array to use if not passed or defined elsewhere

// get language files
if (file_exists('datasummary/datasummaryLanguagesSQL.php')) {
    (@include_once 'datasummary/datasummaryLanguagesSQL.php') or die('FATAL ERROR - Language File FAIL !!');
} else {
    (@include_once 'datasummaryLanguagesSQL.php') or die('FATAL ERROR - Language File FAIL !!');
}

// look for a 'posted' lang - change post name if required
if (isset($_REQUEST['lang']) && $_REQUEST['lang'] != '') { // change from $default_lang
    if (array_key_exists($_REQUEST['lang'], $translit)) {
        $dayfileLang = $_REQUEST['lang'];
    }
}

if (!isset($dayfileLang)) {
    $dayfileLang = $default_lang;
}

/*
$label_items FORMAT
array(*var name of data*,
    menu button text,
    table heading,
    true OR false = show menu button - DO NOT COMMENT OUT LINE !!,
    field# in data file (available from http://wiki.sandaysoft.com/a/Dayfile.txt),
    'type' OR null = for units picker
    'a' AND/OR 's' AND/OR 'h' AND/OR 'l' OR null - display (a)verage and / or (s)um, (h)i, (l)o for month(s)
    )
*var name of data* - MUST have any parsing / display code added !!
NOTE: Menu buttons will be displayed in the same order as the array ;-)
      so adjust order to suit your options.

If you add any new items don't forget the trailing ',' on all but the last array line !
*/

$label_items = array(
   //Data Set           Short Name                                         Long Name                                    Menu? Row field    Units   ashl
    'maxtemp'       => array($translit[$dayfileLang]['maxtemp'][0],       $translit[$dayfileLang]['maxtemp'][1],       true, 1,           'temp', 'ahl'),
    'mintemp'       => array($translit[$dayfileLang]['mintemp'][0],       $translit[$dayfileLang]['mintemp'][1],       true, 1,           'temp', 'ahl'),
    'tdiff'         => array($translit[$dayfileLang]['tdiff'][0],         $translit[$dayfileLang]['tdiff'][1],         true, array(1, 2), 'temp', 'ahl'), // NB: Example of more than one data value grab
    'avgtemp'       => array($translit[$dayfileLang]['avgtemp'][0],       $translit[$dayfileLang]['avgtemp'][1],       true, 1,           'temp', 'ahl'),
    'MaxFeelsLike'  => array($translit[$dayfileLang]['MaxFeelsLike'][0],  $translit[$dayfileLang]['MaxFeelsLike'][1],  true, 1,           'temp', 'ahl'),
    'MinFeelsLike'  => array($translit[$dayfileLang]['MinFeelsLike'][0],  $translit[$dayfileLang]['MinFeelsLike'][1],  true, 1,           'temp', 'ahl'),
    'highDewPoint'  => array($translit[$dayfileLang]['highDewPoint'][0],  $translit[$dayfileLang]['highDewPoint'][1],  true, 1,           'temp', 'ahl'),
    'lowDewPoint'   => array($translit[$dayfileLang]['lowDewPoint'][0],   $translit[$dayfileLang]['lowDewPoint'][1],   true, 1,           'temp', 'ahl'),
    'highHum'       => array($translit[$dayfileLang]['highHum'][0],       $translit[$dayfileLang]['highHum'][1],       true, 1,           null,   'ahl'),
    'lowHum'        => array($translit[$dayfileLang]['lowHum'][0],        $translit[$dayfileLang]['lowHum'][1],        true, 1,           null,   'ahl'),
    'totRainFall'   => array($translit[$dayfileLang]['totRainFall'][0],   $translit[$dayfileLang]['totRainFall'][1],   true, 1,           'rain', 'sah'),
    'totRainDays'   => array($translit[$dayfileLang]['totRainDays'][0],   $translit[$dayfileLang]['totRainDays'][1],   true, 1,           'rain', 's'),
    'highAvgWspeed' => array($translit[$dayfileLang]['highAvgWspeed'][0], $translit[$dayfileLang]['highAvgWspeed'][1], true, 1,           'wind', 'ah'),
    'highWindGust'  => array($translit[$dayfileLang]['highWindGust'][0],  $translit[$dayfileLang]['highWindGust'][1],  true, 1,           'wind', 'ah'),
    'totWindRun'    => array($translit[$dayfileLang]['totWindRun'][0],    $translit[$dayfileLang]['totWindRun'][1],    true, 1,           null,   'sah'),
    'domWindDir'    => array($translit[$dayfileLang]['domWindDir'][0],    $translit[$dayfileLang]['domWindDir'][1],    true, 1,           null,   'a'), // NB: also looks for a windspeed to to be valid
    'maxPress'      => array($translit[$dayfileLang]['maxPress'][0],      $translit[$dayfileLang]['maxPress'][1],      true, 1,           'baro', 'ahl'),
    'minPress'      => array($translit[$dayfileLang]['minPress'][0],      $translit[$dayfileLang]['minPress'][1],      true, 1,           'baro', 'ahl'),
    'HoursSun'      => array($translit[$dayfileLang]['HoursSun'][0],      $translit[$dayfileLang]['HoursSun'][1],      true, 1,           null,   'sah'),
    'HighSolarRad'  => array($translit[$dayfileLang]['HighSolarRad'][0],  $translit[$dayfileLang]['HighSolarRad'][1],  true, 1,           null,   'ah'),
    'totInsol'      => array($translit[$dayfileLang]['totInsol'][0],      $translit[$dayfileLang]['totInsol'][1],      true, 1,           null,   'sah'),
    //'HighUV'        => array($translit[$dayfileLang]['HighUV'][0],        $translit[$dayfileLang]['HighUV'][1],        true, 1,           null,   'ah'),
    'totalEvap'     => array($translit[$dayfileLang]['totalEvap'][0],     $translit[$dayfileLang]['totalEvap'][1],     true, 1,           'rain', 'sah'),
    'HeatDegDays'   => array($translit[$dayfileLang]['HeatDegDays'][0],   $translit[$dayfileLang]['HeatDegDays'][1],   true, 1,           'temp', 'sah'),
    'CoolDegDays'   => array($translit[$dayfileLang]['CoolDegDays'][0],   $translit[$dayfileLang]['CoolDegDays'][1],   true, 1,           'temp', 'sah'),
    'AirQuality'    => array($translit[$dayfileLang]['AirQuality'][0],    $translit[$dayfileLang]['AirQuality'][1],    true, 1,           null,   'a')
);


// Cumulus provides 0 or 0.0 for missing or invalid data - this can make a nonsense of minimum and average values.
// The best thing to do is to edit your dayfile.txt and nullify (,,) any false data.
// However; depending upon your location, some datasets can reasonably be expected to be > 0 (remember these are daily values)
// These COULD include:
// ... 'highAvgWspeed', 'highWindGust', 'totWindRun', 'HoursSun', 'HighSolarRad', 'HighUV', totalEvap

$SANITIZE = false; // true OR false - attempt to ignore zero in the following datasets:
//$zero_as_null = array('highAvgWspeed', 'highWindGust', 'totWindRun', 'HoursSun', 'HighSolarRad', 'HighUV'); // datasets to 'fix' - EDIT TO SUIT
$zero_as_null = array(); // datasets to 'fix' - EDIT TO SUIT

$type_data = array();  //Global to hold the raw data for the selected data type
$type_year = array();

// Solar bar stuff
$bg_lat = 53.326; // If $maxsunhours 0 or 1 set your Latitude in decimal, -negative values for Southern hemisphere
$bg_lon = -2.243; // If $maxsunhours 0 or 1 set your Longitude in decimal, -negative values for West
$bg_time_zone = "";  // If $maxsunhours 0 or 1 set your timezone ONLY if your data is a different TZ to your server - see: http://php.net/manual/en/timezones.php
$maxsunhours = 24; // Set sunshine bar graph option as above
$sunAvailable = 0; // No of hours of available sunshine today


// parse / display code for defined datasets
function formatOP($monthly = false) {
    global $thisValue, $part2, $dataSet, $decimals, $native, $sunAvailable;
    if ($thisValue != '' || $thisValue == 0) { // ***************** added  || $thisValue == 0, don't like it !!!!!!!
        switch ($dataSet) {
        case 'highWindGust':
            $col = gustColour(DoWind($thisValue, 'mph')); // format to colour range uom
            $part2 .= ' style="background-color:#' . $col[0] . '; color:#' . $col[1] . '"';
            $native = $thisValue;
            $thisValue = DoWind($thisValue, null); // format to DISPLAY uom
            break;

        case 'highAvgWspeed':
            $col = windColour(DoWind($thisValue, 'mph')); // format to colour range uom
            $part2 .= ' style="background-color:#' . $col[0] . '; color:#' . $col[1] . '"';
            $native = $thisValue;
            $thisValue = DoWind($thisValue, null); // format to DISPLAY uom
            break;

        case 'maxtemp':
        case 'mintemp':
        case 'avgtemp':
        case 'MaxFeelsLike':
        case 'MinFeelsLike':
        case 'highDewPoint':
        case 'lowDewPoint':
            $col = tempColour(DoTemp($thisValue, 'C')); // format to colour range uom
            $part2 .= ' style="background-color:#' . $col[0] . '; color:#' . $col[1] . '"';
            $native = $thisValue;
            $thisValue = DoTemp($thisValue, null); // format to DISPLAY uom
            break;

        case 'HeatDegDays':
            $native = $thisValue; // used to populate array for seasonal average
            $scaler = $monthly ? 40 : 1;
            if ($thisValue == 0) {
                $col = array('FFF', '9A9A9A');
            } else {
                // need to reverse the scale for heating days - bigger number means it is colder!
                $col = tempColour(DoTempDiff(12 - $thisValue / $scaler, 'C')); // format to colour range uom
            }
            $thisValue = DoTempDiff($thisValue, null); // format to DISPLAY uom
            $part2 .= ' style="background-color:#' . $col[0] . '; color:#' . $col[1] . '"';
            break;

        case 'CoolDegDays':
            $native = $thisValue; // used to populate array for seasonal average
            $scaler = $monthly ? 8 : 1;
            if ($thisValue == 0) {
                $col = array('FFF', '9A9A9A');
            } else {
                $col = tempColour(DoTempDiff($thisValue, 'C') / $scaler * 2 + 10); // format to colour range uom
            }
            $thisValue = DoTempDiff($thisValue, null); // format to DISPLAY uom
            $part2 .= ' style="background-color:#' . $col[0] . '; color:#' . $col[1] . '"';
            break;

        /*
           An example of a calculated value using more than one data field.
           $thisValue *should* be an ARRAY of the data requested - the array will only exist if ALL data is present.
           YOU need to remember in what order you asked for the data !
           In the example below $thisValue[0] is max temp and $thisValue[1] is min temp.
           HOWEVER: when doing averages, hi, lo, etc. OR heat / cooling days it will be a single value !!
           NOTE: Although this is temp 'type', changing eg. one degree C > F is NOT the same as 1 deg C > F !!!
           so we need another bit of code that does NOT give 32 +/- offset
        */
        case 'tdiff':
            if (is_array($thisValue)) { // we need to do some calculations with the multiple data
                $native = $thisValue[0] - $thisValue[1]; // used to populate arrays for hi / lo / average
                $col = tempDiffColour(DoTempDiff($native, 'C')); // format to colour range uom
                $thisValue = DoTempDiff($native, null); // format to DISPLAY uom
            } else { // is a single value from hi / lo / avg
                $native = $thisValue; // used to populate array for seasonal average
                $col = tempDiffColour(DoTempDiff($thisValue, 'C')); // format to colour range uom
                $thisValue = DoTempDiff($thisValue, null); // format to DISPLAY uom
            }
            $part2 .= ' style="background-color:#' . $col[0] . '; color:#' . $col[1] . '"';
            break;
        // END calculated example

        case 'totalEvap':
        case 'totRainFall':
            $val = $dataSet == 'totalEvap' ? $thisValue * 4 : $thisValue; // frig: evap is much less than rainfall
            $val = DoRain($val, 'mm');
            $val = $monthly ? $val / 15 : $val;  // frig: divide value by 15 for monthly totals
            $col = rainColour($val); // format to colour range uom;
            $part2 .= ' style="background-color:#' . $col[0] . '; color:#' . $col[1] . '"';
            $native = $thisValue;
            $thisValue = DoRain($thisValue, null); // format to DISPLAY uom
            break;

        case 'totWindRun':
            $baseTot = $monthly ? 22 : 1;  // frig: divide by 22 for monthly totals
            $col = runColour(DoWind($thisValue / $baseTot, 'mph')); // format to colour range uom;
            $part2 .= ' style="background-color:#' . $col[0] . '; color:#' . $col[1] . '"';
            $native = $thisValue;
            $thisValue = DoWind($thisValue, null); // format to DISPLAY uom
            break;

        case 'domWindDir':
            if (intval($thisValue) > 0) {
                $thisValue = getHeading(intval($thisValue));
            }
            break;

        case 'maxPress':
        case 'minPress':
            $col = baroColour(DoBaro($thisValue, 'hPa')); // format to colour range uom;
            $part2 .= ' style="background-color:#' . $col[0] . '; color:#' . $col[1] . '"';
            $native = $thisValue;
            $thisValue = DoBaro($thisValue, null); // format to DISPLAY uom
            break;

        case 'highHum':
        case 'lowHum':
            $col = humColour($thisValue);
            $part2 .= ' style="background-color:#' . $col[0] . '; color:#' . $col[1] . '"';
            $native = $thisValue;
            // no Unit conversions to do - so 'format' directly
            $thisValue = number_format((float)$thisValue, 0, '.', '');
            break;

        case 'HighUV':
            $col = uvColour($thisValue);
            $part2 .= ' style="background-color:#' . $col[0] . '; color:#' . $col[1] . '"';
            $native = $thisValue;
            // no Unit conversions to do - so 'format' directly
            $thisValue = number_format((float)$thisValue, 1, '.', '');
            break;

        case 'HoursSun': // based on code by Mark Crossley
            $part2 .= '>
' . '' . number_format($thisValue, 1, '.', '') . 'View Source - Hint, actually 'View the page source!'\n"; echo "
\n";
        echo "======= SCRIPT CONTENTS BELOW HERE - VIEW THE PAGE SOURCE! ========\n\n";
        readfile($filenameReal);
        echo '';
        exit;
    }
    echo '

Tough ! - I changed the password !!!

'; } // $disp DEcode look-up array // (t)emp, (r)ain, (w)ind, (b)aro $plank['t'] = array('0' => 'C', '1' => 'F'); $plank['r'] = array('0' => 'mm', '1' => 'in'); $plank['w'] = array('0' => 'mph', '1' => 'm/s', '2' => 'km/h', '3' => 'kts'); $plank['b'] = array('0' => 'hPa', '1' => 'mb', '2' => 'inHg'); // print_r($plank); // which 'table' do we want ? if (!isset($_REQUEST['pane'])) { $pane = 0; // 0 default - show 'daily', 1 - show 'seasonal' } else { $pane = $_REQUEST['pane']; } /* TABLE DISPLAY Units Of Measure */ $displayUOM = array(); // twitch fix if (isset($_COOKIE['theseUOM'])) { $displayUOM = $_COOKIE['theseUOM']; // is an array from users browser if allowed // print_r($displayUOM); } if (!isset($_REQUEST['disp'])) { // 1st time in - populate display units array from cookies if available else defaults $disp = ''; if(!isset($displayUOM['temp'])) $displayUOM['temp'] = $uom['temp']; // no history - use default if(!isset($displayUOM['rain'])) $displayUOM['rain'] = $uom['rain']; // no history - use default if(!isset($displayUOM['wind'])) $displayUOM['wind'] = $uom['wind']; // no history - use default if(!isset($displayUOM['baro'])) $displayUOM['baro'] = $uom['baro']; // no history - use default } else { $disp = $_REQUEST['disp']; } if (isset($_REQUEST['change'])) { // we already have display UOM set one way or another but user wants to change them $flag1 = substr($_REQUEST['change'], 0, 1); $flag2 = substr($_REQUEST['change'], 1, 1); if ($flag1 == 't') { $displayUOM['temp'] = $plank['t'][$flag2]; } elseif ($flag1 == 'r') { $displayUOM['rain'] = $plank['r'][$flag2]; } elseif ($flag1 == 'w') { $displayUOM['wind'] = $plank['w'][$flag2]; } elseif ($flag1 == 'b') { $displayUOM['baro'] = $plank['b'][$flag2]; } } // display units array has been updated if (isset($_REQUEST['change']) || !isset($_REQUEST['disp'])) { // rebuild $disp (to be carried around pages) $disp = ''; if ($displayUOM['temp'] == 'C') $disp .= 't0'; if ($displayUOM['temp'] == 'F') $disp .= 't1'; if ($displayUOM['rain'] == 'mm') $disp .= 'r0'; if ($displayUOM['rain'] == 'in') $disp .= 'r1'; if ($displayUOM['wind'] == 'mph') $disp .= 'w0'; if ($displayUOM['wind'] == 'm/s') $disp .= 'w1'; if ($displayUOM['wind'] == 'km/h') $disp .= 'w2'; if ($displayUOM['wind'] == 'kts') $disp .= 'w3'; if ($displayUOM['baro'] == 'hPa') $disp .= 'b0'; if ($displayUOM['baro'] == 'mb') $disp .= 'b1'; if ($displayUOM['baro'] == 'inHg') $disp .= 'b2'; } // By now $disp MUST now exist AND be uptodate - However; $displayUOM might not be !! // DEcode $disp to ensure $displayUOM is uptodate $thislen = strlen($disp); for ($x = 0; $x <= $thislen - 2; $x += 2) { if (substr($disp, $x, 2) == 't0') $displayUOM['temp'] = 'C'; if (substr($disp, $x, 2) == 't1') $displayUOM['temp'] = 'F'; if (substr($disp, $x, 2) == 'r0') $displayUOM['rain'] = 'mm'; if (substr($disp, $x, 2) == 'r1') $displayUOM['rain'] = 'in'; if (substr($disp, $x, 2) == 'w0') $displayUOM['wind'] = 'mph'; if (substr($disp, $x, 2) == 'w1') $displayUOM['wind'] = 'm/s'; if (substr($disp, $x, 2) == 'w2') $displayUOM['wind'] = 'km/h'; if (substr($disp, $x, 2) == 'w3') $displayUOM['wind'] = 'kts'; if (substr($disp, $x, 2) == 'b0') $displayUOM['baro'] = 'hPa'; if (substr($disp, $x, 2) == 'b1') $displayUOM['baro'] = 'mb'; if (substr($disp, $x, 2) == 'b2') $displayUOM['baro'] = 'inHg'; // echo substr($disp, $x, 2)."
"; } // speed conversions ------ mph, kts, m/s, km/h $mph = array(1, 0.8689762, 0.44704, 1.60934); $kts = array(1.1507794, 1, 0.514444, 1.852); $ms = array(2.23694, 1.9438445, 1, 3.6); $kmh = array(0.621371, 0.5399568, 0.277778, 1); // temperature gradient colours /* $tempGrad = array_merge( gradient('3D0060', '6100A7', 100), // -50 > -40 gradient('6100A7', 'BA00FF', 100), // -40 > -30 gradient('BA00FF', '000096', 100), // -30 > -20 gradient('000096', '54509F', 100), // -20 > -10 gradient('54509F', '00FFD4', 100), // -10 > 0 gradient('00FFD4', '48FF00', 100), // 0 > 10 gradient('48FF00', 'FFDD00', 100), // 10 > 20 gradient('FFDD00', 'FF0000', 100), // 20 > 30 gradient('FF0000', 'BC0000', 100), // 30 > 40 gradient('BC0000', '640000', 100) // 40 > 50 ); */ $tempGrad = array_merge( gradient('808080', '808080', 100), // -50 > -40 gradient('808080', '808080', 100), // -40 > -30 gradient('808080', '808080', 100), // -30 > -20 gradient('7D02C2', '354BC2', 100), // -20 > -10 gradient('354BC2', '00C1DB', 100), // -10 > 0 gradient('00C1DB', '48FF00', 100), // 0 > 10 gradient('48FF00', 'FFDD00', 100), // 10 > 20 gradient('FFDD00', 'FF0000', 100), // 20 > 30 gradient('FF0000', 'FC28C9', 100), // 30 > 40 gradient('808080', '808080', 100) // 40 > 50 ); $tempDiffGrad = array_merge( gradient('1AFF34', 'FFFF00', 100), // 0 > 10 gradient('FFFF00', 'FF2626', 100) // 10 > 20 ); // average wind speed colours $windGrad0to50 = gradient('FFF0F0', 'D00000', 50); // gust wind speed colours $gustGrad0to80 = gradient('FFF0F0', 'D00000', 80); // totRainFall colours $rainGrad0to30 = array_merge( array('FFFFFF'), // zero value gradient('E8E8FF', '0000D0', 30) // 1 > 30 mm ); // totWindRun colours $runGrad0to300 = gradient('F0FFF0', '00A000', 300); // barometer colours $baroGrad = array_merge( gradient('2020C0', 'FFFFFF', 50), // 960 - 1010 gradient('FFFFFF', '44BA36', 40) // 1010 - 1050 ); // HighSolarRad irradiance colours $sunGrad0to10 = gradient('FFFF00', 'FF0000', 1500); // value suggested by Graham64 // UV-I colours (=<1.6 is lo, >= 10 is hi) - gradients suggested by nossis $uvGrad = array_merge( array('FFFFFF'), // zero value gradient('96CC00', 'FFFF00', 14), // 1.6 - 3.0 gradient('FFFF00', 'FF9928', 30), // 3.0 - 6.0 gradient('FF9928', 'FF0000', 20), // 6.0 - 8.0 gradient('FF0000', 'BF00BF', 30), // 8.0 - 11.0 gradient('BF00BF', '7D76AD', 50) // 11.0 - 16.0 ); // humidity colours $humGrad = array_merge( gradient('4A8BFF', '00CCCC', 20), gradient('00CCCC', '00FA36', 10), gradient('00FA36', '00FA36', 30), gradient('00FA36', 'E5E62A', 15), gradient('E5E62A', 'FA9600', 15), gradient('FA9600', 'FF0000', 10) ); // totInsol colours $insolGrad0to55 = gradient('E8FFE8', '00D000', 55); // 0 > 5.5 kWh/m2 // totWindRun 'lookup' units $wrun = array( 'mph' => '- miles', 'm/s' => '- kilometres', 'km/h' => '- kilometres', 'kts' => '- nautical miles' ); /************ Function Definitions *************/ function DoTemp($value, $to) { // convert temperatures global $displayUOM, $uom, $decimals; $temp_dec = 1; $decimals = $temp_dec; if (!$to) { $to = $displayUOM['temp']; } if ($to == 'F' && $uom['temp'] == 'C') { // C => F return number_format((1.8 * $value) + 32, $temp_dec, '.', ''); } elseif ($to == 'C' && $uom['temp'] == 'F') { // F => C return number_format(($value - 32) / 1.8, $temp_dec, '.', ''); } // no change return number_format((float)$value, $temp_dec, '.', ''); } // END function DoTemp() function DoTempDiff($value, $to) { // convert temperatures relative global $displayUOM, $uom, $decimals; $temp_dec = 1; $decimals = $temp_dec; if (!$to) { $to = $displayUOM['temp']; } if ($to == 'F' && $uom['temp'] == 'C') { // C => F return number_format((1.8 * $value), $temp_dec, '.', ''); } elseif ($to == 'C' && $uom['temp'] == 'F') { // F => C return number_format($value / 1.8, $temp_dec, '.', ''); } // no change return number_format((float)$value, $temp_dec, '.', ''); } // END function DoTempDiff() function DoRain($value, $to) { // convert rain units global $displayUOM, $uom, $decimals; $rain_dec = $displayUOM['rain'] === 'mm' ? 1 : 2; $decimals = $rain_dec; if (!$to) { $to = $displayUOM['rain']; } if ($uom['rain'] === 'in' && $to === 'mm') { // in => mm return number_format(($value * 25.4), $rain_dec, '.', ''); } elseif ($uom['rain'] === 'mm' && $to === 'in') { // mm => in return number_format(($value / 25.4), $rain_dec, '.', ''); } // no change return number_format((float)$value, $rain_dec, '.', ''); } // END function DoRain() function DoWind($value, $to) { // convert windspeeds global $displayUOM, $uom, $mph, $kts, $kmh, $ms, $dataSet, $decimals; if (!$to) { $to = $displayUOM['wind']; } if ($to === 'mph') { $ethel = 0; $wind_dec = 0; } elseif ($to === 'kts') { $ethel = 1; $wind_dec = 0; } elseif ($to === 'm/s') { $ethel = ($dataSet === 'totWindRun' ? 3 : 2); $wind_dec = 1; } elseif ($to === 'km/h') { $ethel = 3; $wind_dec = 1; } $wind_dec = ($dataSet === 'totWindRun' ? 0 : $wind_dec); $decimals = $wind_dec; if ($uom['wind'] === 'mph') { $factor = $mph[$ethel]; } elseif ($uom['wind'] === 'kts') { $factor = $kts[$ethel]; } elseif ($uom['wind'] == 'm/s') { $factor = ($dataSet === 'totWindRun' ? $kmh[$ethel] : $ms[$ethel]); } elseif ($uom['wind'] === 'km/h') { $factor = $kmh[$ethel]; } if ($factor != 1) { // conversion required return number_format($value * $factor, $wind_dec, '.', ''); } return number_format((float)$value, $wind_dec, '.', ''); } // END function DoWind() function DoBaro($value, $to) { // convert pressure units global $displayUOM, $uom, $decimals; $baro_dec = ($displayUOM['baro'] === 'inHg' ? 2 : 1); $decimals = $baro_dec; if (!$to) { $to = $displayUOM['baro']; } if (($to === 'hPa' || $to === 'mb') && $uom['baro'] === 'inHg') { // inHg => hPa or mb return number_format($value * 33.86388158, $baro_dec, '.', ''); } elseif ($to === 'inHg' && ($uom['baro'] === 'hPa' || $uom['baro'] === 'mb')) { // hPa or mb => inHg return number_format($value / 33.86388158, $baro_dec, '.', ''); } // no change return number_format((float)$value, $baro_dec, '.', ''); } // END function DoBaro() // *** MAIN table creation function *** // function drawCalendar($tableYear) { global $dataSet, $label_items, $data, $year_list, $displayUOM, $disp, $wrun, $season_data, $translit, $dayfileLang, $decimals, $type_data, $type_year, $thisValue, $part2, $pane, $native, $show_year_averages, $SANITIZE, $zero_as_null, $north_hemisphere, $buttons, $this_file_name, $typeS_year, $calcAvg, $calcSum, $calcHi, $calcLo, $sunAvailable; readDayfile($tableYear, $dataSet); $tablelayout = '
'; if ($buttons) { // start buttons 'menu' $tablelayout .= '
    '; foreach ($label_items as $k => $v) { if ($v[2] == true){ $tablelayout .= ''.$v[0].''; } } $tablelayout .= "
\n"; } // table 'title' $tablelayout .= '

'; // year selector $tablelayout .= ''.$year_list.''; // daily / seasonal selector $tablelayout .= ''; foreach ($label_items as $k => $v) { if ($k === $dataSet) { if ($buttons) { $tablelayout .= ($v[4] ? ' ' . picker($v[4]) . '' : '') . $v[1] . ($dataSet === 'totWindRun' ? ' ' .$wrun[$displayUOM['wind']] : ''); } else { $tablelayout .= ($v[4] ? ' ' . picker($v[4]) : '') . picker2() . ($dataSet === 'totWindRun' ? ' ' .$wrun[$displayUOM['wind']] : ''); } //$dayfilecol = $v[3]; $calcAvg = (strpos($v[5], 'a') > -1 ? true : false); $calcSum = (strpos($v[5], 's') > -1 ? true : false); $calcHi = (strpos($v[5], 'h') > -1 ? true : false); $calcLo = (strpos($v[5], 'l') > -1 ? true : false); break; } } $tablelayout .= "

\n
\n
\n"; // END 'menu' and table 'title' $tablelayout .= "
\n"; // loading overlay $tablelayout .= "
\n"; // daily summaries table $tablelayout .= '
\n"; $tablelayout .= "\n"; $tablelayout .= ''; $mondomWindDir = array(); for ($m = 1; $m <= 12; $m++) { $tablelayout .= ''; $mondomWindDir[$m] = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); // 'twitch fix' } $tablelayout .= "\n"; $monSum = array(); $bg_monSum = array(); for ($d = 1; $d <= 31; $d++) { $tablelayout .= ''; $part1 = ''; } // END months 1 > 12 $tablelayout .= $part1 .= ' ' .$d. '' . $part2; // stitch table together $tablelayout .= "\n"; } // END days upto 31 // total / avg / hi / lo outputs (on-demand) $line = false; $exception = false; if ($calcSum) { if ($dataSet === 'totWindRun') { $decimals = 0; } $fixthis = ($line ? '' : ' topborder'); $tablelayout .= '\n"; for ($m = 1; $m < 13; $m++) { $tablelayout .= ''.($dataSet != 'HoursSun' ? $short : '').$thisValue.''; } else { $tablelayout .= ' class="datacell' .$fixthis. '"> '; } } $tablelayout .= "\n"; $line = true; } // END calcSum if ($calcAvg) { // windirection is an exception where we need to find 'dominant' value if ($dataSet === 'totWindRun') { $decimals = 0; } $fixthis = ($line ? '' : ' topborder'); $tablelayout .= '\n"; for ($m = 1; $m <= 12; $m++) { $tablelayout .= ' $v) { if ($v == $workMax) { // see if number of occurences = max $thisValue = ($k === 0 ? 22 : $k * 22.5); // sort of put back into a degree range break; // only looking for first (clockwise) event } } } else { // everything that really needs averages $thisValue = array_sum($monSum[$m]) / count($monSum[$m]); if ($dataSet == 'HoursSun') { $bg_value = array_sum($bg_monSum[$m]) / count($bg_monSum[$m]); $sunAvailable = round($bg_value, 1); } } if ($thisValue <> '' || (float)$thisValue === 0) { formatOP($dataSet !== 'HoursSun'); $short = (count($monSum[$m]) < cal_days_in_month(CAL_GREGORIAN, $m, $tableYear) ? '*' : ''); if ($short) { $exception = true; } $tablelayout .= ' class="datacell' .$fixthis.'"'.$part2.'>'.($dataSet != 'HoursSun' ? $short : '').$thisValue.''; } else { $tablelayout .= ' class="datacell' .$fixthis. '"> '; } } else { $tablelayout .= ' class="datacell' .$fixthis. '"> '; } } $tablelayout .= "\n"; $line = true; } // END calcAvg if ($calcHi) { $fixthis = ($line ? '' : ' topborder'); $tablelayout .= '\n"; for ($m = 1; $m <= 12; $m++) { $tablelayout .= ' '' || (float)$thisValue === 0){ formatOP(); $short = (count($monSum[$m]) < cal_days_in_month(CAL_GREGORIAN, $m, $tableYear) ? '*' : ''); if ($short) { $exception = true; } $tablelayout .= ' class="datacell' .$fixthis. '"'. $part2.'>'.($dataSet != 'HoursSun' ? $short : '').$thisValue.''; } else { $tablelayout .= ' class="datacell' .$fixthis. '"> '; } } else { $tablelayout .= ' class="datacell' .$fixthis. '"> '; } } $tablelayout .= "\n"; $line = true; } // END calcHi if ($calcLo) { $fixthis = ($line ? '' : ' topborder'); $tablelayout .= '\n"; for ($m = 1; $m <= 12; $m++) { $tablelayout .= ' '' || (float)$thisValue === 0) { formatOP(); $short = (count($monSum[$m]) < cal_days_in_month(CAL_GREGORIAN, $m, $tableYear) ? '*' : ''); if ($short) { $exception = true; } $tablelayout .= ' class="datacell' .$fixthis. '"'.$part2.'>'.($dataSet != 'HoursSun' ? $short : '').$thisValue.''; } else { $tablelayout .= ' class="datacell' .$fixthis. '"> '; } } else { $tablelayout .= ' class="datacell' .$fixthis. '"> '; } } $tablelayout .= "\n"; $line = true; } // END calcLo $sanitized = ''; if ($SANITIZE && in_array($dataSet, $zero_as_null)) { // we want to try to 'nullify' zero values in some datasets $sanitized = ' - '.$translit[$dayfileLang]['note'][2]; // prepare 'Note;' advisory } // 'Note:' line $tablelayout .= '\n\n"; //$tablelayout .= "
'.$translit[$dayfileLang]['mn'][$m - 1].'
'; $part2 = ''; for ($m = 1; $m <= 12; $m++) { if ($d <= cal_days_in_month(CAL_GREGORIAN, $m, $tableYear)) { $theDate = mktime(0,0,0,$m,$d,$tableYear); $theDay = $translit[$dayfileLang]['dy'][date('w', $theDate)]; $part1 .= ''; $part2 .= ' '') { // belts'n'braces if ($dataSet === 'domWindDir') { //if ($thisValue[0] >0 && $thisValue[1] >0 ) { $wval = round($thisValue / 22.5); $mondomWindDir[$m][$wval]++; // creating a 'counter' whose 'key' is the direction (0 > 15) //$thisValue = $thisValue[0]; //} else { //$thisValue = ''; //} } if ($thisValue <> '') { if ($dataSet == "HoursSun") { $sunAvailable = maxsunhours($theDate); $bg_monSum[$m][] = $sunAvailable; } formatOP(); // $thisValue is a global so doesn't need to be 'passed' $part2 .= '>'; $part2 .= $thisValue; // may have been converted by formatOP() $monSum[$m][] = $native; if ($dataSet === 'HoursSun') { $thisValue = true; // a fiddle because of the way it is formated } } //} } } } if ($thisValue === '') { $part2 .= '"> '; // *** attempted logic fix } } else { // not a valid day of month $part2 .= ''; } // END valid days upto 31 $part2 .= '
'.$translit[$dayfileLang]['total'].":
'.($dataSet == 'domWindDir' ? $translit[$dayfileLang]['dom'] : $translit[$dayfileLang]['avg']).":
' .$translit[$dayfileLang]['hi'].":
' .$translit[$dayfileLang]['lo'].":
'.$translit[$dayfileLang]['note'][0].": ".($exception ? '*'.$translit[$dayfileLang]['note'][1] : '').$sanitized."
\n"; // END daily summaries table // START year avg table //$tablelayout .= '\n"; if ($show_year_averages) { $tablelayout .= "\n"; if ($dataSet === 'domWindDir') { $dataType = $translit[$dayfileLang]['dom']; } elseif (in_array($dataSet, array('totRainDays', 'totRainFall', 'HeatDegDays', 'CoolDegDays', 'totalEvap'))) { $dataType = $translit[$dayfileLang]['total']; } else { $dataType = $translit[$dayfileLang]['avg']; } $tablelayout .= ''; for ($m = 0; $m < 12; $m++) { $tablelayout .= ''; } $tablelayout .= "\n"; $bert = count($type_year) -1; $alltime = array(1 => [], 2 => [], 3 => [], 4 => [], 5 => [], 6 => [], 7 => [], 8 => [], 9 => [], 10 => [], 11 => [], 12 => []); if ($dataSet == 'domWindDir') { for ($zz = 1; $zz <= 12; $zz++) { $alltime[$zz] = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); } } $shortMon = array(); for ($d = $bert; $d >= 0; $d--) { // latest year first $shortMon[$d] = array(); $tablelayout .= ''; $tablelayout .= ''; for ($m = 1; $m <= 12; $m++) { $shortMon[$d][$m] = false; $windd = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); // twitch fix $tablelayout .= ' $v) { if ($v <> '') { // only take account of non null entries if ($dataSet === 'domWindDir') { //if ($v[0] >0 && $v[1] >0) { $windd[round($v / 22.5)]++ ; // 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') { $bg_y = $type_year[$d]; $bg_when = mktime(0, 0, 0, $m, $k, $bg_y); $bg_turd[] = maxsunhours($bg_when); } } } } if ($turd) { if ($dataSet === 'domWindDir') { $workMax = max($windd); // find highest occurence $found = false; foreach ($windd as $k => $v) { $alltime[$m][$k] += $v; if ($found !== true && $v === $workMax) { // see if number of occurences = max $thisValue = ($k == 0 ? 22 : $k * 22.5); // sort of put back into a degree range $found = true; // only looking for first (clockwise) event } } } elseif (in_array($dataSet, array('totRainDays', 'totRainFall', 'HeatDegDays', 'CoolDegDays', 'totalEvap'))) { $thisValue = array_sum($turd); } else { // everything that really needs averages $thisValue = array_sum($turd) / count($turd); if ($dataSet == 'HoursSun') { $bg_value = round(array_sum($bg_turd) / count($bg_turd), 1); $sunAvailable = $bg_value; } } } if ($thisValue || $thisValue == 0) { if ($dataSet !== 'domWindDir') { $alltime[$m][] = $thisValue; } formatOP(in_array($dataSet, array('totRainDays', 'totRainFall', 'AirQuality', 'HeatDegDays', 'CoolDegDays', 'totalEvap')) ? true : false); $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.''; } else { $tablelayout .= ' class="nondate"> '; } } else { $tablelayout .= ' class="nondate"> '; } } // END month walk $tablelayout .= "\n"; } // END year walk // now do overall month averages - not for wind direction - too ambitous! // Not for total rain days and total rainfall - only display sum if ($dataSet !== 'domWindDir') { if ($dataSet !== 'domWindDir' && $dataSet !== 'totRainDays') { $decimals = 1; } $tablelayout .= ''; $tablelayout .= ''; for ($m = 1; $m <= 12; $m++) { $tablelayout .= ' $v) { if ($v == $workMax) { // see if number of occurences = max $thisValue = ($k == 0 ? 22 : $k * 22.5); // sort of put back into a degree range break; // only looking for first (clockwise) event } } } elseif (is_array($alltime[$m])) { $thisValue = count($alltime[$m]) ? array_sum($alltime[$m]) / count($alltime[$m]) : '-'; } if ($thisValue) { formatOP(in_array($dataSet, array('domWindDir', 'totRainDays', 'AirQuality', 'HeatDegDays', 'CoolDegDays')) ? true : false); $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.''; } else { $tablelayout .= ' class="nondate topborder"> '; } } else { $tablelayout .= ' class="nondate topborder"> '; } } // END month walk $tablelayout .= "\n"; } } // END overall year averages $tablelayout .= "
'.$dataType.''.$translit[$dayfileLang]['mn'][$m].'
'.$type_year[$d].'
'.($dataSet == 'domWindDir' ? $translit[$dayfileLang]['dom'] : $translit[$dayfileLang]['avg']).'
\n"; // END year averages table // SEASONAL summaries table $tablelayout .= '
\n"; //$m_offset = array(null, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); // simple offset 'look-up' $m_offset = array(null, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2); // simple offset 'look-up' //$exception = false; $tablelayout .= "\n"; $tablelayout .=''; $tablelayout .=''; $tablelayout .=''; $tablelayout .=''; $tablelayout .=''; $tablelayout .=''; $tablelayout .=''; $tablelayout .=''; $tablelayout .=''; $tablelayout .=''; $tablelayout .=''; $tablelayout .=''; $tablelayout .=''; $tablelayout .=''; $tablelayout .= "\n"; $tablelayout .= ''; if ($north_hemisphere) { $tablelayout .= ''; $tablelayout .= ''; $tablelayout .= ''; $tablelayout .= ''; } else { $tablelayout .= ''; $tablelayout .= ''; $tablelayout .= ''; $tablelayout .= ''; } $tablelayout .= "\n"; // months header row as a seperate var so as it can be duplicated after predetermined # of entries $monthRow = "\n"; $monthRow .= ''; $monthRow .= ''; $monthRow .= ''; $monthRow .= ''; $monthRow .= ''; $monthRow .= "\n"; $bert = count($typeS_year) -1; for ($d = $bert; $d >= 0; $d--) { // latest year first $seasonTot = array(0 => [], 1 => [], 2 => [], 3 => []); $shortSeason = array(); $sT = 0; $season = array(); if ($dataSet === 'domWindDir') { for ($zz = 0; $zz < 4; $zz++) { $season[$zz] = array(0 => [], 1 => [], 2 => [], 3 => [], 4 => [], 5 => [], 6 => [], 7 => [], 8 => [], 9 => [], 10=> [], 11=> [], 12 => [], 13 => [], 14 => [], 15 => [], 16 => []); } } $s = 0; $fixrow = ($d === 0 ? '' : ' bottomborder'); $widget = ''.$typeS_year[$d].''; // every 5 years show months row if ($bert - $d === 0 || $bert - $d === 5 || $bert - $d === 10 || $bert - $d === 15) { $tablelayout .= $monthRow; } // we will ALWAYS be at least outputing Avg //total value - month (optional) if ($calcSum) { if ($dataSet === 'totRainDays') { $decimals = 0; } $tablelayout .= ''; $tablelayout .= ''; $widget = ''; for ($m = 1; $m <= 12; $m++) { if ($m <4) { $sT = 0; } elseif ($m >= 4 && $m < 7) { $sT = 1; } elseif ($m >= 7 && $m < 10) { $sT = 2; } elseif ($m >= 10) { $sT = 3; } $fixcol = ($m === 3 || $m === 6 || $m === 9 ? ' rightborder' : ''); $tablelayout .= ' $v) { $native = ''; if ($v <> '') { // only take account of non null entries if (is_array($v)) { // we are dealing with something that needs calculating $thisValue = $v; formatOP(true); // 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 ($turd) { $thisValue = array_sum($turd); } if ($thisValue) { $seasonTot[$sT][] = $thisValue; if ($dataSet == 'HoursSun') { $thisValue = number_format($thisValue, 0); } else { formatOP(true); } $dayCnt = cal_days_in_month(CAL_GREGORIAN, $m_offset[$m], $typeS_year[$d] + ($m_offset[$m] < 3 ? 1 : 0)); $shortSeason[$sT] = count($turd) < $dayCnt; $short = $shortSeason[$sT] ? '*' : ''; // doesn't matter about 'previous' December - will always be 31 //$tablelayout .= ' class="datacell'.$fixcol.'"'.$part2.'>'.($dataSet != 'HoursSun' ? $short : '').$thisValue.''; $tablelayout .= ' class="datacell'.$fixcol.'"'.$part2.'>'.$short.$thisValue.''; } else { $tablelayout .= ' class="nondate'.$fixcol.'"> '; } } else { $tablelayout .= ' class="nondate'.$fixcol.'"> '; } } $tablelayout .= "\n"; // total - season(s) $tablelayout .= ''; $tablelayout .= ''; for ($x = 0; $x < 4; $x++) { // step through seasons $tablelayout .= ''; $tablelayout .= ' class="datacell center'.$fixcol.'">'.$short.$thisValue.''; } else { $tablelayout .= ' class="nondate'.$fixcol.'"> '; } } else { $tablelayout .= ' class="nondate'.$fixcol.'"> '; } } $tablelayout .= "\n"; } // END total(s) (option) //hi value - month (optional) if (!in_array($dataSet, array('domWindDir', 'totRainDays'))) { $tablelayout .= ''; $tablelayout .= ''; $widget = ''; for ($m = 1; $m <= 12; $m++) { $fixcol = ($m === 3 || $m === 6 || $m === 9 ? ' rightborder' : ''); $tablelayout .= ' $v) { $native = ''; if ($v <> '') { // only take account of non null entries 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 ($turd) { $thisValue = max($turd); } if ($thisValue) { if ($dataSet == 'HoursSun') { $thisValue = number_format($thisValue, 1); } else { formatOP(true); } $dayCnt = cal_days_in_month(CAL_GREGORIAN, $m_offset[$m], $typeS_year[$d] + ($m_offset[$m] < 3 ? 1 : 0)); $short = (count($turd) < $dayCnt) ? '*' : ''; // doesn't matter about 'previous' December - will always be 31 //$tablelayout .= ' class="datacell'.$fixcol.'"'.$part2.'>'.($dataSet != 'HoursSun' ? $short : '').$thisValue.''; $tablelayout .= ' class="datacell'.$fixcol.'"'.$part2.'>'.$short.$thisValue.''; } else { $tablelayout .= ' class="nondate'.$fixcol.'"> '; } } else { $tablelayout .= ' class="nondate'.$fixcol.'"> '; } } $tablelayout .= "\n"; } // END hi //lo value - month (optional) if ($calcLo) { $tablelayout .= ''; $tablelayout .= ''; $widget = ''; for ($m = 1; $m <= 12; $m++) { $fixcol = ($m === 3 || $m === 6 || $m === 9 ? ' rightborder' : ''); $tablelayout .= ' $v) { $native = ''; if ($v <> '') { // only take account of non null entries 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 ($turd) { $thisValue = min($turd); } if ($thisValue <> '' || $thisValue == 0) { formatOP(); $dayCnt = cal_days_in_month(CAL_GREGORIAN, $m_offset[$m], $typeS_year[$d] + ($m_offset[$m] < 3 ? 1 : 0)); $short = (count($turd) < $dayCnt) ? '*' : ''; // doesn't matter about 'previous' December - will always be 31 $tablelayout .= ' class="datacell'.$fixcol.'"'.$part2.'>'.($dataSet != 'HoursSun' ? $short : '').$thisValue.''; } else { $tablelayout .= ' class="nondate'.$fixcol.'"> '; } } else { $tablelayout .= ' class="nondate'.$fixcol.'"> '; } } $tablelayout .= "\n"; } // END lo // month avg value - must have? if ($calcAvg) { $tablelayout .= ''; $tablelayout .= ''; $widget = ''; for ($m = 1; $m <= 12; $m++) { $windd = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 0, 14 => 0, 15 => 0, 16 => 0); if ($m <4) { $s = 0; } elseif ($m >= 4 && $m < 7) { $s = 1; } elseif ($m >= 7 && $m < 10) { $s = 2; } elseif ($m >= 10) { $s = 3; } $fixcol = ($m === 3 || $m === 6 || $m === 9 ? ' rightborder' : ''); $tablelayout .= ' $v) { $native = ''; if ($v <> '') { // only take account of non null entries if (is_array($v)) { // we are dealing with something that needs calculating $thisValue = $v; formatOP(true); // only want to use 'native' result $thisValue = ''; // reset $part2 = ''; // reset $turd[] = $native; if ($dataSet !== 'domWindDir') { $season[$s][] = $native; } } else { // 'normal' single piece of data $turd[] = $v; // a 'normal' single data entry $season[$s][] = $v; } } //if ($dataSet == 'domWindDir' && isset($v[0]) && isset($v[1])) { if ($dataSet === 'domWindDir') { //if ($v[0] >0 && $v[1] > 0) { $windd[round($v / 22.5)]++ ; // increment wind dir count //} } } if ($turd) { if ($dataSet === 'domWindDir') { $workMax = max($windd); // find highest occurence $found = false; $season[$s] = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); foreach ($windd as $k => $v) { $season[$s][$k] += $v; if ($found !== true && $v === $workMax) { // see if number of occurences = max $thisValue = ($k == 0 ? 22 : $k * 22.5); // 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); } } if ($thisValue || $thisValue === 0) { if ($dataSet == 'HoursSun') { $thisValue = round($thisValue, 1); } else { formatOP(true); } $dayCnt = cal_days_in_month(CAL_GREGORIAN, $m_offset[$m], $typeS_year[$d] + ($m_offset[$m] < 3 ? 1 : 0)); $short = (count($turd) < $dayCnt) ? '*' : ''; // doesn't matter about 'previous' December - will always be 31 if (count($turd) < $dayCnt) { $shortSeason[$s] = true; } $tablelayout .= ' class="datacell'.$fixcol.'"'.$part2.'>'.($dataSet != 'HoursSun' ? $short : '').$thisValue.''; } else { $tablelayout .= ' class="nondate'.$fixcol.'"> '; } } else { $tablelayout .= ' class="nondate'.$fixcol.'"> '; } } $tablelayout .= "\n"; // END month avg // and finally ... season(s) avg value $tablelayout .= ''; $tablelayout .= ''; for ($x = 0; $x < 4; $x++) { // step through seasons $tablelayout .= ''; $tablelayout .= ' class="datacell center'.$fixcol.$fixrow.'"'.$part2.'>'.$short.$thisValue.''; } else { $tablelayout .= ' class="nondate'.$fixcol.$fixrow.'"> '; } } else { $tablelayout .= ' class="nondate'.$fixcol.$fixrow.'"> '; } } else { $tablelayout .= ' class="nondate'.$fixcol.$fixrow.'"> '; } } // END season walkthrough $tablelayout .= "\n"; } } // END year walk-through // 'Note:' line $tablelayout .= '\n"; $tablelayout .= '\n"; $tablelayout .= "
 '.$translit[$dayfileLang]['season_2'].''.$translit[$dayfileLang]['season_3'].''.$translit[$dayfileLang]['season_4'].''.$translit[$dayfileLang]['season_1'].''.$translit[$dayfileLang]['season_4'].''.$translit[$dayfileLang]['season_1'].''.$translit[$dayfileLang]['season_2'].''.$translit[$dayfileLang]['season_3'].'
 '.$translit[$dayfileLang]['mn'][2].''.$translit[$dayfileLang]['mn'][3].''.$translit[$dayfileLang]['mn'][4].''.$translit[$dayfileLang]['mn'][5].''.$translit[$dayfileLang]['mn'][6].''.$translit[$dayfileLang]['mn'][7].''.$translit[$dayfileLang]['mn'][8].''.$translit[$dayfileLang]['mn'][9].''.$translit[$dayfileLang]['mn'][10].''.$translit[$dayfileLang]['mn'][11].''.$translit[$dayfileLang]['mn'][0].''.$translit[$dayfileLang]['mn'][1].'
'.$widget.$translit[$dayfileLang]['total'].'
'.$widget.$translit[$dayfileLang]['total'].''.($dataSet != 'HoursSun' ? $short.$thisValue : array_sum($seasonTot[$x])).'
'.$widget.$translit[$dayfileLang]['hi'].'
'.$widget.$translit[$dayfileLang]['lo'].'
'.$widget.$translit[$dayfileLang]['avg'].'
'.$translit[$dayfileLang]['avg'].' $v) { if ($v == $workMax) { // see if number of occurences = max $thisValue = ($k == 0 ? 22 : $k * 22.5); // sort of put back into a degree range break; // only looking for first (clockwise) event } } } else { $thisValue = '*'; } } else { $thisValue = array_sum($season[$x]) / count($season[$x]); } if ($thisValue != '*') { if ($thisValue || $thisValue === 0) { if ($dataSet == 'HoursSun') { $thisValue = number_format($thisValue, 1); } else { formatOP(true); } $short = ''; if (array_key_exists($x, $seasonTot) && array_key_exists($x, $shortSeason)) { $short = '*'; $exception = true; } //$tablelayout .= ' class="datacell center'.$fixcol.$fixrow.'"'.$part2.'>'.($dataSet !== 'HoursSun' ? $short : '').$thisValue.'
' .$translit[$dayfileLang]['note'][0]. ": ' .($exception ? '*'.$translit[$dayfileLang]['note'][1] : '').$sanitized."
\n"; $tablelayout .= "\n
\n"; // END season table 'holder' $tablelayout .= "\n
\n"; // END tables 'holder $tablelayout .= "
\n"; // END 'gilliam' // output table(s) to page echo $tablelayout; // 'write' page JavaScript echo '';} // END function drawCalendar() function readDayfile($tableYear, $dataSet) { // grab datafile and collect data 'type' global $datatable, $insoltable, $field_delimiter, $date_delimiter, $year_list, $disp, $label_items, $season_data, $type_data, $type_year, $translit, $dayfileLang, $delim, $SANITIZE, $zero_as_null, $typeS_year; include 'db_ro_details.php'; $current_year = 0; $season_year = 0; $new_year = 0; $year_list = ''; $result = $mysqli->query($query2); if (!$result) { echo 'ERROR - Bad Select Statement2 ' . $mysqli->error . "

" . $query2; exit(); } $data = array(); $multi = is_array($dayfilecol); // import the rows and put the data into array while ($row = $result->fetch_array()) { $datearr = explode('-', $row[0]); if ($multi) { // we are looking for more than one daily value $this_op = array(); foreach ($dayfilecol as $v) { $this_op[] = $row[$v]; } } else { // looking for a single field $this_op = $row[1]; } $new_year = $datearr[0]; if ((int)$datearr[1] < 3) { $season_data[(int)$datearr[0] - 1][(int)$datearr[1]][(int)$datearr[2]] = $this_op; } else { $season_data[(int)$datearr[0]][(int)$datearr[1]][(int)$datearr[2]] = $this_op; } $type_data[(int)$datearr[0]][(int)$datearr[1]][(int)$datearr[2]] = $this_op; if ($season_year != $new_year) { if (!in_array($new_year, $type_year)) $type_year[] = $new_year; if ((int)$datearr[1] < 3) $season_year = (int)$new_year - 1; else $season_year = $new_year; if (!in_array($season_year, $typeS_year)) $typeS_year[] = $season_year; } } // close connection $mysqli->close(); } // END function readDayfile() function maxsunhours($when) { // works out max available sun hours for a given datestamp // based on code by beteljuice global $bg_lat, $bg_lon; // $when is a unix time-stamp $thisday = date( 'j', $when); $sun_info = date_sun_info($when, $bg_lat, $bg_lon); if ($sun_info['sunrise'] > 1 ) { // numeric (datestamp) o/p $upcheck = date( 'j',$sun_info['sunrise']); if ($upcheck != $thisday) { $sun_info['sunrise'] = false; } } if ($sun_info['sunset'] > 1 ) { // numeric (datestamp) o/p $downcheck = date( 'j',$sun_info['sunset']); if ($downcheck != $thisday) { $sun_info['sunset'] = false; } } if ($sun_info['sunrise'] === true && $sun_info['sunset'] === true) $hours = 24; if ($sun_info['sunrise'] === false && $sun_info['sunset'] === false) $hours = 0; if ($sun_info['sunrise'] > 1 && $sun_info['sunset'] > 1) $hours = ($sun_info['sunset'] - $sun_info['sunrise']) / 3600; if ($sun_info['sunrise'] > 1 && $sun_info['sunset'] === false) { $grunt = mktime( 23,59,59, date('n', $when), $thisday, date('Y',$when)); $hours = ($grunt - $sun_info['sunrise']) /60 /60; } // haven't seen this case in the wild if ($sun_info['sunrise'] === false && $sun_info['sunset'] > 1) { $grunt = mktime( 0,0,0, date('n', $when), $thisday, date('Y',$when)); $hours = round((($sun_info['sunset'] - $grunt) /60 /60),1); } $hours = round($hours, 1); return $hours; } // end function maxsunhours() function getHeading($deg) { global $translit, $dayfileLang; $d = floor(($deg + 11.25) / 22.5) % 16; $dd = 15 + $d * 15; return ''.$translit[$dayfileLang]['compass_headings'][$d].'
'; } // END function getHeading() function tempColour($temp) { // expects deg C global $tempGrad; $scaledVal = ($temp < -50 ? -50 : $temp); $scaledVal = ($temp > 50 ? 50 : $scaledVal); $scaledVal = ($scaledVal * 10) + 500; if ($scaledVal >= 1000) $scaledVal = 999; $betel = $tempGrad[$scaledVal]; $text = ($temp >= 24 || $temp <= 0 ? 'FFF': '000'); $ret = array($betel, $text); return $ret; } // END function tempColour() function tempDiffColour($temp) { // expects deg C global $tempDiffGrad; $val = round($temp * 10); if ($val > 199) $val = 199; $text = ($temp >= 20 ? 'FFF' : '000'); return array($tempDiffGrad[$val], $text); } function gustColour($val) { // expects mph global $gustGrad0to80; $val =(int)$val; if ($val > 79) $val = 79; $text = ($val >= 36 ? 'FFF' : '000'); return array($gustGrad0to80[$val], $text); } // END function gustColour() function windColour($val) { // expects mph global $windGrad0to50; $val =(int)$val; if ($val > 49) $val = 49; $text = ($val >= 20 ? 'FFF' : '000'); return array($windGrad0to50[$val], $text); } // END function windColour() function runColour($val) { // expects miles global $runGrad0to300; $val = (int)$val; if ($val > 299) $val = 299; $text = ($val >= 200 ? 'FFF' : '000'); return array($runGrad0to300[$val], $text); } // END function runColour() function rainColour($val) { // expects mm global $rainGrad0to30; $text= ($val >= 10 ? 'FFF' : ($val == 0 ? '9A9A9A' : '000')); $val = ceil($val); if ($val > 30) $val = 30; return array($rainGrad0to30[$val], $text); } // END function rainColour() function baroColour($val) { // expects hPa global $baroGrad; $scaledVal = round(($val - 960)); if ($scaledVal < 0) $scaledVal = 0; if ($scaledVal >= count($baroGrad)) $scaledVal = count($baroGrad) - 1; $text = ($val <= 970 || $val >= 1040) ? 'FFF' : '000'; return array($baroGrad[$scaledVal], $text); } // END function baroColour() function humColour($val) { global $humGrad; $text = (($val >= 90 || $val <= 25) ? 'FFF' : '000'); if ($val > 99) $val = 99; return array($humGrad[$val],$text); } // END function humColour() function uvColour($val) { global $uvGrad; $text = ($val >= 7 ? 'FFF' : ($val == 0 ? '9A9A9A' : '000')); $val = ceil($val * 10); if ($val > 100) $val = 100; return array($uvGrad[$val],$text); } // END function uvColour() function sunColour($val) { // being used for irradiance global $sunGrad0to10; $text = ($val >= 1000 ? 'FFF' : ($val == 0 ? '9A9A9A' : '000')); if ($val > 1500) $val = 1500; return array($sunGrad0to10[round($val)],$text); } // END function uvColour() function insolColour($val) { // expects kWh/m2 global $insolGrad0to55; $text= ($val >= 5.5 ? 'FFF' : '000'); $val = ceil($val); if ($val > 5.4) $val = 5.4; return array($insolGrad0to55[$val * 10], $text); } // END function rainColour() function aqiColour($val) { switch (round($val)) { case 1: return '9cff9c'; case 2: return '31ff00'; case 3: return '31cf00'; case 4: return 'ff0'; case 5: return 'ffcf00'; case 6: return 'ff9a00'; case 7: return 'ff6464'; case 8: return 'f00'; case 9: return '900'; case 10: return 'ce30ff'; default: return 'fff'; } } function gradient($startcol, $endcol, $graduations=10) { $graduations--; $RedOrigin = hexdec(substr($startcol,0,2)); $GrnOrigin = hexdec(substr($startcol,2,2)); $BluOrigin = hexdec(substr($startcol,4,2)); $GradientSizeRed = (hexdec(substr($endcol,0,2))-$RedOrigin)/$graduations; //Graduation Size Red $GradientSizeGrn = (hexdec(substr($endcol,2,2))-$GrnOrigin)/$graduations; $GradientSizeBlu = (hexdec(substr($endcol,4,2))-$BluOrigin)/$graduations; for ($i=0; $i<=$graduations; $i++) { $RetVal[$i] = str_pad(dechex($RedOrigin+($GradientSizeRed*$i)),2,'0',STR_PAD_LEFT) . str_pad(dechex($GrnOrigin+($GradientSizeGrn*$i)),2,'0',STR_PAD_LEFT) . str_pad(dechex($BluOrigin+($GradientSizeBlu*$i)),2,'0',STR_PAD_LEFT); } return $RetVal; } // build unit of measure options (call if required) function picker($type) { global $plank, $displayUOM, $disp, $tableYear, $dataSet; $opt_list = ' '; return $opt_list; } // END function picker() // build dataset options (call if required) function picker2() { global $label_items, $displayUOM, $disp, $tableYear, $dataSet; $opt_list = ' "; return $opt_list; } // END function picker2 $data = ''; if (isset($_GET['year'])) { $tableYear = $_GET['year']; } else { date_default_timezone_set('UTC'); $tableYear = gmdate('Y', strtotime('-1 day')); } if (isset($_GET['data'])) { $dataSet = $_GET['data']; } else { $dataSet = 'maxtemp'; // default dataset } drawCalendar($tableYear);