3 ms·
Here is the data into JSON (keeping the values a $ txr json.txr temp.dat {"radeon-pci-0100":{"temp1":{"crit":120,"hyst":90,"value":50.5}}, "f71889ed-is
by kazinator 5y ago
Here is the data into JSON (keeping the values a
$ txr json.txr temp.dat
{"radeon-pci-0100":{"temp1":{"crit":120,"hyst":90,"value":50.5}},
"f71889ed-isa-0480":{"temp2":{"hyst":77,"value":43,"high":85},"alarm":{"fan3":true,"fan2":true},
"sensor":{"crit":100,"name":"thermistor","hyst":92},"max-voltage":{"in1":2.04},
"temp1":{"hyst":81,"value":31,"high":85},"voltage":{"in5":1.23,"+3.3V":3.23,"in6":1.53,"in2":1.09,"Vbat":3.31,"in1":1.07,
"in4":0.58,"3VSB":3.25,"in3":0.89},
"temp3":{"hyst":68,"value":38,"high":70},"rpm":{"fan3":0,"fan1":3978,"fan2":0}},
"k10temp-pci-00c3":{"temp1":{"crit":80,"hyst":78,"value":36.8,"high":70}}}
Using just a straightforward approach of recognizing the cases that occur without trying to formally parse things. There is significant copy and paste between similar cases. I decided to use a post-processing pass on the dictionary to convert the numeric values to floating-point.
@(bind dict @(hash))
@(name file)
@(repeat)
@idstring
Adapter: @adapter
@ (collect :vars (entry))
@ (line line)
@ (assert error `unhandled stuff occurs at @file:@line`)
@ (some)
@{temp /temp\d+/}: @{val}°C (crit = @{crit}°C,
hyst = @{hyst}°C)
@ (bind entry @#J^{~temp : { "value" : ~val,
"crit" : ~crit,
"hyst" : ~hyst }})
@ (or)
@{temp /temp\d+/}: @{val}°C (high = @{high}°C)
(crit = @{crit}°C,
hyst = @{hyst}°C)
@ (bind entry @#J^{~temp : { "value" : ~val,
"crit" : ~crit,
"hyst" : ~hyst,
"high" : ~high }})
@ (or)
@{temp /temp\d+/}: @{val}°C (high = @{high}°C,
hyst = @{hyst}°C)
@ (bind entry @#J^{~temp : { "value" : ~val,
"high" : ~high,
"hyst" : ~hyst }})
@ (or)
(crit = @{crit}°C,
hyst = @{hyst}°C)
sensor = @sensor
@ (bind entry @#J^{"sensor" : { "name" : ~sensor,
"crit" : ~crit,
"hyst" : ~hyst }})
@ (or)
@label: @voltage V
@ (bind entry @#J^{"voltage" : {~label : ~voltage}})
@ (or)
@label: @voltage V (max = @max V)
@ (bind entry @#J^{"voltage" : {~label : ~voltage},
"max-voltage" : {~label : ~max}})
@ (or)
@label: @rpm RPM
@ (bind entry @#J^{"rpm" : {~label : ~rpm}})
@ (or)
@label: @rpm RPM ALARM
@ (bind entry @#J^{"rpm" : {~label : ~rpm},
"alarm" : {~label : true}})
@ (or)
@ (bind entry @#J{})
@ (end)
@ (until)
@ (end)
@ (do (set [dict idstring]
(reduce-left (op hash-uni @1 @2 hash-uni) entry #J{})))
@(end)
@(do
(defun numify (dict)
(dohash (k v dict dict)
(typecase v
(string (iflet ((f (tofloat v)))
(set [dict k] f)))
(hash (numify v)))))
(put-jsonl (numify dict)))