This commit is contained in:
CH 2020-02-02 14:00:58 +01:00
parent a4dae5342e
commit 01bfd76e84

View File

@ -1,14 +1,18 @@
const fs = require('fs');
const Markup = require('telegraf/markup');
const Extra = require('telegraf/extra');
const request = require('request');
const regression = require('regression');
//=== TOOL FUNCTIONS
const old_url = 'https://gisanddata.maps.arcgis.com/sharing/rest/content/items/bda7594740fd40299423467b48e9ecf6/data?f=json';
const base_url = "https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/cases_time/FeatureServer/0/query?f=json";
const date_arg = "&where=Report_Date%3C%3D%272020-02-02 22:59:59%27";
const more_arg = "&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&orderByFields=Report_Date%20asc&resultOffset=0&resultRecordCount=2000&cacheHint=true";
module.exports = function(){
function get_prognostic(i){
return new Promise((resolve, reject)=>{
request(base_url + date_arg + more_arg, function (error, response, body) {
@ -22,10 +26,56 @@ module.exports = function(){
}
}
var cur_result = regression.polynomial(data, { order: 3 });
resolve(cur_result.predict(cnt.features.length))
resolve(cur_result.predict(cnt.features.length + i))
}else{
reject(error);
}
});
});
}
//=== MAIN MODULE CONFIG
module.exports = function(url){
this.url = url;
return {
name : "Ncov Predictor",
key : 'ncovp',
version : 0.1,
requirements : {
gps: false,
},
text : [
{
trigger : ["/corona"],
public : true,
desc : {
0: "Computes prediction of viral spread",
},
requirements : (bot,event,message)=>{
return new Promise((resolve, reject)=>{
return resolve(200);
});
},
action : (bot,event,message)=>{
return get_prognostic(0).then(val =>{
return event.replyWithMarkdown({'*We expect a total of '+val[1]+' infected people in the next 24 hours');
});
}
},
],
reply : [],
regex : [],
media : [],
callback : [],
inline : [],
new_member : (bot,event)=>{},
weburl : [],
cron : []
};
}