本文整理汇总了Python中journalism.Table.aggregate方法的典型用法代码示例。如果您正苦于以下问题:Python Table.aggregate方法的具体用法?Python Table.aggregate怎么用?Python Table.aggregate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类journalism.Table
的用法示例。
在下文中一共展示了Table.aggregate方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: analyse_photo_efforts
# 需要导入模块: from journalism import Table [as 别名]
# 或者: from journalism.Table import aggregate [as 别名]
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')
示例2: test_aggregeate_bad_column
# 需要导入模块: from journalism import Table [as 别名]
# 或者: from journalism.Table import aggregate [as 别名]
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'), ))
示例3: analyse_insights
# 需要导入模块: from journalism import Table [as 别名]
# 或者: from journalism.Table import aggregate [as 别名]
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)
示例4: test_aggregate_two_ops
# 需要导入模块: from journalism import Table [as 别名]
# 或者: from journalism.Table import aggregate [as 别名]
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))
示例5: analyse_effort_and_analytics
# 需要导入模块: from journalism import Table [as 别名]
# 或者: from journalism.Table import aggregate [as 别名]
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')
示例6: analyse_photo_efforts_fb
# 需要导入模块: from journalism import Table [as 别名]
# 或者: from journalism.Table import aggregate [as 别名]
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')
示例7: test_aggregate_sum_invalid
# 需要导入模块: from journalism import Table [as 别名]
# 或者: from journalism.Table import aggregate [as 别名]
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'), ))