# Path: sfc_models/examples/Quick2DPlot.py
# class Quick2DPlot(object):
#     def __init__(self, x, y, title='', run_now=True, output_directory=None, filename=None):
#         self.X = x
#         self.Y = y
#         self.Title = title
#         self.XLabel = None
#         self.YLabel = None
#         self.Legend = None
#         self.FileName = filename
#         self.LegendPos = 'best'
#         self.OutputDirectory = output_directory
#         if run_now:
#             self.DoPlot()
# 
#     def DoPlot(self):  # pragma: no cover
#         if plt is None:
#             pprint('Attempted to plot the following data; cannot to do because cannot import matplotlib')
#             if type(self.X[0]) == list:
#                 pprint('Series 1')
#                 pprint('%s %20s' % ('X', 'Y'))
#                 for i in range(0, len(self.X[0])):
#                     pprint('%f %20f' % (self.X[0][i], self.Y[0][i]))
#                 pprint('Series 2')
#                 pprint('%s %20s' % ('X', 'Y'))
#                 for i in range(0, len(self.X[1])):
#                     pprint('%f %20f' % (self.X[1][i], self.Y[1][i]))
#             else:
#                 pprint('%s %20s' % ('X', 'Y'))
#                 for i in range(0, len(self.X)):
#                     pprint('%f %20f' % (self.X[i], self.Y[i]))
#             return
#         if type(self.X[0]) == list:
#             fig, ax = plt.subplots()
#             ax.plot(self.X[0], self.Y[0], marker='o', markersize=4)
#             ax.plot(self.X[1], self.Y[1], marker='^', markersize=4.5)
#             # plt.plot(self.X[0], self.Y[0], self.X[1], self.Y[1], marker='o')
#         else:
#             plt.plot(self.X, self.Y, marker='o')
#         params = Quick2DPlotParams()
#         params.ReadFile()
#         plt.rcParams.update({'font.size': params.FontSize})
#         figure = plt.gcf()
#         figure.set_size_inches(4.5, 3)
#         if len(self.Title) > 0:
#             plt.title(self.Title)
#         plt.grid()
#         if self.XLabel is not None:
#             plt.xlabel(self.XLabel)
#         if self.YLabel is not None:
#             plt.ylabel(self.YLabel)
#         if self.Legend is not None:
#             plt.legend(self.Legend, loc=self.LegendPos)
# 
#         if params.OutputDirectory is not None:
#             self.OutputDirectory = params.OutputDirectory
#         if (self.OutputDirectory is not None) and (self.FileName is not None):
#             fullname = os.path.join(self.OutputDirectory, self.FileName)
#             pprint('Saving File: {0} dpi={1}'.format(fullname, params.dpi))
#             plt.savefig(fullname, dpi=params.dpi)
#         plt.show()


from sfc_models.objects import *
from sfc_models.examples.Quick2DPlot import Quick2DPlot
# coding=utf-8


register_standard_logs('output', __file__)
mod = Model()
country = Country(mod, 'CO')
Household(country, 'HH')
ConsolidatedGovernment(country, 'GOV')
FixedMarginBusiness(country, 'BUS', profit_margin=.025)
Market(country, 'GOOD')
Market(country, 'LAB')
TaxFlow(country, 'TAX', taxrate=.2)
# At time period 25, cut spending to 17 (from 20)
mod.AddExogenous('GOV', 'DEM_GOOD', [20.,]* 25 + [17.,]*20)
mod.AddGlobalEquation('DEBT_GDP', 'DEBT-TO-GDP RATIO', '-100.*GOV__F/BUS__SUP_GOOD')
mod.AddGlobalEquation('DEFICIT', 'DEFICIT', '-1.*GOV__INC')
mod.EquationSolver.MaxTime = 40
mod.main()
k = mod.GetTimeSeries('k')

Rat = mod.GetTimeSeries('DEBT_GDP')
Def = mod.GetTimeSeries('GOV__INC')
spend = mod.GetTimeSeries('GOV__DEM_GOOD')


