Skip to content

Commit

Permalink
all works finally
Browse files Browse the repository at this point in the history
  • Loading branch information
leliel12 committed May 9, 2020
1 parent b8fb2dc commit 7256b3a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 59 deletions.
22 changes: 10 additions & 12 deletions arcovid19/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
AREAS_POP_URL = 'https://github.com/ivco19/libs/raw/master/databases/extra/arg_provs.dat' # noqa


DATE_FORMAT = '%m/%d/%y'
LABEL_DATE_FORMAT = "%d.%b"


PROVINCIAS = {
Expand Down Expand Up @@ -160,13 +160,11 @@ def _plot_df(
return pdf

# functions for backwards compatibility
def full_period_period_all(self, *args, **kwargs):
ax = self.curva_epi_pais(*args, **kwargs)
return ax
def grate_full_period_all(self, *args, **kwargs):
return self.curva_epi_pais(*args, **kwargs)

def grate_full_period(self, *args, **kwargs):
ax = self.curva_epi_provincia(*args, **kwargs)
return ax
return self.curva_epi_provincia(*args, **kwargs)

def curva_epi_pais(
self, ax=None, argentina=True,
Expand Down Expand Up @@ -401,12 +399,12 @@ def curva_epi_provincia(
pdf.plot.line(ax=ax, **kwargs, **aesthetics)

# elementos formales del grafico
labels = [d.date() for d in self.cstats.dates]
labels = [d.strftime(LABEL_DATE_FORMAT) for d in self.cstats.dates]
ispace = int(len(labels) / 10)
ticks = np.arange(len(labels))[::ispace]
slabels = [l.strftime("%d.%b") for l in labels][::ispace]
lmin = labels[0].strftime("%d.%b")
lmax = labels[-1].strftime("%d.%b")
slabels = [l for l in labels][::ispace]
lmin = labels[0]
lmax = labels[-1]

ax.set_xticks(ticks=ticks)
ax.set_xticklabels(labels=slabels, rotation=0, fontsize=16)
Expand Down Expand Up @@ -454,7 +452,7 @@ def time_serie_all(
continue
self.time_serie(provincia=code, ax=ax, **kwargs)

labels = [d.date() for d in self.cstats.dates]
labels = [d.strftime(LABEL_DATE_FORMAT) for d in self.cstats.dates]
ticks = np.arange(len(labels))

ax.set_xticks(ticks=ticks)
Expand Down Expand Up @@ -487,7 +485,7 @@ def time_serie(
recovered=recovered, deceased=deceased)
pdf.plot.line(ax=ax, **kwargs)

labels = [d.date() for d in self.cstats.dates]
labels = [d.strftime(LABEL_DATE_FORMAT) for d in self.cstats.dates]
ticks = np.arange(len(labels))

ax.set_xticks(ticks=ticks)
Expand Down
54 changes: 7 additions & 47 deletions tests/test_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from matplotlib.testing.decorators import check_figures_equal

import arcovid19
from arcovid19.cases import LABEL_DATE_FORMAT


# =============================================================================
Expand Down Expand Up @@ -195,17 +196,17 @@ def test_plot_call(fig_test, fig_ref):


@check_figures_equal()
def test_plot_grate_full_period_all(fig_test, fig_ref):
def test_plot_curva_epi_pais(fig_test, fig_ref):
df = arcovid19.load_cases(
cases_url=LOCAL_CASES, areas_pop_url=LOCAL_AREA_POP)

# fig test
test_ax = fig_test.subplots()
test_ax = df.plot("grate_full_period_all", ax=test_ax)
test_ax = df.plot("curva_epi_pais", ax=test_ax)

# expected
exp_ax = fig_ref.subplots()
df.plot.grate_full_period_all(ax=exp_ax)
df.plot.curva_epi_pais(ax=exp_ax)


@check_figures_equal()
Expand All @@ -222,30 +223,6 @@ def test_plot_grate_full_period(fig_test, fig_ref):
df.plot.grate_full_period(ax=exp_ax)


@check_figures_equal()
def test_plot_grate_full_period_all_equivalent_calls(fig_test, fig_ref):
cases = arcovid19.load_cases(
cases_url=LOCAL_CASES, areas_pop_url=LOCAL_AREA_POP)

# fig test
fig_test.set_size_inches(12, 12)
test_ax = fig_test.subplots()
cases.plot.grate_full_period_all(ax=test_ax)
test_ax.set_title("")

# expected
fig_ref.set_size_inches(12, 12)
exp_ax = fig_ref.subplots()

cases.plot.grate_full_period(
deceased=False, active=False, recovered=False, ax=exp_ax)
for prov in sorted(arcovid19.cases.CODE_TO_POVINCIA):
cases.plot.grate_full_period(
prov, deceased=False, active=False, recovered=False, ax=exp_ax)

exp_ax.set_title("")


@check_figures_equal()
def test_plot_time_serie_all(fig_test, fig_ref):
df = arcovid19.load_cases(
Expand Down Expand Up @@ -312,20 +289,6 @@ def test_plot_barplot(fig_test, fig_ref):
df.plot.barplot(ax=exp_ax)


@check_figures_equal()
def test_plot_grate_full_period_all_commented(fig_test, fig_ref):
df = arcovid19.load_cases(
cases_url=LOCAL_CASES, areas_pop_url=LOCAL_AREA_POP)

# fig test
test_ax = fig_test.subplots()
test_ax = df.plot("grate_full_period_all_commented", ax=test_ax)

# expected
exp_ax = fig_ref.subplots()
df.plot.grate_full_period_all_commented(ax=exp_ax)


@check_figures_equal()
def test_plot_boxplot(fig_test, fig_ref):
df = arcovid19.load_cases(
Expand All @@ -345,18 +308,15 @@ def test_plot_boxplot(fig_test, fig_ref):
# =============================================================================

@pytest.mark.parametrize(
"plot_name", [
"time_serie", "time_serie_all",
"grate_full_period", "grate_full_period_all"])
"plot_name", ["time_serie", "time_serie_all"])
def test_plot_all_dates_ticks(plot_name):
df = arcovid19.load_cases(
cases_url=LOCAL_CASES, areas_pop_url=LOCAL_AREA_POP)

expected = [str(d.date()) for d in df.dates]

expected = [d.strftime(LABEL_DATE_FORMAT) for d in df.dates]
ax = df.plot(plot_name)
labels = [l.get_text() for l in ax.get_xticklabels()]
ticks = ax.get_xticks()

assert labels == expected
assert len(labels) == len(ticks)
assert labels == expected

0 comments on commit 7256b3a

Please sign in to comment.