Commit 6f3b0b22 authored by Steven Murdoch's avatar Steven Murdoch
Browse files

Read network status documents

parent 09429712
Loading
Loading
Loading
Loading
+23 −1
Original line number Diff line number Diff line
package org.torproject.metrics.autopromotion

import _root_.java.io._
import _root_.java.text.SimpleDateFormat
import _root_.java.util.Date
import _root_.scala.collection.immutable._

class Status(fn: String)

object AutoPromotion {
    def getAllFiles(root: File): List[File] = {
@@ -14,9 +19,26 @@ object AutoPromotion {
        allFiles
    }

    def getRunningNodes(allFiles: List[File]) = {
        val parseFormat = new SimpleDateFormat("yyyyMMdd-HHmmss")

        def getRunningNodes(allFiles: List[File], acc: Map[Date, Status]): Map[Date, Status] = {
            allFiles match {
                case Nil => acc
                case f :: fs => {
                    val fn = f.getName
                    val timestamp = parseFormat.parse(fn.substring(0, 15))
                    getRunningNodes(fs, acc + (timestamp -> new Status(fn)))
                }
            }
        }
        getRunningNodes(allFiles, HashMap.empty)
    }

    def main(args: Array[String]) {
        val inDir = new File(args(0)) // Directory to search
        System.out.println(getAllFiles(inDir))
        val allFiles = getAllFiles(inDir)
        System.out.println(getRunningNodes(allFiles))
    }
}