本文整理汇总了Python中ralph_pricing.plugins.reports.usage.UsagePlugin类的典型用法代码示例。如果您正苦于以下问题:Python UsagePlugin类的具体用法?Python UsagePlugin怎么用?Python UsagePlugin使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UsagePlugin类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_usages_by_internet_provider
def test_get_usages_by_internet_provider(self):
result = UsagePlugin._get_usages_per_warehouse(
start=datetime.date(2013, 10, 10),
end=datetime.date(2013, 10, 20),
usage_type=self.usage_type_cost_sum,
ventures=self.ventures_subset,
forecast=False,
)
# 5-12: (usages are from 8 to 12)
# usage: 5 * (30 + 60 + 90 + 120) = 1500;
# cost: 1000 + 10000 = 11000;
# price = 11000 / 1500 = 7.(3);
# 13-17:
# usage: 5 * (30 + 60 + 90 + 120) = 1500;
# cost: 2000 + 20000 = 22000;
# price = 22000 / 1500 = 14.(6);
# 18-25: (usages are from 18 to 22)
# usage: 5 * (30 + 60 + 90 + 120) = 1500;
# cost: 4000 + 40000 = 44000;
# price = 44000 / 1500 = 29.(3);
self.assertEquals(result, {
1: {
'ut_3_count': 330.0, # 3 * 30 + 5 * 30 + 3 * 30
'ut_3_cost': D('5500'), # 90*7.(3) + 150*14.(6) + 90*29.(3)
},
2: {
'ut_3_count': 660.0, # 3 * 60 + 5 * 60 + 3 * 60
'ut_3_cost': D('11000'), # 180*7.(3) + 300*14.(6) + 180*29.(3)
},
})
示例2: test_incomplete_price_incomplete_price
def test_incomplete_price_incomplete_price(self):
result = UsagePlugin._incomplete_price(
usage_type=self.usage_type,
start=datetime.date(2013, 10, 10),
end=datetime.date(2013, 11, 20),
)
self.assertEquals(result, 'Incomplete price')
示例3: test_get_usage_type_cost_sum
def test_get_usage_type_cost_sum(self):
result = UsagePlugin._get_total_cost_by_warehouses(
start=datetime.date(2013, 10, 10),
end=datetime.date(2013, 10, 20),
usage_type=self.usage_type_cost_sum,
ventures=self.ventures_subset,
forecast=False,
)
# 5-12: (usages are from 8 to 12)
# usage: 5 * (30 + 60 + 90 + 120) = 1500;
# cost: 1000 + 10000 = 11000;
# price = 11000 / 1500 = 7.(3);
# 13-17:
# usage: 5 * (30 + 60) = 1500;
# cost: 2000 + 20000 = 11000;
# price = 22000 / 1500 = 14.(6);
# 18-25: (usages are from 18 to 22)
# usage: 5 * (30 + 60) = 1500;
# cost: 4000 + 40000 = 44000;
# price = 11000 / 1500 = 29.(3);
#
# 10-12:
# usage: 3 * (30 + 60) = 270;
# cost: 270 * 7.(3) = 1980
# 13-17:
# usage: 5 * (30 + 60) = 450;
# cost: 450 * 14.(6) = 6600
# 18-20:
# usage: 3 * (30 + 60) = 270;
# cost: 270 * 29.(3) = 7920
#
# total cost: 1980 + 6600 + 7920 = 16500
self.assertEquals(result, [990.0, D('16500')])
示例4: test_get_usage_type_cost_sum_forecast
def test_get_usage_type_cost_sum_forecast(self):
result = UsagePlugin._get_total_cost_by_warehouses(
start=datetime.date(2013, 10, 10),
end=datetime.date(2013, 10, 20),
usage_type=self.usage_type_cost_sum,
ventures=[self.venture1],
forecast=True,
)
# 5-12: (usages are from 8 to 12)
# usage: 5 * (30 + 60 + 90 + 120) = 1500;
# cost: 2000 + 20000 = 22000;
# price = 22000 / 1500 = 14.(6);
# 13-17:
# usage: 5 * (30 + 60) = 1500;
# cost: 3000 + 30000 = 33000;
# price = 33000 / 1500 = 22;
# 18-25: (usages are from 18 to 22)
# usage: 5 * (30 + 60) = 1500;
# cost: 5000 + 50000 = 55000;
# price = 55000 / 1500 = 36.(6);
#
# 10-12: usage: 3 * 30 = 90; cost: 90 * 14.(6) = 1320
# 13-17: usage: 5 * 30 = 150; cost: 150 * 22 = 3300
# 18-20: usage: 3 * 30 = 90; cost = 90 * 36.(6) = 3300
# total: usage: 330; cost: 7920
self.assertEquals(result, [330.0, D('7920')])
示例5: test_incomplete_price_internet_providers_no_price
def test_incomplete_price_internet_providers_no_price(self):
result = UsagePlugin._incomplete_price(
usage_type=self.usage_type_cost_sum,
start=datetime.date(2013, 10, 26),
end=datetime.date(2013, 11, 20),
)
self.assertEquals(result, 'No price')
示例6: test_get_usage_type_cost_by_cost
def test_get_usage_type_cost_by_cost(self):
result = UsagePlugin._get_total_cost_by_warehouses(
start=datetime.date(2013, 10, 10),
end=datetime.date(2013, 10, 20),
usage_type=self.usage_type_cost_wh,
ventures=self.ventures_subset,
forecast=False,
)
# 5-12: (usages are from 8 to 12)
# warehouse1:
# usage: 2 * (20 + 40 + 60 + 80) = 400;
# cost: 3600;
# price = 3600 / 400 = 9;
# warehouse2:
# usage: 3 * (20 + 40 + 60 + 80) = 600;
# cost: 3600;
# price = 3600 / 600 = 6;
# 13-17:
# warehouse1:
# usage: 3 * (20 + 40 + 60 + 80) = 600;
# cost: 5400
# price = 5400 / 600 = 9;
# warehouse2:
# usage: 2 * (20 + 40 + 60 + 80) = 400;
# cost: 3600
# price = 3600 / 400 = 9;
# 18-25: (usages are from 18 to 22)
# warehouse1:
# usage: 2 * (20 + 40 + 60 + 80) = 400;
# cost: 4800
# price = 4800 / 400 = 12;
# warehouse2:
# usage: 3 * (20 + 40 + 60 + 80) = 600;
# cost: 7200
# price = 7200 / 600 = 12;
# 10-12:
# warehouse1: usage: 1 * (20 + 40) = 60;
# cost: 60 * 9 = 540
# warehouse2: usage: 2 * (20 + 40) = 120;
# cost: 120 * 6 = 720
# 13-17:
# warehouse1: usage: 3 * (20 + 40) = 180;
# cost: 180 * 9 = 1620
# warehouse2: usage: 2 * (20 + 40) = 120;
# cost: 120 * 9 = 1080
# 18-20:
# warehouse1: usage: 1 * (20 + 40) = 60;
# cost: 60 * 12 = 720
# warehouse2: usage: 2 * (20 + 40) = 120;
# cost: 120 * 12 = 1440
# total:
# warehouse1: usage: 300; cost: 2880
# warehouse2: usage: 360; cost: 3240
# total: cost: 6840
self.assertEquals(
result,
[300.0, D('2880'), 360.0, D('3240'), D('6120')]
)
示例7: test_get_usage_type_cost_by_cost_forecast
def test_get_usage_type_cost_by_cost_forecast(self):
result = UsagePlugin._get_total_cost_by_warehouses(
start=datetime.date(2013, 10, 10),
end=datetime.date(2013, 10, 20),
usage_type=self.usage_type_cost_wh,
ventures=[self.venture1],
forecast=True,
)
# 5-12: (usages are from 8 to 12)
# warehouse1:
# usage: 2 * (20 + 40 + 60 + 80) = 400;
# cost: 2400;
# price = 2400 / 400 = 6;
# warehouse2:
# usage: 3 * (20 + 40 + 60 + 80) = 600;
# cost: 5400;
# price = 5400 / 600 = 9;
# 13-17:
# warehouse1:
# usage: 3 * (20 + 40 + 60 + 80) = 600;
# cost: 5400
# price = 5400 / 600 = 9;
# warehouse2:
# usage: 2 * (20 + 40 + 60 + 80) = 400;
# cost: 1200
# price = 1200 / 400 = 3;
# 18-25: (usages are from 18 to 22)
# warehouse1:
# usage: 2 * (20 + 40 + 60 + 80) = 400;
# cost: 12000
# price = 12000 / 400 = 30;
# warehouse2:
# usage: 3 * (20 + 40 + 60 + 80) = 600;
# cost: 3600
# price = 3600 / 600 = 6;
# 10-12:
# warehouse1: usage: 1 * 20 = 20;
# cost: 20 * 6 = 120
# warehouse2: usage: 2 * 20 = 40;
# cost: 40 * 9 = 360
# 13-17:
# warehouse1: usage: 3 * 20 = 60;
# cost: 60 * 9 = 540
# warehouse2: usage: 2 * 20 = 40;
# cost: 40 * 3 = 120
# 18-20:
# warehouse1: usage: 1 * 20 = 20;
# cost: 20 * 30 = 600
# warehouse2: usage: 2 * 20 = 40;
# cost: 40 * 6 = 240
# total:
# warehouse1: usage: 100; cost: 1260
# warehouse2: usage: 120; cost: 720
# total: cost: 1980
self.assertEquals(
result,
[100.0, D('1260'), 120.0, D('720'), D('1980')]
)
示例8: test_incomplete_price_by_warehouse
def test_incomplete_price_by_warehouse(self):
result = UsagePlugin._incomplete_price(
usage_type=self.usage_type_cost_wh,
start=datetime.date(2013, 10, 10),
end=datetime.date(2013, 10, 20),
warehouse=self.warehouse1,
)
self.assertEquals(result, None)
示例9: test_get_total_cost_sum_whole
def test_get_total_cost_sum_whole(self):
result = UsagePlugin.total_cost(
start=datetime.date(2013, 10, 5),
end=datetime.date(2013, 10, 25),
usage_type=self.usage_type_cost_sum,
ventures=self.ventures,
forecast=False,
)
self.assertEquals(result, D('77000'))
示例10: test_get_total_cost_sum
def test_get_total_cost_sum(self):
result = UsagePlugin.total_cost(
start=datetime.date(2013, 10, 10),
end=datetime.date(2013, 10, 20),
usage_type=self.usage_type_cost_sum,
ventures=self.ventures_subset,
forecast=False,
)
self.assertEquals(result, D('16500'))
示例11: test_get_total_cost_sum_beyond_usageprices
def test_get_total_cost_sum_beyond_usageprices(self):
# even with no_price_msg total cost should return valid cost
result = UsagePlugin.total_cost(
start=datetime.date(2013, 10, 1),
end=datetime.date(2013, 10, 28),
usage_type=self.usage_type_cost_sum,
ventures=self.ventures,
forecast=False,
no_price_msg=True,
)
self.assertEquals(result, D('77000'))
示例12: test_get_usage_type_cost
def test_get_usage_type_cost(self):
result = UsagePlugin._get_total_cost_by_warehouses(
start=datetime.date(2013, 10, 10),
end=datetime.date(2013, 10, 20),
usage_type=self.usage_type,
ventures=self.ventures_subset,
forecast=False,
)
# 10-12: usage: 3 * (10 + 20) = 90; cost: 90 * 10 = 900
# 13-17: usage: 5 * (10 + 20) = 150; cost: 150 * 20 = 3000
# 18-20: usage: 3 * (10 + 20) = 90; cost = 90 * 30 = 2700
# total: usage: 330; cost: 6600
self.assertEquals(result, [330.0, D('6600')])
示例13: test_get_usage_type_cost_forecast
def test_get_usage_type_cost_forecast(self):
result = UsagePlugin._get_total_cost_by_warehouses(
start=datetime.date(2013, 10, 10),
end=datetime.date(2013, 10, 20),
usage_type=self.usage_type,
ventures=[self.venture1],
forecast=True,
)
# 10-12: usage: 3 * 10 = 30; cost: 30 * 50 = 1500
# 13-17: usage: 5 * 10 = 50; cost: 50 * 60 = 3000
# 18-20: usage: 3 * 10 = 30; cost = 30 * 70 = 2100
# total: usage: 110; cost: 6600
self.assertEquals(result, [110.0, D('6600')])
示例14: test_get_usages_per_warehouse_by_device
def test_get_usages_per_warehouse_by_device(self):
result = UsagePlugin._get_usages_per_warehouse(
start=datetime.date(2013, 10, 10),
end=datetime.date(2013, 10, 20),
usage_type=self.usage_type_cost_wh,
ventures=[self.venture1],
forecast=False,
by_device=True,
)
self.assertEquals(result, {
self.ventures_devices[self.venture1].id: {
'ut_2_count_wh_1': 100.0,
'ut_2_cost_wh_1': D('960'),
'ut_2_count_wh_2': 120.0,
'ut_2_cost_wh_2': D('1080'),
'ut_2_total_cost': D('2040'),
}
})
示例15: test_usage_type_average
def test_usage_type_average(self):
result = UsagePlugin.costs(
start=datetime.date(2013, 10, 10),
end=datetime.date(2013, 10, 20),
usage_type=self.usage_type_average,
ventures=self.ventures_subset,
forecast=False,
)
self.assertEquals(result, {
1: {
'ut_4_count': 40.0, # average daily usage
'ut_4_cost': D('8800'),
},
2: {
'ut_4_count': 80.0, # average daily usage
'ut_4_cost': D('17600'),
},
})