(define-module (bffe view activity) #:use-module (srfi srfi-1) #:use-module (srfi srfi-19) #:use-module (ice-9 match) #:use-module (bffe view util) #:use-module ((guix store) #:select (%store-prefix)) #:export (activity)) (define (activity title state) (define categorised-agents (let ((categories '(("x86_64-linux" "i686-linux") ("aarch64-linux" "armhf-linux") ("powerpc64le-linux") ("riscv64-linux") ("i586-gnu")))) (map (lambda (systems) (cons systems (sort (filter (lambda (agent) (not (null? (lset-intersection string=? (vector->list (assoc-ref agent "requested_systems")) systems)))) (vector->list (assoc-ref state "agents"))) (lambda (a b) (stringlist (assoc-ref agent "builds")))) `(div (@ (class "agent") (id ,(string-append "agent-" (assoc-ref agent "uuid"))) (data-name ,(assoc-ref agent "name"))) ,(let ((last-status-update (assoc-ref agent "last_status_update"))) (if (and last-status-update (and=> (assoc-ref last-status-update "timestamp") (lambda (timestamp) (let ((seconds (time-second (time-difference (current-time time-utc) (date->time-utc (string->date (string-append timestamp "Z") "~Y-~m-~d ~H:~M:~S~z")))))) (< seconds (* 60 5)))))) (let* ((1min (assoc-ref last-status-update "1min_load_average")) (cores (assoc-ref last-status-update "processor_count")) (load-percentage (/ (* 100 1min) cores))) `(span (@ (style "float: right;") (id ,(string-append "agent-" (assoc-ref agent "uuid") "-load")) (class ,(string-append "agent-load " (cond ((< load-percentage 150) "agent-load-normal") ((< load-percentage 250) "agent-load-medium") (else "agent-load-high")))) (data-value ,load-percentage)) "Load: " ,(number->string (round load-percentage)) "%")) `(span (@ (style "float: right;") (id ,(string-append "agent-" (assoc-ref agent "uuid") "-load")) (class "agent-load-unknown")) "Status unknown"))) (span (@ (class "agent-plan-size") (id ,(string-append "agent-" (assoc-ref agent "uuid") "-plan-size")) (data-value ,(assoc-ref (assoc-ref agent "allocation_plan") "count"))) "Plan size: " ,(assoc-ref (assoc-ref agent "allocation_plan") "count")) (a (@ (href ,(string-append "/agent/" (assoc-ref agent "uuid")))) (h4 (@ (style "display: block;")) ,(assoc-ref agent "name"))) (div (@ (class "agent-builds") (id ,(string-append "agent-" (assoc-ref agent "uuid") "-builds"))) ,@(map (lambda (build index) (let ((tags (sort (vector->list (assoc-ref build "tags")) (lambda (a b) (string index 3) " hidden" "")))) (a (@ (href ,(string-append "/build/" (assoc-ref build "uuid"))) (style "display: block;")) (span (@ (class "monospace")) ,(abbreviate-derivation (or (assoc-ref build "derivation_name") (assoc-ref build "derivation-name"))))) ,@(append-map (lambda (tag) `((span (@ (class "build-tag")) ,(assoc-ref tag "key") ": " ,(let ((val (assoc-ref tag "value"))) (if (git-commit-hash-length? val) (string-take val 8) val))) (*ENTITY* nbsp))) tags)))) ;; TODO Sort builds by priority? all-builds (iota (length all-builds)))) (span (@ (id ,(string-append "agent-" (assoc-ref agent "uuid") "-plus-x-builds")) (style ,(string-append (if (> (length all-builds) 4) "display: block;" "display: none;") "margin-top: 10px; text-align: center;"))) ,(let ((additional-builds (- (length all-builds) 4))) (if (= additional-builds 1) (simple-format #f "Plus ~A other build" additional-builds) (simple-format #f "Plus ~A other builds" additional-builds)))) (span (@ (id ,(string-append "agent-" (assoc-ref agent "uuid") "-no-allocated-builds")) (style ,(string-append (if (= 0 (length all-builds)) "display: block;" "display: none;") "margin-top: 10px; text-align: center;"))) "No allocated builds"))) #f)) agents))))) categorised-agents) (script (@ (src "/assets/js/activity.js")))))))