From 01bfd76e847e3e3b0452e1a1d7e61228c19a001a Mon Sep 17 00:00:00 2001 From: CH Date: Sun, 2 Feb 2020 14:00:58 +0100 Subject: [PATCH] new code --- index.js => config.js | 56 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 3 deletions(-) rename index.js => config.js (53%) diff --git a/index.js b/config.js similarity index 53% rename from index.js rename to config.js index e03f366..a770274 100644 --- a/index.js +++ b/config.js @@ -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 : [] + }; + + + +} \ No newline at end of file