20 lines
971 B
Plaintext
20 lines
971 B
Plaintext
// the RegExp engine has a low limit on groups so
|
|
// I can't use it to select all fields, only verify them
|
|
re:=RegExp(0'|^(\d+-\d+-\d+)| + 0'|\s+\d+\.\d+\s+-*\d+| * 24 + ".+$");
|
|
w:=[1..].zip(File("readings.txt")); //-->lazy (line #,line)
|
|
reg datep,N, good=0, dd=0;
|
|
foreach n,line in (w){
|
|
N=n; // since n is local to this scope
|
|
if (not re.search(line)){ println("Line %d: malformed".fmt(n)); continue; }
|
|
date:=line[re.matchedNs[1].xplode()]; // I can group the date field
|
|
if (datep==date){ dd+=1; println("Line %4d: dup date: %s".fmt(n,date)); }
|
|
datep=date;
|
|
if (line.replace("\t"," ").split(" ").filter()[1,*] // blow fields apart, drop date
|
|
.pump(Void,Void.Read, // get (reading,status)
|
|
fcn(_,s){ // stop on first problem status and return True
|
|
if(s.strip().toInt()<1) T(Void.Stop,True) else False
|
|
})) continue;
|
|
good+=1;
|
|
}
|
|
println("%d records read, %d duplicate dates, %d valid".fmt(N,dd,good));
|