Split array into chunks based on timestamp in Haskell -


i have array of records (custom data type) in haskell want aggregate based on each records' timestamp. in general terms each record looks this:

data record = record { event :: string,                         time :: double,                         :: int,                         :: int                       } deriving (show, eq) 

i used double timestamp since same format used in tracefile.

and parse them csv file array of records: [record]

now i'm looking approximation of instantaneous events / time. want split array several arrays based on timestamp (say. every 1 seconds) , fold across each smaller array.

the problem can't figure out how split array based on value of record. looking on hoogle found several functions splitevery , splitwhen, i'm lost. considered using splitwhen break list when, say, (mod time 0.1) == 0, if worked remove elements it's splitting on (which don't want do).

i should note records not evenly spaced in time. e.g. timestamp on sequential records not going differ fixed amount.

i more willing store data in different format if can suggest 1 make sort of work easier.

a quick sample of data i'm parsing (from ns2 simulation):

r 0.114 1 2 tcp 1000 ________ 2 1.0 5.0 0 2 r 0.240 1 2 tcp 1000 ________ 2 1.0 5.0 0 2 r 0.914 2 1 tcp 1000 ________ 2 5.0 1.0 0 3 

if have [record] , want group them specific condition, can use data.list.groupby. i'm assuming time :: double, 1 second base unit, time = 1 1 second, time = 100 100 seconds, etc, adjust whatever system you're using:

import data.list import data.function (on)  isinsameclocksecond :: record -> record -> bool isinsameclocksecond = (==) `on` (floor . time :: record -> integer) -- type signature given floor . time remove ambiguity -- due floor's polymorphic type signature.  groupbysameclocksecond :: [record] -> [[record]] groupbysameclocksecond = groupby isinsameclocksecond 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -