@@ -37,10 +37,6 @@ def estimate_host_level(observed, utilities, availability, market_share):
37
37
Estimated demand, spill and recapture for H
38
38
"""
39
39
40
- if len (observed ) != len (utilities ) or len (observed ) != len (availability ):
41
- raise InvalidInputParameters ('`observed`, `utilities` and'
42
- '`availability` must be of the same size' )
43
-
44
40
demand = spill = recapture = 0
45
41
46
42
if observed and utilities and availability :
@@ -84,26 +80,35 @@ def estimate_class_level(observed, utilities, availability, market_share):
84
80
Estimated demand, spill and recapture for H
85
81
"""
86
82
87
- if len (observed ) != len (utilities ) or len (observed ) != len (availability ):
88
- raise InvalidInputParameters ('`observed`, `utilities` and'
89
- '`availability` must be of the same size' )
90
-
91
83
_ , hspill , hrecapture = estimate_host_level (observed , utilities ,
92
84
availability ,
93
85
market_share )
94
86
95
87
estimates = {}
96
88
total_odemand = sum (observed .values ())
97
89
98
- for product , odemand in observed .items ():
90
+ for product in utilities .keys ():
91
+ odemand = observed .get (product , 0 )
99
92
avail = availability .get (product , 0 )
100
- estimate = demand_mass_balance_c (total_odemand , odemand , avail ,
101
- hrecapture )
102
- estimates [product ] = {
103
- 'demand' : estimate [0 ],
104
- 'spill' : estimate [1 ],
105
- 'recapture' : estimate [2 ]
106
- }
93
+
94
+ if avail == 0 and odemand > 0 :
95
+ raise InvalidInputParameters ('Non zero observed demand with '
96
+ 'zero availability' )
97
+
98
+ if avail and odemand :
99
+ estimate = demand_mass_balance_c (total_odemand , odemand , avail ,
100
+ hrecapture )
101
+ estimates [product ] = {
102
+ 'demand' : estimate [0 ],
103
+ 'spill' : estimate [1 ],
104
+ 'recapture' : estimate [2 ]
105
+ }
106
+ else :
107
+ estimates [product ] = {
108
+ 'demand' : 0 ,
109
+ 'spill' : 0 ,
110
+ 'recapture' : 0
111
+ }
107
112
108
113
return calibrate_no_booking (estimates , observed , utilities , availability ,
109
114
market_share , hspill )
0 commit comments