DEV Community

loading...
Cover image for COVID-19 Prediction Charts

COVID-19 Prediction Charts

loouislow profile image Loouis Low Updated on ・3 min read

Content from this website is STRICTLY ONLY for educational and research purposes and may contain errors. The model and data are inaccurate to the complex, evolving, and heterogeneous realities of different countries. Predictions are uncertain by nature. Readers must take any predictions with caution. Over-optimism based on some predicted end dates is dangerous because it may loosen our disciplines and controls and cause the turnaround of the virus and infection, and must be avoided.


I created this project in the earlier April 2020, it's a Python CLI terminal application that predicting COVID-19 infected cases, deaths, and active cases based on raw dataset scraped from the worldometers.info website.

I also made a website to showcase these charts including both linear and logarithmic.

My Github repository page.

Setup

Let's clone a repository at Github,

$ git clone https://github.com/loouislow81/covid19-trend-predictor.git
$ cd covid19-trend-predictor
Enter fullscreen mode Exit fullscreen mode

Without make dirty of your host system, we use the Python virtual environment to encapsulate the project files and ton of necessary dependency modules that we will need to install in order for this application to run properly.

$ virtualenv -p python3 venv
$ source venv/bin/activate
$ (venv) pip install -r requirements.txt --default-timeout=1000
Enter fullscreen mode Exit fullscreen mode

Usage

Before anything else, you will need to add the country name that you want in the configure.py file, like in the example below,

...
countries = [
    "China", "Hong Kong", "Indonesia",
    "Japan", "Malaysia", "Philippines",
    "Singapore", "S. Korea", "Taiwan",
    "Thailand"
]
...
Enter fullscreen mode Exit fullscreen mode

Dataset

And then, we will proceed next to generate a new dataset with the following commands. You choose which one to go generate, one by one.

The generated raw dataset is located in the ./raw_dataset directory with separated cases, deaths, and infected directories,

# generate `cases` datasets
$ (venv) scrapy runspider --nolog cases_dataset.py -o raw_dataset/countries.csv -t csv

# generate `deaths` datasets
$ (venv) scrapy runspider --nolog deaths_dataset.py -o raw_dataset/countries.csv -t csv

# generate `infected` (active cases) datasets
$ (venv) scrapy runspider --nolog infected_dataset.py -o raw_dataset/countries.csv -t csv
Enter fullscreen mode Exit fullscreen mode

Predict

Run predict_model.py with examples below to generate the prediction charts either in linear or logarithmic versions.

# usage

# <model_name> is either `cases`, `deaths` or `infected`
$ predict_model.py -h [-m|--model] <model_name> [-c|--chart] <linear|logarithm> [-d|--day] <day>

# examples

# without args, the default is set to cases model, linear chart and 90 days
$ (venv) python predict_model.py --model cases --chart linear --day 60
$ (venv) python predict_model.py -m cases -c linear -d 60
Enter fullscreen mode Exit fullscreen mode

Results

The generated prediction charts are located in the ./results/ directory with separated directories, such as cases, deaths, and infected.

Web

The website URL to showcase the charts https://covid19-90days-prediction-charts.netlify.app.

Run these commands below to compile and serve the website to run locally on your system.

# move generated charts into `./web/assets/image/` directory.
$ (venv) bash move_to_web.sh

# set up Krugurt.js frontend project
$ (venv) cd web
$ (venv)(web) npm install
$ (venv)(web) npm run build-prod
$ (venv)(web) npm run serve
Enter fullscreen mode Exit fullscreen mode

Screenshots

The Frontend

Visit Website

Alt Text

The Backend

Alt Text

Alt Text


Thank you for reading this article. Please heart or unicorn would encourage me to write more about this kind of article next time.

Discussion (0)

pic
Editor guide