src/Pure/PIDE/document_status.scala
changeset 83229 ad2b6030cb9c
parent 83228 b06ce93632ec
equal deleted inserted replaced
83228:b06ce93632ec 83229:ad2b6030cb9c
   227       state: Document.State,
   227       state: Document.State,
   228       version: Document.Version,
   228       version: Document.Version,
   229       name: Document.Node.Name,
   229       name: Document.Node.Name,
   230       threshold: Time = Time.max
   230       threshold: Time = Time.max
   231     ): Node_Status = {
   231     ): Node_Status = {
       
   232       val node = version.nodes(name)
       
   233 
   232       var theory_status = Document_Status.Theory_Status.NONE
   234       var theory_status = Document_Status.Theory_Status.NONE
   233       var unprocessed = 0
   235       var unprocessed = 0
   234       var running = 0
   236       var running = 0
   235       var warned = 0
   237       var warned = 0
   236       var failed = 0
   238       var failed = 0
   239       var terminated = true
   241       var terminated = true
   240       var total_timing = Timing.zero
   242       var total_timing = Timing.zero
   241       var max_time = Time.zero
   243       var max_time = Time.zero
   242       var command_timings = Map.empty[Command, Command_Timings]
   244       var command_timings = Map.empty[Command, Command_Timings]
   243 
   245 
   244       for (command <- version.nodes(name).commands.iterator) {
   246       for (command <- node.commands.iterator) {
   245         val status = state.command_status(version, command)
   247         val status = state.command_status(version, command)
   246 
   248 
   247         theory_status = Theory_Status.merge(theory_status, status.theory_status)
   249         theory_status = Theory_Status.merge(theory_status, status.theory_status)
   248 
   250 
   249         if (status.is_running) running += 1
   251         if (status.is_running) running += 1
   259         total_timing += status.timings.sum
   261         total_timing += status.timings.sum
   260         if (t > max_time) max_time = t
   262         if (t > max_time) max_time = t
   261         if (t.is_notable(threshold)) command_timings += (command -> status.timings)
   263         if (t.is_notable(threshold)) command_timings += (command -> status.timings)
   262       }
   264       }
   263 
   265 
   264       val total = unprocessed + running + warned + failed + finished
   266       def percent(a: Int, b: Int): Int =
   265 
   267         if (b == 0) 0 else ((a.toDouble / b) * 100).toInt
   266       val percentage: Int =
   268 
   267         if (Theory_Status.consolidated(theory_status)) 100
   269       val percentage: Int = {
   268         else if (total == 0) 0
   270         node.get_theory match {
   269         else (((total - unprocessed).toDouble / total) * 100).toInt min 99
   271           case None =>
       
   272             if (Theory_Status.consolidated(theory_status)) 100
       
   273             else {
       
   274               val total = unprocessed + running + warned + failed + finished
       
   275               percent(total - unprocessed, total).min(99)
       
   276             }
       
   277           case Some(command) =>
       
   278             val total = command.span.theory_commands
       
   279             val processed = state.command_status(version, command).timings.count
       
   280             percent(processed, total)
       
   281         }
       
   282       }
   270 
   283 
   271       Node_Status(
   284       Node_Status(
   272         theory_status = theory_status,
   285         theory_status = theory_status,
   273         suppressed = version.nodes.suppressed(name),
   286         suppressed = version.nodes.suppressed(name),
   274         unprocessed = unprocessed,
   287         unprocessed = unprocessed,