Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrected data filtration logic for season and episode #30

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions thronetalk-game-of-thrones-summarizer/utils/data_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,26 +109,25 @@ def get_filtered_df(self, from_season,
for i in range(from_season,to_season+1):
season_data = self.data.loc[(self.data['Season_Number'] >= from_season) &
(self.data['Season_Number'] <= to_season)]

for j in range(1, 11):
if(i == from_season and j >= from_episode):
filtered_data = season_data[season_data['Episode_Number'] == j]
elif(i == to_season and j <= to_episode):
filtered_data = season_data[season_data['Episode_Number'] == j]
elif(i < to_season and i > from_season):
# Check if current season and episode are within the specified range
if ((i == from_season and j >= from_episode) or
(i == to_season and j <= to_episode) or
(from_season < i < to_season)):
filtered_data = season_data[season_data['Episode_Number'] == j]

return filtered_data

def get_top_n_characters(self, n_char, from_season,
def get_top_n_characters(self, from_season,
to_season=None, from_episode=None,
to_episode=None):
"""
Retrieves the names and dialogue counts of the top `n_char` characters based
Retrieves the names and dialogue counts of the top 15 characters based
on their dialogue frequency within a specified range of seasons and episodes.
Optionally excludes the narrator from the analysis.

Parameters:
n_char (int): The number of top characters to retrieve.
from_season (int): The starting season number.
to_season (int, optional): The ending season number. If not provided,
analysis is limited to `from_season`.
Expand All @@ -141,7 +140,7 @@ def get_top_n_characters(self, n_char, from_season,

Returns:
tuple: A tuple containing two lists:
- The first list contains the names of the top `n_char` characters.
- The first list contains the names of the top 15 characters.
- The second list contains the dialogue counts of these characters.
"""

Expand All @@ -157,7 +156,7 @@ def get_top_n_characters(self, n_char, from_season,
dialogue_count = filtered_data['Character'].str.upper().value_counts()

# Get the top characters
top_characters_names = dialogue_count.head(n_char).index.tolist()
top_characters_dialogues = dialogue_count.head(n_char).tolist()
top_characters_names = dialogue_count.head(15).index.tolist()
top_characters_dialogues = dialogue_count.head(15).tolist()

return top_characters_names, top_characters_dialogues
Loading