commit a4dae5342e6bc9c4490d20c0db79a66f5998a8a2 Author: CH Date: Sun Feb 2 13:52:43 2020 +0100 mv diff --git a/index.js b/index.js new file mode 100644 index 0000000..e03f366 --- /dev/null +++ b/index.js @@ -0,0 +1,31 @@ + +const request = require('request'); +const regression = require('regression'); + +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(){ + 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 }); + resolve(cur_result.predict(cnt.features.length)) + }else{ + reject(error); + } + }); + }); +}