June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -4,7 +4,9 @@ The fields (from the left) are:
|
|||
DATESTAMP [ VALUEn FLAGn ] * 24
|
||||
i.e. a datestamp followed by twenty-four repetitions of a floating-point instrument value and that instrument's associated integer flag. Flag values are >= 1 if the instrument is working and < 1 if there is some problem with it, in which case that instrument's value should be ignored.
|
||||
|
||||
A sample from the full data file [http://rosettacode.org/resources/readings.zip readings.txt], which is also used in the [[Data Munging]] task, follows:
|
||||
A sample from the full data file [http://rosettacode.org/resources/readings.zip readings.txt], which is also used in the [[Text processing/1]] task, follows:
|
||||
|
||||
Data is no longer available at that link. Zipped mirror available [https://github.com/thundergnat/rc/blob/master/resouces/readings.zip here]
|
||||
<pre>
|
||||
1991-03-30 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1
|
||||
1991-03-31 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 10.000 1 20.000 1 20.000 1 20.000 1 35.000 1 50.000 1 60.000 1 40.000 1 30.000 1 30.000 1 30.000 1 25.000 1 20.000 1 20.000 1 20.000 1 20.000 1 20.000 1 35.000 1
|
||||
|
|
|
|||
|
|
@ -4,21 +4,21 @@ check_format(list l)
|
|||
integer i;
|
||||
text s;
|
||||
|
||||
if (l_length(l) != 49) {
|
||||
if (~l != 49) {
|
||||
error("wrong number of fields");
|
||||
}
|
||||
|
||||
s = lf_q_text(l);
|
||||
if (length(s) != 10 || s[4] != '-' || s[7] != '-') {
|
||||
s = l[0];
|
||||
if (~s != 10 || s[4] != '-' || s[7] != '-') {
|
||||
error("bad date format");
|
||||
}
|
||||
atoi(delete(delete(s, 7), 4));
|
||||
l[0] = atoi(delete(delete(s, 7), 4));
|
||||
|
||||
i = 1;
|
||||
while (i < 49) {
|
||||
l_r_real(l, i, atof(l_q_text(l, i)));
|
||||
l[i] = atof(l[i]);
|
||||
i += 1;
|
||||
l_r_integer(l, i, atoi(l_q_text(l, i)));
|
||||
l[i] = atoi(l[i]);
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -26,39 +26,36 @@ check_format(list l)
|
|||
integer
|
||||
main(void)
|
||||
{
|
||||
integer goods;
|
||||
integer goods, i, v;
|
||||
file f;
|
||||
list l;
|
||||
record r;
|
||||
index x;
|
||||
|
||||
goods = 0;
|
||||
|
||||
f_affix(f, "readings.txt");
|
||||
f.affix("readings.txt");
|
||||
|
||||
while (f_list(f, l, 0) != -1) {
|
||||
while (f.list(l, 0) != -1) {
|
||||
if (!trap(check_format, l)) {
|
||||
if (r_key(r, l_head(l))) {
|
||||
v_form("duplicate ~ line\n", l_head(l));
|
||||
} else {
|
||||
integer i;
|
||||
if (x.key(v = lf_pick(l))) {
|
||||
v_form("duplicate ~ line\n", v);
|
||||
}
|
||||
|
||||
r_put(r, l_head(l), 0);
|
||||
i = 2;
|
||||
while (i < 49) {
|
||||
if (l_q_integer(l, i) != 1) {
|
||||
break;
|
||||
}
|
||||
i += 2;
|
||||
}
|
||||
if (49 < i) {
|
||||
goods += 1;
|
||||
x[v] = 0;
|
||||
i = 1;
|
||||
while (i < 48) {
|
||||
if (l[i] < 1) {
|
||||
break;
|
||||
}
|
||||
i += 2;
|
||||
}
|
||||
if (48 < i) {
|
||||
goods += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
o_integer(goods);
|
||||
o_text(" good unique lines\n");
|
||||
o_(goods, " good lines\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
5
Task/Text-processing-2/Julia/text-processing-2.julia
Normal file
5
Task/Text-processing-2/Julia/text-processing-2.julia
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
dupdate = df[nonunique(df[:,[:Date]]),:][:Date]
|
||||
println("The following rows have duplicate DATESTAMP:")
|
||||
println(df[df[:Date] .== dupdate,:])
|
||||
println("All values good in these rows:")
|
||||
println(df[df[:ValidValues] .== 24,:])
|
||||
42
Task/Text-processing-2/Kotlin/text-processing-2.kotlin
Normal file
42
Task/Text-processing-2/Kotlin/text-processing-2.kotlin
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
// version 1.2.31
|
||||
|
||||
import java.io.File
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val rx = Regex("""\s+""")
|
||||
val file = File("readings.txt")
|
||||
var count = 0
|
||||
var invalid = 0
|
||||
var allGood = 0
|
||||
var map = mutableMapOf<String, Int>()
|
||||
file.forEachLine { line ->
|
||||
count++
|
||||
val fields = line.split(rx)
|
||||
val date = fields[0]
|
||||
if (fields.size == 49) {
|
||||
if (map.containsKey(date))
|
||||
map[date] = map[date]!! + 1
|
||||
else
|
||||
map.put(date, 1)
|
||||
var good = 0
|
||||
for (i in 2 until fields.size step 2) {
|
||||
if (fields[i].toInt() >= 1) {
|
||||
good++
|
||||
}
|
||||
}
|
||||
if (good == 24) allGood++
|
||||
}
|
||||
else invalid++
|
||||
}
|
||||
|
||||
println("File = ${file.name}")
|
||||
println("\nDuplicated dates:")
|
||||
for ((k,v) in map) {
|
||||
if (v > 1) println(" $k ($v times)")
|
||||
}
|
||||
println("\nTotal number of records : $count")
|
||||
var percent = invalid.toDouble() / count * 100.0
|
||||
println("Number of invalid records : $invalid (${"%5.2f".format(percent)}%)")
|
||||
percent = allGood.toDouble() / count * 100.0
|
||||
println("Number which are all good : $allGood (${"%5.2f".format(percent)}%)")
|
||||
}
|
||||
19
Task/Text-processing-2/Perl-6/text-processing-2.pl6
Normal file
19
Task/Text-processing-2/Perl-6/text-processing-2.pl6
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
my $good-records;
|
||||
my $line;
|
||||
my %dates;
|
||||
|
||||
for lines() {
|
||||
$line++;
|
||||
/ ^
|
||||
(\d ** 4 '-' \d\d '-' \d\d)
|
||||
[ \h+ \d+'.'\d+ \h+ ('-'?\d+) ] ** 24
|
||||
$ /
|
||||
or note "Bad format at line $line" and next;
|
||||
%dates.push: $0 => $line;
|
||||
$good-records++ if $1.all >= 1;
|
||||
}
|
||||
|
||||
say "$good-records good records out of $line total";
|
||||
|
||||
say 'Repeated timestamps (with line numbers):';
|
||||
.say for sort %dates.pairs.grep: *.value.elems > 1;
|
||||
Loading…
Add table
Add a link
Reference in a new issue