Privacywonk / MMM-Surf

MagicMirror module that pulls in tide, water temp, and Magicseaweed data to show an at-a-glance surf report for your favorite spot.
Other
5 stars 2 forks source link

Forecast Table #2

Closed Privacywonk closed 6 years ago

Privacywonk commented 6 years ago

Current magicseaweed forecast is hard coded to display 10am forecast. Need to identify a way to rank attributes of the forecast and pick the best forecast area.

Privacywonk commented 6 years ago

If swellCompassDirection = config Swell = +1 if swellHeight = between config swell min + max = +1 if wind direction = config wind = +1 if wind speed <= 15mph = +1 if Multiple swell count is 2 or less = +1 if solid rating = +1 for each star

if wind direction = opposite of config wind (e.g. onshore): -1 if wind speed >= 15mph -1 if wind Gusts >=20mph -1

Compute the score and stick it back in the array against each forecast line

Loop the array and find the highest score per day.

If all scores are 0 or tied, display 10am

Privacywonk commented 6 years ago

Implemented with following code:

                var forecastScore = 0;
                if (data[i].solidRating > 0) {forecastScore = data[i].solidRating;}
                if (data[i].swell.components.primary.height >= this.config.spotSwellMin && data[i].swell.components.primary.height <= this.config.spotSwellMax) {forecastScore++;}
                if (data[i].swell.components.primary.period >=8) {forecastScore++;}
                for (z = 0, countz = this.config.spotSwellHold.length; z < countz; z++) {
                        if (this.config.spotSwellHold[z] == data[i].swell.components.primary.compassDirection) {forecastScore++;}
                }
                for (x = 0, countx = this.config.spotWind.length; x < countx; x++) {
                        if (this.config.spotWind[x] == data[i].wind.compassDirection) {forecastScore++;}
                }
                if (Object.keys(data[i].swell.components).length <=2) {forecastScore++;}
                if (data[i].wind.speed < 15) {forecastScore++;}
                if (data[i].wind.speed >= 15) {forecastScore--;}
                if (data[i].wind.gusts >= 20) {forecastScore--;}
                if (moment.unix(data[i].localTimestamp).format('HH') == 01 ||
                        moment.unix(data[i].localTimestamp).format('HH') == 19 ||
                        moment.unix(data[i].localTimestamp).format('HH') == 22) {forecastScore--;} //Penalizes times that are generally unsurfable (1am, 7pm, 10pm)
                data[i].forecastScore = forecastScore;
                data[i].forecastDay = moment.unix(data[i].localTimestamp).format('ddd');