~humaid/areweherdimmuneyet

13d059c10f2b21edb8a1ae2098997ab601d2f92c — Humaid AlQassimi 15 days ago 2b119f4
Use Our World in Data's dataset and fully vaccinated goal

We now use the fully vaccinated figure rather than doses. Also we
remove Nix files.
8 files changed, 44 insertions(+), 494 deletions(-)

M .gitignore
D data.csv
D info.txt
M main.py
M make.sh
D python-packages.nix
D shell.nix
M template.html
M .gitignore => .gitignore +1 -0
@@ 1,3 1,4 @@
public/
chart.svg
index.html
data.csv

D data.csv => data.csv +0 -164
@@ 1,164 0,0 @@
Date,Doses
2021-01-5,8.35
2021-01-6,8.35
2021-01-7,8.98
2021-01-8,9.52
2021-01-9,10.32
2021-01-10,10.99
2021-01-11,11.80
2021-01-12,12.90
2021-01-13,14.10
2021-01-14,15.45
2021-01-15,16.84
2021-01-16,18.18
2021-01-17,19.04
2021-01-18,19.93
2021-01-19,20.88
2021-01-20,21.85
2021-01-21,22.71
2021-01-22,23.65
2021-01-23,24.54
2021-01-24,25.15
2021-01-25,26
2021-01-26,27.07
2021-01-27,27.95
2021-01-28,29
2021-01-29,30.4
2021-01-30,31.49
2021-01-31,33.71
2021-02-01,34.79
2021-02-02,36.04
2021-02-03,37.32
2021-02-04,38.92
2021-02-05,40.53
2021-02-06,42.48
2021-02-07,43.62
2021-02-08,44.63
2021-02-09,45.77
2021-02-10,47.37
2021-02-11,48.45
2021-02-12,49.56
2021-02-13,50.61
2021-02-14,51.11
2021-02-15,51.43
2021-02-16,52.56
2021-02-17,53.43
2021-02-18,54.33
2021-02-19,55.27
2021-02-20,56.15
2021-02-21,56.16
2021-02-22,56.19
2021-02-23,57.31
2021-02-24,58.25
2021-02-25,59.11
2021-02-26,59.99
2021-02-27,60.82
2021-02-28,60.87
2021-03-01,60.95
2021-03-02,61.62
2021-03-03,62.37
2021-03-04,62.73
2021-03-05,63.04
2021-03-06,63.35
2021-03-07,63.43
2021-03-08,63.57
2021-03-09,63.95
2021-03-10,64.38
2021-03-11,64.78
2021-03-12,65.35
2021-03-13,65.89
2021-03-14,66.13
2021-03-15,66.52
2021-03-16,67.43
2021-03-17,69.06
2021-03-18,70.58
2021-03-19,72.03
2021-03-20,72.61
2021-03-21,73.8
2021-03-22,74.56
2021-03-23,75.61
2021-03-24,76.88
2021-03-25,78.16
2021-03-26,78.86
2021-03-27,80.48
2021-03-28,81.71
2021-03-29,82.24
2021-03-30,83.12
2021-03-31,84.01
2021-04-02,85.85
2021-04-03,86.54
2021-04-04,86.74
2021-04-05,86.92
2021-04-06,87.55
2021-04-07,88.04
2021-04-08,89.88
2021-04-09,90.22
2021-04-10,90.74
2021-04-11,91.05
2021-04-12,91.38
2021-04-13,92.58
2021-04-14,93.98
2021-04-15,94.91
2021-04-16,95.95
2021-04-17,97.08
2021-04-18,97.37
2021-04-19,97.82
2021-04-20,98.97
2021-04-21,100.1
2021-04-22,101.2
2021-04-23,102.19
2021-04-24,103.07
2021-04-25,103.29
2021-04-26,103.68
2021-04-27,104.51
2021-04-28,105.23
2021-04-29,105.82
2021-04-30,106.64
2021-05-01,107.28
2021-05-02,107.53
2021-05-03,107.85
2021-05-04,108.99
2021-05-05,109.55
2021-05-06,110.28
2021-05-07,111.71
2021-05-08,112.5
2021-05-09,112.69
2021-05-10,113.1
2021-05-11,113.98
2021-05-12,114.93
2021-05-13,115.49
2021-05-14,115.73
2021-05-15,115.75
2021-05-16,115.78
2021-05-17,116.17
2021-05-18,117.23
2021-05-19,118.34
2021-05-20,119.53
2021-05-21,120.76
2021-05-22,121.68
2021-05-23,122.39
2021-05-24,123.01
2021-05-25,124.31
2021-05-26,125.53
2021-05-27,126.71
2021-05-28,127.86
2021-05-29,128.98
2021-05-30,129.53
2021-05-31,130.13
2021-06-01,131.11
2021-06-02,132.11
2021-06-03,133
2021-06-04,133.74
2021-06-05,134.41
2021-06-06,134.63
2021-06-07,134.95
2021-06-08,135.6
2021-06-09,136.58
2021-06-10,137.41
2021-06-11,138.36
2021-06-12,139.38
2021-06-13,139.61
2021-06-14,140.02
2021-06-15,141.19
2021-06-16,142.24
2021-06-17,143.39

