Package com.x.h Import java.io.File import scala.io.Source/** * Created by xxxxx on 3/7/2017. * Read logs and anlysis the interval time * NOTES://LTSGDB001B/8525691C004D9994/0000035F7480610585255D74006B9E95/5A5A50
0686EEF43F852580DC000884BB */Object Anlysissnslogs extends app{getthelastedfile def getthelastedfile (): Unit ={ var file = new file ("C:\\users\\ibm_admin\\desktop\\cognos\\datastage\\anlysislogs") for (F <-file.listfiles ()
{//Here can be added according to the article title timestamp get the latest article add sorting function println (f.getname.tostring.substring (0,8)) Readfiles (f.tostring)} def readfiles (file:string): Unit ={Import scala.collection.mutable//scala lists are similar to arrays, all of which are of the same type, but they are also different:
The list is immutable, the value cannot be changed once it is defined, and then the list has a recursive structure (that is, a linked table structure) and the array is not.
var jobName =new Array[string] (30)//Here is the definition of an array or problematic var job = 0 var jobtime =new array[string] (30)//There is a problem defining the array here. var job1 = 0 Val Source = source.fromfile (file) for (line <-source.getlines ()) {if (line.coNtains ("STATUS for JOB:") {//Find the line containing a specific string jobName (Job) = line.toString.substring Job +=1
} if (Line.contains ("Job elapsed Time=")) {jobtime (JOB1) = line.toString.substring () job1 +=1 } val Lastarray = JobName.toList.zip (jobtime.tolist) for (loop <-0 to Job-1) {//the array defined above has an exception, the There are real array lengths println (Lastarray (loop). _1.tostring + ":" + Lastarray (loop). _2)}//Lastarray.foreach (x => PR Intln (x._1.tostring + ":" + x._2)) var totaltime = 0 for (getTime <-0 to Job1-1) {val times = Jobtime (g ettime). Split (":") TotalTime + + (0). toint * 3600 + times (1). ToInt * (2). ToInt//Calculation total time} p RINTLN ("Total times is:" + totaltime/3600 + ":" + ((totaltime%3600)/60) + ":" + ((totaltime%3600)%60))//Standard Time total T IME Is:6:28:8}}