policyengine-core 0.1.3__tar.gz → 0.1.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {PolicyEngine-Core-0.1.3 → PolicyEngine-Core-0.1.4}/PKG-INFO +1 -1
- {PolicyEngine-Core-0.1.3 → PolicyEngine-Core-0.1.4}/PolicyEngine_Core.egg-info/PKG-INFO +1 -1
- PolicyEngine-Core-0.1.4/PolicyEngine_Core.egg-info/SOURCES.txt +29 -0
- PolicyEngine-Core-0.1.4/policyengine_core/charts/__init__.py +0 -0
- PolicyEngine-Core-0.1.4/policyengine_core/charts/hypothetical/__init__.py +0 -0
- PolicyEngine-Core-0.1.4/policyengine_core/charts/hypothetical/varying.py +3 -0
- PolicyEngine-Core-0.1.4/policyengine_core/charts/hypothetical/waterfall.py +0 -0
- PolicyEngine-Core-0.1.4/policyengine_core/charts/population/__init__.py +0 -0
- PolicyEngine-Core-0.1.4/policyengine_core/charts/population/distributional.py +3 -0
- PolicyEngine-Core-0.1.4/policyengine_core/charts/population/poverty.py +3 -0
- PolicyEngine-Core-0.1.4/policyengine_core/charts/population/waterfall.py +3 -0
- PolicyEngine-Core-0.1.4/policyengine_core/metrics/__init__.py +0 -0
- PolicyEngine-Core-0.1.4/policyengine_core/metrics/hypothetical.py +3 -0
- PolicyEngine-Core-0.1.4/policyengine_core/metrics/population.py +53 -0
- PolicyEngine-Core-0.1.4/policyengine_core/utils/__init__.py +0 -0
- PolicyEngine-Core-0.1.4/policyengine_core/utils/formatting.py +3 -0
- PolicyEngine-Core-0.1.4/policyengine_core/utils/general.py +42 -0
- {PolicyEngine-Core-0.1.3 → PolicyEngine-Core-0.1.4}/setup.py +1 -1
- PolicyEngine-Core-0.1.3/PolicyEngine_Core.egg-info/SOURCES.txt +0 -15
- {PolicyEngine-Core-0.1.3 → PolicyEngine-Core-0.1.4}/PolicyEngine_Core.egg-info/dependency_links.txt +0 -0
- {PolicyEngine-Core-0.1.3 → PolicyEngine-Core-0.1.4}/PolicyEngine_Core.egg-info/requires.txt +0 -0
- {PolicyEngine-Core-0.1.3 → PolicyEngine-Core-0.1.4}/PolicyEngine_Core.egg-info/top_level.txt +0 -0
- {PolicyEngine-Core-0.1.3 → PolicyEngine-Core-0.1.4}/policyengine_core/__init__.py +0 -0
- {PolicyEngine-Core-0.1.3 → PolicyEngine-Core-0.1.4}/policyengine_core/api/__init__.py +0 -0
- {PolicyEngine-Core-0.1.3 → PolicyEngine-Core-0.1.4}/policyengine_core/api/cloud_run.py +0 -0
- {PolicyEngine-Core-0.1.3 → PolicyEngine-Core-0.1.4}/policyengine_core/api/general.py +0 -0
- {PolicyEngine-Core-0.1.3 → PolicyEngine-Core-0.1.4}/policyengine_core/api/hypothetical.py +0 -0
- {PolicyEngine-Core-0.1.3 → PolicyEngine-Core-0.1.4}/policyengine_core/api/microsimulation.py +0 -0
- {PolicyEngine-Core-0.1.3 → PolicyEngine-Core-0.1.4}/policyengine_core/reforms/__init__.py +0 -0
- {PolicyEngine-Core-0.1.3 → PolicyEngine-Core-0.1.4}/policyengine_core/reforms/utils.py +0 -0
- {PolicyEngine-Core-0.1.3 → PolicyEngine-Core-0.1.4}/policyengine_core/server.py +0 -0
- {PolicyEngine-Core-0.1.3 → PolicyEngine-Core-0.1.4}/setup.cfg +0 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
setup.py
|
|
2
|
+
PolicyEngine_Core.egg-info/PKG-INFO
|
|
3
|
+
PolicyEngine_Core.egg-info/SOURCES.txt
|
|
4
|
+
PolicyEngine_Core.egg-info/dependency_links.txt
|
|
5
|
+
PolicyEngine_Core.egg-info/requires.txt
|
|
6
|
+
PolicyEngine_Core.egg-info/top_level.txt
|
|
7
|
+
policyengine_core/__init__.py
|
|
8
|
+
policyengine_core/server.py
|
|
9
|
+
policyengine_core/api/__init__.py
|
|
10
|
+
policyengine_core/api/cloud_run.py
|
|
11
|
+
policyengine_core/api/general.py
|
|
12
|
+
policyengine_core/api/hypothetical.py
|
|
13
|
+
policyengine_core/api/microsimulation.py
|
|
14
|
+
policyengine_core/charts/__init__.py
|
|
15
|
+
policyengine_core/charts/hypothetical/__init__.py
|
|
16
|
+
policyengine_core/charts/hypothetical/varying.py
|
|
17
|
+
policyengine_core/charts/hypothetical/waterfall.py
|
|
18
|
+
policyengine_core/charts/population/__init__.py
|
|
19
|
+
policyengine_core/charts/population/distributional.py
|
|
20
|
+
policyengine_core/charts/population/poverty.py
|
|
21
|
+
policyengine_core/charts/population/waterfall.py
|
|
22
|
+
policyengine_core/metrics/__init__.py
|
|
23
|
+
policyengine_core/metrics/hypothetical.py
|
|
24
|
+
policyengine_core/metrics/population.py
|
|
25
|
+
policyengine_core/reforms/__init__.py
|
|
26
|
+
policyengine_core/reforms/utils.py
|
|
27
|
+
policyengine_core/utils/__init__.py
|
|
28
|
+
policyengine_core/utils/formatting.py
|
|
29
|
+
policyengine_core/utils/general.py
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Functions generating aggregates and other numerical outputs from microsimulation results.
|
|
3
|
+
"""
|
|
4
|
+
from policyengine_core.api.microsimulation import Microsimulation
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def gbp(x: float) -> str:
|
|
8
|
+
return f"£{round(x / 1e+9, 1)}bn"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def pct_change(x: float, y: float) -> float:
|
|
12
|
+
return (y - x) / x
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def poverty_rate(sim: Microsimulation, population_var: str) -> float:
|
|
16
|
+
return sim.calc("in_poverty_bhc", map_to="person", period=2021)[
|
|
17
|
+
sim.calc(population_var) > 0
|
|
18
|
+
].mean()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def headline_metrics(
|
|
22
|
+
baseline: Microsimulation, reformed: Microsimulation
|
|
23
|
+
) -> dict:
|
|
24
|
+
"""Compute headline society-wide metrics.
|
|
25
|
+
|
|
26
|
+
:param baseline: Baseline simulation.
|
|
27
|
+
:type baseline: Microsimulation
|
|
28
|
+
:param reformed: Reform simulation.
|
|
29
|
+
:type reformed: Microsimulation
|
|
30
|
+
:return: Dictionary with net_cost, poverty_change, winner_share,
|
|
31
|
+
loser_share, and gini_change.
|
|
32
|
+
:rtype: dict
|
|
33
|
+
"""
|
|
34
|
+
new_income = reformed.calc("equiv_household_net_income", map_to="person")
|
|
35
|
+
old_income = baseline.calc("equiv_household_net_income", map_to="person")
|
|
36
|
+
gain = new_income - old_income
|
|
37
|
+
net_cost = (
|
|
38
|
+
reformed.calc("net_income").sum() - baseline.calc("net_income").sum()
|
|
39
|
+
)
|
|
40
|
+
poverty_change = pct_change(
|
|
41
|
+
baseline.calc("in_poverty_bhc", map_to="person").mean(),
|
|
42
|
+
reformed.calc("in_poverty_bhc", map_to="person").mean(),
|
|
43
|
+
)
|
|
44
|
+
winner_share = (gain > 0).mean()
|
|
45
|
+
loser_share = (gain < 0).mean()
|
|
46
|
+
gini_change = pct_change(old_income.gini(), new_income.gini())
|
|
47
|
+
return dict(
|
|
48
|
+
net_cost=gbp(net_cost),
|
|
49
|
+
poverty_change=float(poverty_change),
|
|
50
|
+
winner_share=float(winner_share),
|
|
51
|
+
loser_share=float(loser_share),
|
|
52
|
+
gini_change=float(gini_change),
|
|
53
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from time import time
|
|
3
|
+
from flask import request, make_response
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def dict_to_string(d: dict) -> str:
|
|
7
|
+
return "_".join(["_".join((x, y)) for x, y in d.items()])
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def get_cached_result(
|
|
11
|
+
params: dict, endpoint: str, version: str, bucket
|
|
12
|
+
) -> dict:
|
|
13
|
+
request_id = f"{endpoint}-{dict_to_string(params)}-{version}"
|
|
14
|
+
blob = bucket.blob(request_id + ".json")
|
|
15
|
+
if blob.exists():
|
|
16
|
+
return json.loads(blob.download_as_string())
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def after_request_func(response):
|
|
20
|
+
origin = request.headers.get("Origin")
|
|
21
|
+
if request.method == "OPTIONS":
|
|
22
|
+
response = make_response()
|
|
23
|
+
response.headers.add("Access-Control-Allow-Credentials", "true")
|
|
24
|
+
response.headers.add("Access-Control-Allow-Headers", "Content-Type")
|
|
25
|
+
response.headers.add("Access-Control-Allow-Headers", "x-csrf-token")
|
|
26
|
+
response.headers.add(
|
|
27
|
+
"Access-Control-Allow-Methods",
|
|
28
|
+
"GET, POST, OPTIONS, PUT, PATCH, DELETE",
|
|
29
|
+
)
|
|
30
|
+
if origin:
|
|
31
|
+
response.headers.add("Access-Control-Allow-Origin", origin)
|
|
32
|
+
else:
|
|
33
|
+
response.headers.add("Access-Control-Allow-Credentials", "true")
|
|
34
|
+
if origin:
|
|
35
|
+
response.headers.add("Access-Control-Allow-Origin", origin)
|
|
36
|
+
response.headers[
|
|
37
|
+
"Cache-Control"
|
|
38
|
+
] = "no-cache, no-store, must-revalidate, public, max-age=0"
|
|
39
|
+
response.headers["Pragma"] = "no-cache"
|
|
40
|
+
response.headers["Expires"] = "0"
|
|
41
|
+
|
|
42
|
+
return response
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
setup.py
|
|
2
|
-
PolicyEngine_Core.egg-info/PKG-INFO
|
|
3
|
-
PolicyEngine_Core.egg-info/SOURCES.txt
|
|
4
|
-
PolicyEngine_Core.egg-info/dependency_links.txt
|
|
5
|
-
PolicyEngine_Core.egg-info/requires.txt
|
|
6
|
-
PolicyEngine_Core.egg-info/top_level.txt
|
|
7
|
-
policyengine_core/__init__.py
|
|
8
|
-
policyengine_core/server.py
|
|
9
|
-
policyengine_core/api/__init__.py
|
|
10
|
-
policyengine_core/api/cloud_run.py
|
|
11
|
-
policyengine_core/api/general.py
|
|
12
|
-
policyengine_core/api/hypothetical.py
|
|
13
|
-
policyengine_core/api/microsimulation.py
|
|
14
|
-
policyengine_core/reforms/__init__.py
|
|
15
|
-
policyengine_core/reforms/utils.py
|
{PolicyEngine-Core-0.1.3 → PolicyEngine-Core-0.1.4}/PolicyEngine_Core.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
{PolicyEngine-Core-0.1.3 → PolicyEngine-Core-0.1.4}/PolicyEngine_Core.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{PolicyEngine-Core-0.1.3 → PolicyEngine-Core-0.1.4}/policyengine_core/api/microsimulation.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|