fix: capacity check ignores physically-ended slots; feat: ha_poll_interval setting (default 60s)
Deploy via Portainer / deploy (push) Successful in 0s
Deploy via Portainer / deploy (push) Successful in 0s
This commit is contained in:
Binary file not shown.
@@ -226,6 +226,7 @@ def init_db():
|
||||
('ical_token',''),
|
||||
('ha_url',''),
|
||||
('ha_token',''),
|
||||
('ha_poll_interval','60'),
|
||||
]
|
||||
conn.executemany('INSERT OR IGNORE INTO settings VALUES (?,?)', defaults)
|
||||
|
||||
@@ -1303,8 +1304,11 @@ def job_detail(id):
|
||||
return redirect(url_for('jobs'))
|
||||
import math as _math
|
||||
total_plates_needed = _math.ceil((job['order_qty'] or 1) / max(1, job['pieces_per_plate'] or 1))
|
||||
_s = get_settings()
|
||||
ha_poll_interval = int(_s.get('ha_poll_interval', 60))
|
||||
return render_template('job_detail.html', job=job, slots=slots,
|
||||
total_plates_needed=total_plates_needed)
|
||||
total_plates_needed=total_plates_needed,
|
||||
ha_poll_interval=ha_poll_interval)
|
||||
|
||||
@app.route('/jobs/<int:id>/delete', methods=['POST'])
|
||||
def delete_job(id):
|
||||
@@ -1716,7 +1720,8 @@ def _check_capacity(conn, start_dt, end_dt, max_printers, exclude_id=None):
|
||||
"""
|
||||
q = """SELECT planned_start, planned_end FROM print_slots
|
||||
WHERE status NOT IN ('cancelled','failed','done')
|
||||
AND planned_start < ? AND planned_end > ?"""
|
||||
AND planned_start < ? AND planned_end > ?
|
||||
AND planned_end > datetime('now')"""
|
||||
params = [end_dt.isoformat(), start_dt.isoformat()]
|
||||
if exclude_id:
|
||||
q += ' AND id != ?'
|
||||
@@ -1752,7 +1757,8 @@ def _check_overlap(conn, printer_id, start_dt, end_dt, exclude_id=None):
|
||||
FROM print_slots ps JOIN jobs j ON ps.job_id=j.id
|
||||
WHERE ps.printer_id=?
|
||||
AND ps.status NOT IN ('cancelled','failed','done')
|
||||
AND ps.planned_start < ? AND ps.planned_end > ?"""
|
||||
AND ps.planned_start < ? AND ps.planned_end > ?
|
||||
AND ps.planned_end > datetime('now')"""
|
||||
params = [printer_id, end_dt.isoformat(), start_dt.isoformat()]
|
||||
if exclude_id:
|
||||
q += ' AND ps.id != ?'
|
||||
@@ -2063,7 +2069,14 @@ def _start_ha_poll():
|
||||
time.sleep(10)
|
||||
while True:
|
||||
_ha_sync_once()
|
||||
time.sleep(120)
|
||||
try:
|
||||
_c = sqlite3.connect(DATABASE, timeout=5)
|
||||
_c.row_factory = sqlite3.Row
|
||||
_interval = int(_c.execute("SELECT value FROM settings WHERE key='ha_poll_interval'").fetchone()['value'])
|
||||
_c.close()
|
||||
except Exception:
|
||||
_interval = 60
|
||||
time.sleep(max(10, _interval))
|
||||
t = threading.Thread(target=_loop, daemon=True, name='ha-poll')
|
||||
t.start()
|
||||
|
||||
|
||||
@@ -14,9 +14,15 @@
|
||||
<div class="card-header py-3">Ajouter une exception</div>
|
||||
<div class="card-body">
|
||||
<form method="POST">
|
||||
<div class="mb-3">
|
||||
<label class="form-label fw-semibold">Date</label>
|
||||
<input type="date" name="date" class="form-control" required>
|
||||
<div class="row g-2 mb-3">
|
||||
<div class="col">
|
||||
<label class="form-label fw-semibold">Date de début</label>
|
||||
<input type="date" name="date_start" id="dateStart" class="form-control" required>
|
||||
</div>
|
||||
<div class="col">
|
||||
<label class="form-label fw-semibold">Date de fin <span class="text-muted fw-normal small">(optionnel)</span></label>
|
||||
<input type="date" name="date_end" id="dateEnd" class="form-control">
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label fw-semibold">Type</label>
|
||||
@@ -55,12 +61,17 @@
|
||||
{% if blocks %}
|
||||
<table class="table table-hover mb-0">
|
||||
<thead class="table-light">
|
||||
<tr><th>Date</th><th>Type</th><th>Machine</th><th>Note</th><th></th></tr>
|
||||
<tr><th>Période</th><th>Type</th><th>Machine</th><th>Note</th><th></th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for b in blocks %}
|
||||
<tr>
|
||||
<td class="fw-semibold">{{ b.date }}</td>
|
||||
<td class="fw-semibold" style="white-space:nowrap">
|
||||
{{ b.date }}
|
||||
{% if b.date_end and b.date_end != b.date %}
|
||||
<span class="text-muted fw-normal">→</span> {{ b.date_end }}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if b.type == 'off' %}<span class="badge bg-danger">Off</span>
|
||||
{% elif b.type == 'tt' %}<span class="badge bg-primary">TT</span>
|
||||
@@ -89,3 +100,14 @@
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
const dateStart = document.getElementById('dateStart');
|
||||
const dateEnd = document.getElementById('dateEnd');
|
||||
dateStart.addEventListener('change', () => {
|
||||
dateEnd.min = dateStart.value;
|
||||
if (dateEnd.value && dateEnd.value < dateStart.value) dateEnd.value = dateStart.value;
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
@@ -385,6 +385,129 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ── Plateaux d'impression ────────────────────────────────────────────── -->
|
||||
{% set plates_done = slots | selectattr('status','in',['done']) | list | length %}
|
||||
{% set plates_running = slots | selectattr('status','equalto','running') | list | length %}
|
||||
{% set plates_planned = slots | selectattr('status','in',['planned','running']) | list | length %}
|
||||
{% set plates_total = slots | rejectattr('status','in',['cancelled']) | list | length %}
|
||||
{% set missing_plates = [total_plates_needed - plates_total, 0] | max %}
|
||||
|
||||
<div class="row g-4 mt-0">
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
<div class="card-header py-3 d-flex justify-content-between align-items-center flex-wrap gap-2">
|
||||
<span><i class="bi bi-layers-half me-2"></i>Plateaux d'impression</span>
|
||||
<div class="d-flex align-items-center gap-2 flex-wrap">
|
||||
{% if total_plates_needed > 1 %}
|
||||
<span class="badge rounded-pill
|
||||
{% if plates_done >= total_plates_needed %}bg-success
|
||||
{% elif missing_plates > 0 %}bg-warning text-dark
|
||||
{% else %}bg-primary{% endif %}"
|
||||
style="font-size:.8rem">
|
||||
{{ plates_done }}/{{ total_plates_needed }} terminé{{ 's' if plates_done > 1 else '' }}
|
||||
</span>
|
||||
{% endif %}
|
||||
{% if missing_plates > 0 %}
|
||||
<span class="badge bg-warning text-dark" style="font-size:.75rem">
|
||||
<i class="bi bi-exclamation-triangle-fill me-1"></i>{{ missing_plates }} plateau{{ 'x' if missing_plates > 1 else '' }} à planifier
|
||||
</span>
|
||||
{% endif %}
|
||||
<a href="{{ url_for('planning') }}" class="btn btn-sm btn-outline-primary py-0">
|
||||
<i class="bi bi-calendar-plus me-1"></i>Planning
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if slots %}
|
||||
<div class="card-body p-0">
|
||||
<table class="table table-sm table-hover mb-0">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th class="small ps-3">#</th>
|
||||
<th class="small">Début</th>
|
||||
<th class="small">Machine</th>
|
||||
<th class="small">Pièces</th>
|
||||
<th class="small">Statut / Progression</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for s in slots %}
|
||||
{% if s.status != 'cancelled' %}
|
||||
<tr id="slotRow{{ s.id }}">
|
||||
<td class="ps-3 text-muted small">{{ loop.index }}</td>
|
||||
<td class="small" style="white-space:nowrap">{{ s.planned_start[:16].replace('T',' ') }}</td>
|
||||
<td class="small fw-semibold">{{ s.printer_name }}</td>
|
||||
<td class="small">
|
||||
{% set ep = s.effective_pieces %}
|
||||
{% set ig = s.pieces_ignored %}
|
||||
{% if ig > 0 %}
|
||||
<span class="text-warning fw-semibold">{{ ep - ig }}/{{ ep }}</span>
|
||||
<span class="text-muted" style="font-size:.7rem"> ({{ ig }} ignorée{{ 's' if ig > 1 }})</span>
|
||||
{% else %}{{ ep }}{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% set sc = {'planned':'secondary','running':'primary','done':'success','failed':'danger'} %}
|
||||
{% set sl = {'planned':'Planifié','running':'En cours','done':'Terminé','failed':'Échec'} %}
|
||||
<span class="badge bg-{{ sc.get(s.status,'secondary') }}">{{ sl.get(s.status, s.status) }}</span>
|
||||
{% if s.status == 'running' and s.ha_entity_prefix %}
|
||||
<span id="haLive{{ s.id }}" class="ms-2 small text-muted">
|
||||
<span class="spinner-border spinner-border-sm"></span>
|
||||
</span>
|
||||
{% endif %}
|
||||
{% if s.failure_note %}<br><span class="text-muted" style="font-size:.72rem">{{ s.failure_note }}</span>{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% if s.status == 'running' and s.ha_entity_prefix %}
|
||||
<tr id="haBar{{ s.id }}" class="table-primary">
|
||||
<td colspan="5" class="px-3 py-1">
|
||||
<div class="progress" style="height:6px;border-radius:3px">
|
||||
<div id="haBarInner{{ s.id }}" class="progress-bar bg-primary" style="width:0%"></div>
|
||||
</div>
|
||||
<div id="haBarInfo{{ s.id }}" class="text-muted mt-1" style="font-size:.72rem"></div>
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="card-body text-center text-muted py-4 small">
|
||||
<i class="bi bi-calendar-x fs-3 d-block mb-2"></i>Aucun créneau planifié.
|
||||
<br><a href="{{ url_for('planning') }}" class="btn btn-sm btn-outline-primary mt-2">
|
||||
<i class="bi bi-calendar-plus me-1"></i>Aller au planning
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if total_plates_needed > 1 %}
|
||||
<div class="card-footer py-2 px-3" style="background:#fafafa;border-top:1px solid #f0f0f0">
|
||||
{% set pct = ((plates_done / total_plates_needed) * 100) | round(0) | int %}
|
||||
<div class="d-flex justify-content-between align-items-center mb-1">
|
||||
<small class="text-muted">Progression commande</small>
|
||||
<small class="fw-semibold">{{ pct }}%</small>
|
||||
</div>
|
||||
<div class="progress" style="height:8px;border-radius:4px">
|
||||
<div class="progress-bar bg-success" style="width:{{ pct }}%"></div>
|
||||
{% if plates_running > 0 %}
|
||||
<div class="progress-bar bg-primary progress-bar-striped progress-bar-animated"
|
||||
style="width:{{ ((plates_running / total_plates_needed) * 100) | round(0) | int }}%"></div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="mt-1 d-flex gap-3" style="font-size:.72rem;color:#6b7280">
|
||||
<span><i class="bi bi-check-circle-fill text-success me-1"></i>{{ plates_done }} terminé{{ 's' if plates_done > 1 }}</span>
|
||||
{% if plates_running %}<span><i class="bi bi-arrow-repeat text-primary me-1"></i>{{ plates_running }} en cours</span>{% endif %}
|
||||
{% set plates_sched = plates_planned - plates_running %}
|
||||
{% if plates_sched %}<span><i class="bi bi-clock text-secondary me-1"></i>{{ plates_sched }} planifié{{ 's' if plates_sched > 1 }}</span>{% endif %}
|
||||
{% if missing_plates %}<span class="text-warning"><i class="bi bi-exclamation-triangle-fill me-1"></i>{{ missing_plates }} manquant{{ 's' if missing_plates > 1 }}</span>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ── Modale viewer 3D ──────────────────────────────────────────────────── -->
|
||||
<div class="modal fade" id="viewerModal" tabindex="-1">
|
||||
<div class="modal-dialog modal-xl modal-dialog-centered">
|
||||
@@ -456,6 +579,42 @@
|
||||
</script>
|
||||
{% endif %}
|
||||
|
||||
<!-- ── Live HA status for running slots ──────────────────────────────────── -->
|
||||
{% set running_slots = slots | selectattr('status','equalto','running') | selectattr('ha_entity_prefix') | list %}
|
||||
{% if running_slots %}
|
||||
<script>
|
||||
(async function pollHA() {
|
||||
const HA_POLL_MS = {{ ha_poll_interval * 1000 }};
|
||||
const runningPrinters = {
|
||||
{% for s in running_slots %}
|
||||
"{{ s.printer_id }}": { slotId: {{ s.id }}, prefix: "{{ s.ha_entity_prefix }}" },
|
||||
{% endfor %}
|
||||
};
|
||||
async function refresh() {
|
||||
try {
|
||||
const data = await fetch('/api/ha/status').then(r => r.json());
|
||||
for (const [printerId, info] of Object.entries(runningPrinters)) {
|
||||
const p = data[printerId];
|
||||
if (!p) continue;
|
||||
const liveEl = document.getElementById('haLive' + info.slotId);
|
||||
const barEl = document.getElementById('haBarInner' + info.slotId);
|
||||
const barInfo = document.getElementById('haBarInfo' + info.slotId);
|
||||
if (!liveEl) continue;
|
||||
const pct = p.progress || 0;
|
||||
const layer = p.layer && p.layers_total ? `Couche ${p.layer}/${p.layers_total}` : '';
|
||||
const fin = p.heure_fin ? `Fin ≈ ${p.heure_fin.slice(11,16)}` : '';
|
||||
liveEl.innerHTML = `<strong>${pct}%</strong>${layer ? ' · ' + layer : ''}${fin ? ' · ' + fin : ''}`;
|
||||
if (barEl) barEl.style.width = pct + '%';
|
||||
if (barInfo) barInfo.textContent = [layer, fin].filter(Boolean).join(' · ');
|
||||
}
|
||||
} catch(e) {}
|
||||
setTimeout(refresh, HA_POLL_MS);
|
||||
}
|
||||
refresh();
|
||||
})();
|
||||
</script>
|
||||
{% endif %}
|
||||
|
||||
<!-- JSZip pour parser les 3MF Bambu Studio -->
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
|
||||
<script type="importmap">
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
</button>
|
||||
<span id="parseStatus" class="text-muted small"></span>
|
||||
</div>
|
||||
<div class="form-text mt-1">Choisissez un fichier local <strong>.3mf</strong> ou parcourez Nextcloud — poids et durée seront remplis automatiquement, et le fichier source sera défini.</div>
|
||||
<div class="form-text mt-1">Choisissez un fichier <strong>.3mf</strong> local ou depuis Nextcloud — poids et durée seront remplis automatiquement. <strong class="text-warning"><i class="bi bi-exclamation-triangle-fill me-1"></i>Le fichier doit être un <code>gcode.3mf</code> (exporté depuis Bambu Studio après slicing), pas un simple <code>.3mf</code> de conception.</strong></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -220,6 +220,8 @@
|
||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis.min.css" rel="stylesheet">
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis.min.js"></script>
|
||||
<script>
|
||||
const HA_POLL_MS = {{ (settings.get('ha_poll_interval', '60') | int) * 1000 }};
|
||||
|
||||
const STATUS_COLORS = {
|
||||
planned: '#3b82f6',
|
||||
printing: '#f59e0b',
|
||||
@@ -709,7 +711,7 @@ async function refreshHaStatus() {
|
||||
}
|
||||
}
|
||||
refreshHaStatus();
|
||||
setInterval(refreshHaStatus, 30000);
|
||||
setInterval(refreshHaStatus, HA_POLL_MS);
|
||||
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
+20
-9
@@ -259,15 +259,26 @@
|
||||
value="{{ settings.get('ha_token','') }}">
|
||||
<div class="form-text">Profil HA → Sécurité → Jetons d'accès longue durée.</div>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary" id="testHaBtn">
|
||||
<i class="bi bi-plug me-1"></i>Tester la connexion HA
|
||||
</button>
|
||||
<span id="testHaResult" class="ms-3 small"></span>
|
||||
<div class="form-text mt-1">
|
||||
<i class="bi bi-info-circle me-1"></i>
|
||||
Configurez ensuite le <strong>Préfixe entité HA</strong> pour chaque imprimante (ex : <code>patabambulab01</code>) dans la page <a href="{{ url_for('printers_page') }}">Imprimantes</a>.
|
||||
Le planning se synchronise alors automatiquement toutes les 2 min.
|
||||
<div class="col-md-4">
|
||||
<label class="form-label fw-semibold">Intervalle de synchro</label>
|
||||
<div class="input-group">
|
||||
<input type="number" name="ha_poll_interval" class="form-control"
|
||||
min="10" max="3600" step="5"
|
||||
value="{{ settings.get('ha_poll_interval','60') }}">
|
||||
<span class="input-group-text">secondes</span>
|
||||
</div>
|
||||
<div class="form-text">Min 10 s. Recommandé : 60 s pour ne pas surcharger HA.</div>
|
||||
</div>
|
||||
<div class="col-md-8 d-flex align-items-end">
|
||||
<div>
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary" id="testHaBtn">
|
||||
<i class="bi bi-plug me-1"></i>Tester la connexion HA
|
||||
</button>
|
||||
<span id="testHaResult" class="ms-3 small"></span>
|
||||
<div class="form-text mt-1">
|
||||
<i class="bi bi-info-circle me-1"></i>
|
||||
Configurez ensuite le <strong>Préfixe entité HA</strong> pour chaque imprimante dans la page <a href="{{ url_for('printers_page') }}">Imprimantes</a>.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user