Example #1
0
    $from = array('<', 'mm.', 'cm.', 'in.', 'mm', 'cm', 'in', '>', '+');
    $string = str_replace($from, '', $WXSIMprecip[$i]);
    $wsWxsimPlain[$i]['rain'] = wsConvertRainfall($string, $uoms[1]);
    $wsWxsimPlain[$i]['rainExtra'] = '';
    if (wsFound($WXSIMprecip[$i], '<')) {
        $wsWxsimPlain[$i]['rainExtra'] = langtransstr('<');
    }
    if (wsFound($WXSIMprecip[$i], '>')) {
        $wsWxsimPlain[$i]['rainExtra'] = langtransstr('>');
    }
    $string = str_replace($from, '', $WXSIMsnow[$i]);
    $wsWxsimPlain[$i]['snow'] = wsConvertRainfall($string, $uoms[4], $SITE['uomSnow']);
    $wsWxsimPlain[$i]['snowExtra'] = '';
    if (wsFound($WXSIMsnow[$i], '<')) {
        $wsWxsimPlain[$i]['snowExtra'] = langtransstr('<');
    }
    if (wsFound($WXSIMsnow[$i], '>')) {
        $wsWxsimPlain[$i]['snowExtra'] = langtransstr('>');
    }
    $wsWxsimPlain[$i]['pop'] = $WXSIMpop[$i];
    $wsWxsimPlain[$i]['UV'] = $WXSIMuv[$i];
}
# save array in cache
#echo '<pre> date '.$d.PHP_EOL; print_r($wsWxsimPlain); exit;
$fileTime = time();
// save the time we processed this file and saved to cache
if (!file_put_contents($cacheFile, serialize($wsWxsimPlain))) {
    echo PHP_EOL . "<!-- Could not save data to cache {$cacheFile}. Please make sure your cache directory exists and is writable. -->" . PHP_EOL;
} else {
    echo "<!-- weatherdata ({$cacheFile}) saved to cache  -->" . PHP_EOL;
}
Example #2
0
function cleanCondition($textClouds, $textPrecip, $cover, $rain, $temp)
{
    global $conditionsArr;
    $arrClouds = $conditionsArr[trim($textClouds)];
    // array ('text' =>'clear mostly', 'code' => 100, 'cond' => 'sky');
    switch (TRUE) {
        case $cover < 5:
            $clouds = 0;
            if ($rain > 0) {
                $clouds = 100;
            }
            break;
        case $cover < 25:
            $clouds = 100;
            break;
        case $cover < 50:
            $clouds = 200;
            break;
        case $cover < 80:
            $clouds = 300;
            break;
        default:
            $clouds = 400;
    }
    if ($arrClouds['code'] > $clouds) {
        echo '<!-- $textClouds = ' . $textClouds . ' result = ' . $arrClouds['code'] . ' calculated = ' . $clouds . ' based on $cover = ' . $cover . ' -->' . PHP_EOL;
        $clouds = $arrClouds['code'];
    }
    $textClouds = $arrClouds['out'];
    #
    # echo '<!-- $textClouds = '.$textClouds.' $textPrecip = '.$textPrecip.' -->'.PHP_EOL;
    #
    $precip = 0;
    if (trim($textPrecip) == '') {
        return array($textClouds, $textPrecip, $clouds, $precip);
    }
    #
    $arrPrecip = $conditionsArr[trim($textPrecip)];
    //$$conditionsArr['CHNC. DRZL'] = array ('text' =>'drizzle chance of ', 'out' =>'chance of drizzle', 'code' => 10, 'cond' => 'drizzle');
    $textPrecip = $arrPrecip['out'];
    #
    if (wsFound($textPrecip, 'snow')) {
        $precip = 20;
    } elseif (wsFound($textPrecip, 'flurries')) {
        $precip = 20;
    } elseif (wsFound($textPrecip, 'sleet')) {
        $precip = 30;
    } elseif (wsFound($textPrecip, 'rain')) {
        $precip = 10;
    } elseif (wsFound($textPrecip, 'drizzle')) {
        $precip = 10;
    } elseif (wsFound($textPrecip, 'showers')) {
        $precip = 10;
    } elseif (wsFound($textPrecip, 'fog')) {
        $precip = 50;
    }
    #
    if (!wsFound($textPrecip, 'frost') && !wsFound($textPrecip, 'dew')) {
        if (wsFound($textPrecip, 'light')) {
            $precip = $precip + 0;
        } elseif (wsFound($textPrecip, 'moderate')) {
            $precip = $precip + 1;
        } elseif (wsFound($textPrecip, 'heavy')) {
            $precip = $precip + 2;
        }
    }
    if ($arrPrecip['code'] > $precip) {
        $precip = $arrPrecip['code'];
    }
    echo '<!-- ' . $textClouds . ' ' . $clouds . ' ' . $textPrecip . ' ' . $precip . ' -->' . PHP_EOL;
    return array($textClouds, $textPrecip, $clouds, $precip);
}