Accumulator "firstlast"

110 views
Skip to first unread message

Karen K

unread,
May 3, 2023, 1:22:29 AM5/3/23
to weewx-user
I am not sure, so I don't want to edit the accumulators wiki page, but I want to ask.

The wiki page says "
  • firstlast. This accumulator accumulates only the first and last entry it has seen, along with their times. It is useful for things like strings, although there is no reason it can't be used for other things."
But if I understand the code right there is a reason why this accumulator CANNOT be used for other things than strings. In line 399 of accum.py (version 4.10.2) the provided value is converted to a string. So nothing else than strings can be used with this accumulator.

Should the wiki page be changed?

Tom Keffer

unread,
May 3, 2023, 7:50:55 AM5/3/23
to weewx...@googlegroups.com
Not following. In Python, almost anything can be converted to a string. For example,

str(complex(1,2))

yields

'(1+2j)'



--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/7d92870c-f3f6-4ca1-815c-aa729b48e8ddn%40googlegroups.com.

Karen K

unread,
May 3, 2023, 9:49:13 AM5/3/23
to weewx-user
Ok, the documentation says "It is useful for things like strings, although there is no reason it can't be used for other things". I used it for "other things" and let a service provide an observation type that is a list. In the LOOP packet, there it is still a list. But in the ARCHIVE record, it is a string instead of a list. 

Then assume a template that contains:

#for $ii in $current.myobservationtype.raw
do something
#end for

Here the loop goes over the characters of the string instead of the list elements.

And it is the 'firstlast' accumulator that converts the original list to the string.

So the conclusion is: The 'firstlast' accumulator can only be used for strings but not for "other things" like lists.

Tom Keffer

unread,
May 3, 2023, 5:53:51 PM5/3/23
to weewx...@googlegroups.com
I don't remember why I coerce the type into a string. I'm sure I had a reason, but I don't recall it now.

I'll look into it.

Tom Keffer

unread,
May 3, 2023, 7:12:22 PM5/3/23
to weewx...@googlegroups.com
Whatever reason I had for coercing the value to a string has been lost to antiquity. If you change
string_val = str(val)
to
string_val = val
it should work for your list. 
Fixed in commit 9b203d6, to appear in V5
Reply all
Reply to author
Forward
0 new messages