Skip to content

Commit 9f80213

Browse files
committed
fix(Datasource\CarbonIntensityRTE): ensure that we collect full hours in incremental download
1 parent e96c106 commit 9f80213

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/DataSource/CarbonIntensityRTE.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,26 @@ public function fetchDay(DateTimeImmutable $day, string $zone): array
138138
return [];
139139
}
140140

141+
// Drop data with no carbon intensity (may be returned by the provider)
141142
$response['results'] = array_filter($response['results'], function ($item) {
142143
return $item['taux_co2'] != 0;
143144
});
144145

146+
// Drop last rows until we reach
147+
$safety_count = 0;
148+
while (($last_item = end($response['results'])) !== null) {
149+
$time = DateTime::createFromFormat(DateTimeInterface::ATOM, $last_item['date_heure']);
150+
if ($time->format('i') === '45') {
151+
// We expect 15 minutes steps
152+
break;
153+
}
154+
array_pop($response['results']);
155+
$safety_count++;
156+
if ($safety_count > 3) {
157+
break;
158+
}
159+
}
160+
145161
return $this->formatOutput($response['results'], 15);
146162
}
147163

0 commit comments

Comments
 (0)