Text processing/1: Difference between revisions
Content deleted Content added
→Common utilities: formatting |
→{{header|J}}: give Dates to findLongestRuns as left arg |
||
Line 526: | Line 526: | ||
NB. Find longest run(s) of successive invalid measurements and return |
NB. Find longest run(s) of successive invalid measurements and return |
||
NB. length and date of last measurement(s) in run(s) |
NB. length and date of last measurement(s) in run(s) |
||
NB. Takes matrix of flags as right argument |
NB. Takes matrix of flags as right argument, list of date literals as left argument |
||
findLongestRuns=: |
findLongestRuns=: dyad define |
||
badflags=. , 0 >: y |
badflags=. , 0 >: y |
||
Line 533: | Line 533: | ||
getrunlengths=. [: #(;.1) 0 , }. *. }: |
getrunlengths=. [: #(;.1) 0 , }. *. }: |
||
getidxmax=. >:@I.@e. >./ |
getidxmax=. >:@I.@e. >./ |
||
getlineidx=. (24 <.@%~ +/)@{.~ getidxmax |
|||
maxrun=. >./ getrunlengths badflags |
maxrun=. >./ getrunlengths badflags |
||
lineidx=. (Dates {~ getlineidx@getrunlengths) badflags |
|||
maxrun; |
maxrun;lineidx { x |
||
) |
) |
||
Line 570: | Line 570: | ||
flags=: _99 ". >(2 + +: i.24){"1 dat |
flags=: _99 ". >(2 + +: i.24){"1 dat |
||
DailySumry=: vals summarize@filter"1 flags |
DailySumry=: vals summarize@filter"1 flags |
||
MaxRuns=: findLongestRuns flags |
MaxRuns=: Dates findLongestRuns flags |
||
(_4{.Dates) formatDailySumry _4{. DailySumry |
(_4{.Dates) formatDailySumry _4{. DailySumry |
||
Line 607: | Line 607: | ||
<lang j> |
<lang j> |
||
'Dates DailySumry Flags'=: processBlock fread jpath '~temp/readings.txt' |
'Dates DailySumry Flags'=: processBlock fread jpath '~temp/readings.txt' |
||
MaxRuns=: findLongestRuns Flags |
MaxRuns=: Dates findLongestRuns Flags |
||
(_4{.Dates) formatDailySumry _4{. DailySumry |
(_4{.Dates) formatDailySumry _4{. DailySumry |
||
Line 638: | Line 638: | ||
strt=. newstrt |
strt=. newstrt |
||
end. |
end. |
||
MaxRuns=. findLongestRuns Flags |
MaxRuns=. Dates findLongestRuns Flags |
||
smoutput (_4{. Dates) formatDailySumry _4{. DailySumry |
smoutput (_4{. Dates) formatDailySumry _4{. DailySumry |
||
smoutput '' |
smoutput '' |
||
Line 676: | Line 676: | ||
processLine=: monad define |
processLine=: monad define |
||
'dates dat'=. parseLine y |
'dates dat'=. parseLine y |
||
⚫ | |||
'vals flags'=. |: _2 ]\ dat |
'vals flags'=. |: _2 ]\ dat |
||
⚫ | |||
sumry=. vals summarize@filter flags |
sumry=. vals summarize@filter flags |
||
⚫ | |||
DailySumry=: DailySumry,sumry |
DailySumry=: DailySumry,sumry |
||
⚫ | |||
) |
) |
||
Line 693: | Line 693: | ||
processLine fapplylines y |
processLine fapplylines y |
||
MaxRuns=. findLongestRuns Flags |
MaxRuns=. Dates findLongestRuns Flags |
||
NB. Format output |
NB. Format output |
||
smoutput (_4{. Dates) formatDailySumry _4{. DailySumry |
smoutput (_4{. Dates) formatDailySumry _4{. DailySumry |