A website for producing interactive charts without writing a single line of code. Built with Common Lisp and Python. https://charts.craigoates.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

52 lines
1.8 KiB

(defpackage #:convert
(:use #:cl
#:app-constants)
(:export #:bool-to-checkbox
#:checkbox-to-bool
#:dimension-to-clean-string
#:universal-time-to-prefix))
(in-package #:convert)
(defun bool-to-checkbox (value)
"Converts `VALUE' so it can populate an HTML checkbox.
It is assumed you are converting a SQLite version of a Boolean so
either 1 (true) or 0 (false). If you need a traditional Boolean value,
DO NOT USE THIS FUNCTION."
(cond ((= value 0) "off")
((null value) "off")
(t "on")))
(defun checkbox-to-bool (value)
"Converts a HTML Checkbox `VALUE' to a Boolean.
The `VALUE' will either be 'on' or 'off'. 'Boolean' in this instance
is assuming you are using SQLite and need to convert `VALUE' to an
integer/number. If you are needing a traditional Boolean value, DO NOT USE
THIS FUNCTION."
(cond ((string= "on" value) +true+)
((string= "off" value) +false+)
((null value) +false+)))
(defun dimension-to-clean-string (dimension)
"Takes a string like '148.0d0' and changes to '148.00'.
This funciton is needed because of how the dimensions in the /art
section are rendered in the /art/edit.html template. The djula
template renders the dimensions as strings but the database stores
them as numbers. This means they are capable of possessing letters in
them -- like '148.0d0' -- which breaks when these values come into
contact with mito."
(if (not (null dimension))
(format nil "~,2F" dimension)
(format nil "")))
(defun universal-time-to-prefix ()
"Converts an encoded universal time to something a human can make sense of."
(multiple-value-bind
(second minute hour day month year)
(get-decoded-time)
(format nil "~d~2,'0d~d_~2,'0d~2,'0d~2,'0d"
year
month
day
hour
minute
second)))