-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from masterismail/issue9
Added GH workflow files for auto deployment of docs and to test deployment in PR
- Loading branch information
Showing
6 changed files
with
254 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Pull request | ||
on: | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
Test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.9 | ||
|
||
- name: install dependencies | ||
run: | | ||
pip install jupyter-book | ||
pip install furo | ||
- name: Generate documentation | ||
run: make docs | ||
|
||
- name: Check documentation build | ||
run: | | ||
if [ -d "docs/_build/html" ]; then | ||
echo "Documentation built successfully" | ||
else | ||
echo "Documentation build failed" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Push | ||
on: | ||
push: | ||
branches: [ main ] | ||
|
||
jobs: | ||
Deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.9 | ||
|
||
- name: install dependencies | ||
run: | | ||
pip install jupyter-book | ||
pip install furo | ||
pip install sphinx-argparse | ||
- name: Generate documentation | ||
run: make docs | ||
|
||
- name: Deploy documentation | ||
uses: JamesIves/github-pages-deploy-action@releases/v3 | ||
with: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
BRANCH: gh-pages | ||
FOLDER: docs/_build/html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.PHONY: docs | ||
|
||
docs: | ||
jupyter-book build docs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
policyengine/economic_impact/inequality_impact/inequality_impact.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
from typing import Union | ||
|
||
class BaseMetricCalculator: | ||
""" | ||
Base class for calculating metrics based on baseline and reformed data. | ||
Attributes: | ||
baseline (object): Object representing baseline data. | ||
reformed (object): Object representing reformed data. | ||
""" | ||
|
||
def __init__(self, baseline: object, reformed: object) -> None: | ||
""" | ||
Initialize with baseline and reformed data objects. | ||
Args: | ||
baseline (object): Object representing baseline data. | ||
reformed (object): Object representing reformed data. | ||
""" | ||
self.baseline = baseline | ||
self.reformed = reformed | ||
|
||
def calculate_baseline(self, variable: str, period: int = 2024, map_to: str = "person") -> Union[float, int]: | ||
""" | ||
Calculate baseline metric value. | ||
Args: | ||
variable (str): Variable to calculate. | ||
period (int): Year or period for calculation (default: 2024). | ||
map_to (str): Mapping type (default: "person"). | ||
Returns: | ||
Union[float, int]: Calculated metric value. | ||
""" | ||
return self.baseline.calculate(variable, period=period, map_to=map_to) | ||
|
||
def calculate_reformed(self, variable: str, period: int = 2024, map_to: str = "person") -> Union[float, int]: | ||
""" | ||
Calculate reformed metric value. | ||
Args: | ||
variable (str): Variable to calculate. | ||
period (int): Year or period for calculation (default: 2024). | ||
map_to (str): Mapping type (default: "person"). | ||
Returns: | ||
Union[float, int]: Calculated metric value. | ||
""" | ||
return self.reformed.calculate(variable, period=period, map_to=map_to) | ||
|
||
class GiniCalculator(BaseMetricCalculator): | ||
""" | ||
Calculate Gini coefficient metrics based on baseline and reformed data. | ||
Inherits from BaseMetricCalculator. | ||
""" | ||
|
||
def calculate(self) -> dict: | ||
""" | ||
Calculate Gini coefficient metrics. | ||
Returns: | ||
dict: Dictionary containing "baseline", "reform", and "change" values. | ||
""" | ||
baseline_person = self.calculate_baseline("household_net_income") | ||
reformed_person = self.calculate_reformed("household_net_income") | ||
|
||
baseline_value = baseline_person.gini() | ||
reformed_value = reformed_person.gini() | ||
change_value = reformed_value - baseline_value | ||
|
||
return { | ||
"baseline": baseline_value, | ||
"reform": reformed_value, | ||
"change": change_value | ||
} | ||
|
||
class Top1PctShareCalculator(BaseMetricCalculator): | ||
""" | ||
Calculate top 1% income share metrics based on baseline and reformed data. | ||
Inherits from BaseMetricCalculator. | ||
""" | ||
|
||
def calculate(self) -> dict: | ||
""" | ||
Calculate top 1% income share metrics. | ||
Returns: | ||
dict: Dictionary containing "baseline", "reform", and "change" values. | ||
""" | ||
baseline_person = self.calculate_baseline("household_net_income") | ||
reformed_person = self.calculate_reformed("household_net_income") | ||
|
||
baseline_value = baseline_person.top_1_pct_share() | ||
reformed_value = reformed_person.top_1_pct_share() | ||
change_value = reformed_value - baseline_value | ||
|
||
return { | ||
"baseline": baseline_value, | ||
"reform": reformed_value, | ||
"change": change_value | ||
} | ||
|
||
class Top10PctShareCalculator(BaseMetricCalculator): | ||
""" | ||
Calculate top 10% income share metrics based on baseline and reformed data. | ||
Inherits from BaseMetricCalculator. | ||
""" | ||
|
||
def calculate(self) -> dict: | ||
""" | ||
Calculate top 10% income share metrics. | ||
Returns: | ||
dict: Dictionary containing "baseline", "reform", and "change" values. | ||
""" | ||
baseline_person = self.calculate_baseline("household_net_income") | ||
reformed_person = self.calculate_reformed("household_net_income") | ||
|
||
baseline_value = baseline_person.top_10_pct_share() | ||
reformed_value = reformed_person.top_10_pct_share() | ||
change_value = reformed_value - baseline_value | ||
|
||
return { | ||
"baseline": baseline_value, | ||
"reform": reformed_value, | ||
"change": change_value | ||
} |