Spaces:
Running

auto-lab-571 / index.html
LOLIVEJ's picture
Upload index.html with huggingface_hub
7b25674 verified
Raw History Blame Contribute Delete
29.5 kB
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Modèle de développement du maïs FAO 200/300/400 - Base 6°C</title>
<meta name="description" content="Modèle de développement du maïs dynamique (FAO 200/300/400) basé sur les sommes de températures (base 6°C). Import CSV/Excel, météo réelle (Open-Meteo, Clermont-Ferrand), phases clés, graphiques et export." />
<style>
:root {
--bg: #0f172a;
--panel: #111827;
--accent: #22c55e;
--accent-2: #f59e0b;
--text: #e5e7eb;
--muted: #9ca3af;
--border: #1f2937;
--card: #0b1220;
}
* { box-sizing: border-box; }
body {
margin: 0;
font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
background: radial-gradient(1200px 600px at 70% 10%, rgba(34,197,94,.12), transparent 60%) , var(--bg);
color: var(--text);
line-height: 1.45;
}
header {
padding: 18px 20px;
border-bottom: 1px solid var(--border);
background: linear-gradient(180deg, rgba(17,24,39,.6), rgba(17,24,39,.2));
position: sticky; top: 0; z-index: 20; backdrop-filter: blur(10px);
}
.container { max-width: 1200px; margin: 0 auto; padding: 20px; }
h1 {
margin: 0 0 8px 0; font-size: 26px; font-weight: 700;
display: flex; align-items: center; gap: 12px;
}
.brand {
display: inline-flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px;
}
.brand a { color: var(--accent); text-decoration: none; }
.brand a:hover { text-decoration: underline; }
.grid { display: grid; gap: 18px; }
@media (min-width: 960px) {
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 1.2fr .8fr .8fr; }
}
.card {
background: linear-gradient(180deg, rgba(255,255,255,.02), rgba(255,255,255,.01));
border: 1px solid var(--border);
border-radius: 14px;
padding: 18px;
box-shadow: 0 10px 30px rgba(0,0,0,.25), inset 0 1px 0 rgba(255,255,255,.03);
}
.card h2, .card h3 { margin: 0 0 12px 0; font-size: 18px; }
label { display: block; font-weight: 600; margin: 8px 0 6px; color: var(--muted); font-size: 13px; }
input[type="date"], input[type="file"], input[type="number"], input[type="text"], select {
width: 100%; padding: 10px 12px; background: #0b1220; color: var(--text);
border: 1px solid var(--border); border-radius: 8px; outline: none;
}
input[type="file"] { padding: 8px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.btn {
background: linear-gradient(180deg, var(--accent), #16a34a);
color: white; border: 0; padding: 10px 14px; border-radius: 10px; cursor: pointer;
font-weight: 700; letter-spacing: .2px; box-shadow: 0 8px 20px rgba(34,197,94,.25);
}
.btn.secondary {
background: linear-gradient(180deg, #3b82f6, #2563eb);
box-shadow: 0 8px 20px rgba(59,130,246,.25);
}
.btn.ghost {
background: transparent; border: 1px solid var(--border); color: var(--text);
}
.btn:disabled { opacity: .6; cursor: not-allowed; }
.small { font-size: 12px; color: var(--muted); }
.pill {
display: inline-flex; align-items: center; gap: 8px;
background: #0b1220; border: 1px solid var(--border); color: var(--text);
padding: 6px 10px; border-radius: 999px; font-size: 12px;
}
.stat {
display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
padding: 10px 0; border-bottom: 1px dashed var(--border);
}
.stat:last-child { border-bottom: 0; }
.progress {
height: 10px; background: #0b1220; border-radius: 999px; overflow: hidden; border: 1px solid var(--border);
}
.progress > span {
display: block; height: 100%;
background: linear-gradient(90deg, var(--accent), var(--accent-2));
width: 0%;
}
.stages { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.stage {
background: #0b1220; border: 1px solid var(--border); border-radius: 12px; padding: 12px;
}
.stage h4 { margin: 0 0 8px; font-size: 14px; }
.stage canvas { width: 100%; height: 120px; background: #0a0f1a; border-radius: 8px; }
.muted { color: var(--muted); }
.footer {
margin-top: 30px; padding: 20px; text-align: center; color: var(--muted); font-size: 13px;
border-top: 1px solid var(--border);
}
canvas { display: block; max-width: 100%; }
.dropzone {
border: 2px dashed #334155; border-radius: 12px; padding: 18px; text-align: center; color: var(--muted);
transition: .2s border-color, .2s background;
}
.dropzone.dragover {
border-color: var(--accent); background: rgba(34,197,94,.05);
}
.tag { font-size: 11px; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.hint { background: #0a0f1a; border: 1px solid var(--border); padding: 10px; border-radius: 8px; font-size: 12px; }
</style>
</head>
<body>
<header>
<div class="container row" style="justify-content: space-between;">
<div>
<h1>🌽 Modèle de développement du maïs FAO 300 (Base 6°C)</h1>
<div class="brand">
Modèle GDD avec phases clés, import météo, graphiques et export —
<a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" rel="noopener">Built with anycoder</a>
</div>
</div>
<div class="row">
<button class="btn ghost" id="btn-download-template">📥 Télécharger le modèle CSV</button>
<button class="btn" id="btn-quick-start">⚡ Démarrage rapide</button>
</div>
</div>
</header>
<main class="container">
<div class="grid grid-2">
<section class="card">
<h2>1) Paramètres et import des données météo</h2>
<div class="grid grid-2">
<div>
<label for="sowingDate">Date de semis (jj/mm/aaaa)</label>
<input type="date" id="sowingDate" value="2024-04-20" />
</div>
<div>
<label for="baseTemp">Température de base (°C)</label>
<input type="number" id="baseTemp" value="6" step="0.5" min="-5" max="20" />
</div>
<div>
<label for="faoIndex">Indice FAO (précocité)</label>
<select id="faoIndex">
<option value="200">FAO 200 (tardif)</option>
<option value="300" selected>FAO 300 (semi-tardif)</option>
<option value="400">FAO 400 (précoce)</option>
</select>
</div>
</div>
<div class="grid" style="margin-top: 12px;">
<div>
<label>Importer un fichier météo (CSV ou Excel .xlsx)</label>
<div class="dropzone" id="dropzone">
<div class="row" style="justify-content: center;">
<div>
<div>Glissez-déposez votre fichier CSV ou Excel ici</div>
<div class="small">ou</div>
<div style="margin-top: 6px;">
<input type="file" id="fileInput" accept=".csv, text/csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, .xlsx" />
</div>
</div>
</div>
<div class="hint" style="margin-top: 12px;">
<strong>📋 Format requis pour Excel/CSV:</strong>
<br/>• <strong>Colonnes obligatoires:</strong> date, tmin, tmax
<br/>• <strong>date:</strong> format YYYY-MM-DD (recommandé) ou DD/MM/YYYY
<br/>• <strong>tmin:</strong> température minimale journalière en °C
<br/>• <strong>tmax:</strong> température maximale journalière en °C
<br/><br/><strong>📊 Exemple Excel (.xlsx):</strong>
<br/>A1: date | B1: tmin | C1: tmax
<br/>A2: 20/04/2024 | B2: 8 | C2: 18
<br/>A3: 21/04/2024 | B3: 9 | C3: 19
<br/><br/><strong>📄 Exemple CSV (.csv):</strong>
<br/>date,tmin,tmax
<br/>2024-04-20,8,18
<br/>2024-04-21,9,19
<br/><span class="muted">⚠️ Sauvegardez avec séparateur virgule et encodage UTF-8.</span>
</div>
</div>
</div>
</div>
<div class="row" style="margin-top: 12px;">
<button class="btn" id="btn-run">▶️ Lancer le modèle (tous calculs)</button>
<button class="btn secondary" id="btn-demo">🧪 Météo démo théorique (Clermont-Ferrand)</button>
<button class="btn ghost" id="btn-fetch-real">🌤️ Récupérer météo réelle (Clermont-Ferrand — Open‑Meteo)</button>
<button class="btn ghost" id="btn-reset">🔄 Réinitialiser</button>
<span class="tag" id="dataStatus">Aucune donnée chargée</span>
</div>
<div class="small muted" style="margin-top: 8px;">
📌 <strong>Utilisateur:</strong> "Lancer le modèle" exécute tous les calculs et génère les graphiques. Modifiez les paramètres (date, FAO, température de base) puis recliquez pour recalculer.
<br/>💡 Par défaut (bouton démo), une série théorique 365 jours est générée autour du 20/04 de l'année précédente. Avec "Récupérer", les vraies données récentes sont chargées (Open‑Meteo).
</div>
</section>
<section class="card">
<h2>2) Source des données météo</h2>
<div class="small muted" style="margin-bottom: 10px;">
Source utilisée pour le calcul (syntétique = théorique autour du 20/04/YYYY).
</div>
<div class="row">
<span class="tag" id="source-tag">Synthétique (theoretical)</span>
</div>
</section>
</div>
<section class="card">
<h2>3) Résultats et visualisations</h2>
<div class="grid grid-3">
<div class="grid" style="gap: 12px;">
<canvas id="chart" width="800" height="320" aria-label="Graphique des GDD cumulés"></canvas>
<button class="btn ghost" id="btn-export-chart">🖼️ Exporter le graphique PNG</button>
</div>
<div>
<h3>Résumé des stades</h3>
<div class="small muted" id="summary"></div>
<div style="margin-top: 10px;">
<div class="progress"><span id="progress-bar"></span></div>
<div class="small muted" id="progress-label" style="margin-top: 4px;"></div>
</div>
</div>
<div>
<h3>Actions d'export</h3>
<div class="row" style="flex-direction: column; align-items: stretch;">
<button class="btn secondary" id="btn-export-csv">📄 Exporter les GDD (CSV)</button>
<button class="btn ghost" id="btn-export-summary">📋 Exporter le résumé (CSV)</button>
<button class="btn ghost" id="btn-export-json">🧾 Exporter tout (JSON)</button>
</div>
<div class="hint" style="margin-top: 10px;">
Les exports sont générés localement dans votre navigateur. Aucun envoi de données.
</div>
</div>
</div>
</section>
<section class="card">
<h2>4) Paramètres du modèle et seuils GDD (base 6°C)</h2>
<div class="small muted" style="margin-bottom: 10px;">
Seuils dynamiques selon l'indice FAO sélectionné. Ajustez si nécessaire.
</div>
<div class="stat">
<span class="pill">🌱 Germination / Levée</span>
<div><span class="muted">≥</span> <strong id="thr-emergence">120 GDD</strong></div>
<span class="muted" id="dur-emergence">≈ 10 j</span>
</div>
<div class="stat">
<span class="pill">🌿 3–4 feuilles (V3–V4)</span>
<div><span class="muted">≥</span> <strong id="thr-v3">220 GDD</strong></div>
<span class="muted" id="dur-v3">≈ 20 j</span>
</div>
<div class="stat">
<span class="pill">🌾 6 feuilles (V6)</span>
<div><span class="muted">≥</span> <strong id="thr-v6">350 GDD</strong></div>
<span class="muted" id="dur-v6">≈ 30 j</span>
</div>
<div class="stat">
<span class="pill">🌽 Sortie panicule</span>
<div><span class="muted">≥</span> <strong id="thr-tasseling">800 GDD</strong></div>
<span class="muted" id="dur-tasseling">≈ 65 j</span>
</div>
<div class="stat">
<span class="pill">🌾 Floraison femelle</span>
<div><span class="muted">≥</span> <strong id="thr-silking">900 GDD</strong></div>
<span class="muted" id="dur-silking">≈ 75 j</span>
</div>
<div class="stat">
<span class="pill">🥬 Grain laiteux</span>
<div><span class="muted">≥</span> <strong id="thr-dough">1100 GDD</strong></div>
<span class="muted" id="dur-dough">≈ 95 j</span>
</div>
<div class="stat">
<span class="pill">🌾 Maturité physiologique</span>
<div><span class="muted">≥</span> <strong id="thr-maturity">1500 GDD</strong></div>
<span class="muted" id="dur-maturity">≈ 130 j</span>
</div>
</section>
<section class="card">
<h2>5) Fresque des stades du maïs (schémas)</h2>
<div class="small muted" style="margin-bottom: 10px;">
Illustrations réalistes des principaux stades de développement du maïs selon les sommes de températures (base 6°C).
</div>
<div class="stages" id="stageGallery">
<div class="stage">
<h4>🌱 Germination/Levée</h4>
<canvas width="200" height="120" data-stage="emergence"></canvas>
<div class="small muted">≥ 120 GDD • ≈ 10 jours</div>
</div>
<div class="stage">
<h4>🌿 V3-V4 (3-4 feuilles)</h4>
<canvas width="200" height="120" data-stage="v3"></canvas>
<div class="small muted">≥ 220 GDD • ≈ 20 jours</div>
</div>
<div class="stage">
<h4>🌾 V6 (6 feuilles)</h4>
<canvas width="200" height="120" data-stage="v6"></canvas>
<div class="small muted">≥ 350 GDD • ≈ 30 jours</div>
</div>
<div class="stage">
<h4>🌽 Sortie panicule</h4>
<canvas width="200" height="120" data-stage="tasseling"></canvas>
<div class="small muted">≥ 800 GDD • ≈ 65 jours</div>
</div>
<div class="stage">
<h4>🌾 Floraison femelle</h4>
<canvas width="200" height="120" data-stage="silking"></canvas>
<div class="small muted">≥ 900 GDD • ≈ 75 jours</div>
</div>
<div class="stage">
<h4>🥬 Grain laiteux</h4>
<canvas width="200" height="120" data-stage="dough"></canvas>
<div class="small muted">≥ 1100 GDD • ≈ 95 jours</div>
</div>
<div class="stage">
<h4>🌾 Maturité</h4>
<canvas width="200" height="120" data-stage="maturity"></canvas>
<div class="small muted">≥ 1500 GDD • ≈ 130 jours</div>
</div>
</div>
</section>
<div class="footer">
Modèle pédagogique GDD base 6°C — Multi-FAO (200/300/400) — © 2024
</div>
</main>
<!-- External libs for Excel parsing and Chart.js for charts -->
<script src="https://cdn.jsdelivr.net/npm/xlsx@0.19.3/dist/xlsx.full.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.3/dist/chart.umd.min.js"></script>
<script>
// ========= Utilities =========
const el = {
sowingDate: document.getElementById('sowingDate'),
baseTemp: document.getElementById('baseTemp'),
faoIndex: document.getElementById('faoIndex'),
dropzone: document.getElementById('dropzone'),
fileInput: document.getElementById('fileInput'),
run: document.getElementById('btn-run'),
demo: document.getElementById('btn-demo'),
fetchReal: document.getElementById('btn-fetch-real'),
dataStatus: document.getElementById('dataStatus'),
sourceTag: document.getElementById('source-tag'),
chart: document.getElementById('chart'),
summary: document.getElementById('summary'),
progressBar: document.getElementById('progress-bar'),
progressLabel: document.getElementById('progress-label'),
exportChart: document.getElementById('btn-export-chart'),
exportCSV: document.getElementById('btn-export-csv'),
exportSummary: document.getElementById('btn-export-summary'),
exportJSON: document.getElementById('btn-export-json'),
reset: document.getElementById('btn-reset'),
quickStart: document.getElementById('btn-quick-start'),
downloadTemplate: document.getElementById('btn-download-template'),
};
// State
let weather = []; // {date: Date, tmin, tmax}
let computed = null; // computed results
let sourceUsed = 'Aucune';
let chartInstance = null;
// FAO threshold sets (GDD base 6°C)
const FAO_THRESHOLDS = {
200: { emergence: 120, v3: 220, v6: 350, tasseling: 800, silking: 900, dough: 1100, maturity: 1500 }, // tardif
300: { emergence: 110, v3: 200, v6: 320, tasseling: 750, silking: 850, dough: 1050, maturity: 1450 }, // semi-tardif (par défaut)
400: { emergence: 100, v3: 180, v6: 300, tasseling: 700, silking: 800, dough: 1000, maturity: 1400 } // précoce
};
// Helpers
const clamp = (v, a, b) => Math.max(a, Math.min(b, v));
const fmtDate = d => d.toISOString().slice(0, 10);
const parseDateFlexible = s => {
if (!s) return null;
s = String(s).trim();
// Try ISO first
const iso = new Date(s);
if (!isNaN(iso)) return iso;
// Try DD/MM/YYYY or DD-MM-YYYY
const m = s.match(/^(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})$/);
if (m) {
const dd = +m[1], mm = +m[2] - 1, yyyy = +m[3];
const dt = new Date(yyyy, mm, dd);
return isNaN(dt) ? null : dt;
}
return null;
};
// GDD computation (base 6°C)
function dailyGDD(tmin, tmax, base) {
const tmean = (tmin + tmax) / 2;
return Math.max(0, tmean - base);
}
function dateAddDays(d, days) {
const nd = new Date(d);
nd.setDate(nd.getDate() + days);
return nd;
}
// ---------- Demo / Real data ----------
function generateTheoreticalWeather(startDate) {
// 365 days starting at startDate
const data = [];
let prevTmin = 8, prevTmax = 18;
for (let i = 0; i < 365; i++) {
const d = dateAddDays(startDate, i);
// Seasonal sinus wave for temps
const dayOfYear = Math.floor((d - new Date(d.getFullYear(), 0, 0)) / 86400000);
const amp = 8 + 6 * Math.sin((2 * Math.PI * dayOfYear) / 365);
const offset = 4 * Math.sin((2 * Math.PI * dayOfYear) / 365 + Math.PI / 3);
let tmax = 18 + amp + offset + (Math.random() * 4 - 2);
let tmin = tmax - 8 - Math.random() * 2;
// Smooth with previous day
tmax = 0.7 * tmax + 0.3 * prevTmax;
tmin = 0.7 * tmin + 0.3 * prevTmin;
prevTmax = tmax; prevTmin = tmin;
data.push({ date: d, tmin: +tmin.toFixed(1), tmax: +tmax.toFixed(1) });
}
return data;
}
async function fetchRealWeatherClermont(startDate) {
// Pull last 365 days from Open-Meteo (daily)
const endDate = dateAddDays(startDate, 364);
const url = `https://api.open-meteo.com/v1/forecast?latitude=45.78&longitude=3.09&daily=temperature_2m_max,temperature_2m_min&timezone=Europe%2FParis&start_date=${fmtDate(startDate)}&end_date=${fmtDate(endDate)}`;
const res = await fetch(url);
if (!res.ok) throw new Error('Open-Meteo error');
const json = await res.json();
const data = [];
for (let i = 0; i < json.daily.time.length; i++) {
data.push({
date: new Date(json.daily.time[i]),
tmin: json.daily.temperature_2m_min[i],
tmax: json.daily.temperature_2m_max[i]
});
}
return data;
}
// ---------- Parse files ----------
function parseCSV(text) {
// Simple CSV: date,tmin,tmax (ignore quoted commas)
const lines = text.split(/\r?\n/).map(l => l.trim()).filter(l => l);
if (lines.length === 0) return [];
const header = lines[0].split(',').map(h => h.trim().toLowerCase());
const idxDate = header.indexOf('date');
const idxTmin = header.indexOf('tmin');
const idxTmax = header.indexOf('tmax');
if (idxDate < 0 || idxTmin < 0 || idxTmax < 0) return null;
const out = [];
for (let i = 1; i < lines.length; i++) {
const cols = lines[i].split(',').map(c => c.trim());
const d = parseDateFlexible(cols[idxDate]);
const tmin = parseFloat(cols[idxTmin]);
const tmax = parseFloat(cols[idxTmax]);
if (d && isFinite(tmin) && isFinite(tmax)) {
out.push({ date: new Date(d.getFullYear(), d.getMonth(), d.getDate()), tmin, tmax });
}
}
// sort and dedup by date
out.sort((a, b) => a.date - b.date);
const dedup = [];
let lastKey = '';
for (const r of out) {
const k = fmtDate(r.date);
if (k !== lastKey) {
dedup.push(r);
lastKey = k;
}
}
return dedup;
}
function parseExcel(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onerror = reject;
reader.onload = e => {
try {
const data = new Uint8Array(e.target.result);
const wb = XLSX.read(data, { type: 'array' });
const ws = wb.Sheets[wb.SheetNames[0]];
const json = XLSX.utils.sheet_to_json(ws, { header: 1 });
if (json.length < 2) return resolve([]);
const header = (json[0] || []).map(h => String(h || '').trim().toLowerCase());
const idxDate = header.indexOf('date');
const idxTmin = header.indexOf('tmin');
const idxTmax = header.indexOf('tmax');
if (idxDate < 0 || idxTmin < 0 || idxTmax < 0) return resolve(null);
const out = [];
for (let i = 1; i < json.length; i++) {
const row = json[i] || [];
const d = parseDateFlexible(row[idxDate]);
const tmin = parseFloat(row[idxTmin]);
const tmax = parseFloat(row[idxTmax]);
if (d && isFinite(tmin) && isFinite(tmax)) {
out.push({ date: new Date(d.getFullYear(), d.getMonth(), d.getDate()), tmin, tmax });
}
}
out.sort((a, b) => a.date - b.date);
// dedup
const dedup = [];
let lastKey = '';
for (const r of out) {
const k = fmtDate(r.date);
if (k !== lastKey) {
dedup.push(r);
lastKey = k;
}
}
resolve(dedup);
} catch (err) {
reject(err);
}
};
reader.readAsArrayBuffer(file);
});
}
// ---------- Core computation ----------
function computeModel(weatherData, sowingDate, baseTemp, fao) {
const thresholds = { ...FAO_THRESHOLDS[fao] };
const gddSeries = [];
let cum = 0;
for (const w of weatherData) {
const gdd = dailyGDD(w.tmin, w.tmax, baseTemp);
cum += gdd;
gddSeries.push({ ...w, gdd, cum });
}
// Find stage dates
const findDateForGDD = target => {
for (const p of gddSeries) {
if (p.cum >= target) return p.date;
}
return null;
};
const stageDates = {
sowing: sowingDate,
emergence: findDateForGDD(thresholds.emergence),
v3: findDateForGDD(thresholds.v3),
v6: findDateForGDD(thresholds.v6),
tasseling: findDateForGDD(thresholds.tasseling),
silking: findDateForGDD(thresholds.silking),
dough: findDateForGDD(thresholds.dough),
maturity: findDateForGDD(thresholds.maturity)
};
// Current progress
let currentStage = 'semis';
if (stageDates.maturity) currentStage = 'maturity';
else if (stageDates.dough) currentStage = 'dough';
else if (stageDates.silking) currentStage = 'silking';
else if (stageDates.tasseling) currentStage = 'tasseling';
else if (stageDates.v6) currentStage = 'v6';
else if (stageDates.v3) currentStage = 'v3';
else if (stageDates.emergence) currentStage = 'emergence';
const totalDays = gddSeries.length;
const maturityDayIdx = gddSeries.findIndex(p => stageDates.maturity && fmtDate(p.date) === fmtDate(stageDates.maturity));
const maturityDays = maturityDayIdx >= 0 ? (maturityDayIdx + 1) : null;
const maturityGDD = stageDates.maturity ? gddSeries[maturityDayIdx].cum : null;
return {
thresholds,
gddSeries,
stageDates,
currentStage,
stats: {
totalDays,
maturityDays,
maturityGDD