{"size": 3559, "ext": "js", "max_stars_repo_path": "app.js", "max_stars_repo_name": "ManojNallusamy/COVID19-WEB", "max_stars_repo_stars_event_min_datetime": "2020-05-27T10:06:43.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-12T06:32:54.000Z", "max_issues_repo_path": "app.js", "max_issues_repo_name": "ManojNallusamy/COVID19-WEB", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app.js", "max_forks_repo_name": "ManojNallusamy/COVID19-WEB", "max_forks_repo_forks_event_min_datetime": "2020-05-16T18:08:58.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-30T10:18:44.000Z"}
{"max_stars_count": 10, "max_issues_count": null, "max_forks_count": 6, "avg_line_length": 31.7767857143, "max_line_length": 135, "alphanum_fraction": 0.5833099185}
var express = require("express"),
    app=express(),
    request = require("request"),
    mongoose= require("mongoose")
    cron=require('cron');


app.set("view engine","ejs");
app.use(express.static("public"));

//DB connect
// mongoose.connect("mongodb://localhost:27017/covid_app",{useNewUrlParser: true , useUnifiedTopology: true});
uri = //provide your url for mongodbatlas bucket;
mongoose
     .connect( uri, { useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true })
     .then(() => console.log( 'Database Connected' ))
     .catch(err => console.log( err ));
var statewise = require("./models/statewise");
var dailydata = require("./models/dailydata");
var global = require("./models/global");
//load india data
//load district data
var districtdata
request("https://api.covid19india.org/v2/state_district_wise.json",(error,response,body)=>{
    if(!error && response.statusCode == 200)
    {
        districtdata = body;
    }
})
var loadstatewise = require("./seeds");
var updatetime = new Date().toLocaleString("en-US", {timeZone: "Asia/Kolkata"});
updatetime = new Date(updatetime);
day=updatetime.getDate();
mnth=updatetime.getMonth();
var month=['Jan','Feb','Mar','Apr','May','June','July','Aug','Sept','Oct','Nov','Dec'];
updatetime = updatetime.toLocaleTimeString();
// loadstatewise();
// load
var st,dt;
setTimeout(()=>{
    updatetime =  new Date().toLocaleString("en-US", {timeZone: "Asia/Kolkata"});
    updatetime = new Date(updatetime);
    updatetime = updatetime.toLocaleTimeString();
    loadstatewise();
    st=undefined;
    dt=undefined;
},1000*60*5);
setInterval(()=>{
    updatetime =  new Date().toLocaleString("en-US", {timeZone: "Asia/Kolkata"});
    updatetime = new Date(updatetime);
    updatetime = updatetime.toLocaleTimeString();
    loadstatewise();
    st=undefined;
    dt=undefined;
},1000*60*60*2);
var dailyarr=[],mean=0;
app.get("/",(req,res)=>{
    if(!st || !dt)
    {
        mean=0;
        dailyarr=[]
        statewise.find({},(err,statedata)=>{
            dailydata.find({},(err,daily)=>{
                // console.log(statedata)
                st=statedata;
                daily.sort((a,b)=>{ 
                    return new Date(a["date"])- new Date(b["date"]); 
                   }) 
                dt=daily;   
                daily.forEach((res)=>{
                    dailyarr.push(res['confirmed']);
                })
                first=dailyarr.length-10;
                for(i=first;i<dailyarr.length;i++)
                {
                    mean+=dailyarr[i]/dailyarr[i-1];
                }
                mean=mean/10;
                console.log(mean)
                res.render("index",{mean: mean,statedata: statedata, daily: JSON.stringify(daily),time: [updatetime,day,month[mnth]]});
                console.log("Index page served.");
            });
        });
    }
    if(st && dt)
    {
        res.render("index",{mean: mean,statedata: st, daily: JSON.stringify(dt),time: [updatetime,day,month[mnth]]});
        console.log("Index page served.");
    }
});   

app.get("/global",(req,res)=>{
    console.log("Global page served.");
    res.render("global");
})


app.get("/district",(req,res)=>{
    console.log("State page served.")
    res.render("district",{data:JSON.parse(districtdata)});
})
app.get("/info",(req,res)=>{
    console.log("Info page served")
    res.render("info");
})
let port = process.env.PORT;
if (port == null || port == "") {
  port = 4000;
}    
app.listen(port,()=>{
    console.log("Covid App Server Started!!!");
})    