Download backend/models.py from Tremick/PIOE: direct link, hf CLI and curl.
- Browser
- Download file 7.55 kB
-
https://huggingface.co/spaces/Tremick/PIOE/resolve/main/backend/models.py
- Command line
-
hf download hf://spaces/Tremick/PIOE/backend/models.py
-
curl -L -o models.py https://huggingface.co/spaces/Tremick/PIOE/resolve/main/backend/models.py
7.55 kB
| """ | |
| PIOE Database Models - Version 2.0 | |
| Personal Advantage Engine | |
| """ | |
| from sqlalchemy import Column, String, Float, DateTime, Text, Boolean, Integer, JSON, ForeignKey, Enum as SQLEnum | |
| from sqlalchemy.orm import relationship | |
| from datetime import datetime | |
| import uuid | |
| import enum | |
| from .database import Base | |
| class OpportunityCategory(str, enum.Enum): | |
| """Categories for opportunity classification - PIOE 2.0 Extended.""" | |
| # Standard opportunities | |
| SCHOLARSHIP = "scholarship" | |
| FELLOWSHIP = "fellowship" | |
| INTERNSHIP = "internship" | |
| JOB = "job" | |
| RESEARCH = "research" | |
| HACKATHON = "hackathon" | |
| COMPETITION = "competition" | |
| CONFERENCE = "conference" | |
| OPEN_SOURCE = "open_source" | |
| # Grant types (PIOE 2.0) | |
| GRANT = "grant" | |
| MICRO_GRANT = "micro_grant" | |
| ECOSYSTEM_GRANT = "ecosystem_grant" | |
| INNOVATION_FUND = "innovation_fund" | |
| # Partnership & Collaboration (PIOE 2.0) | |
| PARTNERSHIP = "partnership" | |
| COLLABORATION = "collaboration" | |
| # Events & Showcases (PIOE 2.0) | |
| PITCH_EVENT = "pitch_event" | |
| DEMO_DAY = "demo_day" | |
| TALENT_CALL = "talent_call" | |
| # Web3/Crypto specific (PIOE 2.0) | |
| BOUNTY = "bounty" | |
| AMBASSADOR = "ambassador" | |
| # Silent/Implicit opportunities (PIOE 2.0) | |
| PRE_GRANT_SIGNAL = "pre_grant_signal" | |
| PRE_HIRING_SIGNAL = "pre_hiring_signal" | |
| WEAK_SIGNAL = "weak_signal" | |
| # Other | |
| INVESTMENT = "investment" | |
| OTHER = "other" | |
| class OpportunityStatus(str, enum.Enum): | |
| """User interaction status.""" | |
| NEW = "new" | |
| SAVED = "saved" | |
| APPLIED = "applied" | |
| TRACKING = "tracking" | |
| DISMISSED = "dismissed" | |
| EXPIRED = "expired" | |
| class SourceType(str, enum.Enum): | |
| """Types of data sources.""" | |
| ARXIV = "arxiv" | |
| GITHUB = "github" | |
| RSS = "rss" | |
| REDDIT = "reddit" | |
| TWITTER = "twitter" | |
| LINKEDIN = "linkedin" | |
| SUPERTEAM = "superteam" | |
| WEB_SCRAPE = "web_scrape" | |
| DISCORD = "discord" | |
| GOV_PORTAL = "gov_portal" | |
| GRANT_PLATFORM = "grant_platform" | |
| class Domain(str, enum.Enum): | |
| """Domain classification.""" | |
| AI = "ai" | |
| COMPUTER_VISION = "computer_vision" | |
| ROBOTICS = "robotics" | |
| FINANCE = "finance" | |
| CRYPTO = "crypto" | |
| ACADEMIA = "academia" | |
| WEB3 = "web3" | |
| MIXED = "mixed" | |
| class Region(str, enum.Enum): | |
| """Regional accessibility - PIOE 2.0.""" | |
| NIGERIA = "nigeria" | |
| AFRICA = "africa" | |
| GLOBAL = "global" | |
| REMOTE_AFRICA = "remote_africa" # Remote but Africa-accessible | |
| REMOTE_GLOBAL = "remote_global" | |
| class RiskLevel(str, enum.Enum): | |
| """Time investment risk level.""" | |
| LOW = "low" | |
| MEDIUM = "medium" | |
| HIGH = "high" | |
| class Source(Base): | |
| """Data source configuration.""" | |
| __tablename__ = "sources" | |
| id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4())) | |
| name = Column(String, nullable=False) | |
| type = Column(SQLEnum(SourceType), nullable=False) | |
| url = Column(String) | |
| config = Column(JSON, default={}) | |
| credibility_score = Column(Float, default=0.7) | |
| last_fetch = Column(DateTime) | |
| is_active = Column(Boolean, default=True) | |
| created_at = Column(DateTime, default=datetime.utcnow) | |
| opportunities = relationship("Opportunity", back_populates="source") | |
| class Opportunity(Base): | |
| """Normalized opportunity item - PIOE 2.0 Enhanced.""" | |
| __tablename__ = "opportunities" | |
| id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4())) | |
| title = Column(String, nullable=False) | |
| source_id = Column(String, ForeignKey("sources.id")) | |
| source_name = Column(String) | |
| source_type = Column(SQLEnum(SourceType)) | |
| domain = Column(SQLEnum(Domain), default=Domain.MIXED) | |
| category = Column(SQLEnum(OpportunityCategory), default=OpportunityCategory.OTHER) | |
| # Regional accessibility (PIOE 2.0) | |
| region = Column(SQLEnum(Region), default=Region.GLOBAL) | |
| region_weight = Column(Float, default=1.0) # 1.0 = perfect match for user | |
| # Timestamps | |
| discovered_at = Column(DateTime, default=datetime.utcnow) | |
| published_at = Column(DateTime) | |
| deadline = Column(DateTime) | |
| # Content | |
| raw_text = Column(Text) | |
| summary = Column(Text) | |
| url = Column(String) | |
| # Core Scores (0.0 to 1.0) | |
| relevance_score = Column(Float, default=0.0) | |
| novelty_score = Column(Float, default=1.0) | |
| credibility_score = Column(Float, default=0.5) | |
| signal_strength = Column(Float, default=0.5) | |
| combined_score = Column(Float, default=0.0) | |
| # PIOE 2.0: Decision Intelligence Scores | |
| roi_score = Column(Float, default=0.5) # Is this worth my time? | |
| unlock_potential = Column(Float, default=0.0) # Opens doors to what? | |
| risk_level = Column(SQLEnum(RiskLevel), default=RiskLevel.MEDIUM) | |
| competition_level = Column(Float, default=0.5) # Estimated competition | |
| # Social engagement (from social sources) | |
| social_engagement = Column(Integer, default=0) | |
| # User status | |
| status = Column(SQLEnum(OpportunityStatus), default=OpportunityStatus.NEW) | |
| # Grant-specific metadata (PIOE 2.0) | |
| # Stored in extra_data: | |
| # - grant_size_min, grant_size_max | |
| # - required_output (MVP, paper, OSS) | |
| # - timeline_months | |
| # - ecosystem (ethereum, solana, government) | |
| # - eligibility_regions | |
| # - technical_depth | |
| # Action guidance (PIOE 2.0) | |
| # Stored in extra_data: | |
| # - recommended_action | |
| # - skill_to_highlight | |
| # - timing (early/optimal/late) | |
| # - success_probability | |
| # - preparation_steps | |
| # Opportunity chaining (PIOE 2.0) | |
| # - chain_next: list of potential next opportunity IDs | |
| # - chain_unlocks: what this unlocks | |
| extra_data = Column(JSON, default={}) | |
| # Embedding for novelty detection | |
| embedding = Column(JSON) | |
| source = relationship("Source", back_populates="opportunities") | |
| interactions = relationship("UserInteraction", back_populates="opportunity") | |
| class UserInteraction(Base): | |
| """Track user actions for personalization.""" | |
| __tablename__ = "user_interactions" | |
| id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4())) | |
| opportunity_id = Column(String, ForeignKey("opportunities.id")) | |
| action = Column(String) # view, apply, save, dismiss, track | |
| timestamp = Column(DateTime, default=datetime.utcnow) | |
| opportunity = relationship("Opportunity", back_populates="interactions") | |
| class Author(Base): | |
| """Track authors for credibility and social graph.""" | |
| __tablename__ = "authors" | |
| id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4())) | |
| name = Column(String, nullable=False) | |
| platform = Column(String) # reddit, twitter, github, etc. | |
| platform_id = Column(String) # username or ID on platform | |
| credibility_score = Column(Float, default=0.5) | |
| opportunity_creator_score = Column(Float, default=0.0) # Do they create opportunities? | |
| first_seen = Column(DateTime, default=datetime.utcnow) | |
| extra_data = Column(JSON, default={}) | |
| class OpportunityChain(Base): | |
| """Track opportunity sequences/paths - PIOE 2.0.""" | |
| __tablename__ = "opportunity_chains" | |
| id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4())) | |
| name = Column(String) # e.g., "Hackathon to Startup Path" | |
| description = Column(Text) | |
| steps = Column(JSON) # Ordered list of opportunity categories/types | |
| success_rate = Column(Float, default=0.0) | |
| example_urls = Column(JSON, default=[]) | |
| created_at = Column(DateTime, default=datetime.utcnow) | |