def test_add_revenue_value_spot_check(self, sample_data): rev = GrossRevenue(aligned_data=sample_data) rev.add_revenue_column() z = rev.aligned_data.iloc[42, :] assert isclose(z[0], 9.14, rel_tol=1e-04) assert isclose(z[1], 2517.049924, rel_tol=1e-04) assert isclose(z[2], 25.164100, rel_tol=1e-04) assert isclose(z[3], 6.333930, rel_tol=1e-04)
def test_subset_data_badpeak(self, sample_data): rev = GrossRevenue(aligned_data=sample_data) rev.add_revenue_column() subdf = rev.subset_data(subset_on="perk") oncount = subdf.isna().sum() offcount = subdf.notnull().sum() for elem in oncount: assert elem == 4380 for elem in offcount: assert elem == 4380
def test_write_grouped_data_to_file(self, sample_data): rev = GrossRevenue(aligned_data=sample_data) rev.add_revenue_column() subdf = rev.subset_data(subset_on="peak") grouped = rev.group_data(subdf) outfile = "peak-data.csv" rev.save_grouped_data(grouped, outfile) assert os.path.isfile(outfile)
def test_groupby_runs_default_methods(self, sample_data): rev = GrossRevenue(aligned_data=sample_data) rev.add_revenue_column() subdf = rev.subset_data(subset_on="peak") grouped = rev.group_data(subdf) assert grouped.shape == (12, 4) print(grouped) assert grouped.index.min() == 1 assert grouped.index.max() == 12
def test_groupby_other_methods_spotcheck(self, sample_data): rev = GrossRevenue(aligned_data=sample_data) rev.add_revenue_column() subdf = rev.subset_data(subset_on="peak") grouped = rev.group_data(subdf, [max, min, max, min]) z = grouped.iloc[6, :] print(z) assert isclose(z[0], 9.530556, rel_tol=1e-04) assert isclose(z[1], 131.111105, rel_tol=1e-04) assert isclose(z[2], 43.969100, rel_tol=1e-04) assert isclose(z[3], 0.309022, rel_tol=1e-04)
def test_groupby_defaults_spotcheck(self, sample_data): rev = GrossRevenue(aligned_data=sample_data) rev.add_revenue_column() subdf = rev.subset_data(subset_on="peak") grouped = rev.group_data(subdf) z = grouped.iloc[6, :] print(z) assert isclose(z[0], 6.793248, rel_tol=1e-04) assert isclose(z[1], 1422.076282, rel_tol=1e-04) assert isclose(z[2], 10184.529100, rel_tol=1e-04) assert isclose(z[3], 1469.932431, rel_tol=1e-04)
def test_add_revenue_column_na_size(self, sample_data): rev = GrossRevenue(aligned_data=sample_data) rev.add_revenue_column() assert rev.aligned_data.isna().sum().all() == 0 assert rev.aligned_data.shape == (8760, 4)
def test_revenue_init_aligned_data_na_size(self, sample_data): rev = GrossRevenue(aligned_data=sample_data) assert rev.aligned_data.isna().sum().all() == 0 assert rev.aligned_data.shape == (8760, 3)
def test_revenue_init_defined_peak_hours(self, sample_data): pkhrs = PeakHours(peak=[4, 5, 1, 10], offpeak=[2, 3, 1, 8, 9]) rev = GrossRevenue(aligned_data=sample_data, peak_hours=pkhrs) val = rev.peak_hours.get_peak_hours() assert (val[0] == [4, 5, 1, 10]).all() assert (val[1] == [2, 3, 1, 8, 9]).all()
def test_revenue_init_default_peak_hours(self, sample_data): rev = GrossRevenue(aligned_data=sample_data) val = rev.peak_hours.get_peak_hours() assert (val[0] == peak_default).all() assert (val[1] == off_peak_default).all()
def test_calculate_gross_revenue(self, sample_data): rev = GrossRevenue(aligned_data=sample_data) rev.calculate_gross_revenue() assert os.path.isfile('GrossRevenue-PeakHrs.csv') assert os.path.isfile('GrossRevenue-OffPeakHrs.csv')
def test_groupby_runs_other_methods(self, sample_data): rev = GrossRevenue(aligned_data=sample_data) rev.add_revenue_column() subdf = rev.subset_data(subset_on="peak") grouped = rev.group_data(subdf, [max, min, max, min]) assert grouped.shape == (12, 4)