File size: 7,552 Bytes
4d92cd5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | """
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)
|