actually remove old entries that are valid but overwritten

master
Dirk Heilig 2024-09-23 14:43:38 +02:00
parent 9d36ec5c0f
commit 835828f014
1 changed files with 20 additions and 25 deletions

View File

@ -114,7 +114,7 @@ logit("Subscribed");
$timer = 0; $timer = 0;
logit( logit(
"Started listening for incoming messages\n will wait 60 seconds before starting to export data" "Started listening for incoming messages\n will wait 65 seconds before starting to export data"
); );
$realStart = time() + 15; $realStart = time() + 15;
logit( logit(
@ -374,35 +374,30 @@ function filter(): void
return $v > time() - 60 * 60 * 24 * 14; return $v > time() - 60 * 60 * 24 * 14;
}); });
} }
// remove data points with the same name and labels, keep the newest
/* $filterEntries = []; usort($data, function ($a, $b) {
foreach ($data as $key => $entry) { return $b["timestamp"] - $a["timestamp"];
$sort = $entry["labels"] ?? []; });
ksort($sort);
$sort[] = $entry["name"]; $used = [];
$hash = md5(strval(json_encode($sort))); #logit("pre filter count: " . count($data));
if (!isset($filterEntries[$hash])) { foreach ($data as $k => $entry) {
$filterEntries[$hash] = [ $sortedLabels = $entry["labels"] ?? [];
"key" => $key, ksort($sortedLabels);
"timestamp" => $entry["timestamp"], $j = json_encode([$sortedLabels, $entry["name"]]);
]; if (false === $j) {
unset($data[$k]);
continue; continue;
} }
if ($filterEntries[$hash]["timestamp"] < $entry["timestamp"]) { $hash = md5($j);
$filterEntries[$hash] = [ if (isset($used[$hash])) {
"key" => $key, unset($data[$k]);
"timestamp" => $entry["timestamp"], echo "unset $k\n";
];
} }
$used[$hash] = true;
} }
$keysToKeep = array_map(function ($v) {
return $v["key"];
}, $filterEntries);
$data = array_filter((array) $data, function ($key) use ($keysToKeep) {
return in_array($key, $keysToKeep);
});
$data = array_values($data); $data = array_values($data);
*/ #logit("post filter count: " . count($data));
} }
function getEnvWithDefaultStr(string $key, string $default): string function getEnvWithDefaultStr(string $key, string $default): string