June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
78
Task/Text-processing-1/Phix/text-processing-1.phix
Normal file
78
Task/Text-processing-1/Phix/text-processing-1.phix
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
constant lines = split(data,'\n')
|
||||
|
||||
include builtins\timedate.e
|
||||
|
||||
integer count = 0,
|
||||
max_count = 0,
|
||||
ntot = 0
|
||||
atom readtot = 0
|
||||
timedate run_start, max_start
|
||||
|
||||
procedure end_bad_run()
|
||||
if count then
|
||||
if count>max_count then
|
||||
max_count = count
|
||||
max_start = run_start
|
||||
end if
|
||||
count = 0
|
||||
end if
|
||||
end procedure
|
||||
|
||||
for i=1 to length(lines) do
|
||||
sequence oneline = split(lines[i],no_empty:=true), r
|
||||
if length(oneline)!=49 then
|
||||
?"bad line (length!=49)"
|
||||
else
|
||||
r = parse_date_string(oneline[1],{"YYYY-MM-DD"})
|
||||
if not timedate(r) then
|
||||
?{"bad date",oneline[1]}
|
||||
else
|
||||
timedate td = r
|
||||
integer rejects=0, accepts=0
|
||||
atom readsum = 0
|
||||
for j=2 to 48 by 2 do
|
||||
r = scanf(oneline[j],"%f")
|
||||
if length(r)!=1 then
|
||||
?{"error scanning",oneline[j]}
|
||||
rejects += 1
|
||||
else
|
||||
atom reading = r[1][1]
|
||||
r = scanf(oneline[j+1],"%d")
|
||||
if length(r)!=1 then
|
||||
?{"error scanning",oneline[j+1]}
|
||||
rejects += 1
|
||||
else
|
||||
integer flag = r[1][1]
|
||||
if flag<=0 then
|
||||
if count=0 then
|
||||
run_start = td
|
||||
end if
|
||||
count += 1
|
||||
rejects += 1
|
||||
else
|
||||
end_bad_run()
|
||||
accepts += 1
|
||||
readsum += reading
|
||||
end if
|
||||
end if
|
||||
end if
|
||||
end for
|
||||
if rejects=0 then
|
||||
readtot += readsum
|
||||
ntot += 1
|
||||
end if
|
||||
-- readtot += readsum
|
||||
-- ntot += accepts
|
||||
printf(1,"Date: %s, Rejects: %2d, Accepts: %2d, Line total: %7.3f, Average %6.3f\n",
|
||||
{format_timedate(td,"DD/MM/YYYY"),rejects, accepts, readsum, readsum/accepts})
|
||||
end if
|
||||
end if
|
||||
end for
|
||||
|
||||
printf(1,"Average: %.3f (of %d entirely valid days)\n",{readtot/(24*ntot),ntot})
|
||||
--printf(1,"Average: %.3f\n",{readtot/ntot})
|
||||
end_bad_run()
|
||||
if max_count then
|
||||
printf(1,"Maximum run of %d consecutive false readings starting: %s\n",
|
||||
{max_count,format_timedate(max_start,"DD/MM/YYYY")})
|
||||
end if
|
||||
Loading…
Add table
Add a link
Reference in a new issue