# 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
# This next line imports all of the objects used.
# The syntax "from <module> import *" is frowned upon, but I want to reduce the number of lines of
# code in these simpler examples.


def main():
    # The next line of code sets the name of the output files based on the code file's name.
    # This means that if you paste this code into a new file, get a new log name.
    register_standard_logs('output', __file__)
    # Create model, which holds all entities
    mod = Model()
    mod.EquationSolver.TraceStep = 10
    # Create first country - Canada. (This model only has one country.)
    can = Country(mod, 'CA', 'Canada')
    # Create sectors
    gov = ConsolidatedGovernment(can, 'GOV', 'Government')
    hh = Household(can, 'HH', 'Household')
    # A literally non-profit business sector
    bus = FixedMarginBusiness(can, 'BUS', 'Business Sector')
    # Create the linkages between sectors - tax flow, markets - labour ('LAB'), goods ('GOOD')
    tax = TaxFlow(can, 'TF', 'TaxFlow', .2)
    labour = Market(can, 'LAB', 'Labour market')
    goods = Market(can, 'GOOD', 'Goods market')
    # Need to set the exogenous variable - Government demand for Goods ("G" in economist symbology)
    mod.AddExogenous('GOV', 'DEM_GOOD', '[0.,]*5 + [20.,] * 105')
    # Build the model
    mod.main()
    CUT = 30
    k = mod.GetTimeSeries('k', cutoff=CUT)
    goods_produced = mod.GetTimeSeries('BUS__SUP_GOOD', cutoff=CUT)

# 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/build_SIM_model.py
from sfc_models.objects import *
from sfc_models.examples.Quick2DPlot import Quick2DPlot

# This next line imports all of the objects used.
# The syntax "from <module> import *" is frowned upon, but I want to reduce the number of lines of
# code in these simpler examples.


def main():
    # The next line of code sets the name of the output files based on the code file's name.
    # This means that if you paste this code into a new file, get a new log name.
    register_standard_logs('output', __file__)
    # Create model, which holds all entities
    mod = Model()
    mod.EquationSolver.TraceStep = 10
    # Create first country - Canada. (This model only has one country.)
    can = Country(mod, 'CA', 'Canada')
    # Create sectors
    gov = ConsolidatedGovernment(can, 'GOV', 'Government')
    hh = Household(can, 'HH', 'Household')
    # A literally non-profit business sector
    bus = FixedMarginBusiness(can, 'BUS', 'Business Sector')
    # Create the linkages between sectors - tax flow, markets - labour ('LAB'), goods ('GOOD')
    tax = TaxFlow(can, 'TF', 'TaxFlow', .2)
    labour = Market(can, 'LAB', 'Labour market')
    goods = Market(can, 'GOOD', 'Goods market')
    # Need to set the exogenous variable - Government demand for Goods ("G" in economist symbology)
    mod.AddExogenous('GOV', 'DEM_GOOD', '[0.,]*5 + [20.,] * 105')
    # Build the model
    mod.main()
    CUT = 30
    k = mod.GetTimeSeries('k', cutoff=CUT)
    goods_produced = mod.GetTimeSeries('BUS__SUP_GOOD', cutoff=CUT)

    Quick2DPlot(k, goods_produced, 'Goods Produced (National Output)')