plot-data.scm 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env guile
  2. !#
  3. (use-modules (charting) (charting csv) (ice-9 match)
  4. ((srfi srfi-1) #:select (filter-map)))
  5. (define (parse-scenario headers data)
  6. (let lp ((in data) (out (make-list (length headers) '())))
  7. (if (null? in)
  8. (map cons
  9. headers
  10. (map (lambda (test-data) (filter-map string->number test-data))
  11. out))
  12. (lp (cdr in) (map cons (vector->list (car in)) out)))))
  13. (define (read-scenario file)
  14. (let ((rows (csv-port->row-list (open-input-file file) #\tab)))
  15. (if (null? rows)
  16. '()
  17. (cons (let ((name (basename file)))
  18. (if (string-suffix? ".csv" name)
  19. (substring name 0 (- (string-length name) 4))
  20. name))
  21. (parse-scenario (vector->list (car rows)) (cdr rows))))))
  22. (define (main args)
  23. (match args
  24. ((title output file file* ...)
  25. (unless (string-suffix? ".png" output)
  26. ;; Otherwise we would have the possibility of overwriting data.
  27. ;; That would be bad!
  28. (format (current-error-port)
  29. "Error: output name does not end with .png: ~a\n" output)
  30. (exit 1))
  31. (make-performance-chart title (map read-scenario (cons file file*))
  32. #:write-to-png output))
  33. (_
  34. (format (current-error-port)
  35. "Usage: plot-data.scm title output file1 file2 ...
  36. The files are expected to be in CSV format, with one row of headers,
  37. and one row per run. The different file names identify the different
  38. scenarios that you want to compare.
  39. ")
  40. (exit 1))))
  41. (main (cdr (command-line)))