Text processing/1: Difference between revisions
Content added Content deleted
(Actually done the changes described in previous edit.) |
Alextretyak (talk | contribs) (Added 11l) |
||
Line 34: | Line 34: | ||
Structure your program to show statistics for each line of the file, (similar to the original Python, Perl, and AWK examples below), followed by summary statistics for the file. When showing example output just show a few line statistics and the full end summary. |
Structure your program to show statistics for each line of the file, (similar to the original Python, Perl, and AWK examples below), followed by summary statistics for the file. When showing example output just show a few line statistics and the full end summary. |
||
=={{header|11l}}== |
|||
{{trans|Python}} |
|||
<lang 11l>V nodata = 0 |
|||
V nodata_max = -1 |
|||
[String] nodata_maxline |
|||
V tot_file = 0.0 |
|||
V num_file = 0 |
|||
:start: |
|||
L(line) File(:argv[1]).read().rtrim("\n").split("\n") |
|||
V tot_line = 0.0 |
|||
V num_line = 0 |
|||
V field = line.split("\t") |
|||
V date = field[0] |
|||
V data = field[(1..).step(2)].map(f -> Float(f)) |
|||
V flags = field[(2..).step(2)].map(f -> Int(f)) |
|||
L(datum, flag) zip(data, flags) |
|||
I flag < 1 |
|||
nodata++ |
|||
E |
|||
I nodata_max == nodata & nodata > 0 |
|||
nodata_maxline.append(date) |
|||
I nodata_max < nodata & nodata > 0 |
|||
nodata_max = nodata |
|||
nodata_maxline = [date] |
|||
nodata = 0 |
|||
tot_line += datum |
|||
num_line++ |
|||
tot_file += tot_line |
|||
num_file += num_line |
|||
print(‘Line: #11 Reject: #2 Accept: #2 Line_tot: #6.3 Line_avg: #6.3’.format( |
|||
date, data.len - num_line, num_line, tot_line, I (num_line > 0) {tot_line / num_line} E 0)) |
|||
print() |
|||
print(‘File(s) = #.’.format(:argv[1])) |
|||
print(‘Total = #6.3’.format(tot_file)) |
|||
print(‘Readings = #6’.format(num_file)) |
|||
print(‘Average = #6.3’.format(tot_file / num_file)) |
|||
print("\nMaximum run(s) of #. consecutive false readings ends at line starting with date(s): #.".format(nodata_max, nodata_maxline.join(‘, ’)))</lang> |
|||
{{out}} |
|||
<pre> |
|||
... |
|||
Line: 2004-12-29 Reject: 1 Accept: 23 Line_tot: 56.300 Line_avg: 2.448 |
|||
Line: 2004-12-30 Reject: 1 Accept: 23 Line_tot: 65.300 Line_avg: 2.839 |
|||
Line: 2004-12-31 Reject: 1 Accept: 23 Line_tot: 47.300 Line_avg: 2.057 |
|||
File(s) = readings.txt |
|||
Total = 1358393.400 |
|||
Readings = 129403 |
|||
Average = 10.497 |
|||
Maximum run(s) of 589 consecutive false readings ends at line starting with date(s): 1993-03-05 |
|||
</pre> |
|||
=={{header|Ada}}== |
=={{header|Ada}}== |