Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
51
Task/Text-processing-1/Kotlin/text-processing-1.kotlin
Normal file
51
Task/Text-processing-1/Kotlin/text-processing-1.kotlin
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
// version 1.2.31
|
||||
|
||||
import java.io.File
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val rx = Regex("""\s+""")
|
||||
val file = File("readings.txt")
|
||||
val fmt = "Line: %s Reject: %2d Accept: %2d Line_tot: %7.3f Line_avg: %7.3f"
|
||||
var grandTotal = 0.0
|
||||
var readings = 0
|
||||
var date = ""
|
||||
var run = 0
|
||||
var maxRun = -1
|
||||
var finishLine = ""
|
||||
file.forEachLine { line ->
|
||||
val fields = line.split(rx)
|
||||
date = fields[0]
|
||||
if (fields.size == 49) {
|
||||
var accept = 0
|
||||
var total = 0.0
|
||||
for (i in 1 until fields.size step 2) {
|
||||
if (fields[i + 1].toInt() >= 1) {
|
||||
accept++
|
||||
total += fields[i].toDouble()
|
||||
if (run > maxRun) {
|
||||
maxRun = run
|
||||
finishLine = date
|
||||
}
|
||||
run = 0
|
||||
}
|
||||
else run++
|
||||
}
|
||||
grandTotal += total
|
||||
readings += accept
|
||||
println(fmt.format(date, 24 - accept, accept, total, total / accept))
|
||||
}
|
||||
else println("Line: $date does not have 49 fields and has been ignored")
|
||||
}
|
||||
|
||||
if (run > maxRun) {
|
||||
maxRun = run
|
||||
finishLine = date
|
||||
}
|
||||
val average = grandTotal / readings
|
||||
println("\nFile = ${file.name}")
|
||||
println("Total = ${"%7.3f".format(grandTotal)}")
|
||||
println("Readings = $readings")
|
||||
println("Average = ${"%-7.3f".format(average)}")
|
||||
println("\nMaximum run of $maxRun consecutive false readings")
|
||||
println("ends at line starting with date: $finishLine")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue