Ejemplo n.º 1
0
def analyse_photo_efforts():
    column_types = (number_type, text_type, text_type, text_type, boolean_type)

    with open('www/live-data/photo_efforts.csv') as f:
        rows = list(csv.reader(f))

    column_names = rows.pop(0)
    table = Table(rows, column_types, column_names)

    homepage_summary = table.aggregate('on_homepage', (('duration', 'sum'),))

    count_grand_total = homepage_summary.columns['on_homepage_count'].sum()
    homepage_summary = homepage_summary.compute('on_homepage_count_pct', number_type,
        lambda x: (x['on_homepage_count']/count_grand_total) * 100)

    count_grand_total = homepage_summary.columns['duration_sum'].sum()
    homepage_summary = homepage_summary.compute('duration_sum_pct', number_type,
        lambda x: (x['duration_sum']/count_grand_total) * 100)

    _write_summary_csv(homepage_summary, 'www/live-data/homepage_summary.csv')

    contribution_summary = table.aggregate('contribution', (('duration', 'sum'),))
    contribution_summary = contribution_summary.order_by('contribution_count', reverse=True)
    contribution_summary = contribution_summary.compute('contribution_count_pct', number_type,
        lambda x: (x['contribution_count']/count_grand_total) * 100)

    contribution_summary = contribution_summary.compute('duration_sum_pct', number_type,
        lambda x: (x['duration_sum']/count_grand_total) * 100)

    _write_summary_csv(contribution_summary, 'www/live-data/contribution_summary.csv')
Ejemplo n.º 2
0
    def test_aggregeate_bad_column(self):
        table = Table(self.rows, self.column_types, self.column_names)

        with self.assertRaises(ColumnDoesNotExistError):
            table.aggregate('bad', (('one', 'sum'), ))

        with self.assertRaises(ColumnDoesNotExistError):
            table.aggregate('two', (('bad', 'sum'), ))
Ejemplo n.º 3
0
    def test_aggregeate_bad_column(self):
        table = Table(self.rows, self.column_types, self.column_names)

        with self.assertRaises(ColumnDoesNotExistError):
            table.aggregate('bad', (('one', 'sum'), ))

        with self.assertRaises(ColumnDoesNotExistError):
            table.aggregate('two', (('bad', 'sum'), ))
Ejemplo n.º 4
0
def analyse_insights():
    """
    generate reports from insights data
    """
    column_types = (date_type, number_type, number_type, number_type, number_type, number_type, boolean_type, text_type, text_type, text_type, text_type, boolean_type, text_type, text_type)

    with open('www/live-data/insights.csv') as f:
        rows = list(csv.reader(f))

    column_names = rows.pop(0)

    table = Table(rows, column_types, column_names)

    summary_definition = list(itertools.product(FACEBOOK_METRICS, SUMMARY_TYPES))

    summary = table.aggregate('provider_type', summary_definition)

    count_grand_total = summary.columns['provider_type_count'].sum()
    summary = summary.compute('provider_type_count_pct', number_type,
        lambda x: (x['provider_type_count']/count_grand_total) * 100)

    summary = summary.order_by('provider_type')

    _write_summary_csv(summary, 'www/live-data/insights_summary.csv')

    for metric in FACEBOOK_METRICS:
        _generate_insights_histograms(metric, table, summary)
Ejemplo n.º 5
0
def analyse_insights():
    """
    generate reports from insights data
    """
    column_types = (date_type, number_type, number_type, number_type,
                    number_type, number_type, boolean_type, text_type,
                    text_type, text_type, text_type, boolean_type, text_type,
                    text_type)

    with open('www/live-data/insights.csv') as f:
        rows = list(csv.reader(f))

    column_names = rows.pop(0)

    table = Table(rows, column_types, column_names)

    summary_definition = list(
        itertools.product(FACEBOOK_METRICS, SUMMARY_TYPES))

    summary = table.aggregate('provider_type', summary_definition)

    count_grand_total = summary.columns['provider_type_count'].sum()
    summary = summary.compute(
        'provider_type_count_pct', number_type, lambda x:
        (x['provider_type_count'] / count_grand_total) * 100)

    summary = summary.order_by('provider_type')

    _write_summary_csv(summary, 'www/live-data/insights_summary.csv')

    for metric in FACEBOOK_METRICS:
        _generate_insights_histograms(metric, table, summary)
Ejemplo n.º 6
0
    def test_aggregate_two_ops(self):
        table = Table(self.rows, self.column_types, self.column_names)

        new_table = table.aggregate('one', (('two', 'sum'), ('two', 'mean')))

        self.assertIsNot(new_table, table)
        self.assertEqual(len(new_table.rows), 3)
        self.assertEqual(len(new_table.columns), 4)
        self.assertSequenceEqual(new_table._column_names, ('one', 'one_count', 'two_sum', 'two_mean'))
        self.assertSequenceEqual(new_table.rows[0], ('a', 2, 4, 2))
        self.assertSequenceEqual(new_table.rows[1], (None, 1, 3, 3))
        self.assertSequenceEqual(new_table.rows[2], ('b', 1, 3, 3))
Ejemplo n.º 7
0
def analyse_effort_and_analytics():
    column_types = (text_type, text_type, number_type, number_type, boolean_type)

    with open('www/live-data/raw_effort_and_analytics.csv') as f:
        rows = list(csv.reader(f))

    column_names = rows.pop(0)
    table = Table(rows, column_types, column_names)
    #import ipdb; ipdb.set_trace();
    summary = table.aggregate('visuals_contributed', (('pageviews', 'sum'), ('pageviews', 'mean'), ('pageviews', 'median'), ('sessions', 'sum'), ('sessions', 'mean'), ('sessions', 'median')))
    for row in summary.rows:
        print row
    _write_summary_csv(summary, 'www/live-data/effort_and_analytics_summary.csv')
