company.pyβ’4.14 kB
"""
Company data models
"""
from typing import Optional, List, Dict, Any
from pydantic import BaseModel, Field
from datetime import date
class CompanyOverview(BaseModel):
"""Company overview data model"""
company_name: str = Field(description="Official company name")
stock_code: str = Field(description="6-digit stock code")
market_type: str = Field(description="Market type (KOSPI, KOSDAQ, etc.)")
industry: str = Field(description="Industry classification")
ceo_name: Optional[str] = Field(default=None, description="CEO name")
establishment_date: Optional[str] = Field(default=None, description="Company establishment date")
description: Optional[str] = Field(default=None, description="Company description")
def to_dict(self) -> Dict[str, Any]:
"""Convert to dictionary for easy serialization"""
return {
"company_name": self.company_name,
"stock_code": self.stock_code,
"market_type": self.market_type,
"industry": self.industry,
"ceo_name": self.ceo_name,
"establishment_date": self.establishment_date,
"description": self.description
}
class FinancialData(BaseModel):
"""Financial data model"""
year: int = Field(description="Financial year")
revenue: int = Field(description="Revenue in KRW")
operating_profit: int = Field(description="Operating profit in KRW")
net_profit: int = Field(description="Net profit in KRW")
total_assets: int = Field(description="Total assets in KRW")
def to_dict(self) -> Dict[str, Any]:
"""Convert to dictionary for easy serialization"""
return {
"year": self.year,
"revenue": self.revenue,
"operating_profit": self.operating_profit,
"net_profit": self.net_profit,
"total_assets": self.total_assets
}
class FinancialStatements(BaseModel):
"""Financial statements collection"""
company_code: str = Field(description="Company stock code")
period: str = Field(description="Time period")
financial_data: List[FinancialData] = Field(description="List of financial data")
def to_dict(self) -> Dict[str, Any]:
"""Convert to dictionary for easy serialization"""
return {
"company_code": self.company_code,
"period": self.period,
"financial_data": [data.to_dict() for data in self.financial_data]
}
class BusinessSegment(BaseModel):
"""Business segment information"""
segment_name: str = Field(description="Business segment name")
revenue: int = Field(description="Segment revenue")
operating_profit: int = Field(description="Segment operating profit")
revenue_ratio: float = Field(description="Revenue ratio in percentage")
profit_margin: float = Field(description="Profit margin in percentage")
yoy_growth: float = Field(description="Year-over-year growth in percentage")
def to_dict(self) -> Dict[str, Any]:
"""Convert to dictionary for easy serialization"""
return {
"segment_name": self.segment_name,
"revenue": self.revenue,
"operating_profit": self.operating_profit,
"revenue_ratio": self.revenue_ratio,
"profit_margin": self.profit_margin,
"yoy_growth": self.yoy_growth
}
class ShareholderInfo(BaseModel):
"""Shareholder information"""
shareholder_name: str = Field(description="Shareholder name")
share_count: int = Field(description="Number of shares held")
share_ratio: float = Field(description="Shareholding ratio in percentage")
shareholder_type: str = Field(description="Type of shareholder (individual, institution, etc.)")
def to_dict(self) -> Dict[str, Any]:
"""Convert to dictionary for easy serialization"""
return {
"shareholder_name": self.shareholder_name,
"share_count": self.share_count,
"share_ratio": self.share_ratio,
"shareholder_type": self.shareholder_type
}