2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
|
(begin
(for-each
(lambda (fieldname) ;; fields
(let ((all-dat-qrystr (conc "SELECT " timef "," varfn "," valfn " FROM " tablen " WHERE " varfn "='" fieldname "' AND " timef " >= " tstart " AND " timef " <= " tend " ORDER BY " timef " ASC"))
(zeroth-point (conc "SELECT " timef "," varfn "," valfn " FROM " tablen " WHERE " varfn "='" fieldname "' AND " timef " < " tstart " LIMIT 1")))
(print "all-dat-qrystr: " all-dat-qrystr)
(hash-table-set! res-ht fieldname ;; (fetch-rows (sql db qrystr)))))
(sqlite3:fold-row
(lambda (res t var val)
(cons (vector t var val) res))
'() db all-dat-qrystr))
(let ((zeropt (handle-exceptions
exn
#f
(sqlite3:first-row db all-dat-qrystr))))
(if zeropt
(hash-table-set! res-ht
fieldname
(cons
(apply vector tstart (cdr zeropt))
(hash-table-ref/default res-ht fieldname '())))))))
fields)
res-ht)
#f)))))
;; graph data
;; tsc=timescale, tfn=function; time->x
;;
(define (dboard:graph commondat tabdat tabnum llx lly ulx uly tstart tend tsc tfn compname cmargin)
(let* ((dwg (dboard:tabdat-drawing tabdat))
(lib (vg:get/create-lib dwg "runslib"))
(cnv (dboard:tabdat-cnv tabdat))
(dur (- tstart tend)) ;; time duration
(cmp (vg:get-component dwg "runslib" compname))
(cfg (configf:get-section *configdat* "graph"))
(stdcolor (vg:rgb->number 20 30 40)))
(vg:add-obj-to-comp
cmp
(vg:make-rect-obj llx lly ulx uly))
(for-each
(lambda (cf)
(let* ((alldat (dboard:graph-read-data (cadr cf) tstart tend)))
(if alldat
(for-each
(lambda (fieldn)
(let* ((dat (hash-table-ref alldat fieldn ))
(vals (map (lambda (x)(vector-ref x 2)) dat)))
(if (not (null? vals))
(let* ((maxval (apply max vals))
(minval (apply min vals))
(yoff (- lly minval))
(yscale (/ (- maxval minval)(- uly lly)))
(yfunc (lambda (y)(* (+ y yoff) yscale))))
;; (print (car cf) ": " (hash-table->alist
(for-each
(lambda (dpt)
(let* ((tval (vector-ref dpt 0))
(yval (vector-ref dpt 2))
(stval (tfn tval))
(syval (yfunc yval)))
(vg:add-obj-to-comp
cmp
(vg:make-rect-obj (- stval 2) lly (+ stval 2)(+ lly (* yval yscale))
fill-color: stdcolor))))
dat))))) ;; for each data point in the series
(hash-table-keys alldat)))))
cfg)))
;; run times tab
;;
(define (dashboard:run-times-tab-layout-updater commondat tabdat tab-num)
|
>
|
|
|
|
|
|
|
|
|
|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
|
|
|
>
|
|
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
|
(begin
(for-each
(lambda (fieldname) ;; fields
(let ((all-dat-qrystr (conc "SELECT " timef "," varfn "," valfn " FROM " tablen " WHERE " varfn "='" fieldname "' AND " timef " >= " tstart " AND " timef " <= " tend " ORDER BY " timef " ASC"))
(zeroth-point (conc "SELECT " timef "," varfn "," valfn " FROM " tablen " WHERE " varfn "='" fieldname "' AND " timef " < " tstart " LIMIT 1")))
(print "all-dat-qrystr: " all-dat-qrystr)
(hash-table-set! res-ht fieldname ;; (fetch-rows (sql db qrystr)))))
(reverse
(sqlite3:fold-row
(lambda (res t var val)
(cons (vector t var val) res))
'() db all-dat-qrystr)))
(let ((zeropt (handle-exceptions
exn
#f
(sqlite3:first-row db all-dat-qrystr))))
(if zeropt ;; NOTE: Add zeropt to the beginning of the list as the list was reversed above.
(hash-table-set! res-ht
fieldname
(cons
(apply vector tstart (cdr zeropt))
(hash-table-ref/default res-ht fieldname '())))))))
fields)
res-ht)
#f)))))
;; graph data
;; tsc=timescale, tfn=function; time->x
;;
(define (dboard:graph commondat tabdat tabnum llx lly ulx uly tstart tend tsc tfn compname cmargin)
(let* ((dwg (dboard:tabdat-drawing tabdat))
(lib (vg:get/create-lib dwg "runslib"))
(cnv (dboard:tabdat-cnv tabdat))
(dur (- tstart tend)) ;; time duration
(cmp (vg:get-component dwg "runslib" compname))
(cfg (configf:get-section *configdat* "graph"))
(stdcolor (vg:rgb->number 120 130 140)))
(vg:add-obj-to-comp
cmp
(vg:make-rect-obj llx lly ulx uly))
(for-each
(lambda (cf)
(let* ((alldat (dboard:graph-read-data (cadr cf) tstart tend)))
(if alldat
(for-each
(lambda (fieldn)
(let* ((dat (hash-table-ref alldat fieldn ))
(vals (map (lambda (x)(vector-ref x 2)) dat)))
(if (not (null? vals))
(let* ((maxval (apply max vals))
(minval (apply min vals))
(yoff (- lly minval))
(deltaval (- maxval minval))
(yscale (/ (- uly lly)(if (eq? deltaval 0) 1 deltaval)))
(yfunc (lambda (y)(* (+ y yoff) yscale))))
;; (print (car cf) ": " (hash-table->alist
(fold
(lambda (next prev) ;; #(time ? val) #(time ? val)
(if prev
(let* ((last-tval (tfn (vector-ref prev 0)))
(last-yval (+ lly (* yscale (vector-ref prev 2))))
(curr-tval (tfn (vector-ref next 0))))
(if (> curr-tval last-tval)
(vg:add-obj-to-comp
cmp
(vg:make-rect-obj last-tval lly curr-tval last-yval ;; (- stval 2) lly (+ stval 2)(+ lly (* yval yscale))
fill-color: stdcolor
line-color: stdcolor))
(print "ERROR: curr-tval is not > last-tval; curr-tval " curr-tval ", last-tval " last-tval))))
next)
;; for init create vector tstart,0
#f ;; (vector tstart minval minval)
dat)
;; (for-each
;; (lambda (dpt)
;; (let* ((tval (vector-ref dpt 0))
;; (yval (vector-ref dpt 2))
;; (stval (tfn tval))
;; (syval (yfunc yval)))
;; (vg:add-obj-to-comp
;; cmp
;; (vg:make-rect-obj (- stval 2) lly (+ stval 2)(+ lly (* yval yscale))
;; fill-color: stdcolor))))
;; dat)
)))) ;; for each data point in the series
(hash-table-keys alldat)))))
cfg)))
;; run times tab
;;
(define (dashboard:run-times-tab-layout-updater commondat tabdat tab-num)
|