Closed EvanKirshenbaum closed 8 months ago
This issue was referenced by the following commits before migration:
Okay, this all seems to be working. It's a bit clunkier than I would like on the Python end, because it turns out that I can't simply create a Sample[T]
because there are actually three types involved:
_ItemT
), which is the type of the items added to the sample and the values returned by first
, last
, min_val
and max_val
._DiffT
), returned by range
, and std_dev
.
_ItemT
for Sample[TemperaturePoint]
, where _DiffT
is Temperature
and for Sample[Timestamp]
, where _DiffT
is Time
._ContT
), returned by mean
, median
, harmonic_mean
, and geometric_mean
.
_ItemT
for Sample[int]
where _ContT
is float
.
So what I wound up with is Sample[_ItemT, _DiffT, _ContT]
, with subclasses IntSample
, FloatSample
, QuantitySample
, TimestampSample
, and TemperaturePointSample
. To create samples, you can (and should) say, e.g.,
s = Sample.for_type(int, (1, 5, 7))
The overloads will tell you that what you get back will be an IntSample
and that, therefore, the mean
will be a float
.
On the DML side, samples are referred to as, e.g., temperature sample
, voltage sample
, or float sample
. To create them, you can say
s1 = an empty int sample;
s2 = a sample containing 3, 6, and 8.5;
(s2
will be inferred to be float sample
.) For the containing
expression, the and
is optional, but if it's there and there are more than two elements, the Oxford comma is mandatory. (I couldn't figure out a way to get the grammar to not consider a, b and c
to be a two element list where the last element is b and c
, which requires to booleans.)
An int sample
automatically converts to an int
by taking the mean. Samples have the following attributes: count
, first
(first value
), last
(last value
), min
(minimum
, min value
, minimum value
), max
(maximum
, max value
, maximum value
), range
, mean
(arithmetic mean
), median
, std dev
(standard dev
, std deviation
, standard deviation
), harmonic mean
, and geometric mean
.
You can add elements to a sample by
add(s, e)
s : add(e)
While working on sensor support (#264), I'm realizing that it would be nice to be able to actually do something with the results in DML.
At the moment, you can say
and it writes to a CSV file, but you can't actually do anything with the readings. The operation just returns the number of readings taken.
What I'm thinking of doing is to say that what it returns is a
Readings
(subclassed by sensor, e.g.,ESELogReadings
) and that each of the attributes of this object is aT sample
, which itself has attributes such asmean
,min
,max
,count
,variance
,std dev
,median
,first
,last
. Other properties:T sample
can be implicitly converted to aT
by taking the mean.maybe
value.T sample
bys : add(t)
.sampleable_param_type
out frombase_param_type
, so I don't try to take the mean of a bunch of pads or bools.quantity_param_type
andcomponent_param_type
andnumeric_param_type
.Migrated from internal repository. Originally created by @EvanKirshenbaum on May 31, 2023 at 4:20 PM PDT. Closed on Jun 22, 2023 at 2:58 PM PDT.