"""
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)
[((13, 0, 13, 24), 'sys.path.insert', 'sys.path.insert', ({(13, 16, 13, 17): '(0)', (13, 19, 13, 23): '""".."""'}, {}), "(0, '..')", False, 'import sys\n'), ((22, 0, 22, 32), 'matplotlib.pyplot.style.use', 'plt.style.use', ({(22, 14, 22, 31): '"""fivethirtyeight"""'}, {}), "('fivethirtyeight')", True, 'import matplotlib.pyplot as plt\n'), ((28, 12, 31, 47), 'os.path.join', 'os.path.join', ({(29, 4, 29, 13): 'BASE_PATH', (30, 4, 30, 31): '"""csse_covid_19_time_series"""', (31, 4, 31, 46): '"""time_series_covid19_confirmed_global.csv"""'}, {}), "(BASE_PATH, 'csse_covid_19_time_series',\n    'time_series_covid19_confirmed_global.csv')", False, 'import os\n'), ((32, 12, 32, 41), 'utils.data.load_csv_data', 'data.load_csv_data', ({(32, 31, 32, 40): 'confirmed'}, {}), '(confirmed)', False, 'from utils import data\n'), ((36, 6, 36, 34), 'matplotlib.pyplot.figure', 'plt.figure', (), '', True, 'import matplotlib.pyplot as plt\n'), ((38, 5, 38, 24), 'matplotlib.pyplot.get_cmap', 'plt.get_cmap', ({(38, 18, 38, 23): '"""jet"""'}, {}), "('jet')", True, 'import matplotlib.pyplot as plt\n'), ((43, 12, 43, 59), 'os.path.join', 'os.path.join', ({(43, 25, 43, 42): '"""../exp/results/"""', (43, 44, 43, 58): '"""knn_raw.json"""'}, {}), "('../exp/results/', 'knn_raw.json')", False, 'import os\n'), ((45, 12, 45, 24), 'json.load', 'json.load', ({(45, 22, 45, 23): 'f'}, {}), '(f)', False, 'import json\n'), ((48, 4, 48, 36), 'matplotlib.pyplot.style.use', 'plt.style.use', ({(48, 18, 48, 35): '"""fivethirtyeight"""'}, {}), "('fivethirtyeight')", True, 'import matplotlib.pyplot as plt\n'), ((50, 10, 50, 38), 'matplotlib.pyplot.figure', 'plt.figure', (), '', True, 'import matplotlib.pyplot as plt\n'), ((52, 9, 52, 28), 'matplotlib.pyplot.get_cmap', 'plt.get_cmap', ({(52, 22, 52, 27): '"""jet"""'}, {}), "('jet')", True, 'import matplotlib.pyplot as plt\n'), ((68, 4, 68, 22), 'matplotlib.pyplot.tight_layout', 'plt.tight_layout', ({}, {}), '()', True, 'import matplotlib.pyplot as plt\n'), ((71, 4, 71, 74), 'matplotlib.pyplot.title', 'plt.title', ({(71, 14, 71, 73): 'f"""Comparing confirmed cases in {region} and {other_region}"""'}, {}), "(f'Comparing confirmed cases in {region} and {other_region}')", True, 'import matplotlib.pyplot as plt\n'), ((72, 4, 72, 54), 'matplotlib.pyplot.savefig', 'plt.savefig', ({(72, 16, 72, 53): 'f"""results/raw_manhattan/{region}.png"""'}, {}), "(f'results/raw_manhattan/{region}.png')", True, 'import matplotlib.pyplot as plt\n'), ((73, 4, 73, 15), 'matplotlib.pyplot.close', 'plt.close', ({}, {}), '()', True, 'import matplotlib.pyplot as plt\n'), ((57, 13, 58, 45), 'utils.data.filter_by_attribute', 'data.filter_by_attribute', ({(58, 12, 58, 21): 'confirmed', (58, 23, 58, 39): '"""Country/Region"""', (58, 41, 58, 44): 'val'}, {}), "(confirmed, 'Country/Region', val)", False, 'from utils import data\n'), ((59, 24, 59, 58), 'utils.data.get_cases_chronologically', 'data.get_cases_chronologically', ({(59, 55, 59, 57): 'df'}, {}), '(df)', False, 'from utils import data\n')]