Skip to content

Commit

Permalink
[feat] 연령 템플릿 데이터 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
pingpingy1 committed Nov 22, 2023
1 parent 3c426d0 commit df60a62
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 2 deletions.
42 changes: 41 additions & 1 deletion model/ScrapResult.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,47 @@ class GenderTemplateData(BaseModel):


class AgeTemplateData(BaseModel):
ageDiversityIndex: float
class AgeRankingParagraphData(BaseModel):
class AgeRankingAllIndices(BaseModel):
metroId: int
rank: int
ageDiversityIndex: float

ageDiversityIndex: float
allIndices: list[AgeRankingAllIndices]

class AgeIndexHistoryParagraphData(BaseModel):
class AgeIndexHistoryIndexData(BaseModel):
year: int
unit: int
candidateCount: int
candidateDiversityIndex: float
candidateDiversityRank: int
electedDiversityIndex: float
electedDiversityRank: int

mostRecentYear: int
history: list[AgeIndexHistoryIndexData]

class AgeHistogramParagraphData(BaseModel):
class AgeHistogramAreaData(BaseModel):
localId: int
firstQuintile: int
lastQuintile: int

year: int
candidateCount: int
electedCount: int
firstQuintile: int
lastQuintile: int
divArea: AgeHistogramAreaData
uniArea: AgeHistogramAreaData

metroId: int
localId: int
rankingParagraph: AgeRankingParagraphData
indexHistoryParagraph: AgeIndexHistoryParagraphData
ageHistogramParagraph: AgeHistogramParagraphData


class PartyTemplateData(BaseModel):
Expand Down
53 changes: 52 additions & 1 deletion routers/scrapResult.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,58 @@ async def getLocalTemplateData(
age_list = [councilor["age"] async for councilor in councilors]
age_diversity_index = diversity.gini_simpson(age_list, stair=AGE_STAIR)
return ScrapResult.AgeTemplateData.model_validate(
{"ageDiversityIndex": age_diversity_index}
{
"metroId": metroId,
"localId": localId,
"rankingParagraph": {
"ageDiversityIndex": age_diversity_index,
"allIndices": [
{"metroId": 3, "rank": 2, "ageDiversityIndex": 0.9},
{"metroId": 14, "rank": 7, "ageDiversityIndex": 0.4},
{"metroId": 15, "rank": 18, "ageDiversityIndex": 0.2},
],
},
"indexHistoryParagraph": {
"mostRecentYear": 2022,
"history": [
{
"year": 2022,
"unit": 8,
"candidateCount": 80,
"candidateDiversityIndex": 0.11,
"candidateDiversityRank": 33,
"electedDiversityIndex": 0.42,
"electedDiversityRank": 12,
},
{
"year": 2018,
"unit": 7,
"candidateCount": 70,
"candidateDiversityIndex": 0.73,
"candidateDiversityRank": 3,
"electedDiversityIndex": 0.85,
"electedDiversityRank": 2,
},
],
},
"ageHistogramParagraph": {
"year": 2022,
"candidateCount": 80,
"electedCount": 16,
"firstQuintile": 66,
"lastQuintile": 29,
"divArea": {
"localId": 172,
"firstQuintile": 43,
"lastQuintile": 21,
},
"uniArea": {
"localId": 63,
"firstQuintile": 84,
"lastQuintile": 56,
},
},
}
)

case ScrapResult.FactorType.party:
Expand Down

0 comments on commit df60a62

Please sign in to comment.