telebot-ncov/config.js

81 lines
2.1 KiB
JavaScript
Raw Normal View History

2020-02-02 14:00:58 +01:00
const fs = require('fs');
const Markup = require('telegraf/markup');
const Extra = require('telegraf/extra');
2020-02-02 13:52:43 +01:00
const request = require('request');
const regression = require('regression');
2020-02-02 14:00:58 +01:00
//=== TOOL FUNCTIONS
2020-02-02 13:52:43 +01:00
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";
2020-02-02 14:00:58 +01:00
function get_prognostic(i){
2020-02-02 13:52:43 +01:00
return new Promise((resolve, reject)=>{
request(base_url + date_arg + more_arg, function (error, response, body) {
if(response.statusCode == 200){
const cnt = JSON.parse(body);
//console.log('body:',cnt.features); // Print the HTML for the Google homepage.
var data = [[0,0]];
for (var dp of cnt.features) {
if(dp.attributes.Total_Confirmed != null){
data.push([dp.attributes.ObjectId, dp.attributes.Total_Confirmed]);
}
}
var cur_result = regression.polynomial(data, { order: 3 });
2020-02-02 14:00:58 +01:00
resolve(cur_result.predict(cnt.features.length + i))
2020-02-02 13:52:43 +01:00
}else{
reject(error);
}
});
});
}
2020-02-02 14:00:58 +01:00
//=== 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 : []
};
}