branch: main
commit c263b657908a46aa79d153f26da626afc23e081b
Author: Ludovic Courtès <[email protected]>
AuthorDate: Sun Jan 5 17:27:12 2025 +0100
metrics: Add #:timestamp? to ‘db-get-metrics-with-id’.
* src/cuirass/metrics.scm (db-get-metrics-with-id): Add #:timestamp? and
honor it.
---
src/cuirass/metrics.scm | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/src/cuirass/metrics.scm b/src/cuirass/metrics.scm
index e4c6cf5..28bf128 100644
--- a/src/cuirass/metrics.scm
+++ b/src/cuirass/metrics.scm
@@ -378,28 +378,34 @@ DELETE FROM Metrics WHERE type =" index " AND field = "
name ";")))
(define* (db-get-metrics-with-id id
#:key
+ timestamp?
limit
(order "id DESC"))
- "Return the metrics with the given ID. If LIMIT is set, the resulting list
-if restricted to LIMIT records."
+ "Return the metrics with the given ID as a key/value alist or, when
+TIMESTAMP? is true, as a list of timestamp/key/value tuples. If LIMIT is set,
+the resulting list is restricted to LIMIT records."
(with-db-connection db
(let* ((metric (find-metric id))
(type (metric->type metric))
(field-type (metric-field-type metric))
(limit (or limit "ALL")))
- (let ((query (format #f "SELECT field, value from Metrics
+ (let ((query (format #f "SELECT field, value, timestamp FROM Metrics
WHERE type = :type ORDER BY ~a LIMIT ~a" order limit))
(params `((#:type . ,type))))
(let loop ((rows (exec-query/bind-params db query params))
(metrics '()))
(match rows
(() (reverse metrics))
- (((field value) . rest)
+ (((field value timestamp) . rest)
(let ((field (match field-type
('int (string->number field))
(else field))))
(loop rest
- `((,field . ,(locale-string->inexact value))
+ `(,(if timestamp?
+ `(,(string->number timestamp)
+ ,field
+ ,(locale-string->inexact value))
+ `(,field . ,(locale-string->inexact value)))
,@metrics))))))))))
(define* (db-update-metric id #:optional field