Skip to content

Commit

Permalink
Make flask cachek search string aware
Browse files Browse the repository at this point in the history
  • Loading branch information
sverhoeven committed Jan 20, 2025
1 parent aa42a7b commit 50e6bd2
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@


@app.get("/pathwayCarbon")
@cache.cached()
@cache.cached(query_string=True)
def pathwayCarbon():
"""Get global carbon pathway for a given selection.
Expand Down Expand Up @@ -90,7 +90,7 @@ def pathwayCarbon():


@app.get("/pathwayChoices")
@cache.cached()
@cache.cached(query_string=True)
def pathwayChoices():
return {
"temperature": dsGlobal.Temperature.values.tolist(),
Expand Down Expand Up @@ -224,13 +224,13 @@ def build_regions():


@app.get("/regions")
@cache.cached()
@cache.cached(query_string=True)
def regions():
return available_regions


@app.get("/regions/<region>")
@cache.cached()
@cache.cached(query_string=True)
def region(region):
for r in available_regions:
if r["iso3"] == region:
Expand All @@ -239,7 +239,7 @@ def region(region):


@app.get("/pathwayStats")
@cache.cached()
@cache.cached(query_string=True)
def pathwayStats():
def stats(emission_type):
if emission_type == 'ghg':
Expand Down Expand Up @@ -289,7 +289,7 @@ def stats(emission_type):


@app.get("/historicalCarbon/<region>")
@cache.cached()
@cache.cached(query_string=True)
def historicalCarbon(region="EARTH"):
start = request.args.get("start")
end = request.args.get("end")
Expand All @@ -303,7 +303,7 @@ def historicalCarbon(region="EARTH"):


@app.get("/populationOverTime/<region>")
@cache.cached()
@cache.cached(query_string=True)
def populationOverTime(region):
start = request.args.get("start")
end = request.args.get("end")
Expand All @@ -318,7 +318,7 @@ def populationOverTime(region):


@app.get("/gdpOverTime/<region>")
@cache.cached()
@cache.cached(query_string=True)
def gdpOverTime(region):
start = request.args.get("start")
end = request.args.get("end")
Expand All @@ -345,7 +345,7 @@ def population_map(year, scenario="SSP2"):


@app.get("/map/<year>/GHG")
@cache.cached()
@cache.cached(query_string=True)
def fullCenturyBudgetSpatial(year):
"""Get map of GHG by year"""
effortSharing = request.args.get("effortSharing", "PCC")
Expand Down Expand Up @@ -404,7 +404,7 @@ def fullCenturyBudgetSpatial(year):


@app.get("/policyPathway/<policy>/<region>")
@cache.cached()
@cache.cached(query_string=True)
def policyPathway(policy, region):
assert policy in {"CurPol", "NDC", "NetZero"}
policy_ds = (
Expand Down Expand Up @@ -494,7 +494,7 @@ def ndcRange_jones(region):


@app.get("/indicators/<region>")
@cache.cached()
@cache.cached(query_string=True)
def indicators(region):
start = request.args.get("start", 1850)
end = request.args.get("end", 2100)
Expand All @@ -518,7 +518,7 @@ def get_ds(ISO):


@app.get("/<ISO>/<principle>")
@cache.cached()
@cache.cached(query_string=True)
def effortSharing(ISO, principle):
selection = pathwaySelection()
ds = (get_ds(ISO)[principle]
Expand Down Expand Up @@ -559,7 +559,7 @@ def effortSharing(ISO, principle):


@app.get("/<ISO>/effortSharings")
@cache.cached()
@cache.cached(query_string=True)
def effortSharings(ISO):
"""
http://127.0.0.1:5000//USA/GF?exceedanceRisk=0.67&negativeEmissions=0.4&effortSharing=PCC&temperature=1.8: 36.94ms
Expand All @@ -576,7 +576,7 @@ def effortSharings(ISO):


@app.get("/<ISO>/effortSharingReductions")
@cache.cached()
@cache.cached(query_string=True)
def effortSharingReductions(ISO):
periods = (2030, 2040)
selection = dict(
Expand Down

0 comments on commit 50e6bd2

Please sign in to comment.