Skip to content

Commit

Permalink
Add comments in flickr/photos_detail.py and some minor styling changes
Browse files Browse the repository at this point in the history
Signed-off-by: Priyanshi Gaur <noxdot1134@gmail.com>
  • Loading branch information
nox1134 committed Mar 12, 2024
1 parent 2be88a6 commit 6f73b00
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 84 deletions.
14 changes: 7 additions & 7 deletions analyze/data_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ def time_trend_helper(df):
Extract year-wise count of entries from a DataFrame.
Args:
df (DataFrame): Input DataFrame containing dates.
- df (DataFrame): Input DataFrame containing dates.
Returns:
DataFrame: DataFrame with counts of entries per year.
- DataFrame: DataFrame with counts of entries per year.
"""
year_list = []
for date_row in df["dates"][0:]:
Expand All @@ -167,7 +167,7 @@ def time_trend(csv_path):
Generate a line graph to show the time trend of the license usage.
Args:
csv_path (str): Path to the CSV file.
- csv_path (str): Path to the CSV file.
"""
df = pd.read_csv(csv_path)
count_df = time_trend_helper(df)
Expand Down Expand Up @@ -205,10 +205,10 @@ def time_trend_compile_helper(yearly_count):
Filter yearly trend data for the years between 2018 and 2022.
Args:
yearly_count (DataFrame): DataFrame with "year" and "Counts" columns.
- yearly_count (DataFrame): DataFrame with "year" and "Counts" columns.
Returns:
DataFrame: Filtered yearly count data.
- DataFrame: Filtered yearly count data.
"""
Years = np.arange(2018, 2023)
yearly_count["year"] = list(yearly_count.index)
Expand Down Expand Up @@ -370,10 +370,10 @@ def view_compare_helper(df):
Calculate maximum views of pictures under a license.
Args:
df (DataFrame): Input DataFrame.
- df (DataFrame): Input DataFrame.
Returns:
int: Maximum views.
- int: Maximum views.
"""
highest_view = int(max(df["views"]))
df = df.sort_values("views", ascending=False)
Expand Down
28 changes: 13 additions & 15 deletions deviantart/deviantart_scratcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def get_license_list():
Provides the list of license from 2018's record of Creative Commons.
Returns:
np.array: An array containing all license types that should be
searched via Programmable Search Engine.
- np.array: An array containing all license types that should be
searched via Programmable Search Engine.
"""
# Read license data from file
cc_license_data = pd.read_csv(f"{CWD}/legal-tool-paths.txt", header=None)
Expand All @@ -61,11 +61,11 @@ def get_request_url(license):
"""
Provides the API Endpoint URL for specified parameter combinations.
Args:
license (str): A string representing the type of license. It's a
segment of the URL towards the license description.
- license (str): A string representing the type of license. It's a
segment of the URL towards the license description.
Returns:
str: The API Endpoint URL for the query specified by parameters.
- str: The API Endpoint URL for the query specified by parameters.
"""
try:
api_key = API_KEYS[API_KEYS_IND]
Expand All @@ -86,14 +86,13 @@ def get_response_elems(license):
"""
Provides the metadata for query of specified parameters
Args:
license (str):
A string representing the type of license. It's a segment of the URL
towards the license description. If not provided, it defaults to None,
indicating no assumption about the license type.
- license (str): A string representing the type of license.
It's a segment of the URL towards the license description. If not provided,
it defaults to None, indicating no assumption about the license type.
Returns:
dict: A dictionary mapping metadata to its value provided from the API
query.
- dict: A dictionary mapping metadata to its value provided from the API
query.
"""
try:
# Make a request to the API and handle potential retries
Expand Down Expand Up @@ -136,10 +135,9 @@ def set_up_data_file():
def record_license_data(license_type):
"""Writes the row for LICENSE_TYPE to the file to contain DeviantArt data.
Args:
license_type(str):
A string representing the type of license. It's a segment of the
URL towards the license description. If not provided, it defaults
to None, indicating no assumption about the license type.
- license_type(str): A string representing the type of license.
It's a segment of the URL towards the license description. If not provided,
it defaults to None, indicating no assumption about the license type.
"""
data_log = (
f"{license_type},"
Expand Down
16 changes: 8 additions & 8 deletions flickr/data_cleaning.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def drop_empty_column(csv_path, new_csv_path):
"""
Drops columns with 'Unnamed' in the name from the CSV file.
Args:
csv_path (str): Path to the original CSV file.
new_csv_path (str): Path to save the cleaned CSV file.
- csv_path (str): Path to the original CSV file.
- new_csv_path (str): Path to save the cleaned CSV file.
"""
df = pd.read_csv(csv_path)
for col in df.columns:
Expand All @@ -41,8 +41,8 @@ def drop_duplicate_id(csv_path, new_csv_path):
Drops duplicate rows based on the 'id' column from the CSV file.
Args:
csv_path (str): Path to the original CSV file.
new_csv_path (str): Path to save the cleaned CSV file.
- csv_path (str): Path to the original CSV file.
- new_csv_path (str): Path to save the cleaned CSV file.
"""
df = pd.read_csv(csv_path)
data = df.drop_duplicates(subset=["id"])
Expand All @@ -55,10 +55,10 @@ def save_new_data(csv_path, column_name_list, new_csv_path):
Saves specified columns from the original CSV file to a new CSV file.
Args:
csv_path (str): Path to the original CSV file.
column_name_list (list of str): List of column names to be saved
(belongs to the existing column names from original csv)
new_csv_path (str): Path to save the new CSV file.
- csv_path (str): Path to the original CSV file.
- column_name_list (list of str): List of column names to be saved
(belongs to the existing column names from original csv)
- new_csv_path (str): Path to save the new CSV file.
"""
df = pd.read_csv(csv_path)
new_df = pd.DataFrame()
Expand Down
Loading

0 comments on commit 6f73b00

Please sign in to comment.