style: run python linter & prettifier on backend code

This commit is contained in:
2026-03-25 19:34:43 +00:00
parent aae10c4d9d
commit 376773a0cc
17 changed files with 408 additions and 315 deletions

View File

@@ -2,6 +2,7 @@ import pandas as pd
from server.analysis.nlp import NLP
class DatasetEnrichment:
def __init__(self, df: pd.DataFrame, topics: dict):
self.df = self._explode_comments(df)
@@ -10,7 +11,9 @@ class DatasetEnrichment:
def _explode_comments(self, df) -> pd.DataFrame:
comments_df = df[["id", "comments"]].explode("comments")
comments_df = comments_df[comments_df["comments"].apply(lambda x: isinstance(x, dict))]
comments_df = comments_df[
comments_df["comments"].apply(lambda x: isinstance(x, dict))
]
comments_df = pd.json_normalize(comments_df["comments"])
posts_df = df.drop(columns=["comments"])
@@ -24,16 +27,16 @@ class DatasetEnrichment:
df.drop(columns=["post_id"], inplace=True, errors="ignore")
return df
def enrich(self) -> pd.DataFrame:
self.df['timestamp'] = pd.to_numeric(self.df['timestamp'], errors='raise')
self.df['date'] = pd.to_datetime(self.df['timestamp'], unit='s').dt.date
self.df["timestamp"] = pd.to_numeric(self.df["timestamp"], errors="raise")
self.df["date"] = pd.to_datetime(self.df["timestamp"], unit="s").dt.date
self.df["dt"] = pd.to_datetime(self.df["timestamp"], unit="s", utc=True)
self.df["hour"] = self.df["dt"].dt.hour
self.df["weekday"] = self.df["dt"].dt.day_name()
self.nlp.add_emotion_cols()
self.nlp.add_topic_col()
self.nlp.add_ner_cols()
return self.df
return self.df