This commit is contained in:
@@ -51,8 +51,9 @@ class MobileMood(str, Enum):
|
||||
"""Mood values used in the mobile app"""
|
||||
HAPPY = "HAPPY"
|
||||
SAD = "SAD"
|
||||
NORMAL = "NORMAL" # Added for mobile app support
|
||||
ANXIOUS = "ANXIOUS"
|
||||
IRRITABLE = "IRRITABLE"
|
||||
IRRITATED = "IRRITATED"
|
||||
ENERGETIC = "ENERGETIC"
|
||||
TIRED = "TIRED"
|
||||
|
||||
@@ -65,8 +66,9 @@ class MobileMood(str, Enum):
|
||||
mapping = {
|
||||
cls.HAPPY: MoodType.HAPPY,
|
||||
cls.SAD: MoodType.SAD,
|
||||
cls.NORMAL: MoodType.HAPPY, # NORMAL maps to HAPPY
|
||||
cls.ANXIOUS: MoodType.ANXIOUS,
|
||||
cls.IRRITABLE: MoodType.IRRITATED, # Different spelling
|
||||
cls.IRRITATED: MoodType.IRRITATED, # Different spelling
|
||||
cls.ENERGETIC: MoodType.ENERGETIC,
|
||||
cls.TIRED: MoodType.TIRED,
|
||||
}
|
||||
@@ -194,4 +196,71 @@ def convert_server_response_to_mobile_app(
|
||||
notes=server_response.notes,
|
||||
created_at=getattr(server_response, "created_at", date.today()),
|
||||
updated_at=getattr(server_response, "created_at", date.today()), # Fallback to created_at
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def convert_mobile_entry_type(mobile_type: str) -> str:
|
||||
"""Конвертирует тип записи из мобильного формата в формат API"""
|
||||
mapping = {
|
||||
"MENSTRUATION": "period",
|
||||
"OVULATION": "ovulation",
|
||||
"FERTILE": "fertile_window",
|
||||
"OTHER": "other"
|
||||
}
|
||||
return mapping.get(mobile_type, "other")
|
||||
|
||||
|
||||
def convert_mobile_flow_intensity(intensity: int) -> str:
|
||||
"""Конвертирует интенсивность потока из мобильного формата в формат API"""
|
||||
if intensity is None:
|
||||
return None
|
||||
|
||||
mapping = {
|
||||
1: "very_light",
|
||||
2: "light",
|
||||
3: "medium",
|
||||
4: "heavy",
|
||||
5: "very_heavy"
|
||||
}
|
||||
return mapping.get(intensity, "medium")
|
||||
|
||||
|
||||
def convert_mobile_mood(mood: str) -> str:
|
||||
"""Конвертирует настроение из мобильного формата в формат API"""
|
||||
if mood is None:
|
||||
return None
|
||||
|
||||
mapping = {
|
||||
"HAPPY": "happy",
|
||||
"SAD": "sad",
|
||||
"NORMAL": "happy", # NORMAL мапится на happy
|
||||
"ANXIOUS": "anxious",
|
||||
"IRRITATED": "irritated",
|
||||
"ENERGETIC": "energetic",
|
||||
"TIRED": "tired"
|
||||
}
|
||||
return mapping.get(mood, "happy")
|
||||
|
||||
|
||||
def convert_mobile_symptoms(symptoms: List[str]) -> str:
|
||||
"""Конвертирует список симптомов из мобильного формата в строку для API"""
|
||||
if not symptoms:
|
||||
return ""
|
||||
|
||||
# Преобразуем все симптомы в нижний регистр и соединяем запятыми
|
||||
return ",".join([symptom.lower() for symptom in symptoms])
|
||||
|
||||
|
||||
def mobile_to_api_format(mobile_data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""Конвертирует данные из мобильного формата в формат API"""
|
||||
api_data = {
|
||||
"entry_date": mobile_data.get("date"),
|
||||
"entry_type": convert_mobile_entry_type(mobile_data.get("type")),
|
||||
"flow_intensity": convert_mobile_flow_intensity(mobile_data.get("flow_intensity")),
|
||||
"mood": convert_mobile_mood(mobile_data.get("mood")),
|
||||
"symptoms": convert_mobile_symptoms(mobile_data.get("symptoms")),
|
||||
"notes": mobile_data.get("notes", "")
|
||||
}
|
||||
|
||||
# Удаляем None значения
|
||||
return {k: v for k, v in api_data.items() if v is not None}
|
||||
|
||||
Reference in New Issue
Block a user