added new level system logic

master
cheetah 2 years ago
parent af63266744
commit 965a63a14b

@ -1,32 +1,25 @@
{
"pager": {
"url": "http://127.0.0.1:3000/api/message/advanced",
"params": {
"type": "simple",
"routing": {
"device": "generic",
"connectors": [
[
"dummy",
"1234567"
]
]
}
}
"url": "http://127.0.0.1:3000/api/message/advanced"
},
"germanUmlautSupport": true,
"regions": [
{
"name": "muc",
"name": "Magdeburg",
"active": true,
"dwdID": "mxx",
"_id": "eyJuYW1lIjoibXVjIiwiYWN0aXZlIjp0cnVlLCJkd2RJRCI6Im14eCIsIl9pZCI6ImV5SnVZVzFsSWpvaWJYVmpJaXdpWVdOMGFYWmxJanAwY25WbExDSmtkMlJKUkNJNkltMTRlQ0lzSWw5cFpDSTZJbVY1U25WWlZ6RnNTV3B2YVdKWVZtcEphWGRwV1ZkT01HRllXbXhKYW5Bd1kyNVdiRXhEU210a01sSktVa05KTmtsdE1UUmxRMGx6U1d3NWNGcERTVFpKYlZZMVUyNVdXbFo2Um5OVFYzQjJZVmRLV1ZadGNFcGhXR1J3VjFaa1QwMUhSbGxYYlhoS1lXNUJkMWt5TlZkaVJYaEVVMjEwYTAxc1NrdFZhMDVLVG10c2RFMVVVbXhSTUd4NlUxZDNOV05HY0VSVFZGcEtZbFpaTVZVeU5WZFhiRm8yVW01T1ZGWXpRakpaVm1STFYxWmFkR05GY0doWFIxSjNWakZhYTFRd01VaFNiR3hZWWxob1MxbFhOVUprTVd0NVRsWmthVkpZYUVWVk1qRXdZVEF4YzFOcmRGWmhNRFZMVkcxMGMyUkZNVlZWYlhoU1RVZDRObFV4WkROT1YwNUhZMFZTVkZaR2NFdFpiRnBhVFZaVmVVNVdaRmhpUm04eVZXMDFUMVpHV1hwUmFrcGFWbTFTVEZZeFdtRmtSMDVHWTBkb1dGSXhTak5XYWtaaFlURlJkMDFWYUZOaVIzaFpXV3hvYjFNeGJGaE9WVXByVFZkME5WUnNXbXRoVmtwWllVVldWazFxUlhkWlZFRjRZekZPY21SR1dtaE5S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yV2s5VGJVMTNZa2hTVTJKWVFuSlZha296WlZaa2MxUnJjRTlpVmtwS1ZUSndSMWxXVlhwYVNFSllZVEpvY2xsVVJrOVdiRlpZWWtaQ2FGWllRWGxXTVZwclRUSkdXRmRzU2xGV1JFSndXbXhGT1ZCVFNqa2lmUT09In0="
"dwdID": "mdx",
"preset": "184d015919c",
"levels": {
"wind_storm": 1,
"thunderstorm": 1,
"rain1": 2,
"rain2": 2,
"snow": 1,
"ice": 666,
"frost": 1,
"fog": 1,
"other": 0
}
}
]
}

@ -193,6 +193,12 @@
{ text: 'Level 1', value: 1 },
]
},
{ n: 1, k: 'Andere Warnmeldungen', u: 'other',
i: [
{ text: 'ignore', value: 666 },
{ text: 'allow', value: 0 },
]
},
],
}
},
@ -224,6 +230,10 @@
},
storeConfig() {
const storeConfig = JSON.parse(JSON.stringify(this.configData))
storeConfig.regions = storeConfig.regions.map((x) => {
delete x._id
return x
})
this.$http.post('/config', storeConfig).then(response => {
})
.then(this.$http.post('/restart'))

@ -31,6 +31,17 @@ const umlautMapIntl = {
'\u00df': 'ss',
}
function itnlUmlaute(str) {
let umlautMap = umlautMapIntl
return str
.replace(/[\u00dc|\u00c4|\u00d6][a-z]/g, (a) => {
const big = umlautMap[a.slice(0, 1)];
return big.charAt(0) + big.charAt(1).toLowerCase() + a.slice(1);
})
.replace(new RegExp('['+Object.keys(umlautMap).join('|')+']',"g"),
(a) => umlautMapIntl[a]
);
}
function replaceUmlaute(str) {
let umlautMap = config.germanUmlautSupport
? umlautMapGermany
@ -56,6 +67,33 @@ async function sendPage(preset, payload) {
} catch (e) {}
}
function analyzeCategory(txt) {
//console.log('analyzing text', txt)
if (txt.indexOf('WINDBOEN')>-1) return 'wind_storm'
if (txt.indexOf('STURMBOEN')>-1) return 'wind_storm'
if (txt.indexOf('ORKANBOEN')>-1) return 'wind_storm'
if (txt.indexOf('STARKREGEN')>-1) return 'rain1'
if (txt.indexOf('DAUERREGEN')>-1) return 'rain2'
if (txt.indexOf('GEWITTER')>-1) return 'thunderstorm'
if (txt.indexOf('SCHNEE')>-1) return 'snow'
if (txt.indexOf('FROST')>-1) return 'frost'
if (txt.indexOf('GLATTE')>-1) return 'ice'
if (txt.indexOf('NEBEL')>-1) return 'fog'
return 'none'
}
function analyzeLevel(txt) {
if (txt.indexOf('STUFE 1 VON ')>-1) return 1
if (txt.indexOf('STUFE 2 VON ')>-1) return 2
if (txt.indexOf('STUFE 3 VON ')>-1) return 3
if (txt.indexOf('STUFE 4 VON ')>-1) return 4
return 0
}
async function checkDWD() {
for (region of config.regions) {
if (!region.active) continue
@ -65,6 +103,14 @@ async function checkDWD() {
rssData.entries.sort((a,b) => new Date(b.published).valueOf() - new Date(a.published).valueOf())
if (rssData.entries.length > 0) {
msg = rssData.entries[0].description
const msgCategory = analyzeCategory(itnlUmlaute(msg.toUpperCase()))
const msgLevel = analyzeLevel(itnlUmlaute(msg.toUpperCase()))
//console.log('type', msgCategory, 'level', msgLevel)
const msgLevelTrigger = !!region.levels[msgCategory]
? region.levels[msgCategory]
: 0
//console.log(msgLevelTrigger, 'is the trigger level for', msgCategory)
if (msgLevel >= msgLevelTrigger) { } else continue // ignore the stuff we want to ignore
msg = msg.replace('DWD WETTERWARNUNG:', 'DWD:')
msg = msg.replace(' in ', ' ')
msg = msg.replace(' von ', '/')

Loading…
Cancel
Save