D info.txt => info.txt +0 -1
@@ 1,1 0,0 @@
UAE population according to NCEMA: 9,889,700

M main.py => main.py +27 -58
@@ 3,26 3,37 @@ import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import sys
import math
from datetime import date, timedelta, datetime
import requests
from quik import FileLoader

# Doses goal for calculations
EFFICACY = 0.86
DOSES_GOAL = 120 + ((1-EFFICACY)*200)
print(DOSES_GOAL)
UAE_POP = 9890620
R0 = 6.5
GOAL = (1 - (1/R0))*100
print("goal", GOAL)

dataset = pd.read_csv('data.csv')
owid = pd.read_csv('data.csv')

dat = [ ] 

for index, row in owid.iterrows():
    fully = row['people_fully_vaccinated']
    if not math.isnan(fully):
        dat.append([row['date'], (fully/UAE_POP)*100])

dataset = pd.DataFrame(dat, columns=['Date', 'Percentage'])
dataset['Date'] = pd.to_datetime(dataset['Date'])

x = mdates.date2num(pd.Index(dataset.Date).to_pydatetime())
y = dataset['Doses']
y = dataset['Percentage']


def get_herd_immunity():
    model = np.poly1d(np.polyfit(x, y, 2))
    x0 = (model - DOSES_GOAL).roots
    # print(mdates.num2date(x0[0]), mdates.num2date(x[1]))
    x0 = (model - GOAL).roots
    #print(mdates.num2date(x0[0]), mdates.num2date(x[1]))
    return (model, mdates.num2date(x0[1]))




@@ 36,8 47,7 @@ def gen_html(estimate):
         'goalMs': round(estimate.timestamp()),
         'today': date.today().strftime("%d %B"),
         'ver': round(datetime.now().timestamp()),
         'goal': DOSES_GOAL,
         'perc': int((DOSES_GOAL/200)*100)},
         'goal': int(GOAL)},
        loader=loader).encode('utf-8')
    f = open("index.html", "w")
    f.write(res.decode("utf-8"))


@@ 60,7 70,7 @@ def gen_img():
    fig.set_facecolor("#fafafa")

    dayloc = mdates.DayLocator()
    fdloc = mdates.DayLocator(interval=5)
    fdloc = mdates.DayLocator(interval=15)
    maj_fmt = mdates.DateFormatter('%-d %b')
    ax.xaxis.set_major_formatter(maj_fmt)
    ax.xaxis.set_major_locator(fdloc)


