Spaces:
Runtime error
Runtime error
Download app/models/gamification.py from lmends/MoneyCouple: direct link, hf CLI and curl.
- Browser
- Download file 4.58 kB
-
https://huggingface.co/spaces/lmends/MoneyCouple/resolve/main/app/models/gamification.py
- Command line
-
hf download hf://spaces/lmends/MoneyCouple/app/models/gamification.py
-
curl -L -o gamification.py https://huggingface.co/spaces/lmends/MoneyCouple/resolve/main/app/models/gamification.py
4.58 kB
| import uuid | |
| from datetime import datetime, timezone | |
| from app import db | |
| class Badge(db.Model): | |
| """Achievements / badges earned by users.""" | |
| __tablename__ = "badges" | |
| id = db.Column(db.String(36), primary_key=True, default=lambda: str(uuid.uuid4())) | |
| slug = db.Column(db.String(50), nullable=False) # unique key for the badge type | |
| user_id = db.Column(db.String(36), db.ForeignKey("users.id"), nullable=False) | |
| earned_at = db.Column(db.DateTime, default=lambda: datetime.now(timezone.utc)) | |
| user = db.relationship("User", foreign_keys=[user_id]) | |
| def to_dict(self): | |
| meta = BADGE_CATALOG.get(self.slug, {}) | |
| return { | |
| "id": self.id, | |
| "slug": self.slug, | |
| "name": meta.get("name", self.slug), | |
| "description": meta.get("description", ""), | |
| "icon": meta.get("icon", "π "), | |
| "color": meta.get("color", "#f59e0b"), | |
| "earned_at": self.earned_at.isoformat(), | |
| } | |
| class Challenge(db.Model): | |
| """Quick financial challenges (e.g. 'No delivery week').""" | |
| __tablename__ = "challenges" | |
| id = db.Column(db.String(36), primary_key=True, default=lambda: str(uuid.uuid4())) | |
| title = db.Column(db.String(150), nullable=False) | |
| description = db.Column(db.Text, nullable=True) | |
| start_date = db.Column(db.Date, nullable=False) | |
| end_date = db.Column(db.Date, nullable=False) | |
| target_category_id = db.Column(db.String(36), db.ForeignKey("categories.id"), nullable=True) | |
| max_amount = db.Column(db.Float, nullable=True) # budget ceiling during challenge | |
| is_completed = db.Column(db.Boolean, default=False) | |
| user_id = db.Column(db.String(36), db.ForeignKey("users.id"), nullable=False) | |
| couple_id = db.Column(db.String(36), db.ForeignKey("couples.id"), nullable=True) | |
| created_at = db.Column(db.DateTime, default=lambda: datetime.now(timezone.utc)) | |
| category = db.relationship("Category", foreign_keys=[target_category_id]) | |
| def to_dict(self): | |
| return { | |
| "id": self.id, | |
| "title": self.title, | |
| "description": self.description, | |
| "start_date": self.start_date.isoformat(), | |
| "end_date": self.end_date.isoformat(), | |
| "target_category_id": self.target_category_id, | |
| "category": self.category.to_dict() if self.category else None, | |
| "max_amount": self.max_amount, | |
| "is_completed": self.is_completed, | |
| "user_id": self.user_id, | |
| "couple_id": self.couple_id, | |
| "created_at": self.created_at.isoformat(), | |
| } | |
| # ββ Badge Catalog βββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| BADGE_CATALOG = { | |
| "first_transaction": { | |
| "name": "Primeiro Passo", | |
| "description": "Criou o primeiro lanΓ§amento", | |
| "icon": "π―", | |
| "color": "#3b82f6", | |
| }, | |
| "budget_master": { | |
| "name": "MΓ£o Fechada", | |
| "description": "Ficou abaixo do orΓ§amento em todas as categorias por um mΓͺs", | |
| "icon": "β", | |
| "color": "#10b981", | |
| }, | |
| "investor": { | |
| "name": "Investidor", | |
| "description": "Acumulou R$1.000 em cofrinhos", | |
| "icon": "π", | |
| "color": "#6366f1", | |
| }, | |
| "saver_streak": { | |
| "name": "Poupador Serial", | |
| "description": "3 meses consecutivos com saldo positivo", | |
| "icon": "π₯", | |
| "color": "#ef4444", | |
| }, | |
| "couple_goals": { | |
| "name": "Casal Unido", | |
| "description": "Completou uma meta de casal juntos", | |
| "icon": "π", | |
| "color": "#ec4899", | |
| }, | |
| "no_delivery_week": { | |
| "name": "Cozinheiro(a)", | |
| "description": "Passou uma semana sem delivery", | |
| "icon": "π³", | |
| "color": "#f97316", | |
| }, | |
| "emergency_ready": { | |
| "name": "Reserva OK", | |
| "description": "Reserva de emergΓͺncia cobre 6+ meses", | |
| "icon": "π‘οΈ", | |
| "color": "#14b8a6", | |
| }, | |
| "goal_complete": { | |
| "name": "Meta Atingida", | |
| "description": "Completou 100% de um cofrinho", | |
| "icon": "π", | |
| "color": "#f59e0b", | |
| }, | |
| "subscription_audit": { | |
| "name": "Auditor", | |
| "description": "Cancelou pelo menos uma assinatura", | |
| "icon": "π", | |
| "color": "#8b5cf6", | |
| }, | |
| "split_fair": { | |
| "name": "DivisΓ£o Justa", | |
| "description": "Usou o Split Justo por 3 meses", | |
| "icon": "βοΈ", | |
| "color": "#06b6d4", | |
| }, | |
| } | |