Ejemplo n.º 1
0
    def test_evaluate_and_resolve_expression(self):
        expression = Expression()

        util = DatabaseUtilities()
        util.delete_lookups()
        util.insert_lookups('somevalue', 0, 2)
        util.insert_lookups('m.monthval', 201703, 4)

        monthly = DataStructure()
        monthly.ProdMonth = 201703
        monthly.ProdVol = 100
        monthly.SalesVol = 90
        monthly.GJ = 1000
        monthly.Heat = 65.01

        s = "asdf =(prod + sales + gj + heat + somevalue + m.monthval) more stuff in here"

        self.assertEqual(1196 + 65.01,
                         expression.evaluate_expression(s, monthly))
        self.assertEqual(
            "asdf =(100 + 90 + 1000 + 65.01 + 2 + 4) more stuff in here",
            expression.resolve_expression(s, monthly))

        s = "asdf =(prod + sales + gj + notfoundvalue) more stuff in here"
        self.assertRaises(AppError, expression.evaluate_expression, s, monthly)
Ejemplo n.º 2
0
    def test_lookup_vars(self):
        expression = Expression()

        util = DatabaseUtilities()
        util.delete_lookups()
        util.insert_lookups('somevalue', 0, 1234)
        util.insert_lookups('m.monthval', 201703, 5678)

        monthly = DataStructure()
        monthly.ProdMonth = 201703
        monthly.ProdVol = 100
        monthly.SalesVol = 90
        monthly.GJ = 1000
        monthly.Heat = 65.01
        monthly.SalesPrice = 50.00
        monthly.TransRate = 10.00
        monthly.ProcessingRate = 5.00
        monthly.GCARate = 3.00
        calc = DataStructure()
        calc.RoyaltyPrice = 27.12

        rv = expression.lookup_vars(
            {
                "prod", "sales", "gj", "heat", "price", "trans", "processing",
                "gca", "royalty_price", "somevalue", "m.monthval"
            }, monthly, calc)

        self.assertEqual(100, rv["prod"])
        self.assertEqual(90, rv["sales"])
        self.assertEqual(1000, rv["gj"])
        self.assertEqual(65.01, rv["heat"])
        self.assertEqual(50, rv["price"])
        self.assertEqual(10, rv["trans"])
        self.assertEqual(5, rv["processing"])
        self.assertEqual(3, rv["gca"])
        self.assertEqual(27.12, rv["royalty_price"])
        self.assertEqual(1234, rv["somevalue"])
        self.assertEqual(5678, rv["m.monthval"])

        self.assertRaises(AppError, expression.lookup_vars, {"notfooundvalue"},
                          monthly)

        monthly.GJ = None
        self.assertRaises(AppError, expression.lookup_vars, {"gj", "sales"},
                          monthly)
    def test_calc_royalties(self):
        dbu = DatabaseUtilities()
        dbu.delete_all_tables()
        dbu.create_some_test_econdata()

        pr = ProcessRoyalties()
        well = DataStructure()
        royalty = DataStructure()
        calc = DataStructure()
        monthly = DataStructure()
        well_lease_link = DataStructure()
        rtp_info = DataStructure()

        monthly.Product = "OIL"
        monthly.ProdMonth = 201501
        monthly.ProdVol = 100
        monthly.ProdHours = 744
        monthly.SalesPrice = 210.0
        royalty.RoyaltyScheme = "SKProvCrownVar"
        royalty.OverrideRoyaltyClassification = None
        royalty.ValuationMethod = "ActSales"
        royalty.CrownModifier = None
        royalty.MinRoyaltyRate = None
        royalty.CrownMultiplier = 1.0
        royalty.MinRoyaltyDollar = None
        royalty.TransDeducted = None
        well.CommencementDate = date(2015, 1, 22)
        well.RoyaltyClassification = "Old Oil"
        well.Classification = "Other"
        well.SRC = 0.0
        well_lease_link.PEFNInterest = 1.0
        rtp_info.Percent = 100.0
        calc.SuppRoyaltyValue = 0.0
        calc.GorrRoyaltyValue = 0.0
        calc.TransGorrValue = 0.0

        pr.calc_royalties(well, royalty, calc, monthly, well_lease_link, rtp_info)

        royalty.RoyaltyScheme = "IOGR1995"
        pr.calc_royalties(well, royalty, calc, monthly, well_lease_link, rtp_info)

        royalty.RoyaltyScheme = "IOGR1995,GORR"
        royalty.Gorr = "fixed,0,.02"
        pr.calc_royalties(well, royalty, calc, monthly, well_lease_link, rtp_info)
    def test_formatter_prod_month(self):
        well = DataStructure()
        well.ProdMonth = 201602

        self.assertEqual(well._format.ProdMonth, '2016-02')
    def test_calcSaskOilIOGR1995(self):
        m = DataStructure()
        # m.WellHeadPrice = 221.123456
        m.SalesPrice = 221.123456
        m.TransRate = 2.123455
        m.ProcessingRate = 0.123455
        m.ProdVol = 70
        m.ProdMonth = 201501

        calc = DataStructure()
        calc.BaseRoyaltyValue = 0.0
        calc.CommencementPeriod = 0
        calc.BaseRoyaltyVolume = 0.0
        calc.RoyaltyPrice = 0.0

        crown_multiplier = 1.2
        fn_interest = 0.25
        rp_interest = 100

        pr = ProcessRoyalties()
        # all tests for SaskWellHead
        pr.calc_sask_oil_iogr1995(
            datetime(2015, 1, 1), "SaskWellHead", crown_multiplier, fn_interest, rp_interest, m, calc
        )
        self.assertEqual(464.36, calc.BaseRoyaltyValue)
        self.assertEqual(calc.CommencementPeriod, 0)
        self.assertEqual(calc.BaseRoyaltyVolume, 7)
        self.assertEqual(calc.RoyaltyPrice, 221.123456)

        m.ProdVol = 100
        crown_multiplier = 0.25
        fn_interest = 3
        rp_interest = 100
        pr.calc_sask_oil_iogr1995(
            datetime(2015, 4, 2), "SaskWellHead", crown_multiplier, fn_interest, rp_interest, m, calc
        )
        self.assertEqual(calc.BaseRoyaltyValue, 1990.11)

        m.ProdVol = 170
        crown_multiplier = 1.0
        fn_interest = 1
        rp_interest = 100
        pr.calc_sask_oil_iogr1995(
            datetime(2015, 5, 1), "SaskWellHead", crown_multiplier, fn_interest, rp_interest, m, calc
        )
        self.assertEqual(calc.BaseRoyaltyValue, 5881.88)

        m.ProdVol = 79.9
        crown_multiplier = 3
        fn_interest = 2
        rp_interest = 100
        pr.calc_sask_oil_iogr1995(
            datetime(2010, 1, 1), "SaskWellHead", crown_multiplier, fn_interest, rp_interest, m, calc
        )
        self.assertEqual(calc.BaseRoyaltyValue, 10600.66)

        m.ProdVol = 150
        crown_multiplier = 2
        fn_interest = 4
        rp_interest = 100
        pr.calc_sask_oil_iogr1995(
            datetime(2009, 7, 3), "SaskWellHead", crown_multiplier, fn_interest, rp_interest, m, calc
        )
        self.assertEqual(calc.BaseRoyaltyValue, 38917.73)

        m.ProdVol = 500
        crown_multiplier = 1
        fn_interest = 5
        rp_interest = 100
        pr.calc_sask_oil_iogr1995(
            datetime(2007, 8, 2), "SaskWellHead", crown_multiplier, fn_interest, rp_interest, m, calc
        )
        self.assertEqual(calc.BaseRoyaltyValue, 124271.38)

        m.ProdVol = 800
        crown_multiplier = 5
        fn_interest = 0.1
        rp_interest = 100
        pr.calc_sask_oil_iogr1995(
            datetime(2008, 9, 9), "SaskWellHead", crown_multiplier, fn_interest, rp_interest, m, calc
        )
        self.assertEqual(calc.BaseRoyaltyValue, 21117.29)

        m.ProdVol = 800
        crown_multiplier = 5
        fn_interest = 0.1
        rp_interest = 50
        pr.calc_sask_oil_iogr1995(
            datetime(2008, 9, 9), "SaskWellHead", crown_multiplier, fn_interest, rp_interest, m, calc
        )
        self.assertEqual(calc.BaseRoyaltyValue, 10558.65)
    def test_formatter_prod_month(self):
        well = DataStructure()
        well.ProdMonth = 201602

        # If there is no attribute in the object called 'LeaseID' use the ID attribute to format the lease string
        self.assertEqual(well._format.ProdMonth, "2016-02")