carbon-budget-explorer / cabe

Web application to explore carbon budgets
Apache License 2.0
1 stars 0 forks source link

Flask web service #58

Closed Peter9192 closed 11 months ago

Peter9192 commented 11 months ago

Moving python data reading to a separate webservice built with Flask

TODO:

Peter9192 commented 11 months ago

I was able to roughly reproduce Stefan's initial testing from #55. With flask I get a much higher success rate and 3x faster request handling. I used 2 workers instead of 4.

Peter9192 commented 11 months ago

I've move all pyodide calls to the flask backend. Sometimes the site crashes; it seems to happen when I quickly go from the home page through global and map to country. The URL changes to something like http://localhost:5173/regions/USA?%3Ftemperature=2&exceedanceRisk=0.33&nonCO2Mitigation=0.65&negativeEmissions=0.4&effortSharing=GDR&variable=2100 (note the ?%3). Then, the flask server crashes.

Still lots of optimizations possible, but the site, in general, seems to run much more smoothly now.

Peter9192 commented 11 months ago

Current endpoints (search = temperature + risk + nonco2 + negco2):

/pathwayChoices
/regions

/pathwayStats + search

/populationOverTime/${region}?start=${start}&end=${end}
/gdpOverTime/${region}?start=${start}&end=${end}

/fullCenturyBudgetSpatial${search}
/policyPathway/${policy}/${Region}

/historicalCarbon/${region}?start=${start}&end=${end}

/pathwayCarbon + search         --> global_pathway
/${ISO}/${principle}${search}   --> country_pathway

New design idea:

timeseries / <ISO/global> / gdp / ? start & end
timeseries / <ISO/global> / population ? start & end

timeseries / <ISO/global> / emissions / historical ? start & end
timeseries / <ISO/global> / emissions / reference ? <name=NDC/CurPol/NetZero>
timeseries / <ISO/global> / emissions / customized ? search & principles(?) & start & end

// map / <year> / gdp
// map / <year> / population
map / <year> / emissions ? search & principle

statistics / <ISO/global> / emissions ? search & principle(?) & operator='mean'

# Would be nice for gaps
values / <ISO/global> / year / emissions ? search & principles(?)
sverhoeven commented 11 months ago

I've move all pyodide calls to the flask backend. Sometimes the site crashes; it seems to happen when I quickly go from the home page through global and map to country. The URL changes to something like http://localhost:5173/regions/USA?%3Ftemperature=2&exceedanceRisk=0.33&nonCO2Mitigation=0.65&negativeEmissions=0.4&effortSharing=GDR&variable=2100 (note the ?%3). Then, the flask server crashes.

Still lots of optimizations possible, but the site, in general, seems to run much more smoothly now.

We could add a debounce to the sliders or only update url when slider is released.

Peter9192 commented 11 months ago

Already fixed it in my last commit. But could still be good

Peter9192 commented 11 months ago

Okay this works now and CI is green. I'll move the remaining todo's to a new issue so work on the hosting can start