INNER CODE UNIT · Python
create_population
cmu-sei/GHOSTS · experimental/grms/grms/main.py:336
async def create_population(profile: PopulationProfile):
if not profile.validate_segments():
raise HTTPException(400, "Population segments must sum to approximately 1.0")
populations[_pop_key(profile.country, profile.period)] = profile
return profile
@app.get("/api/v1/populations", response_model=list[PopulationProfile])
async def list_populations():
return list(populations.values())
@app.get("/api/v1/populations/{country}", response_model=PopulationProfile)
async def get_population(country: str, period: str = "current"):
key = _pop_key(country, period)
if key not in populations:
if period != "current":
raise HTTPException(404, "Population profile not found")