Thanks folks for the ideas. Between them and some time "sawing logs" I
have a found a solution using a UDF that does math on the DateTime value.
Here is demo code:
m.TSref = DATETIME()
CREATE CURSOR joe (Stamp T, Value n(4))
FOR nn = 1 TO 100000
INSERT INTO joe VALUES (m.TSref + nn, 1000*RAND())
NEXT
SELECT Period(Stamp) as Period, Stamp, AVG(Value) as Joe;
FROM joe;
GROUP BY 1;
INTO CURSOR Out
FUNCTION Period
PARAMETERS m.ts
RETURN INT((m.Ts - m.TSref) / 60) && 60 = 1 per minute, 3600 = 1 per hour
etc
Now that I have the grouping issue solved I need to combine multiple
selects into one cursor. I'll start another thread unless I find the
answer right away.
Thanks again,
Joe
On Mon, Jun 9, 2014 at 9:47 AM, Tracy Pearson <[email protected]> wrote:
> Joe Yoder wrote on 2014-06-08:
> > Scenario:
> > - Cursor with 2 fields TimeStamp T, and Value N(4.0) - 1 record per
> > second - Output needed - BegStamp as the beginning of a time period
> > X seconds long and Avg as the average of the Value field for X
> > seconds
> > With X = 3600 the results should give the average value for each hour.
> >
> > I'm stuck on what to use for a group by expression and suspect that the
> > best way may be to hard code a pair of loops that increments through the
> > cursor one time period at a time.
> >
> > Does anyone want to show me a better way?
> >
> > Thanks in advance,
> >
> > Joe
> >
>
> Joe,
>
> I would accomplish this using a subquery.
>
> CREATE CURSOR joe (TimeStamp T, Value n(4))
> FOR nn = 1 TO 10000
> INSERT INTO joe VALUES (DATETIME() + nn, 1000*RAND())
> NEXT
>
> startTime = DATETIME() + 1234
> endTime = startTime + 3600 - 1 && fencepost
>
> SELECT grouping, AVG(value) ;
> FROM (SELECT value, 1 as grouping ;
> FROM joe ;
> WHERE TimeStamp between startTime AND endTime) ;
> average GROUP BY 1
>
>
> Tracy Pearson
> PowerChurch Software
>
>
[excessive quoting removed by server]
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message:
http://leafe.com/archives/byMID/profox/cabqednwpemv+yh21kbp-nb2y7rkfq+qy-epxr6eevjketyj...@mail.gmail.com
** All postings, unless explicitly stated otherwise, are the opinions of the
author, and do not constitute legal or medical advice. This statement is added
to the messages for those lawyers who are too stupid to see the obvious.