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)
| 89 | return indices.tolist() |
| 90 | |
| 91 | def 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 | |
| 130 | def percentage_difference(list_price: float, best_price: float) -> dict: |
| 131 | """ |