"""
Experiment summary
------------------
Treat each province/state in a country cases over time
as a vector, do a simple K-Nearest Neighbor between
countries. What country has the most similar trajectory
to a given country?

Plots similar countries
"""

import sys
sys.path.insert(0, '..')

from utils import data
import os
import sklearn
import numpy as np
import json
import matplotlib.pyplot as plt

plt.style.use('fivethirtyeight')

# ------------ HYPERPARAMETERS -------------
BASE_PATH = '../COVID-19/csse_covid_19_data/'
# ------------------------------------------

confirmed = os.path.join(
    BASE_PATH,
    'csse_covid_19_time_series',
    'time_series_covid19_confirmed_global.csv')
confirmed = data.load_csv_data(confirmed)
features = []
targets = []

fig = plt.figure(figsize=(12, 12))
ax = fig.add_subplot(111)
cm = plt.get_cmap('jet')
NUM_COLORS = 0
LINE_STYLES = ['solid', 'dashed', 'dotted']
NUM_STYLES = len(LINE_STYLES)

dist_diff = os.path.join('../exp/results/', 'knn_raw.json')
f = open(dist_diff,)
dist_diff = json.load(f)

for region, dist in dist_diff.items():
    plt.style.use('fivethirtyeight')

    fig = plt.figure(figsize=(12, 12))
    ax = fig.add_subplot(111)
    cm = plt.get_cmap('jet')

    other_region = dist['manhattan'][0]
    regions = [region, other_region]
    for val in regions:
        df = data.filter_by_attribute(
            confirmed, "Country/Region", val)
        cases, labels = data.get_cases_chronologically(df)
        cases = cases.sum(axis=0)

        lines = ax.plot(cases, label=val)

    ax.set_ylabel('# of confirmed cases')
    ax.set_xlabel("Time (days since Jan 22, 2020)")
    ax.set_yscale('log')
    ax.legend()
    plt.tight_layout()
    region = region.replace('*', '')
    other_region = other_region.replace('*', '')
    plt.title(f'Comparing confirmed cases in {region} and {other_region}')
    plt.savefig(f'results/raw_manhattan/{region}.png')
    plt.close()
    print(region)
[((266, 290), 'sys.path.insert', 'sys.path.insert', (['(0)', '""".."""'], {}), "(0, '..')\n", (281, 290), False, 'import sys\n'), ((404, 436), 'matplotlib.pyplot.style.use', 'plt.style.use', (['"""fivethirtyeight"""'], {}), "('fivethirtyeight')\n", (417, 436), True, 'import matplotlib.pyplot as plt\n'), ((587, 687), 'os.path.join', 'os.path.join', (['BASE_PATH', '"""csse_covid_19_time_series"""', '"""time_series_covid19_confirmed_global.csv"""'], {}), "(BASE_PATH, 'csse_covid_19_time_series',\n    'time_series_covid19_confirmed_global.csv')\n", (599, 687), False, 'import os\n'), ((709, 738), 'utils.data.load_csv_data', 'data.load_csv_data', (['confirmed'], {}), '(confirmed)\n', (727, 738), False, 'from utils import data\n'), ((773, 801), 'matplotlib.pyplot.figure', 'plt.figure', ([], {'figsize': '(12, 12)'}), '(figsize=(12, 12))\n', (783, 801), True, 'import matplotlib.pyplot as plt\n'), ((833, 852), 'matplotlib.pyplot.get_cmap', 'plt.get_cmap', (['"""jet"""'], {}), "('jet')\n", (845, 852), True, 'import matplotlib.pyplot as plt\n'), ((955, 1002), 'os.path.join', 'os.path.join', (['"""../exp/results/"""', '"""knn_raw.json"""'], {}), "('../exp/results/', 'knn_raw.json')\n", (967, 1002), False, 'import os\n'), ((1036, 1048), 'json.load', 'json.load', (['f'], {}), '(f)\n', (1045, 1048), False, 'import json\n'), ((1093, 1125), 'matplotlib.pyplot.style.use', 'plt.style.use', (['"""fivethirtyeight"""'], {}), "('fivethirtyeight')\n", (1106, 1125), True, 'import matplotlib.pyplot as plt\n'), ((1137, 1165), 'matplotlib.pyplot.figure', 'plt.figure', ([], {'figsize': '(12, 12)'}), '(figsize=(12, 12))\n', (1147, 1165), True, 'import matplotlib.pyplot as plt\n'), ((1205, 1224), 'matplotlib.pyplot.get_cmap', 'plt.get_cmap', (['"""jet"""'], {}), "('jet')\n", (1217, 1224), True, 'import matplotlib.pyplot as plt\n'), ((1688, 1706), 'matplotlib.pyplot.tight_layout', 'plt.tight_layout', ([], {}), '()\n', (1704, 1706), True, 'import matplotlib.pyplot as plt\n'), ((1797, 1867), 'matplotlib.pyplot.title', 'plt.title', (['f"""Comparing confirmed cases in {region} and {other_region}"""'], {}), "(f'Comparing confirmed cases in {region} and {other_region}')\n", (1806, 1867), True, 'import matplotlib.pyplot as plt\n'), ((1872, 1922), 'matplotlib.pyplot.savefig', 'plt.savefig', (['f"""results/raw_manhattan/{region}.png"""'], {}), "(f'results/raw_manhattan/{region}.png')\n", (1883, 1922), True, 'import matplotlib.pyplot as plt\n'), ((1927, 1938), 'matplotlib.pyplot.close', 'plt.close', ([], {}), '()\n', (1936, 1938), True, 'import matplotlib.pyplot as plt\n'), ((1340, 1398), 'utils.data.filter_by_attribute', 'data.filter_by_attribute', (['confirmed', '"""Country/Region"""', 'val'], {}), "(confirmed, 'Country/Region', val)\n", (1364, 1398), False, 'from utils import data\n'), ((1436, 1470), 'utils.data.get_cases_chronologically', 'data.get_cases_chronologically', (['df'], {}), '(df)\n', (1466, 1470), False, 'from utils import data\n')]