# Path: sfc_models/examples/Quick2DPlot.py
# class Quick2DPlot(object):
#     def __init__(self, x, y, title='', run_now=True, output_directory=None, filename=None):
#         self.X = x
#         self.Y = y
#         self.Title = title
#         self.XLabel = None
#         self.YLabel = None
#         self.Legend = None
#         self.FileName = filename
#         self.LegendPos = 'best'
#         self.OutputDirectory = output_directory
#         if run_now:
#             self.DoPlot()
# 
#     def DoPlot(self):  # pragma: no cover
#         if plt is None:
#             pprint('Attempted to plot the following data; cannot to do because cannot import matplotlib')
#             if type(self.X[0]) == list:
#                 pprint('Series 1')
#                 pprint('%s %20s' % ('X', 'Y'))
#                 for i in range(0, len(self.X[0])):
#                     pprint('%f %20f' % (self.X[0][i], self.Y[0][i]))
#                 pprint('Series 2')
#                 pprint('%s %20s' % ('X', 'Y'))
#                 for i in range(0, len(self.X[1])):
#                     pprint('%f %20f' % (self.X[1][i], self.Y[1][i]))
#             else:
#                 pprint('%s %20s' % ('X', 'Y'))
#                 for i in range(0, len(self.X)):
#                     pprint('%f %20f' % (self.X[i], self.Y[i]))
#             return
#         if type(self.X[0]) == list:
#             fig, ax = plt.subplots()
#             ax.plot(self.X[0], self.Y[0], marker='o', markersize=4)
#             ax.plot(self.X[1], self.Y[1], marker='^', markersize=4.5)
#             # plt.plot(self.X[0], self.Y[0], self.X[1], self.Y[1], marker='o')
#         else:
#             plt.plot(self.X, self.Y, marker='o')
#         params = Quick2DPlotParams()
#         params.ReadFile()
#         plt.rcParams.update({'font.size': params.FontSize})
#         figure = plt.gcf()
#         figure.set_size_inches(4.5, 3)
#         if len(self.Title) > 0:
#             plt.title(self.Title)
#         plt.grid()
#         if self.XLabel is not None:
#             plt.xlabel(self.XLabel)
#         if self.YLabel is not None:
#             plt.ylabel(self.YLabel)
#         if self.Legend is not None:
#             plt.legend(self.Legend, loc=self.LegendPos)
# 
#         if params.OutputDirectory is not None:
#             self.OutputDirectory = params.OutputDirectory
#         if (self.OutputDirectory is not None) and (self.FileName is not None):
#             fullname = os.path.join(self.OutputDirectory, self.FileName)
#             pprint('Saving File: {0} dpi={1}'.format(fullname, params.dpi))
#             plt.savefig(fullname, dpi=params.dpi)
#         plt.show()


# Path: sfc_models/examples/scripts/intro_X_XX_sim_multiplier.py
from sfc_models.objects import *
from sfc_models.examples.Quick2DPlot import Quick2DPlot

# coding=utf-8


register_standard_logs('output', __file__)
mod = Model()
country = Country(mod, 'CO')
Household(country, 'HH')
ConsolidatedGovernment(country, 'GOV')
FixedMarginBusiness(country, 'BUS', profit_margin=.025)
Market(country, 'GOOD')
Market(country, 'LAB')
TaxFlow(country, 'TAX', taxrate=.2)
# At time period 25, cut spending to 17 (from 20)
mod.AddExogenous('GOV', 'DEM_GOOD', [20.,]* 25 + [17.,]*20)
mod.AddGlobalEquation('DEBT_GDP', 'DEBT-TO-GDP RATIO', '-100.*GOV__F/BUS__SUP_GOOD')
mod.AddGlobalEquation('DEFICIT', 'DEFICIT', '-1.*GOV__INC')
mod.EquationSolver.MaxTime = 40
mod.main()
k = mod.GetTimeSeries('k')

Rat = mod.GetTimeSeries('DEBT_GDP')
Def = mod.GetTimeSeries('GOV__INC')
spend = mod.GetTimeSeries('GOV__DEM_GOOD')


p = Quick2DPlot([k, k], [spend, Def], title='Spending and Deficit', filename='intro_X_XX_multiplier_deficit.png',