Ejemplo n.º 8
0
    def test_aggregate_two_ops(self):
        table = Table(self.rows, self.column_types, self.column_names)

        new_table = table.aggregate('one', (('two', 'sum'), ('two', 'mean')))

        self.assertIsNot(new_table, table)
        self.assertEqual(len(new_table.rows), 3)
        self.assertEqual(len(new_table.columns), 4)
        self.assertSequenceEqual(new_table._column_names,
                                 ('one', 'one_count', 'two_sum', 'two_mean'))
        self.assertSequenceEqual(new_table.rows[0], ('a', 2, 4, 2))
        self.assertSequenceEqual(new_table.rows[1], (None, 1, 3, 3))
        self.assertSequenceEqual(new_table.rows[2], ('b', 1, 3, 3))
Ejemplo n.º 9
0
def analyse_photo_efforts():
    column_types = (number_type, text_type, text_type, text_type, boolean_type)

    with open('www/live-data/photo_efforts.csv') as f:
        rows = list(csv.reader(f))

    column_names = rows.pop(0)
    table = Table(rows, column_types, column_names)

    homepage_summary = table.aggregate('on_homepage', (('duration', 'sum'), ))

    count_grand_total = homepage_summary.columns['on_homepage_count'].sum()
    homepage_summary = homepage_summary.compute(
        'on_homepage_count_pct', number_type, lambda x:
        (x['on_homepage_count'] / count_grand_total) * 100)

    count_grand_total = homepage_summary.columns['duration_sum'].sum()
    homepage_summary = homepage_summary.compute(
        'duration_sum_pct', number_type, lambda x:
        (x['duration_sum'] / count_grand_total) * 100)

    _write_summary_csv(homepage_summary, 'www/live-data/homepage_summary.csv')

    contribution_summary = table.aggregate('contribution',
                                           (('duration', 'sum'), ))
    contribution_summary = contribution_summary.order_by('contribution_count',
                                                         reverse=True)
    contribution_summary = contribution_summary.compute(
        'contribution_count_pct', number_type, lambda x:
        (x['contribution_count'] / count_grand_total) * 100)

    contribution_summary = contribution_summary.compute(
        'duration_sum_pct', number_type, lambda x:
        (x['duration_sum'] / count_grand_total) * 100)

    _write_summary_csv(contribution_summary,
                       'www/live-data/contribution_summary.csv')
Ejemplo n.º 10
0
def analyse_effort_and_analytics():
    column_types = (text_type, text_type, number_type, number_type,
                    boolean_type)

    with open('www/live-data/raw_effort_and_analytics.csv') as f:
        rows = list(csv.reader(f))

    column_names = rows.pop(0)
    table = Table(rows, column_types, column_names)
    #import ipdb; ipdb.set_trace();
    summary = table.aggregate('visuals_contributed',
                              (('pageviews', 'sum'), ('pageviews', 'mean'),
                               ('pageviews', 'median'), ('sessions', 'sum'),
                               ('sessions', 'mean'), ('sessions', 'median')))
    for row in summary.rows:
        print row
    _write_summary_csv(summary,
                       'www/live-data/effort_and_analytics_summary.csv')
Ejemplo n.º 11
0
def analyse_photo_efforts_fb():
    column_types = (number_type, text_type, text_type, text_type, boolean_type)

    with open('www/live-data/photo_efforts_fb.csv') as f:
        rows = list(csv.reader(f))

    column_names = rows.pop(0)
    table = Table(rows, column_types, column_names)

    facebook_summary = table.aggregate('on_facebook', (('duration', 'sum'),))

    count_grand_total = facebook_summary.columns['on_facebook_count'].sum()
    facebook_summary = facebook_summary.compute('on_facebook_count_pct', number_type,
        lambda x: (x['on_facebook_count']/count_grand_total) * 100)

    count_grand_total = facebook_summary.columns['duration_sum'].sum()
    facebook_summary = facebook_summary.compute('duration_sum_pct', number_type,
        lambda x: (x['duration_sum']/count_grand_total) * 100)

    _write_summary_csv(facebook_summary, 'www/live-data/facebook_summary.csv')
Ejemplo n.º 12
0
def analyse_photo_efforts_fb():
    column_types = (number_type, text_type, text_type, text_type, boolean_type)

    with open('www/live-data/photo_efforts_fb.csv') as f:
        rows = list(csv.reader(f))

    column_names = rows.pop(0)
    table = Table(rows, column_types, column_names)

    facebook_summary = table.aggregate('on_facebook', (('duration', 'sum'), ))

    count_grand_total = facebook_summary.columns['on_facebook_count'].sum()
    facebook_summary = facebook_summary.compute(
        'on_facebook_count_pct', number_type, lambda x:
        (x['on_facebook_count'] / count_grand_total) * 100)

    count_grand_total = facebook_summary.columns['duration_sum'].sum()
    facebook_summary = facebook_summary.compute(
        'duration_sum_pct', number_type, lambda x:
        (x['duration_sum'] / count_grand_total) * 100)

    _write_summary_csv(facebook_summary, 'www/live-data/facebook_summary.csv')
Ejemplo n.º 13
0
    def test_aggregate_sum_invalid(self):
        table = Table(self.rows, self.column_types, self.column_names)

        with self.assertRaises(UnsupportedOperationError):
            table.aggregate('two', (('one', 'sum'), ))
Ejemplo n.º 14
0
    def test_aggregate_sum_invalid(self):
        table = Table(self.rows, self.column_types, self.column_names)

        with self.assertRaises(UnsupportedOperationError):
            table.aggregate('two', (('one', 'sum'), ))