updated logic to be able to get models based on name OR key

updated web page to pull proper fields for name/value
added example system
updated readme with system definition field explanations
This commit is contained in:
a. fox 2023-07-05 11:41:02 -04:00
parent 1831eeb8bc
commit 877a48b6ad
5 changed files with 31 additions and 9 deletions

View File

@ -13,6 +13,16 @@ and use the web interface to select the conversion targets and see the result.
all css is handwritten and embedded in the page, however if there is a "custom.css" file alongside the
`timecalc` binary, it will be included in the page that gets rendered
## System Definition Explanation
`key`: the internal key that is used for that system. used for command line arguments `--to` and `--from`
`name`: the name of the system. this is mostly used for output, but these can also be used for `--to` and `--from`
`gtsYear`: one year of the target system, converted into a GTS year (seconds)
see `systems/example.system` for an example
## Building
1. Install [roswell](https://github.com/roswell/roswell)

View File

@ -15,16 +15,23 @@
"loads model FILES into memory"
(loop :for f :in files
:do (let ((file-def (jzon:parse f)))
(setf (gethash (string-upcase (gethash "name" file-def)) *models*)
(setf (gethash (string-upcase (gethash "key" file-def)) *models*)
file-def))))
(defun get-model (key-or-name)
(let ((model-key (gethash (string-upcase key-or-name) *models*))
(name-key (loop :for m :being :the :hash-value :of *models*
:when (string= (gethash "name" m "") key-or-name)
:return m)))
(or model-key name-key)))
(defun convert (time from to)
(let ((from-model (gethash (string-upcase from) *models*))
(to-model (gethash (string-upcase to) *models*)))
(let ((from-model (get-model from))
(to-model (get-model to)))
(unless from-model
(error "FROM system doesn't exist in our database"))
(error "FROM system doesn't exist"))
(unless to-model
(error "TO system doesn't exist in our database"))
(error "TO system doesn't exist"))
;; okay so the process to convert from one time to another we need to convert
;; to GTS first and then convert to the target system time
;;

View File

5
systems/example.system Normal file
View File

@ -0,0 +1,5 @@
{
"key": "example",
"name": "Example System",
"gtsYear": 42069
}

View File

@ -55,13 +55,13 @@ input { height: 42px; font-size: 1rem;}
(:br)
(:div :class "convert-container"
(:select :name "from"
(loop :for name :being :the :hash-key :of timecalc-logic::*models*
(loop :for model :being :the :hash-value :of timecalc-logic::*models*
:collect
(markup (:option :value name (string-capitalize name)))))
(markup (:option :value (gethash "key" model) (gethash "name" model)))))
(:p :class "needs-space" "To")
(:select :name "from"
(loop :for name :being :the :hash-key :of timecalc-logic::*models*
(loop :for model :being :the :hash-value :of timecalc-logic::*models*
:collect
(markup (:option :value name (string-capitalize name))))))
(markup (:option :value (gethash "key" model) (gethash "name" model))))))
(:br)
(:input :type "submit" :value "Convert")))))