MCPcopy Create free account
hub / github.com/Marketscrape/marketscrape-web / price_difference_rating

Function price_difference_rating

scraper/utils.py:91–128  ·  view source on GitHub ↗

The rating is based on the difference between the initial and final price. The rating is 0 if the final price is greater than the initial price, and 1 if the initial price is greater than the final price. Otherwise, the rating is the ratio of the initial price to the final price

(initial: float, final: float, days: int)

Source from the content-addressed store, hash-verified

89 return indices.tolist()
90
91def price_difference_rating(initial: float, final: float, days: int) -> float:
92 """
93 The rating is based on the difference between the initial and final
94 price. The rating is 0 if the final price is greater than the initial
95 price, and 1 if the initial price is greater than the final price.
96 Otherwise, the rating is the ratio of the initial price to the final
97 price.
98
99 Args:
100 initial: The initial price.
101 final: The final price.
102 days: The number of days a listing has been active.
103
104 Returns:
105 The rating.
106 """
107
108 # Decay constant (a value greater than 0)
109 decay_constant = 0.01
110
111 # Adjust this value to control the rate of increase of the penalty
112 linear_factor = 0.0125
113
114 # Threshold number of days after which the penalty is applied
115 threshold_days = 7
116
117 if days >= threshold_days:
118 days_past_threshold = days - threshold_days
119 penalty_amount = initial*np.exp(-decay_constant*days_past_threshold) + linear_factor*days_past_threshold*initial
120 initial += penalty_amount
121
122 if initial <= final:
123 rating = 5.0
124 else:
125 price_difference = initial - final
126 rating = 5.0 - (price_difference/initial)*5.0
127
128 return max(0.0, min(rating, 5.0))
129
130def percentage_difference(list_price: float, best_price: float) -> dict:
131 """

Callers 1

postMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected