From 8c76476cd3cd739a2bc645b0df900df2ee9bbf79 Mon Sep 17 00:00:00 2001 From: Dylan De Faoite Date: Mon, 23 Feb 2026 18:14:24 +0000 Subject: [PATCH] fix(api): broken analysis calls due to overlap in attribute and method names --- server/app.py | 21 +++++++++++++++++---- server/stat_gen.py | 12 ++++++------ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/server/app.py b/server/app.py index 760e48d..7118f4c 100644 --- a/server/app.py +++ b/server/app.py @@ -55,7 +55,7 @@ def word_frequencies(): return jsonify({"error": "No data uploaded"}), 400 try: - return jsonify(stat_obj.content_analysis()), 200 + return jsonify(stat_obj.get_content_analysis()), 200 except ValueError as e: return jsonify({"error": f"Malformed or missing data: {str(e)}"}), 400 except Exception as e: @@ -80,7 +80,7 @@ def get_time_analysis(): return jsonify({"error": "No data uploaded"}), 400 try: - return jsonify(stat_obj.time_analysis()), 200 + return jsonify(stat_obj.get_time_analysis()), 200 except ValueError as e: return jsonify({"error": f"Malformed or missing data: {str(e)}"}), 400 except Exception as e: @@ -93,7 +93,7 @@ def get_user_analysis(): return jsonify({"error": "No data uploaded"}), 400 try: - return jsonify(stat_obj.user_analysis()), 200 + return jsonify(stat_obj.get_user_analysis()), 200 except ValueError as e: return jsonify({"error": f"Malformed or missing data: {str(e)}"}), 400 except Exception as e: @@ -106,13 +106,26 @@ def get_cultural_analysis(): return jsonify({"error": "No data uploaded"}), 400 try: - return jsonify(stat_obj.cultural_analysis()), 200 + return jsonify(stat_obj.get_cultural_analysis()), 200 except ValueError as e: return jsonify({"error": f"Malformed or missing data: {str(e)}"}), 400 except Exception as e: print(traceback.format_exc()) return jsonify({"error": f"An unexpected error occurred: {str(e)}"}), 500 + +@app.route("/stats/interaction", methods=["GET"]) +def get_interaction_analysis(): + if stat_obj is None: + return jsonify({"error": "No data uploaded"}), 400 + try: + return jsonify(stat_obj.get_interactional_analysis()), 200 + except ValueError as e: + return jsonify({"error": f"Malformed or missing data: {str(e)}"}), 400 + except Exception as e: + print(traceback.format_exc()) + return jsonify({"error": f"An unexpected error occurred: {str(e)}"}), 500 + @app.route('/filter/search', methods=["POST"]) def search_dataset(): if stat_obj is None: diff --git a/server/stat_gen.py b/server/stat_gen.py index 014f95f..209589b 100644 --- a/server/stat_gen.py +++ b/server/stat_gen.py @@ -66,14 +66,14 @@ class StatGen: # topics over time # emotions over time - def time_analysis(self) -> pd.DataFrame: + def get_time_analysis(self) -> pd.DataFrame: return { "events_per_day": self.temporal_analysis.posts_per_day(), "weekday_hour_heatmap": self.temporal_analysis.heatmap() } # average topic duration - def content_analysis(self) -> dict: + def get_content_analysis(self) -> dict: return { "word_frequencies": self.linguistic_analysis.word_frequencies(), "common_two_phrases": self.linguistic_analysis.ngrams(), @@ -84,7 +84,7 @@ class StatGen: # average emotion per user # average chain length - def user_analysis(self) -> dict: + def get_user_analysis(self) -> dict: return { "top_users": self.interaction_analysis.top_users(), "users": self.interaction_analysis.per_user_analysis(), @@ -94,14 +94,14 @@ class StatGen: # average / max thread depth # high engagment threads based on volume - def conversational_analysis(self) -> dict: + def get_interactional_analysis(self) -> dict: return { - + "average_thread_depth": self.interaction_analysis.average_thread_depth(), } # detect community jargon # in-group and out-group linguistic markers - def cultural_analysis(self) -> dict: + def get_cultural_analysis(self) -> dict: return { "identity_markers": self.linguistic_analysis.identity_markers() }