Add calibration dates
This commit is contained in:
parent
bd3160643f
commit
ed4a448016
3
app.py
3
app.py
|
|
@ -170,9 +170,8 @@ def validate_calibration():
|
||||||
if calib is None:
|
if calib is None:
|
||||||
return 'oops', 404
|
return 'oops', 404
|
||||||
|
|
||||||
calib.state = db.CalibrationState.IsValidated
|
|
||||||
with conn:
|
with conn:
|
||||||
calib.save(conn)
|
calib.validate(conn)
|
||||||
|
|
||||||
return redirect('/')
|
return redirect('/')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
|
def format_month(month: int) -> str:
|
||||||
|
if month == 1:
|
||||||
|
return 'janvier'
|
||||||
|
elif month == 2:
|
||||||
|
return 'février'
|
||||||
|
elif month == 3:
|
||||||
|
return 'mars'
|
||||||
|
elif month == 4:
|
||||||
|
return 'avril'
|
||||||
|
elif month == 5:
|
||||||
|
return 'mai'
|
||||||
|
elif month == 6:
|
||||||
|
return 'juin'
|
||||||
|
elif month == 7:
|
||||||
|
return 'juillet'
|
||||||
|
elif month == 8:
|
||||||
|
return 'août'
|
||||||
|
elif month == 9:
|
||||||
|
return 'septembre'
|
||||||
|
elif month == 10:
|
||||||
|
return 'octobre'
|
||||||
|
elif month == 11:
|
||||||
|
return 'novembre'
|
||||||
|
elif month == 12:
|
||||||
|
return 'décembre'
|
||||||
|
else:
|
||||||
|
raise RuntimeError(f'No such month: {month}')
|
||||||
|
|
||||||
|
|
||||||
|
def format(date: datetime) -> str:
|
||||||
|
return f'{date.day} {format_month(date.month)} {date.year} à {date.hour:02}h{date.minute:02}'
|
||||||
29
db.py
29
db.py
|
|
@ -10,9 +10,10 @@ import sqlite3
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
if __name__ != '__main__':
|
if __name__ != '__main__':
|
||||||
from . import config
|
from . import config, dateutils
|
||||||
else:
|
else:
|
||||||
import config
|
import config
|
||||||
|
import dateutils
|
||||||
|
|
||||||
|
|
||||||
def get() -> sqlite3.Connection:
|
def get() -> sqlite3.Connection:
|
||||||
|
|
@ -55,17 +56,21 @@ class CalibrationState(IntEnum):
|
||||||
class Calibration:
|
class Calibration:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def select_args() -> str:
|
def select_args() -> str:
|
||||||
return 'id, state'
|
return 'id, state, validated_date'
|
||||||
|
|
||||||
def __init__(self, calibration_id: int, state: int):
|
def __init__(self, calibration_id: int, state: int, validated_date: Optional[int]):
|
||||||
self.id = calibration_id
|
self.id = calibration_id
|
||||||
self.state = CalibrationState(state)
|
self.state = CalibrationState(state)
|
||||||
|
if validated_date is None:
|
||||||
|
self.validated_date = None
|
||||||
|
else:
|
||||||
|
self.validated_date = datetime.fromtimestamp(validated_date)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create(db: sqlite3.Connection) -> 'Calibration':
|
def create(db: sqlite3.Connection) -> 'Calibration':
|
||||||
cur = db.cursor()
|
cur = db.cursor()
|
||||||
response = cur.execute(
|
response = cur.execute(
|
||||||
'INSERT INTO calibration(state) VALUES (?) RETURNING ' + Calibration.select_args() + ';',
|
'INSERT INTO calibration(state, validated_date) VALUES (?, NULL) RETURNING ' + Calibration.select_args() + ';',
|
||||||
[int(CalibrationState.Empty)]
|
[int(CalibrationState.Empty)]
|
||||||
)
|
)
|
||||||
calibration = Calibration.from_row(response.fetchone())
|
calibration = Calibration.from_row(response.fetchone())
|
||||||
|
|
@ -83,8 +88,8 @@ class Calibration:
|
||||||
def save(self, db: sqlite3.Connection):
|
def save(self, db: sqlite3.Connection):
|
||||||
cur = db.cursor()
|
cur = db.cursor()
|
||||||
cur.execute(
|
cur.execute(
|
||||||
'UPDATE calibration SET state = ? WHERE id = ?',
|
'UPDATE calibration SET state = ?, validated_date = ? WHERE id = ?',
|
||||||
[int(self.state), self.id]
|
[int(self.state), int(self.validated_date.timestamp()) if self.validated_date is not None else None, self.id]
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
@ -100,13 +105,21 @@ class Calibration:
|
||||||
def get_last(db: sqlite3.Connection) -> Optional['Calibration']:
|
def get_last(db: sqlite3.Connection) -> Optional['Calibration']:
|
||||||
cur = db.cursor()
|
cur = db.cursor()
|
||||||
response = cur.execute(
|
response = cur.execute(
|
||||||
'SELECT ' + Calibration.select_args() + ' FROM calibration WHERE state = 3 ORDER BY id DESC LIMIT 1;',
|
'SELECT ' + Calibration.select_args() + ' FROM calibration WHERE state = 3 ORDER BY validated_date DESC LIMIT 1;',
|
||||||
[]
|
[]
|
||||||
)
|
)
|
||||||
return Calibration.from_row(response.fetchone())
|
return Calibration.from_row(response.fetchone())
|
||||||
|
|
||||||
|
def validate(self, db: sqlite3.Connection):
|
||||||
|
self.state = CalibrationState.IsValidated
|
||||||
|
self.validated_date = datetime.now()
|
||||||
|
self.save(db)
|
||||||
|
|
||||||
Calibration.Dummy = Calibration(-1, CalibrationState.Empty)
|
def get_pretty_date(self) -> str:
|
||||||
|
return dateutils.format(self.validated_date)
|
||||||
|
|
||||||
|
|
||||||
|
Calibration.Dummy = Calibration(-1, CalibrationState.Empty, None)
|
||||||
|
|
||||||
|
|
||||||
class Acquisition:
|
class Acquisition:
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@ DROP TABLE IF EXISTS object;
|
||||||
|
|
||||||
CREATE TABLE calibration (
|
CREATE TABLE calibration (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
state INTEGER NOT NULL
|
state INTEGER NOT NULL,
|
||||||
|
validated_date INTEGER
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE acquisition (
|
CREATE TABLE acquisition (
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@
|
||||||
<section class="section">
|
<section class="section">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h1 class="title is-2">Visualisation de l'étalonnage {{ calibration.id }}</h1>
|
<h1 class="title is-2">Visualisation de l'étalonnage {{ calibration.id }}</h1>
|
||||||
|
{% if calibration.validated_date %}
|
||||||
|
<h2 class="title is-5 is-italic">Validé le {{ calibration.get_pretty_date() }}</h2>{% endif %}
|
||||||
<div class="columns">
|
<div class="columns">
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<h2 class="title is-3">Positions 3D des LEDs</h2>
|
<h2 class="title is-3">Positions 3D des LEDs</h2>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue