chart fixed
This commit is contained in:
@@ -90,20 +90,23 @@ class ZaarboxPriceService
|
||||
*/
|
||||
public function getAllPrices(): array
|
||||
{
|
||||
$snapshot = app(PriceSnapshotService::class);
|
||||
|
||||
if ($this->config->getBool('chart_use_local_data', false)) {
|
||||
$local = app(PriceSnapshotService::class)->chartFromDatabase();
|
||||
$local = $snapshot->chartFromDatabase();
|
||||
if (! empty($local['DAILY'])) {
|
||||
return app(PriceSnapshotService::class)->sanitizeChartPrices($local);
|
||||
return $snapshot->sanitizeChartPrices($local);
|
||||
}
|
||||
}
|
||||
|
||||
$minRial = $snapshot->minValidChartPriceRialForExternalFeed();
|
||||
$cached = Cache::get($this->cacheKey());
|
||||
|
||||
if (is_array($cached) && isset($cached['prices'])) {
|
||||
return app(PriceSnapshotService::class)->sanitizeChartPrices($cached['prices']);
|
||||
return $snapshot->sanitizeChartPrices($cached['prices'], $minRial);
|
||||
}
|
||||
|
||||
return app(PriceSnapshotService::class)->sanitizeChartPrices($this->refreshCache());
|
||||
return $snapshot->sanitizeChartPrices($this->refreshCache(), $minRial);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -483,6 +486,8 @@ class ZaarboxPriceService
|
||||
}
|
||||
});
|
||||
|
||||
$minRial = app(PriceSnapshotService::class)->minValidChartPriceRialForExternalFeed();
|
||||
|
||||
foreach (self::PERIODS as $key => $config) {
|
||||
$response = $responses[$key] ?? null;
|
||||
$start = $now->copy()->subHours($config['hours']);
|
||||
@@ -501,7 +506,8 @@ class ZaarboxPriceService
|
||||
$history,
|
||||
$this->toMillis($start),
|
||||
$this->toMillis($now),
|
||||
$config['intervalMs']
|
||||
$config['intervalMs'],
|
||||
$minRial
|
||||
);
|
||||
}
|
||||
|
||||
@@ -510,8 +516,14 @@ class ZaarboxPriceService
|
||||
|
||||
private function historyUrl(Carbon $start, Carbon $end): string
|
||||
{
|
||||
$base = rtrim($this->apiUrl(), '/');
|
||||
if (str_ends_with($base, '/free')) {
|
||||
$base = substr($base, 0, -strlen('/free'));
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
'https://price.zaarbox.ir/api/history/%s?start=%s&end=%s&limit=1000000000',
|
||||
'%s/history/%s?start=%s&end=%s&limit=1000000000',
|
||||
$base,
|
||||
$this->historyId(),
|
||||
$this->toIso8601($start),
|
||||
$this->toIso8601($end)
|
||||
@@ -532,7 +544,7 @@ class ZaarboxPriceService
|
||||
* @param array<int, array<string, mixed>> $history
|
||||
* @return array<int, array{timestamp: int, value: int}>
|
||||
*/
|
||||
private function mapHistory(array $history, int $startMs, int $endMs, int $intervalMs): array
|
||||
private function mapHistory(array $history, int $startMs, int $endMs, int $intervalMs, int $minRial): array
|
||||
{
|
||||
$points = [];
|
||||
|
||||
@@ -566,7 +578,7 @@ class ZaarboxPriceService
|
||||
|
||||
for ($bucket = $firstBucket; $bucket <= $endMs; $bucket += $intervalMs) {
|
||||
while ($index < $count && $points[$index]['timestamp'] <= $bucket) {
|
||||
if ($points[$index]['price'] > PriceSnapshotService::MIN_VALID_CHART_PRICE_RIAL) {
|
||||
if ($points[$index]['price'] > $minRial) {
|
||||
$lastPoint = $points[$index];
|
||||
}
|
||||
$index++;
|
||||
|
||||
Reference in New Issue
Block a user