MIDAS entity coercion: raw API responses → idiomatic Clojure maps.
Two-layer data model: Raw layer — direct JSON→EDN, PascalCase keys, string values Coerced layer — namespaced keywords, native types (java.time, BigDecimal)
All coerced entities carry the original raw data as :midas/raw metadata.
MIDAS entity coercion: raw API responses → idiomatic Clojure maps. Two-layer data model: Raw layer — direct JSON→EDN, PascalCase keys, string values Coerced layer — namespaced keywords, native types (java.time, BigDecimal) All coerced entities carry the original raw data as :midas/raw metadata.
(->holiday raw)Coerce a raw HolidayEntry.
Raw shape: {:EnergyCode "PG" :EnergyDescription "Pacific Gas and Electric" :DateOfHoliday "2023-12-25T00:00:00" :HolidayDescription "Christmas 2023"}
Coerced shape: {:midas.holiday/energy-code "PG" :midas.holiday/energy-name "Pacific Gas and Electric" :midas.holiday/date #local-date 2023-12-25 :midas.holiday/description "Christmas 2023"}
Coerce a raw HolidayEntry.
Raw shape:
{:EnergyCode "PG" :EnergyDescription "Pacific Gas and Electric"
:DateOfHoliday "2023-12-25T00:00:00" :HolidayDescription "Christmas 2023"}
Coerced shape:
{:midas.holiday/energy-code "PG"
:midas.holiday/energy-name "Pacific Gas and Electric"
:midas.holiday/date #local-date 2023-12-25
:midas.holiday/description "Christmas 2023"}(->lookup-entry raw)Coerce a raw LookupEntry.
Raw shape: {:UploadCode "PG" :Description "Pacific Gas and Electric"}
Coerced shape: {:midas.lookup/code "PG" :midas.lookup/description "Pacific Gas and Electric"}
Coerce a raw LookupEntry.
Raw shape:
{:UploadCode "PG" :Description "Pacific Gas and Electric"}
Coerced shape:
{:midas.lookup/code "PG"
:midas.lookup/description "Pacific Gas and Electric"}(->rate-info raw)Coerce a raw RateInfo response to an idiomatic Clojure map.
Raw shape: {:RateID "USCA-TSTS-TTOU-TEST" :RateName "CEC TEST24HTOU" :ValueInformation [...] ...}
Coerced shape: {:midas.rate/id "USCA-TSTS-TTOU-TEST" :midas.rate/name "CEC TEST24HTOU" :midas.rate/values [<ValueData> ...] ...}
Coerce a raw RateInfo response to an idiomatic Clojure map.
Raw shape:
{:RateID "USCA-TSTS-TTOU-TEST" :RateName "CEC TEST24HTOU"
:ValueInformation [...] ...}
Coerced shape:
{:midas.rate/id "USCA-TSTS-TTOU-TEST"
:midas.rate/name "CEC TEST24HTOU"
:midas.rate/values [<ValueData> ...]
...}(->rin-list-entry raw)Coerce a raw RIN list entry.
Raw shape: {:RateID "USCA-TSTS-TTOU-TEST" :SignalType "Rates" :Description "..." :LastUpdated "2023-06-07T15:57:48.023"}
Coerced shape: {:midas.rin/id "USCA-TSTS-TTOU-TEST" :midas.rin/signal-type :midas.signal-type/rates :midas.rin/description "..." :midas.rin/last-updated #inst ...}
Coerce a raw RIN list entry.
Raw shape:
{:RateID "USCA-TSTS-TTOU-TEST" :SignalType "Rates"
:Description "..." :LastUpdated "2023-06-07T15:57:48.023"}
Coerced shape:
{:midas.rin/id "USCA-TSTS-TTOU-TEST"
:midas.rin/signal-type :midas.signal-type/rates
:midas.rin/description "..."
:midas.rin/last-updated #inst ...}(->value-data raw)Coerce a raw ValueData interval to an idiomatic Clojure map.
Raw shape: {:ValueName "winter off peak" :DateStart "2023-05-01" ...}
Coerced shape: {:midas.value/name "winter off peak" :midas.value/date-start #local-date ... :midas.value/price 0.1006M :tick/beginning #local-date-time ... :tick/end #local-date-time ... ...}
When both date and time are present for a boundary, the map also carries :tick/beginning and :tick/end keys (LocalDateTime), making it directly usable as a tick interval.
Coerce a raw ValueData interval to an idiomatic Clojure map.
Raw shape:
{:ValueName "winter off peak" :DateStart "2023-05-01" ...}
Coerced shape:
{:midas.value/name "winter off peak"
:midas.value/date-start #local-date ...
:midas.value/price 0.1006M
:tick/beginning #local-date-time ...
:tick/end #local-date-time ...
...}
When both date and time are present for a boundary, the map also carries
:tick/beginning and :tick/end keys (LocalDateTime), making it directly
usable as a tick interval.(annotate-rin parsed-rin lookup-tables)Add human-readable labels to a parsed RIN map.
lookup-tables is a map of lookup table name to a sequence of coerced
LookupEntry maps (as returned by (entities/lookup-table response)).
Recognized keys: "Distribution" and "Energy".
Example: (annotate-rin (parse-rin "USCA-PGPG-TOU4-0000") {"Distribution" dist-entries "Energy" energy-entries}) ;=> {:midas.rin/country "US" ; :midas.rin/state "CA" ; :midas.rin/distribution "PG" ; :midas.rin/distribution-name "Pacific Gas and Electric" ; :midas.rin/energy "PG" ; :midas.rin/energy-name "Pacific Gas and Electric" ; :midas.rin/rate "TOU4" ; :midas.rin/location "0000"}
Add human-readable labels to a parsed RIN map.
lookup-tables is a map of lookup table name to a sequence of coerced
LookupEntry maps (as returned by `(entities/lookup-table response)`).
Recognized keys: "Distribution" and "Energy".
Example:
(annotate-rin (parse-rin "USCA-PGPG-TOU4-0000")
{"Distribution" dist-entries
"Energy" energy-entries})
;=> {:midas.rin/country "US"
; :midas.rin/state "CA"
; :midas.rin/distribution "PG"
; :midas.rin/distribution-name "Pacific Gas and Electric"
; :midas.rin/energy "PG"
; :midas.rin/energy-name "Pacific Gas and Electric"
; :midas.rin/rate "TOU4"
; :midas.rin/location "0000"}(flex-alert-active? rate)True if the Flex Alert rate-info indicates an active alert. Active when any value interval has a non-zero value.
True if the Flex Alert rate-info indicates an active alert. Active when any value interval has a non-zero value.
(flex-alert? rate)True if rate-info represents a Flex Alert signal.
True if rate-info represents a Flex Alert signal.
(ghg? rate)True if rate-info represents a GHG (greenhouse gas emissions) signal.
True if rate-info represents a GHG (greenhouse gas emissions) signal.
(historical-data response)Extract and coerce historical rate data from a get-historical-data response.
Extract and coerce historical rate data from a get-historical-data response.
(historical-list response)Extract and coerce historical RIN list from a get-historical-list response. Deduplicates by RIN ID (the live API returns duplicates).
Extract and coerce historical RIN list from a get-historical-list response. Deduplicates by RIN ID (the live API returns duplicates).
(holidays response)Extract and coerce holidays from a get-holidays response.
Extract and coerce holidays from a get-holidays response.
(lookup-table response)Extract and coerce lookup table entries from a get-lookup-table response.
Extract and coerce lookup table entries from a get-lookup-table response.
(parse-rin rin)Parse a RIN string into its component fields.
Example: (parse-rin "USCA-PGPG-TOU4-0000") ;=> {:midas.rin/country "US" ; :midas.rin/state "CA" ; :midas.rin/distribution "PG" ; :midas.rin/energy "PG" ; :midas.rin/rate "TOU4" ; :midas.rin/location "0000"}
Returns nil if the string does not match the RIN format.
Parse a RIN string into its component fields.
Example:
(parse-rin "USCA-PGPG-TOU4-0000")
;=> {:midas.rin/country "US"
; :midas.rin/state "CA"
; :midas.rin/distribution "PG"
; :midas.rin/energy "PG"
; :midas.rin/rate "TOU4"
; :midas.rin/location "0000"}
Returns nil if the string does not match the RIN format.(rate-info response)Extract and coerce rate info from a get-rate-values response.
Extract and coerce rate info from a get-rate-values response.
(rin-list response)Extract and coerce RIN list entries from a get-rin-list response.
Extract and coerce RIN list entries from a get-rin-list response.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |