Spaces:
Sleeping
Sleeping
Update database_connection.py
Browse files31 unmodified lines32333435363738394041424344454647484950515253545531 unmodified linesreturn pd.DataFrame()def add_feedback(self, course: str, stanine: int, gwa: float, strand: str,rating: int, hobbies: str) -> bool:"""Add new feedback to the database"""try:url = f"{self.base_url}/student_feedback_counts"data = {"course": course,"stanine": stanine,"gwa": gwa,"strand": strand,"rating": rating,"hobbies": hobbies}response = self.session.post(url, json=data)response.raise_for_status()return Trueexcept Exception as e:print(f"Error adding feedback: {e}")return Falsedef update_feedback_count(self, feedback_id: int, count: int) -> bool:"""Update the count for existing feedback"""31 unmodified lines32333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818231 unmodified linesreturn pd.DataFrame()def add_feedback(self, course: str, stanine: int, gwa: float, strand: str,rating: str, hobbies: str) -> bool:"""Add new feedback to the database"""try:# Try the original structure first (matching the existing data)url = f"{self.base_url}/student_feedback_counts"# Rating is already a string ("like" or "dislike")rating_str = ratingdata = {"course": course,"stanine": stanine,"gwa": gwa,"strand": strand,"rating": rating_str,"hobbies": hobbies,"count": 1}response = self.session.post(url, json=data)response.raise_for_status()return Trueexcept Exception as e:print(f"Error adding feedback: {e}")# If the above fails, try the API structure you providedtry:print("Trying alternative API structure...")feedback_type = rating # Rating is already "like" or "dislike"import hashlibstudent_data = f"{stanine}_{gwa}_{strand}_{hobbies}"student_id = hashlib.md5(student_data.encode()).hexdigest()[:8]data = {"student_id": student_id,"feedback_type": feedback_type,"count": 1}response = self.session.post(url, json=data)response.raise_for_status()return Trueexcept Exception as e2:print(f"Alternative method also failed: {e2}")return Falsedef update_feedback_count(self, feedback_id: int, count: int) -> bool:"""Update the count for existing feedback"""
database_connection.py+31-4