[+] Class attributes

This commit is contained in:
Hykilpikonna
2021-12-13 17:37:00 -05:00
parent 1eb28a62bb
commit c1b04a741e
4 changed files with 43 additions and 18 deletions
+1
View File
@@ -4,6 +4,7 @@ It contains functions related scraping users/tweets, including:
- getting the tweets of a user - getting the tweets of a user
- downloading many users by checking their followers and follower's followers, etc. - downloading many users by checking their followers and follower's followers, etc.
""" """
import json import json
import math import math
import os import os
+19 -11
View File
@@ -27,14 +27,16 @@ class ProcessedUser(NamedTuple):
example, using dataclass, the json for one UserPopularity object will be: example, using dataclass, the json for one UserPopularity object will be:
{"username": "a", "popularity": 1, "num_postings": 1}, while using NamedTuple, the json will be: {"username": "a", "popularity": 1, "num_postings": 1}, while using NamedTuple, the json will be:
["a", 1, 1], which saves an entire 42 bytes for each user. ["a", 1, 1], which saves an entire 42 bytes for each user.
Attributes:
- username: The Twitter user's screen name
- popularity: A measurement of a user's popularity, such as followers count
- num_postings: Number of tweets
- language: Language code in Twitter's language code format
""" """
# Username
username: str username: str
# A measurement of a user's popularity, such as followers count
popularity: int popularity: int
# Number of tweets
num_postings: int num_postings: int
# Language
lang: str lang: str
@@ -107,6 +109,11 @@ class UserSample:
""" """
This is a data class storing our different samples. This is a data class storing our different samples.
Attributes:
- most_popular: Our sample of the most popular users on Twitter
- random: Our sample of random users on Twitter
- english_news: Our sample of news media accounts on Twitter
Representation Invariants: Representation Invariants:
- all(news != '' for news in self.english_news) - all(news != '' for news in self.english_news)
@@ -224,20 +231,21 @@ def load_user_sample() -> UserSample:
class Posting(NamedTuple): class Posting(NamedTuple):
""" """
Posting data stores the processed tweets data, and it contains info such as whether or not a Posting data stores the processed tweets data, and it contains info such as whether a tweet is
tweet is covid-related covid-related
Attributes:
- covid_related: True if the post is determined to be covid-related
- popularity: A measure of tweet popularity measured by comments + likes
- repost: Whether the post is a repost
- date: Posting date and time in ISO format ("YYYY-MM-DDThh-mm-ss")
Representation Invariants: Representation Invariants:
- popularity >= 0 - popularity >= 0
""" """
# Full text of the post's content
covid_related: bool covid_related: bool
# Popularity of the post
popularity: int popularity: int
# Is it a repost
repost: bool repost: bool
# Date in ISO format
date: str date: str
+3
View File
@@ -20,6 +20,9 @@ def generate_report() -> str:
""" """
Compile the report document and generate a markdown report Compile the report document and generate a markdown report
Preconditions:
- RES_DIR exists, and contains the necessary resources used in this project.
:return: Markdown report :return: Markdown report
""" """
# Load markdown # Load markdown
+20 -7
View File
@@ -30,9 +30,12 @@ class UserFloat:
This is used for both COVID tweet frequency and popularity ratio data, because both of these This is used for both COVID tweet frequency and popularity ratio data, because both of these
are floating point data. are floating point data.
Attributes:
- name: Twitter user's screen name
- data: The float data that's associated with this user
Representation Invariants: Representation Invariants:
- self.name != '' - self.name != ''
""" """
name: str name: str
data: float data: float
@@ -42,23 +45,33 @@ class Sample:
""" """
A sample of many users, containing statistical data that will be used in graphs. A sample of many users, containing statistical data that will be used in graphs.
Attributes:
- name: Sample name
- users: List of user screen names in this sample
- user_freqs: Total frequencies of all posts for each user across all dates (sorted)
- user_pops: Total popularity ratios of all posts for each user across all dates (sorted)
- user_all_pop_avg: Average popularity of all u's posts
- user_date_covid_pop_avg: Average popularity of COVID tweets by a specific user on a date
(user_covid_tweets_pop[user][date] = Average popularity of COVID-posts by {user} on {date})
- date_covid_freq: Total COVID-tweets frequency on a specific date for all users.
- dates: dates[i] = The i-th day since the first tweet
- date_freqs: date_freqs[i] = COVID frequency of all posts from all sampled users on date[i]
- date_pops: date_pops[i] = Average pop-ratio of all posts from all sampled users on date[i]
Representation Invariants: Representation Invariants:
- self.name != '' - self.name != ''
- all(name != '' for name in self.users) - all(name != '' for name in self.users)
""" """
name: str name: str
users: list[str] users: list[str]
# Total frequencies of all posts for each user across all dates (sorted)
user_freqs: list[UserFloat] user_freqs: list[UserFloat]
# Total popularity ratios of all posts for each user across all dates (sorted)
user_pops: list[UserFloat] user_pops: list[UserFloat]
# Average popularity of all u's posts
user_all_pop_avg: dict[str, float] user_all_pop_avg: dict[str, float]
# Average popularity of COVID tweets by a specific user on a specific date
# user_covid_tweets_pop[user][date] = Average popularity of COVID-posts by {user} on {date} # user_covid_tweets_pop[user][date] = Average popularity of COVID-posts by {user} on {date}
user_date_covid_pop_avg: dict[str, dict[str, float]] user_date_covid_pop_avg: dict[str, dict[str, float]]
# Total COVID-tweets frequency on a specific date for all users.
date_covid_freq: dict[str, float] date_covid_freq: dict[str, float]
# dates[i] = The i-th day since the first tweet # dates[i] = The i-th day since the first tweet
dates: list[datetime] dates: list[datetime]