@@ 69,64 79,23 @@ def gen_img():
    ax.grid(True)
    ax.grid(b=True, which="minor")

    plt.plot(dataset.Date, y, label="Inoculations per 100 people",
    plt.plot(dataset.Date, y, label="People fully vaccinated",
             color="tab:green")
    plt.plot(myline, model(myline), label="Estimate (polynomial regression)",
             linestyle=":", color="tab:orange")
    plt.plot(mdates.date2num(estimate), DOSES_GOAL, 'g*',
             label="Estimated Goal (120 doses)")
    plt.text(mdates.date2num(estimate)-15, DOSES_GOAL-2, "("+estimate_txt+")")
    plt.ylabel('Doses')
    plt.plot(mdates.date2num(estimate), GOAL, 'g*',
            label="Estimated Goal ("+str(int(GOAL))+"%)")
    plt.text(mdates.date2num(estimate)-15, GOAL-2, "("+estimate_txt+")")
    plt.ylabel('Percentage')
    plt.xlabel('Date')
    plt.title('COVID-19 Vaccine Doses per 100')
    plt.title('People Fully Vaccinated')
    plt.legend()

    # horizontal line
    # plt.axhline(y=DOSES_GOAL, color='r', linestyle=':')

    ax.tick_params(axis='x', which='both', labelsize=5)
    plt.savefig('chart.svg')

    print("We will reach herd immunity at: " + estimate_txt)
    gen_html(estimate)


def pull_data():
    api = "http://covid19.ncema.gov.ae/ar/Home/InitializeDosesLineChart"
    params = dict(
            Year=0,
            Month=0,
            Type="LatestTenDays",
            screenWidth=1080,
    )

    resp = requests.post(url=api, json=params, verify=False)
    data = resp.json()
    dataset = data['ChartDataSets'][0]["data"]
    latest_doses = dataset[len(dataset)-1]

    d = date.today().strftime("%Y-%m-%d")
    entry = d+","+latest_doses
    print(entry)
    conf = input("Do you want to add this entry (y/n)? ")
    if conf == "y":
        f = open("data.csv", "a")
        f.write(entry+"\n")
        f.close()
        gen_img()


def main():
    if len(sys.argv) == 1:
        print("usage: ./awhiy <OPTION>\n")
        print("OPTIONS:")
        print("\tgen: generate a new graph image (SVG)")
        print("\tpull: pull latest vaccine doses entry from NCEMA")
    if sys.argv[1] == "gen":
        gen_img()
    elif sys.argv[1] == "pull":
        pull_data()


if __name__ == "__main__":
    main()
    gen_img()

M make.sh => make.sh +6 -0
@@ 1,4 1,10 @@
#!/bin/sh
wget \
	https://raw.githubusercontent.com/owid/covid-19-data/master/public/data/vaccinations/country_data/United%20Arab%20Emirates.csv \
	-O data.csv


python3 main.py
minify index.html > public/index.html
minify chart.svg > public/chart.svg
scp -P 2202 public/* root@duisk:/var/www/herd/

D python-packages.nix => python-packages.nix +0 -250
@@ 1,250 0,0 @@
# Generated by pip2nix 0.8.0.dev1
# See https://github.com/nix-community/pip2nix

{ pkgs, fetchurl, fetchgit, fetchhg }:

self: super: {
  "certifi" = super.buildPythonPackage rec {
    pname = "certifi";
    version = "2020.12.5";
    src = fetchurl {
      url = "https://files.pythonhosted.org/packages/5e/a0/5f06e1e1d463903cf0c0eebeb751791119ed7a4b3737fdc9a77f1cdfb51f/certifi-2020.12.5-py2.py3-none-any.whl";
      sha256 = "0c4qsp7q10hhiryvl6dyxsfh9r1mpja8sfkzri2bvf9kkvxp96ki";
    };
    format = "wheel";
    doCheck = false;
    buildInputs = [];
    checkInputs = [];
    nativeBuildInputs = [];
    propagatedBuildInputs = [];
  };
  "chardet" = super.buildPythonPackage rec {
    pname = "chardet";
    version = "3.0.4";
    src = fetchurl {
      url = "https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl";
      sha256 = "14b621614q2lw7ik2igdv4qdbblqgdsiglgl5fhf1l5fmvy3ycpw";
    };
    format = "wheel";
    doCheck = false;
    buildInputs = [];
    checkInputs = [];
    nativeBuildInputs = [];
    propagatedBuildInputs = [];
  };
  "cycler" = super.buildPythonPackage rec {
    pname = "cycler";
    version = "0.10.0";
    src = fetchurl {
      url = "https://files.pythonhosted.org/packages/f7/d2/e07d3ebb2bd7af696440ce7e754c59dd546ffe1bbe732c8ab68b9c834e61/cycler-0.10.0-py2.py3-none-any.whl";
      sha256 = "0bfb10mrib6f2rrw6iy6xq595n1a4f0ya4c87swzjp3czzhmm2hx";
    };
    format = "wheel";
    doCheck = false;
    buildInputs = [];
    checkInputs = [];
    nativeBuildInputs = [];
    propagatedBuildInputs = [
      self."six"
    ];
  };
  "idna" = super.buildPythonPackage rec {
    pname = "idna";
    version = "2.10";
    src = fetchurl {
      url = "https://files.pythonhosted.org/packages/a2/38/928ddce2273eaa564f6f50de919327bf3a00f091b5baba8dfa9460f3a8a8/idna-2.10-py2.py3-none-any.whl";
      sha256 = "1h280sli58v5dapmf79rnnqdrrk0xjn8vi3pxppknllv3r5q0zdr";
    };
    format = "wheel";
    doCheck = false;
    buildInputs = [];
    checkInputs = [];
    nativeBuildInputs = [];
    propagatedBuildInputs = [];
  };
  "kiwisolver" = super.buildPythonPackage rec {
    pname = "kiwisolver";
    version = "1.3.1";
    src = fetchurl {
      url = "https://files.pythonhosted.org/packages/90/55/399ab9f2e171047d28933ae4b686d9382d17e6c09a01bead4a6f6b5038f4/kiwisolver-1.3.1.tar.gz";
      sha256 = "0j722s7y2yg9mhbv4n7c6f23lnjx6kwj20xils1ldnd826cij2lm";
    };
    format = "setuptools";
    doCheck = false;
    buildInputs = [];
    checkInputs = [];
    nativeBuildInputs = [];
    propagatedBuildInputs = [];
  };
  "matplotlib" = super.buildPythonPackage rec {
    pname = "matplotlib";
    version = "3.3.3";
    src = fetchurl {
      url = "https://files.pythonhosted.org/packages/7b/b3/7c48f648bf83f39d4385e0169d1b68218b838e185047f7f613b1cfc57947/matplotlib-3.3.3.tar.gz";
      sha256 = "1v5xwk8amb9b8lx383yy0mgkvzbnfh9d7c4arzjykky4frj0rdmi";
    };
    format = "setuptools";
    doCheck = false;
    buildInputs = [];
    checkInputs = [];
    nativeBuildInputs = [];
    propagatedBuildInputs = [
      self."cycler"
      self."kiwisolver"
      self."numpy"
      self."pillow"
      self."pyparsing"
      self."python-dateutil"
    ];
  };
  "numpy" = super.buildPythonPackage rec {
    pname = "numpy";
    version = "1.19.4";
    src = fetchurl {
      url = "https://files.pythonhosted.org/packages/c5/63/a48648ebc57711348420670bb074998f79828291f68aebfff1642be212ec/numpy-1.19.4.zip";
      sha256 = "04h5af0v376vk5gs07k2vf7cr4yiajcjhx875dzrrf0a62iw67hl";
    };
    format = "setuptools";
    doCheck = false;
    buildInputs = [];
    checkInputs = [];
    nativeBuildInputs = [
      pkgs."unzip"
    ];
    propagatedBuildInputs = [];
  };
  "pandas" = super.buildPythonPackage rec {
    pname = "pandas";
    version = "1.1.4";
    src = fetchurl {
      url = "https://files.pythonhosted.org/packages/09/39/fb93ed98962d032963418cd1ea5927b9e11c4c80cb1e0b45dea769d8f9a5/pandas-1.1.4.tar.gz";
      sha256 = "1dp3dm788zc7nkdiqqw838vlbpa5dhjfcyga9nan6p0k9d0d0yd9";
    };
    format = "setuptools";
    doCheck = false;
    buildInputs = [];
    checkInputs = [];
    nativeBuildInputs = [];
    propagatedBuildInputs = [
      self."numpy"
      self."python-dateutil"
      self."pytz"
    ];
  };
  "pillow" = super.buildPythonPackage rec {
    pname = "pillow";
    version = "8.2.0";
    src = fetchurl {
      url = "https://files.pythonhosted.org/packages/21/23/af6bac2a601be6670064a817273d4190b79df6f74d8012926a39bc7aa77f/Pillow-8.2.0.tar.gz";
      sha256 = "1qf3bz1sfz58ff6hclg8phgqyy210x3aqdk5yzjr8m5vsw8ap1x7";
    };
    format = "setuptools";
    doCheck = false;
    buildInputs = [];
    checkInputs = [];
    nativeBuildInputs = [];
    propagatedBuildInputs = [];
  };
  "pyparsing" = super.buildPythonPackage rec {
    pname = "pyparsing";
    version = "2.4.7";
    src = fetchurl {
      url = "https://files.pythonhosted.org/packages/8a/bb/488841f56197b13700afd5658fc279a2025a39e22449b7cf29864669b15d/pyparsing-2.4.7-py2.py3-none-any.whl";
      sha256 = "12y8xwjb118a4jqvvfg9k90kqg03n4d3ygb5csz0l81wxy4pb7gg";
    };
    format = "wheel";
    doCheck = false;
    buildInputs = [];
    checkInputs = [];
    nativeBuildInputs = [];
    propagatedBuildInputs = [];
  };
  "python-dateutil" = super.buildPythonPackage rec {
    pname = "python-dateutil";
    version = "2.8.1";
    src = fetchurl {
      url = "https://files.pythonhosted.org/packages/d4/70/d60450c3dd48ef87586924207ae8907090de0b306af2bce5d134d78615cb/python_dateutil-2.8.1-py2.py3-none-any.whl";
      sha256 = "0answacgnckybm5iyfnaqsgval3mdbpak4i6fsbi2vv8x8qkzfvm";
    };
    format = "wheel";
    doCheck = false;
    buildInputs = [];
    checkInputs = [];
    nativeBuildInputs = [];
    propagatedBuildInputs = [
      self."six"
    ];
  };
  "pytz" = super.buildPythonPackage rec {
    pname = "pytz";
    version = "2021.1";
    src = fetchurl {
      url = "https://files.pythonhosted.org/packages/70/94/784178ca5dd892a98f113cdd923372024dc04b8d40abe77ca76b5fb90ca6/pytz-2021.1-py2.py3-none-any.whl";
      sha256 = "1607gl2x9290ks5sa6dvqw9dgg1kwdf9fj9xcb9jw19nfwzcw47b";
    };
    format = "wheel";
    doCheck = false;
    buildInputs = [];
    checkInputs = [];
    nativeBuildInputs = [];
    propagatedBuildInputs = [];
  };
  "quik" = super.buildPythonPackage rec {
    pname = "quik";
    version = "0.2.2";
    src = ./../../../.cache/pip/wheels/dd/73/9c/58a6fb92510ea486e85b0c09c8da49e6b61b82a3288b04b4e8/quik-0.2.2-py3-none-any.whl;
    format = "wheel";
    doCheck = false;
    buildInputs = [];
    checkInputs = [];
    nativeBuildInputs = [];
    propagatedBuildInputs = [];
  };
  "requests" = super.buildPythonPackage rec {
    pname = "requests";
    version = "2.24.0";
    src = fetchurl {
      url = "https://files.pythonhosted.org/packages/45/1e/0c169c6a5381e241ba7404532c16a21d86ab872c9bed8bdcd4c423954103/requests-2.24.0-py2.py3-none-any.whl";
      sha256 = "165qrd22rm0fp23kzfdc6qy12jv0fm7j4jbhzi394fs4m6acqxgy";
    };
    format = "wheel";
    doCheck = false;
    buildInputs = [];
    checkInputs = [];
    nativeBuildInputs = [];
    propagatedBuildInputs = [
      self."certifi"
      self."chardet"
      self."idna"
      self."urllib3"
    ];
  };
  "six" = super.buildPythonPackage rec {
    pname = "six";
    version = "1.16.0";
    src = fetchurl {
      url = "https://files.pythonhosted.org/packages/d9/5a/e7c31adbe875f2abbb91bd84cf2dc52d792b5a01506781dbcf25c91daf11/six-1.16.0-py2.py3-none-any.whl";
      sha256 = "0m02dsi8lvrjf4bi20ab6lm7rr6krz7pg6lzk3xjs2l9hqfjzfwa";
    };
    format = "wheel";
    doCheck = false;
    buildInputs = [];
    checkInputs = [];
    nativeBuildInputs = [];
    propagatedBuildInputs = [];
  };
  "urllib3" = super.buildPythonPackage rec {
    pname = "urllib3";
    version = "1.25.11";
    src = fetchurl {
      url = "https://files.pythonhosted.org/packages/56/aa/4ef5aa67a9a62505db124a5cb5262332d1d4153462eb8fd89c9fa41e5d92/urllib3-1.25.11-py2.py3-none-any.whl";
      sha256 = "0pnxjyc33d162wrxmk285av9x44h9sqpzzhbzl7gmzpk9fz1ycpm";
    };
    format = "wheel";
    doCheck = false;
    buildInputs = [];
    checkInputs = [];
    nativeBuildInputs = [];
    propagatedBuildInputs = [];
  };
}

D shell.nix => shell.nix +0 -16
@@ 1,16 0,0 @@
let pkgs = import <nixpkgs> { };
in
let
  packageOverrides = pkgs.callPackage ./python-packages.nix { };
  python = pkgs.python3.override { inherit packageOverrides; };
  pythonWithPackages = python.withPackages (ps: [
    ps.quik
    pkgs.python3.pkgs.matplotlib
    pkgs.python3.pkgs.numpy
    pkgs.python3.pkgs.pandas
    pkgs.python3.pkgs.requests
  ]);
in
pkgs.mkShell {
  nativeBuildInputs = [ pythonWithPackages ];
}

M template.html => template.html +10 -5
@@ 50,18 50,23 @@ img {
      countdown! Code is released under BSD-2.</small></noscript></p>
  <img src="chart.svg?v=@ver" />
  <h3>Explanation</h3>
  <p><small>The goal of @goal doses per 100 person is based on the Sinopharm
    efficacy rate (79%) on top of 60% herd-immunity target.</small></p>
  <p><small>The goal of @goal% of the people fully vaccinated is based on the
    estimated R0 rate of the delta variant. Estimates show the R0 of the delta
    variant is between 4-9, we assume an R0 of 6.5.</small></p>

  <p><small>This estimate is predicted using polynomial regression, expect it
    to change frequently.  Remember, this is <b>just an estimation</b> on an
    to change frequently. Remember, this is <b>just an estimation</b> on an
    <b>arbitrary goal</b>.</small></p>

  <p><small>This is a hobbyist website, which is
    unaffiliated with any authority or official body.</small></p>

  <p><small>Data source: <a href="https://covid19.ncema.gov.ae/">UAE National
      Emergency Crisis and Disasters Management Authority</a></small></p>
  <p><small>Data source: <a href="https://github.com/owid/covid-19-data">
    Our World in Data</a></small></p>
  <p><small>[1]: <a
                     href="https://www.npr.org/sections/goatsandsoda/2021/05/07/994710459/is-the-variant-from-india-the-most-contagious-coronavirus-mutant-on-the-planet">
      Is The Variant From India The Most Contagious Coronavirus Mutant On The
      Planet?: NPR</a></small></p>

  <p><small>Last updated: @today</small></p>
  <p><small><a href="https://git.sr.ht/~humaid/areweherdimmuneyet"