예제 #1
0
파일: plotter.py 프로젝트: mrktrvr/tasks
def plot_day_of_week_all(data, tar_months):
    for tar_month in tar_months:
        print('Month: %s' % dh.month_no_to_name(tar_month))
        for data_name in data.keys():
            df = data[data_name]
            print('dataset:%s, Monday to Sunday in %s' %
                  (data_name, dh.month_no_to_name(tar_month)))
            plot_day_of_week(df, tar_month, data_name)
            plt.show()
예제 #2
0
파일: plotter.py 프로젝트: mrktrvr/tasks
def plot_stats_weekly(data):
    n_data = len(data)
    weekday_names = [dh.week_no_to_name(i) for i in range(7)]
    n_cols = 2
    n_rows = int(np.ceil(n_data / float(n_cols)))
    for tar_month in [1, 5, 7, 10]:
        print('month %d' % tar_month)
        fig = plt.figure(tar_month, figsize=(6 * n_cols, 4 * n_rows))
        for i, (data_name, data_df) in enumerate(data.items(), 1):
            df_month = dh.get_df_month(data_df, tar_month)
            mins = []
            maxs = []
            means = []
            stds = []
            meds = []
            for tar_day in range(7):
                df_weekday = dh.get_df_dayofweek(df_month, tar_day)
                mins.append(df_weekday.min().values[0])
                maxs.append(df_weekday.max().values[0])
                means.append(df_weekday.mean().values[0])
                stds.append(df_weekday.std().values[0])
                meds.append(df_weekday.median().values[0])
            ax = fig.add_subplot(n_rows, n_cols, i)
            plot_stats(mins, maxs, means, stds, meds, ax, '-')
            month_name = dh.month_no_to_name(tar_month)
            _ = ax.set_title('dataset:%s, month:%s' % (data_name, month_name))
            _ = ax.set_xticks(range(7))
            _ = ax.set_xticklabels(weekday_names, rotation=90)
            _ = ax.set_ylim(ymin=0)
        plt.tight_layout()
        plt.show()
예제 #3
0
 def test_no_to_str(self):
     self.assertEqual(dh.week_no_to_name(-1), 'Unknown')
     self.assertEqual(dh.week_no_to_name(0), 'Mon')
     self.assertEqual(dh.week_no_to_name(1), 'Tue')
     self.assertEqual(dh.week_no_to_name(2), 'Wed')
     self.assertEqual(dh.week_no_to_name(3), 'Thu')
     self.assertEqual(dh.week_no_to_name(4), 'Fri')
     self.assertEqual(dh.week_no_to_name(5), 'Sat')
     self.assertEqual(dh.week_no_to_name(6), 'Sun')
     self.assertEqual(dh.week_no_to_name(7), 'Unknown')
     self.assertEqual(dh.month_no_to_name(-1), 'Unknown')
     self.assertEqual(dh.month_no_to_name(1), 'January')
     self.assertEqual(dh.month_no_to_name(4), 'April')
     self.assertEqual(dh.month_no_to_name(7), 'July')
     self.assertEqual(dh.month_no_to_name(10), 'October')
     self.assertEqual(dh.month_no_to_name(13), 'Unknown')
예제 #4
0
파일: plotter.py 프로젝트: mrktrvr/tasks
def plot_seasonaly(data, tar_months):
    for data_name, data_df in data.items():
        plot_src = {}
        print(
            'dataset:%s, daily consumptions in %s' %
            (data_name, ', '.join([dh.month_no_to_name(m)
                                   for m in tar_months])))
        for i, m in enumerate(tar_months, 1):
            df_month = dh.get_df_month(data_df, m)
            plot_src.update({m: dh.reshape_day_by_day(df_month)})
        ymin = np.nanmin([x.values.min() for x in plot_src.values()])
        ymax = np.nanmax([x.values.max() for x in plot_src.values()])
        n_rows = 2
        n_cols = len(tar_months)
        fig = plt.figure(figsize=(len(tar_months) * 6, n_rows * 4))
        for i, (m, v) in enumerate(sorted(plot_src.items()), 1):
            ax = fig.add_subplot(n_rows, len(tar_months), i)
            plot_daily_all(ax, v, ymin, ymax, i, m, data_name)
            ax = fig.add_subplot(n_rows, len(tar_months), i + len(tar_months))
            plot_daily_ave_med_std(ax, v, ymin, ymax, m, data_name)
            # ax = fig.add_subplot(n_rows, n_cols, i + 2 * len(tar_months))
            # plot_daily_ave(ax, v, ymin, ymax, m, data_name)
        plt.show()
예제 #5
0
파일: plotter.py 프로젝트: mrktrvr/tasks
def plot_stats_data_comparison(data):
    min_list = [data[k].min().values[0] for k in data.keys()]
    max_list = [data[k].max().values[0] for k in data.keys()]
    mean_list = [data[k].mean().values for k in data.keys()]
    std_list = [data[k].std().values[0] for k in data.keys()]
    med_list = [data[k].median().values[0] for k in data.keys()]
    n_cols = 2
    n_rows = 3
    fig = plt.figure(1, figsize=(6 * n_cols, 4 * n_rows))
    ax = fig.add_subplot(n_rows, n_cols, 1)
    plot_stats(min_list, max_list, mean_list, std_list, med_list, ax)
    _ = ax.set_xticks(range(len(data)))
    _ = ax.set_xticklabels(data.keys(), rotation=90)
    _ = ax.set_ylim(0, 65000)
    _ = ax.set_title('min, max, mean and std of all months')

    for i, tar_month in enumerate([1, 4, 7, 10], 3):
        min_list = []
        max_list = []
        mean_list = []
        std_list = []
        med_list = []
        for k in data.keys():
            dfm = dh.get_df_month(data[k], tar_month)
            min_list.append(dfm.min().values[0])
            max_list.append(dfm.max().values[0])
            mean_list.append(dfm.mean().values[0])
            std_list.append(dfm.std().values[0])
            med_list.append(dfm.median().values[0])
        ax = fig.add_subplot(n_rows, n_cols, i)
        plot_stats(min_list, max_list, mean_list, std_list, med_list, ax)
        month_name = dh.month_no_to_name(tar_month)
        _ = ax.set_title('month:%s' % month_name)
        _ = ax.set_xticks(range(len(data)))
        _ = ax.set_xticklabels(data.keys(), rotation=90)
        _ = ax.set_ylim(0, 65000)
    plt.tight_layout()
예제 #6
0
파일: plotter.py 프로젝트: mrktrvr/tasks
def plot_diff_days_hours_each_month(data, tar_months):
    for data_name, data_df in data.items():
        for month_no in tar_months:
            df_month = dh.get_df_month(data_df, month_no)
            dname_month = '%s(%s)' % (data_name, dh.month_no_to_name(month_no))
            plot_diff_days_hours(dname_month, df_month)