4RBE543WLHA7PIYT4W7YEJPF6XKZ2UGKPJBQ3CTLJ44AOMGHCEYQC
// Fetch moth metadata in a separate query
const mothMetadataResults = await db
.select({
fileId: mothMetadata.fileId,
gain: mothMetadata.gain,
batteryV: mothMetadata.batteryV,
tempC: mothMetadata.tempC
})
.from(mothMetadata)
.where(sqlExpr`${mothMetadata.fileId} IN (${sqlExpr.raw(fileIdsQuoted)})`);
// Create a map of file ID to moth metadata
mothMetadataMap = mothMetadataResults.reduce((acc, item) => {
acc[item.fileId] = {
gain: item.gain,
batteryV: item.batteryV !== null ? Number(item.batteryV) : null,
tempC: item.tempC !== null ? Number(item.tempC) : null
};
return acc;
}, {} as Record<string, {
gain: string | null;
batteryV: number | null;
tempC: number | null;
}>);
const formatDateTime = (isoString: string): string => {
// Keep these formatters commented out for future use
// const formatDateTime = (isoString: string): string => {
// try {
// const date = new Date(isoString);
// return new Intl.DateTimeFormat('en-GB', {
// year: 'numeric',
// month: 'short',
// day: '2-digit',
// hour: '2-digit',
// minute: '2-digit',
// hour12: false
// }).format(date);
// } catch {
// return isoString;
// }
// };
// const formatSampleRate = (rate: number): string => {
// return `${(rate / 1000).toFixed(1)} kHz`;
// };
const formatMoonPhase = (phase: number | null | undefined): string => {
if (phase === null || phase === undefined) return "—";
const formatSampleRate = (rate: number): string => {
return `${(rate / 1000).toFixed(1)} kHz`;
const formatBatteryVoltage = (volts: number | null | undefined): string => {
if (volts === null || volts === undefined) return "—";
try {
return Number(volts).toFixed(1) + 'V';
} catch {
return "—";
}
{hasMothMetadata && (
<>
<TableCell className="whitespace-normal break-words">
{file.mothMetadata?.gain || "—"}
</TableCell>
<TableCell className="whitespace-normal break-words">
{formatBatteryVoltage(file.mothMetadata?.batteryV)}
</TableCell>
<TableCell className="whitespace-normal break-words">
{formatTemperature(file.mothMetadata?.tempC)}
</TableCell>
</>
)}