[M] Split table creating into a separate function
This commit is contained in:
@@ -117,12 +117,25 @@ def calculate_sample_data(users: list[str]) -> tuple[list[UserFloat], list[UserF
|
|||||||
return frequency, popularity, all_tweets
|
return frequency, popularity, all_tweets
|
||||||
|
|
||||||
|
|
||||||
def view_covid_tweets_freq(sample: Sample) -> None:
|
def report_top_20_tables(sample: Sample) -> None:
|
||||||
"""
|
"""
|
||||||
|
Get top-20 most frequent or most relatively popular users and store them in a table.
|
||||||
|
|
||||||
:param sample: Sample
|
:param sample: Sample
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
|
r = Reporter(f'1-frequencies/{sample.name}-top-20.md')
|
||||||
|
r.print(tabulate([[u.name, f'{u.data * 100:.1f}%'] for u in sample.frequencies[:20]],
|
||||||
|
['Username', 'Frequency'], tablefmt="github"))
|
||||||
|
r.save()
|
||||||
|
|
||||||
|
r = Reporter(f'2-popularity-ratios/{sample.name}-top-20.md')
|
||||||
|
r.print(tabulate([[u.name, f'{u.data * 100:.1f}%'] for u in sample.popularity_ratios[:20]],
|
||||||
|
['Username', 'Popularity Ratio'], tablefmt="github"))
|
||||||
|
r.save()
|
||||||
|
|
||||||
|
|
||||||
|
def temp(sample: Sample):
|
||||||
# Init reporter
|
# Init reporter
|
||||||
r = Reporter(f'{REPORT_DIR}/report.report.1-covid-tweet-frequency/{sample.name}.md')
|
r = Reporter(f'{REPORT_DIR}/report.report.1-covid-tweet-frequency/{sample.name}.md')
|
||||||
r.print(f"In {sample.name} -")
|
r.print(f"In {sample.name} -")
|
||||||
@@ -136,8 +149,6 @@ def view_covid_tweets_freq(sample: Sample) -> None:
|
|||||||
|
|
||||||
# Top 20
|
# Top 20
|
||||||
r.print(f"20 Users of who post COVID-related tweets most frequently:")
|
r.print(f"20 Users of who post COVID-related tweets most frequently:")
|
||||||
r.print(tabulate([[u.name, f'{u.data * 100:.1f}%'] for u in sample.frequencies[:20]],
|
|
||||||
['Username', 'Frequency'], tablefmt="github"))
|
|
||||||
|
|
||||||
# Save report
|
# Save report
|
||||||
r.save()
|
r.save()
|
||||||
@@ -165,12 +176,6 @@ def view_covid_tweets_pop(sample: Sample) -> None:
|
|||||||
f"in this list.")
|
f"in this list.")
|
||||||
r.print()
|
r.print()
|
||||||
|
|
||||||
# Top 20
|
|
||||||
r.print(f"20 Users of whose COVID-related posts are the most popular:")
|
|
||||||
r.print(tabulate([[u.name, f'{u.data:.2f}'] for u in sample.popularity_ratios[:20]],
|
|
||||||
['Username', 'Popularity Ratio'], tablefmt="github"))
|
|
||||||
r.print()
|
|
||||||
|
|
||||||
# Calculate statistics
|
# Calculate statistics
|
||||||
x_list = [f.data for f in sample.popularity_ratios]
|
x_list = [f.data for f in sample.popularity_ratios]
|
||||||
s = get_statistics(x_list)
|
s = get_statistics(x_list)
|
||||||
|
|||||||
Reference in New Issue
Block a user