update
This commit is contained in:
@@ -45,8 +45,8 @@ REGION_INTERVAL = 8
|
||||
LOCK_SECONDS = 15 * 60
|
||||
ERROR_COOLDOWN_SECONDS = 5 * 60
|
||||
REDIS_TIMEOUT_SECONDS = 1
|
||||
# 统计范围和单位已改变,旧缓存的万金币/元均值不能作为新的元/万金币单价返回。
|
||||
CACHE_PREFIX = 'openapi:colg:thirdpart_gold:v2'
|
||||
# v2缓存已将元/万金币单价舍入至0.01,无法还原比例,改用新缓存重新采集。
|
||||
CACHE_PREFIX = 'openapi:colg:thirdpart_gold:v3'
|
||||
LOCK_KEY = f'{CACHE_PREFIX}:lock'
|
||||
COOLDOWN_KEY = f'{CACHE_PREFIX}:cooldown'
|
||||
RELEASE_LOCK = """
|
||||
@@ -128,7 +128,7 @@ def make_payload(channel: dict, seed: dict, user: dict) -> dict:
|
||||
|
||||
|
||||
def first_page_average(offers: list[dict]) -> tuple[float, int]:
|
||||
"""匹配公开页面 i.item1 的第4~10条,平均显示单价(元/万金币)。"""
|
||||
"""取页面第4~10条报价,逐条按1/Price换算后平均,单位万金币/元。"""
|
||||
valid = []
|
||||
for offer in offers:
|
||||
try:
|
||||
@@ -137,7 +137,9 @@ def first_page_average(offers: list[dict]) -> tuple[float, int]:
|
||||
number = float(offer['Number'])
|
||||
except (KeyError, TypeError, ValueError, OverflowError):
|
||||
continue
|
||||
if not all(math.isfinite(value) for value in (price, money, number)) or price < 0:
|
||||
if not all(math.isfinite(value) for value in (price, money, number)) or price <= 0:
|
||||
continue
|
||||
if not math.isfinite(1 / price):
|
||||
continue
|
||||
# 页面默认展示条件,不额外设置price1/price2价格过滤。
|
||||
if money != -1 and (money * number < 5 or price == 0):
|
||||
@@ -160,9 +162,9 @@ def first_page_average(offers: list[dict]) -> tuple[float, int]:
|
||||
selected = page[SAMPLE_SLICE]
|
||||
if not selected:
|
||||
raise ValueError('YXDR 未返回有效报价')
|
||||
# 页面 Math.floorDigits(price, 5) 先toFixed(6)再删掉末位。
|
||||
prices = [float(f"{item['Price']:.6f}"[:-1]) for item in selected]
|
||||
return round(fmean(prices), 2), len(prices)
|
||||
# 对原始单价取倒数后求均值,最后才保留两位,避免先舍入单价丢失比例差异。
|
||||
ratios = [1 / item['Price'] for item in selected]
|
||||
return round(fmean(ratios), 2), len(ratios)
|
||||
|
||||
|
||||
async def _read_response(resp) -> str:
|
||||
|
||||
Reference in New Issue
Block a user