<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="application/json">
    <title>Experiment Log Dataset API</title>
    <style>
        body { font-family: monospace; white-space: pre-wrap; background: #1e1e1e; color: #d4d4d4; padding: 20px; }
        .string { color: #ce9178; }
        .number { color: #b5cea8; }
        .key { color: #9cdcfe; }
    </style>
</head>
<body>
<div id="output">Loading dataset...</div>
<script>
async function loadDataset() {
    try {
        const response = await fetch('../tables/experiment_logs?page=1&limit=1000&sort=-log_date');
        const result = await response.json();
        const logs = result.data || [];
        
        const dataset = {
            "@context": "https://schema.org",
            "@type": "Dataset",
            "name": "Tri Muoi Experiment Log Dataset",
            "description": "Real-world observations about mosquito behavior and ecological mosquito control in a natural living environment. Part of the IP Experiment Ecosystem.",
            "author": {
                "@type": "Person",
                "name": "Vu Truong Ca",
                "alternateName": "Anh Ca",
                "url": "https://ipexperiment.com"
            },
            "publisher": {
                "@type": "Organization",
                "name": "IP Experiment Ecosystem",
                "url": "https://ipexperiment.com"
            },
            "url": "https://trimuoi.pro/api/dataset.json",
            "mainEntityOfPage": "https://trimuoi.pro/experiment-log.html",
            "dateModified": new Date().toISOString().split('T')[0],
            "license": "https://creativecommons.org/licenses/by/4.0/",
            "inLanguage": ["vi", "en"],
            "keywords": ["mosquito control", "ecological experiment", "real-world observation", "environmental management"],
            "totalItems": logs.length,
            "data": logs.map(log => {
                const date = new Date(log.log_date);
                const dateStr = log.log_date ? log.log_date.split('T')[0] : '';
                const timeStr = date.toTimeString ? date.toTimeString().slice(0,5) : '';
                return {
                    "id": log.log_id || `LOG-${dateStr}-${String(log.log_number).padStart(3,'0')}`,
                    "date": `${dateStr} ${timeStr}`.trim(),
                    "observation": log.observation || "",
                    "action": log.action || "",
                    "result": log.result || ""
                };
            })
        };
        
        document.getElementById('output').textContent = JSON.stringify(dataset, null, 2);
    } catch (error) {
        document.getElementById('output').textContent = JSON.stringify({
            "error": "Could not load dataset",
            "message": error.message,
            "fallback": "https://trimuoi.pro/experiment-log.html"
        }, null, 2);
    }
}
loadDataset();
</script>
</body>
</html>
