matthew.farant commited on
Commit
e8ef367
·
1 Parent(s): 1cde511

Adjustment

Browse files
Files changed (1) hide show
  1. app/utils.py +38 -10
app/utils.py CHANGED
@@ -995,8 +995,10 @@ def get_user_life_status(user_id):
995
  "relationship": user.relationship_score
996
  }
997
 
 
 
998
  # Get current life score
999
- if len(user.score_history)==0:
1000
  thirtydays_life_score = cumulative_life_score
1001
  else:
1002
  # Calculate previous 30 days date
@@ -1004,22 +1006,48 @@ def get_user_life_status(user_id):
1004
  thirty_days_ago = now - pd.Timedelta(days=30)
1005
 
1006
  # Filter the data
1007
- filtered_data = [entry for entry in user.score_history if thirty_days_ago <= entry["created_at"] <= now]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1008
 
1009
  # Sum points_added, group by area
1010
  temp_df = pd.DataFrame(filtered_data)
1011
  grouped_points = temp_df.groupby("area")["points_added"].sum()
1012
 
1013
- # Structure the output
 
 
 
1014
  thirtydays_life_score = {
1015
- "overall": grouped_points.get("Personal Growth", 0) + grouped_points.get("Career Growth", 0) + grouped_points.get("Health and Wellness", 0) + grouped_points.get("Mental Well-being", 0) + grouped_points.get("Relationship", 0),
1016
- "personal_growth": grouped_points.get("Personal Growth", 0),
1017
- "health_and_wellness": grouped_points.get("Health and Wellness", 0),
1018
- "mental_well_being": grouped_points.get("Mental Well-being", 0),
1019
- "career_growth": grouped_points.get("Career Growth", 0),
1020
- "relationship": grouped_points.get("Relationship", 0)
 
 
 
 
 
 
1021
  }
1022
 
 
 
 
1023
  # Get current goal
1024
  current_goal = '' if not user.goal else user.goal[-1].content
1025
  # Get life score achievements in list
@@ -1035,7 +1063,7 @@ def get_user_life_status(user_id):
1035
  }
1036
 
1037
  # Step 4: Return the JSON reports
1038
- logger.info(f"User life status generated successfully for user {user_id}", extra={'user_id': user_id, 'endpoint': function_name})
1039
  return reports
1040
 
1041
  async def get_api_key(api_key_header: str = Security(api_key_header)) -> str:
 
995
  "relationship": user.relationship_score
996
  }
997
 
998
+ logger.info(f"{user.score_history}",extra={'user_id': user_id, 'endpoint': function_name})
999
+
1000
  # Get current life score
1001
+ if len(user.score_history) == 0:
1002
  thirtydays_life_score = cumulative_life_score
1003
  else:
1004
  # Calculate previous 30 days date
 
1006
  thirty_days_ago = now - pd.Timedelta(days=30)
1007
 
1008
  # Filter the data
1009
+ filtered_data = [entry for entry in user.score_history if thirty_days_ago <= entry["created_at"] <= now]
1010
+ logger.info(f"Filtered Data: {filtered_data}", extra={'user_id': user_id, 'endpoint': function_name})
1011
+
1012
+ # Normalize area names to match expected keys
1013
+ area_mapping = {
1014
+ "Personal Growth": "personal_growth",
1015
+ "Health and Wellness": "health_and_wellness",
1016
+ "Mental Well-being": "mental_well_being",
1017
+ "Career Growth": "career_growth",
1018
+ "Relationship": "relationship"
1019
+ }
1020
+
1021
+ # Normalize area names in filtered data
1022
+ for entry in filtered_data:
1023
+ entry["area"] = area_mapping.get(entry["area"], entry["area"])
1024
 
1025
  # Sum points_added, group by area
1026
  temp_df = pd.DataFrame(filtered_data)
1027
  grouped_points = temp_df.groupby("area")["points_added"].sum()
1028
 
1029
+ # Debug: Check the grouped points result
1030
+ logger.info(f"Grouped Points: {grouped_points}", extra={'user_id': user_id, 'endpoint': function_name})
1031
+
1032
+ # Structure the output safely
1033
  thirtydays_life_score = {
1034
+ "overall": sum([
1035
+ grouped_points.get("personal_growth", 0),
1036
+ grouped_points.get("career_growth", 0),
1037
+ grouped_points.get("health_and_wellness", 0),
1038
+ grouped_points.get("mental_well_being", 0),
1039
+ grouped_points.get("relationship", 0),
1040
+ ]),
1041
+ "personal_growth": grouped_points.get("personal_growth", 0),
1042
+ "health_and_wellness": grouped_points.get("health_and_wellness", 0),
1043
+ "mental_well_being": grouped_points.get("mental_well_being", 0),
1044
+ "career_growth": grouped_points.get("career_growth", 0),
1045
+ "relationship": grouped_points.get("relationship", 0)
1046
  }
1047
 
1048
+ # Debug: Check the final structured result
1049
+ logger.info(f"Final Thirty Days Life Score: {thirtydays_life_score}", extra={'user_id': user_id, 'endpoint': function_name})
1050
+
1051
  # Get current goal
1052
  current_goal = '' if not user.goal else user.goal[-1].content
1053
  # Get life score achievements in list
 
1063
  }
1064
 
1065
  # Step 4: Return the JSON reports
1066
+ logger.info(f"User life status generated successfully for user {user_id}: {reports}", extra={'user_id': user_id, 'endpoint': function_name})
1067
  return reports
1068
 
1069
  async def get_api_key(api_key_header: str = Security(api_key_header)) -> str: