[O] Separate didn't post tables and histograms
This commit is contained in:
@@ -127,38 +127,42 @@ def report_top_20_tables(sample: Sample) -> None:
|
|||||||
r = Reporter(f'1-frequencies/{sample.name}-top-20.md')
|
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]],
|
r.print(tabulate([[u.name, f'{u.data * 100:.1f}%'] for u in sample.frequencies[:20]],
|
||||||
['Username', 'Frequency'], tablefmt="github"))
|
['Username', 'Frequency'], tablefmt="github"))
|
||||||
r.save()
|
|
||||||
|
|
||||||
r = Reporter(f'2-popularity-ratios/{sample.name}-top-20.md')
|
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]],
|
r.print(tabulate([[u.name, f'{u.data * 100:.1f}%'] for u in sample.popularity_ratios[:20]],
|
||||||
['Username', 'Popularity Ratio'], tablefmt="github"))
|
['Username', 'Popularity Ratio'], tablefmt="github"))
|
||||||
r.save()
|
|
||||||
|
|
||||||
|
|
||||||
def temp(sample: Sample):
|
def report_freq_didnt_post(samples: list[Sample]) -> None:
|
||||||
# Init reporter
|
"""
|
||||||
r = Reporter(f'{REPORT_DIR}/report.report.1-covid-tweet-frequency/{sample.name}.md')
|
Report how many people didn't post about covid or posted less than 1% about COVID across
|
||||||
r.print(f"In {sample.name} -")
|
different samples.
|
||||||
|
|
||||||
# How many people didn't post about COVID?
|
:param samples: Samples
|
||||||
r.print("How many people didn't post about COVID:",
|
:return: None
|
||||||
len([a for a in sample.frequencies if a.data == 0]))
|
"""
|
||||||
r.print("How many people have less than 1% of their posts about COVID:",
|
# Create table
|
||||||
len([a for a in sample.frequencies if a.data <= 0.01]))
|
table = [["Didn't post at all"] +
|
||||||
r.print()
|
[str(len([1 for a in s.frequencies if a.data == 0])) for s in samples],
|
||||||
|
["Posted less than 1%"] +
|
||||||
|
[str(len([1 for a in s.frequencies if a.data < 0.01])) for s in samples]]
|
||||||
|
|
||||||
# Top 20
|
r = Reporter(f'1-frequencies/didnt_post.md')
|
||||||
r.print(f"20 Users of who post COVID-related tweets most frequently:")
|
r.print(tabulate(table, [s.name for s in samples], tablefmt="github"))
|
||||||
|
|
||||||
# Save report
|
|
||||||
r.save()
|
|
||||||
|
|
||||||
# Graph histogram
|
def report_freq_histogram(sample: Sample) -> None:
|
||||||
|
"""
|
||||||
|
Report histogram of COVID posting frequencies
|
||||||
|
|
||||||
|
:param sample: Sample
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
plt.title(f'COVID-related posting frequency for {sample.name}')
|
plt.title(f'COVID-related posting frequency for {sample.name}')
|
||||||
plt.xticks(rotation=90)
|
plt.xticks(rotation=90)
|
||||||
plt.tight_layout()
|
plt.tight_layout()
|
||||||
plt.hist([f.data for f in sample.frequencies], bins=100, color='#ffcccc')
|
plt.hist([f.data for f in sample.frequencies], bins=100, color='#ffcccc')
|
||||||
plt.savefig(f'{REPORT_DIR}/report.report.1-covid-tweet-frequency/{sample.name}.png')
|
plt.savefig(f'1-frequencies/{sample.name}-hist.png')
|
||||||
|
|
||||||
|
|
||||||
def view_covid_tweets_pop(sample: Sample) -> None:
|
def view_covid_tweets_pop(sample: Sample) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user