snippets from my gauges-lite.js code:


// forecast descriptions associated with forecastRule.
// one forecast desc per line, the first line corresponds to forecastRule 0
var FORECASTRULES_FILE = "forecastrules.txt”;
… … 


var Forecast_list = null;            // table of forecast strings

function start_gauges_updating() {

    // get and remember the forecast descriptions
    if (! Forecast_list) {
        var text = loadSmallTextFile(FORECASTRULES_FILE);
        if (text) {
            Forecast_list = text.split('\n');
        } else {
            console.error(FORECASTRULES_FILE + ": no forecasts provided");
            Forecast_list = [];
        }
    }
    … … 

    // remember the forecast element, updated for each forecast update.
    // usually populated by a description from forecast_list, major errors
    // are also flagged here
    forecast_el = document.getElementById("gauges_forecast"); // NOT var
    … … 
}
… … 


    // update forecast
    var forecast;
    var fcrule = observ_list['forecast’]; // <<<< however you get your fcrule value                                   
    if (fcrule) {
        forecast = Forecast_list[fcrule];
    }
    if (forecast) {
        forecast_el.textContent = forecast;
    } else {
        forecast_el.textContent = "Forecast not available";
    }
    … …


// obtain contents of a small file.
// uses synchronous GET so file should be quite small
//
function loadSmallTextFile(file_name) {

    var xhr = new XMLHttpRequest();
    xhr.overrideMimeType('application/json');
    xhr._onerror_ = function() {
        console.error(“loadSmallTextFile: " + xhr.statusText);
    };
    var d = new Date();
    var fnam = file_name + "?v=" + d.getTime();  // defeat cache
    xhr.open('GET', fnam, false);  // synchronous
    xhr.send(null);
    var file_text;  // defaults to undefined
    if (xhr.readyState == 4 && (xhr.status == 0 || xhr.status == 200)) {
        file_text = xhr.responseText;
    }
    return file_text;
}


where ‘gauges_forecast’ is an element in your html file

copy of ‘forecastrules.txt’ attached. note that this is for southern hemisphere - for northern you would need to change all references from NW to SW etc

--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/AA39F3A2-F63A-4C1E-85FB-ED3A926C4BAC%40gmail.com.
Mostly clear and cooler.
Mostly clear with little temperature change.
Mostly clear for 12 hours with little temperature change.
Mostly clear for 12 to 24 hours and cooler.
Mostly clear with little temperature change.
Partly cloudy and cooler.
Partly cloudy with little temperature change.
Partly cloudy with little temperature change.
Mostly clear and warmer.
Partly cloudy with little temperature change.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Increasing clouds and warmer. Precipitation possible within 24 to 48 hours.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Increasing clouds with little temperature change. Precipitation possible within 
24 hours.
Mostly clear with little temperature change.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Increasing clouds with little temperature change. Precipitation possible within 
12 hours.
Mostly clear with little temperature change.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Increasing clouds and warmer. Precipitation possible within 24 hours.
Mostly clear and warmer. Increasing winds.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Increasing clouds and warmer. Precipitation possible within 12 hours. 
Increasing winds.
Mostly clear and warmer. Increasing winds.
Increasing clouds and warmer.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Increasing clouds and warmer. Precipitation possible within 12 hours. 
Increasing winds.
Mostly clear and warmer. Increasing winds.
Increasing clouds and warmer.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Increasing clouds and warmer. Precipitation possible within 12 hours. 
Increasing winds.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Mostly clear and warmer. Precipitation possible within 48 hours.
Mostly clear and warmer.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Increasing clouds with little temperature change. Precipitation possible within 
24 to 48 hours.
Increasing clouds with little temperature change.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Increasing clouds and warmer. Precipitation possible within 12 to 24 hours.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Increasing clouds and warmer. Precipitation possible within 12 to 24 hours. 
Windy.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Increasing clouds and warmer. Precipitation possible within 12 to 24 hours. 
Windy.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Increasing clouds and warmer. Precipitation possible within 6 to 12 hours.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Increasing clouds and warmer. Precipitation possible within 6 to 12 hours. 
Windy.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Increasing clouds and warmer. Precipitation possible within 12 to 24 hours. 
Windy.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Increasing clouds and warmer. Precipitation possible within 12 hours.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Increasing clouds and warmer. Precipitation likley.
Clearing and cooler. Precipitation ending within 6 hours.
Partly cloudy with little temperature change.
Clearing and cooler. Precipitation ending within 6 hours.
Mostly clear with little temperature change.
Clearing and cooler. Precipitation ending within 6 hours.
Partly cloudy and cooler.
Partly cloudy with little temperature change.
Mostly clear and cooler.
Clearing and cooler. Precipitation ending within 6 hours.
Mostly clear with little temperature change.
Clearing and cooler. Precipitation ending within 6 hours.
Mostly clear and cooler.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Increasing clouds with little temperature change. Precipitation possible within 
24 hours.
Mostly cloudy and cooler. Precipitation continuing.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Mostly cloudy and cooler. Precipitation likely.
Mostly cloudy with little temperature change. Precipitation continuing.
Mostly cloudy with little temperature change. Precipitation likely.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Increasing clouds and cooler. Precipitation possible and windy within 6 hours.
Increasing clouds with little temperature change. Precipitation possible and 
windy within 6 hours.
Mostly cloudy and cooler. Precipitation continuing. Increasing winds.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Mostly cloudy and cooler. Precipitation likely. Increasing winds.
Mostly cloudy with little temperature change. Precipitation continuing. 
Increasing winds.
Mostly cloudy with little temperature change. Precipitation likely. Increasing 
winds.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Increasing clouds and cooler. Precipitation possible within 12 to 24 hours 
possible wind shift to the W SW or S.
Increasing clouds with little temperature change. Precipitation possible within 
12 to 24 hours possible wind shift to the W SW or S.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Increasing clouds and cooler. Precipitation possible within 6 hours possible 
wind shift to the W SW or S.
Increasing clouds with little temperature change. Precipitation possible within 
6 hours possible wind shift to the W SW or S.
Mostly cloudy and cooler. Precipitation ending within 12 hours possible wind 
shift to the W SW or S.
Mostly cloudy and cooler. Possible wind shift to the W SW or S.
Mostly cloudy with little temperature change. Precipitation ending within 12 
hours possible wind shift to the W SW or S.
Mostly cloudy with little temperature change. Possible wind shift to the W SW 
or S.
Mostly cloudy and cooler. Precipitation ending within 12 hours possible wind 
shift to the W SW or S.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Mostly cloudy and cooler. Precipitation possible within 24 hours possible wind 
shift to the W SW or S.
Mostly cloudy with little temperature change. Precipitation ending within 12 
hours possible wind shift to the W SW or S.
Mostly cloudy with little temperature change. Precipitation possible within 24 
hours possible wind shift to the W SW or S.
Clearing cooler and windy. Precipitation ending within 6 hours.
Clearing cooler and windy.
Mostly cloudy and cooler. Precipitation ending within 6 hours. Windy with 
possible wind shift to the W SW or S.
Mostly cloudy and cooler. Windy with possible wind shift to the W SW or S.
Clearing cooler and windy.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Mostly cloudy with little temperature change. Precipitation possible within 12 
hours. Windy.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Increasing clouds and cooler. Precipitation possible within 12 hours possibly 
heavy at times. Windy.
Mostly cloudy and cooler. Precipitation ending within 6 hours. Windy.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Mostly cloudy and cooler. Precipitation possible within 12 hours. Windy.
Mostly cloudy and cooler. Precipitation ending in 12 to 24 hours.
Mostly cloudy and cooler.
Mostly cloudy and cooler. Precipitation continuing possible heavy at times. 
Windy.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Mostly cloudy and cooler. Precipitation possible within 6 to 12 hours. Windy.
Mostly cloudy with little temperature change. Precipitation continuing possibly 
heavy at times. Windy.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Mostly cloudy with little temperature change. Precipitation possible within 6 
to 12 hours. Windy.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Increasing clouds with little temperature change. Precipitation possible within 
12 hours possibly heavy at times. Windy.
Mostly cloudy and cooler. Windy.
Mostly cloudy and cooler. Precipitation continuing possibly heavy at times. 
Windy.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Mostly cloudy and cooler. Precipitation likely possibly heavy at times. Windy.
Mostly cloudy with little temperature change. Precipitation continuing possibly 
heavy at times. Windy.
Mostly cloudy with little temperature change. Precipitation likely possibly 
heavy at times. Windy.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Increasing clouds and cooler. Precipitation possible within 6 hours. Windy.
Increasing clouds with little temperature change. Precipitation possible within 
6 hours. Windy
Increasing clouds and cooler. Precipitation continuing. Windy with possible 
wind shift to the W SW or S.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Mostly cloudy and cooler. Precipitation likely. Windy with possible wind shift 
to the W SW or S.
Mostly cloudy with little temperature change. Precipitation continuing. Windy 
with possible wind shift to the W SW or S.
Mostly cloudy with little temperature change. Precipitation likely. Windy with 
possible wind shift to the W SW or S.
Increasing clouds and cooler. Precipitation possible within 6 hours. Windy with 
possible wind shift to the W SW or S.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Increasing clouds and cooler. Precipitation possible within 6 hours possible 
wind shift to the W SW or S.
Increasing clouds with little temperature change. Precipitation possible within 
6 hours. Windy with possible wind shift to the W SW or S.
Increasing clouds with little temperature change. Precipitation possible within 
6 hours possible wind shift to the W SW or S.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Increasing clouds and cooler. Precipitation possible within 6 hours. Windy with 
possible wind shift to the W SW or S.
Increasing clouds with little temperature change. Precipitation possible within 
6 hours. Windy with possible wind shift to the W SW or S.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Increasing clouds and cooler. Precipitation possible within 12 to 24 hours. 
Windy with possible wind shift to the W SW or S.
Increasing clouds with little temperature change. Precipitation possible within 
12 to 24 hours. Windy with possible wind shift to the W SW or S.
Mostly cloudy and cooler. Precipitation possibly heavy at times and ending 
within 12 hours. Windy with possible wind shift to the W SW or S.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Mostly cloudy and cooler. Precipitation possible within 6 to 12 hours possibly 
heavy at times. Windy with possible wind shift to the W SW or S.
Mostly cloudy with little temperature change. Precipitation ending within 12 
hours. Windy with possible wind shift to the W SW or S.
Mostly cloudy with little temperature change. Precipitation possible within 6 
to 12 hours possibly heavy at times. Windy with possible wind shift to the W SW 
or S.
Mostly cloudy and cooler. Precipitation continuing.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Mostly cloudy and cooler. Precipitation likely. Windy with possible wind shift 
to the W SW or S.
Mostly cloudy with little temperature change. Precipitation continuing.
Mostly cloudy with little temperature change. Precipitation likely.
Partly cloudy with little temperature change.
Mostly clear with little temperature change.
Mostly cloudy and cooler. Precipitation possible within 12 hours possibly heavy 
at times. Windy.
FORECAST REQUIRES 3 HOURS OF RECENT DATA
Mostly clear and cooler.
Mostly clear and cooler.
Mostly clear and cooler.

cheers
____________
Graham Eddy

On 15 Nov 2019, at 8:39 am, PJD <[email protected]> wrote:

I'm trying to write code that will take Davis's forecastRule (a number) and display this on my webpage as text by reading the number off an array and returning the text corresponding to that number.

For example if the Davis forecastRule returned is 5, I want the webpage to display "Partly cloudy and cooler" which is the corresponding forecast in text form.

I'm not sure on the best way to do this but am trying to do it with _javascript_ with instructions to pull the text from an external text file (set up as a JS array) containing the nearly 200 text strings.

I'm getting bogged down with the syntax and would appreciate any help.  Should I be doing it a different way ie not using JS?

I don't know how to declare the variable if the array lives in an external file.

Thanks for any help!

PJD


-- 
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/f562b9c5-c551-45b2-a9a4-25848d847aad%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/AA39F3A2-F63A-4C1E-85FB-ED3A926C4BAC%40gmail.com.

Reply via email to