package uk.ac.man.cs.lethe.internal.application.statistics

import java.io.{ File, PrintStream }
import java.io.FileNotFoundException
import java.io.PrintWriter
import java.text.SimpleDateFormat

import scala.collection.SortedSet
import scala.collection.mutable.HashMap
import scala.io.Source
import scala.sys.process._


object Evaluator2 { 

  def getAllowedOntologies() = Set[String]()

  def evaluate(file: File) = { 

    val allowed = getAllowedOntologies()

    val reOntology = """Ontology: ../../ontologies/bioportal_H/(.*)""".r
    val reExtStatements = """Output Ext statements: (\d+)""".r
    val reExtAvgAxiomSize = """Output Ext avg axiom size: (\d+)""".r
    val reExtMaxStatementSize = """Output Ext max statement size: (\d+)""".r
    val reExtSignature = """Output Ext signature (\d+)""".r
    val reExtDuration = """Duration Ext: (\d+\.\d+)sec.""".r
    val reExtTimeout = """Ext Timeout""".r

    val resultsLines = 
      Source.fromFile(file)(io.Codec("ISO-8859-1")).getLines()


    var allowedOntology = false
    var sum = 0
    var sizes = 0.0
    var statements = 0.0
    var durations = 0.0
    var timeouts = 0
    var signatures = 0.0

    resultsLines.foreach { _ match { 
      case reOntology(ontology) => allowedOntology = allowed(ontology)
      case reExtStatements(st) => if(allowedOntology) { statements = st.toDouble; sum += 1 }
      case reExtAvgAxiomSize(size) => if(allowedOntology) { sizes += statements*size.toDouble }
      case reExtSignature(sig) => if(allowedOntology) { signatures += sig.toDouble }
      case reExtDuration(dur) => if(allowedOntology) { durations += dur.toDouble }
      case reExtTimeout => if(allowedOntology) { timeouts += 1 }
    }}

  }
}
