chart fixed
This commit is contained in:
@@ -8,9 +8,30 @@ use Carbon\Carbon;
|
||||
|
||||
class PriceSnapshotService
|
||||
{
|
||||
/** حداقل قیمت معتبر آبشده (ریال) — زیر این در نمودار نمایش داده نمیشود */
|
||||
/** حداقل قیمت معتبر آبشده (ریال) — برای تاریخچه ذخیرهشده در DB */
|
||||
public const MIN_VALID_CHART_PRICE_RIAL = 30_000_000;
|
||||
|
||||
/** حداقل پیشفرض نمودار Zaarbox — مس و کالاهای ارزانتر از آبشده */
|
||||
public const MIN_VALID_ZAARBOX_CHART_PRICE_RIAL = 1_000_000;
|
||||
|
||||
/**
|
||||
* آستانه حداقل قیمت نمودار تابلو — قابل تنظیم با chart_min_valid_price.
|
||||
* پیشفرض Zaarbox پایینتر از آبشده است تا مس (~۲۲M) فیلتر نشود.
|
||||
*/
|
||||
public function minValidChartPriceRialForExternalFeed(): int
|
||||
{
|
||||
$configured = (int) app(ConfigService::class)->getString('chart_min_valid_price', '0');
|
||||
if ($configured > 0) {
|
||||
return $configured;
|
||||
}
|
||||
|
||||
if (app(ConfigService::class)->usesZaarboxPricing()) {
|
||||
return self::MIN_VALID_ZAARBOX_CHART_PRICE_RIAL;
|
||||
}
|
||||
|
||||
return self::MIN_VALID_CHART_PRICE_RIAL;
|
||||
}
|
||||
|
||||
/** هر تیک کران — ذخیره در prices برای نمودار (هرگز صفر ثبت نمیشود) */
|
||||
public function recordTick(array $payload): void
|
||||
{
|
||||
@@ -23,6 +44,11 @@ class PriceSnapshotService
|
||||
$priceValue = (int) $last->price;
|
||||
}
|
||||
|
||||
$lastRecorded = Price::query()->orderByDesc('id')->first();
|
||||
if ($lastRecorded && (int) $lastRecorded->price === $priceValue) {
|
||||
return;
|
||||
}
|
||||
|
||||
Price::create([
|
||||
'price' => $priceValue,
|
||||
'date_at' => Carbon::now()->toDateString(),
|
||||
@@ -199,9 +225,10 @@ class PriceSnapshotService
|
||||
* @param array{DAILY?: array, WEEKLY?: array, MONTHLY?: array} $prices
|
||||
* @return array{DAILY: array, WEEKLY: array, MONTHLY: array}
|
||||
*/
|
||||
public function sanitizeChartPrices(array $prices): array
|
||||
public function sanitizeChartPrices(array $prices, ?int $minRial = null): array
|
||||
{
|
||||
$minScaled = intdiv(self::MIN_VALID_CHART_PRICE_RIAL, 1000);
|
||||
$minRial ??= self::MIN_VALID_CHART_PRICE_RIAL;
|
||||
$minScaled = intdiv($minRial, 1000);
|
||||
|
||||
foreach (['DAILY', 'WEEKLY', 'MONTHLY'] as $period) {
|
||||
if (! isset($prices[$period]) || ! is_array($prices[$period])) {
|
||||
@@ -220,7 +247,7 @@ class PriceSnapshotService
|
||||
continue;
|
||||
}
|
||||
|
||||
$isValid = $value > self::MIN_VALID_CHART_PRICE_RIAL
|
||||
$isValid = $value > $minRial
|
||||
|| ($value > $minScaled && $value <= self::MIN_VALID_CHART_PRICE_RIAL);
|
||||
|
||||
if ($isValid) {
|
||||
|
||||
Reference in New Issue
Block a user