-
Notifications
You must be signed in to change notification settings - Fork 2
Fdmsstar private sector #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: staging
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| import pandas as pd | ||
|
|
||
| from fdms.utils.mixins import SumAndSpliceMixin | ||
| from fdms.utils.splicer import Splicer | ||
| from fdms.utils.operators import Operators | ||
| from fdms.utils.series import export_to_excel | ||
|
|
||
|
|
||
| # STEP 16 | ||
| class ExternalSector(SumAndSpliceMixin): | ||
| def perform_computation(self, result_1, result_3, ameco_h_df): | ||
| # TODO: Check the scales of the output variables | ||
| splicer = Splicer() | ||
| operators = Operators() | ||
|
|
||
| # UBYA.1.0.0.0 | ||
|
|
||
| addends = {'UBYA.1.0.0.0': ['UBRA.1.0.0.0', 'UBTA.1.0.0.0']} | ||
| self._sum_and_splice(addends, result_1, ameco_h_df, splice=False) | ||
| new_input_df = self.result.set_index(['Country Ameco', 'Variable Code'], drop=True) | ||
| new_input_df = pd.concat([new_input_df, result_1, result_3], sort=True) | ||
|
|
||
|
|
||
| # UBCA.1.0.0.0 | ||
|
|
||
| addends = {'UBCA.1.0.0.0': ['UXGS.1.0.0.0', '-UMGS.1.0.0.0', 'UBYA.1.0.0.0']} | ||
| self._sum_and_splice(addends, new_input_df, ameco_h_df, splice=False) | ||
| new_input_df = self.result.set_index(['Country Ameco', 'Variable Code'], drop=True) | ||
| new_input_df = pd.concat([new_input_df, result_1, result_3], sort=True) | ||
|
|
||
| # UBLA.1.0.0.0 | ||
|
|
||
| addends = {'UBLA.1.0.0.0': ['UBCA.1.0.0.0', 'UBKA.1.0.0.0']} | ||
| self._sum_and_splice(addends, new_input_df, ameco_h_df, splice=False) | ||
|
|
||
| # DXGT.1.0.0.0 | ||
|
|
||
| dxge_data = self.get_data(new_input_df, 'DXGE.1.0.0.0') | ||
| dxgi_data = self.get_data(new_input_df, 'DXGI.1.0.0.0') | ||
| dxgt_data = dxge_data + dxgi_data | ||
| series_meta = self.get_meta('DXGT.1.0.0.0') | ||
| series = pd.Series(series_meta) | ||
| series = series.append(dxgt_data) | ||
| self.result = self.result.append(series, ignore_index=True, sort=True) | ||
| new_input_df = self.result.set_index(['Country Ameco', 'Variable Code'], drop=True) | ||
| new_input_df = pd.concat([new_input_df, result_1], sort=True) | ||
|
|
||
| # DMGT.1.0.0.0 | ||
|
|
||
| dmge_data = self.get_data(new_input_df, 'DMGE.1.0.0.0') | ||
| dmgi_data = self.get_data(new_input_df, 'DMGI.1.0.0.0') | ||
| dmgt_data = dmge_data + dmgi_data | ||
| series_meta = self.get_meta('DMGT.1.0.0.0') | ||
| series = pd.Series(series_meta) | ||
| series = series.append(dmgt_data) | ||
| self.result = self.result.append(series, ignore_index=True, sort=True) | ||
| new_input_df = self.result.set_index(['Country Ameco', 'Variable Code'], drop=True) | ||
| new_input_df = pd.concat([new_input_df, result_1], sort=True) | ||
|
|
||
| # DBGT.1.0.0.0 | ||
|
|
||
| dxgt_data = self.get_data(new_input_df, 'DXGT.1.0.0.0') | ||
| dmgt_data = self.get_data(new_input_df, 'DMGT.1.0.0.0') | ||
| dbgt_data = dxgt_data - dmgt_data | ||
| series_meta = self.get_meta('DBGT.1.0.0.0') | ||
| series = pd.Series(series_meta) | ||
| series = series.append(dbgt_data) | ||
| self.result = self.result.append(series, ignore_index=True, sort=True) | ||
|
|
||
| # DBGE.1.0.0.0 | ||
|
|
||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix this calculation, it doesn't match the original one |
||
| dxge_data = self.get_data(new_input_df, 'DXGT.1.0.0.0') | ||
| dmge_data = self.get_data(new_input_df, 'DMGT.1.0.0.0') | ||
| dbge_data = dxge_data - dmge_data | ||
| series_meta = self.get_meta('DBGE.1.0.0.0') | ||
| series = pd.Series(series_meta) | ||
| series = series.append(dbge_data) | ||
| self.result = self.result.append(series, ignore_index=True, sort=True) | ||
|
|
||
| # TODO: DBGI.1.0.0.0 | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Finish the module, perform the last calculation. |
||
|
|
||
| self.result.set_index(['Country Ameco', 'Variable Code'], drop=True, inplace=True) | ||
| self.apply_scale() | ||
|
|
||
| export_to_excel(self.result, step=16) | ||
|
|
||
|
|
||
| return self.result | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import pandas as pd | ||
|
|
||
| from fdms.utils.mixins import SumAndSpliceMixin | ||
| from fdms.utils.splicer import Splicer | ||
| from fdms.utils.operators import Operators | ||
| from fdms.utils.series import export_to_excel | ||
|
|
||
|
|
||
| # STEP 15 | ||
| class PrivateSector(SumAndSpliceMixin): | ||
| def perform_computation(self, result_1, result_12, result_13, result_14, ameco_h_df): | ||
| breakpoint() | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remember to delete all breakpoints |
||
| # TODO: Check the scales of the output variables | ||
| splicer = Splicer() | ||
| operators = Operators() | ||
|
|
||
| # USGN.1.0.0.0 | ||
|
|
||
| addends = {'USGN.1.0.0.0': ['UVGD', 'UBRA', 'UBTA', '-UCPH', '-UCTG']} | ||
|
|
||
| self._sum_and_splice(addends, result_1, ameco_h_df, splice=False) | ||
| new_input_df = self.result.set_index(['Country Ameco', 'Variable Code'], drop=True) | ||
| new_input_df = pd.concat([new_input_df, result_1, result_13, result_14], sort=True) | ||
|
|
||
| # UBLP.1.0.0.0 | ||
|
|
||
| addends = {'UBLP.1.0.0.0': ['UBLC.1.0.0.0', 'UBLH.1.0.0.0']} | ||
|
|
||
| self._sum_and_splice(addends, new_input_df, ameco_h_df, splice=False) | ||
| new_input_df = self.result.set_index(['Country Ameco', 'Variable Code'], drop=True) | ||
| new_input_df = pd.concat([new_input_df, result_1, result_12], sort=True) | ||
|
|
||
| # USGP.1.0.0.0 | ||
|
|
||
| addends = {'USGP.1.0.0.0': ['USGN.1.0.0.0','USGG.1.0.0.0']} | ||
|
|
||
| self._sum_and_splice(addends, new_input_df, ameco_h_df, splice=False) | ||
|
|
||
| self.result.set_index(['Country Ameco', 'Variable Code'], drop=True, inplace=True) | ||
| self.apply_scale() | ||
|
|
||
| export_to_excel(self.result, step=15) | ||
|
|
||
| return self.result | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,9 @@ | |
| from fdms.computation.country.annual.fiscal_sector import FiscalSector | ||
| from fdms.computation.country.annual.corporate_sector import CorporateSector | ||
| from fdms.computation.country.annual.household_sector import HouseholdSector | ||
| from fdms.computation.country.annual.private_sector import PrivateSector | ||
| from fdms.computation.country.annual.external_sector import ExternalSector | ||
|
|
||
| from fdms.config import YEARS | ||
| from fdms.config.scale_correction import fix_scales | ||
| from fdms.config.variable_groups import NA_VO, T_VO | ||
|
|
@@ -201,6 +204,17 @@ def test_country_calculation_BE(self): | |
| missing_vars = [v for v in variables if v not in list(result_14.loc[self.country].index)] | ||
| self.assertFalse(missing_vars) | ||
|
|
||
| # STEP 15 | ||
| step_15 = PrivateSector(scales=self.scales) | ||
| result_15 = step_15.perform_computation(self.result_1, result_12, result_13, result_14, self.ameco_df) | ||
|
|
||
| # STEP 16 | ||
| step_16 = ExternalSector(scales=self.scales) | ||
| result_16 = step_16.perform_computation(self.result_1, result_3, self.ameco_df) | ||
|
|
||
| breakpoint() | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another breakpoint |
||
|
|
||
|
|
||
| # TODO: Fix all scales | ||
| result = pd.concat([self.result_1, result_2, result_3, result_4, result_5, result_6, result_7, result_8, | ||
| result_9, result_10, result_11, result_12, result_13, result_14], sort=True) | ||
|
|
@@ -227,3 +241,5 @@ def test_country_calculation_BE(self): | |
| wrong_names = [series.name for series in wrong_series] | ||
| res_wrong, exp_wrong = res.loc[wrong_names].copy(), exp.loc[wrong_names].copy() | ||
| report_diff(res_wrong, exp_wrong) | ||
|
|
||
| #breakpoint() | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need this comment? |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two lines are not required?