[add][mod] added consoleUtil to lib, beautified output

- simple coloring for print
 - [mod] changed console output to use colors
This commit is contained in:
2020-01-29 01:19:11 -06:00
parent 646bea1117
commit b61dbaa266
2 changed files with 32 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
package scim.components package scim.components
import scim.datastruct.{Cell, Group, SensorResult, SharedMemory, Time, Truth} import scim.datastruct.{Cell, Group, SensorResult, SharedMemory, Time, Truth}
import scim.lib.consoleUtil.Color._
class Output(sharedMemory: SharedMemory, printOutput: Boolean = true) extends Runnable { class Output(sharedMemory: SharedMemory, printOutput: Boolean = true) extends Runnable {
def run(): Unit = { def run(): Unit = {
@@ -14,20 +15,19 @@ class Output(sharedMemory: SharedMemory, printOutput: Boolean = true) extends Ru
} }
def outputData(time: Time, sensors: Map[Cell, Map[Group, Vector[SensorResult]]], groundTruths: Map[Cell, Map[Group, Truth]]): Unit = { def outputData(time: Time, sensors: Map[Cell, Map[Group, Vector[SensorResult]]], groundTruths: Map[Cell, Map[Group, Truth]]): Unit = {
println("\n\nTICK: " + time) println(RED("\n\nTICK: ") + time)
if(!printOutput) return if(!printOutput) return
sensors.foreach(cells => { sensors.foreach(cells => {
val cell = cells._1 val cell = cells._1
println("Cell: " + cell) println(CYAN("Cell: ") + cell)
cells._2.foreach(groups => { cells._2.foreach(groups => {
val group = groups._1 val group = groups._1
print("Group: " + group + " ") val lastElement = groups._2.lastOption
groups._2.foreach(res => print(res.get._3.getOrElse("None") + " | ")) print(BLUE(" Group: ") + group + (if(!lastElement.isEmpty) MAGENTA("\n Results: ") else ""))
if(groundTruths.contains(cell) && groundTruths(cell).contains(group)) print("\nGround Truth: " + groundTruths(cell)(group).peak().getOrElse("None")) groups._2.foreach(res => print(res.get._3.getOrElse("None") + (if(res.eq(lastElement.get)) "" else " | ")))
if(groundTruths.contains(cell) && groundTruths(cell).contains(group)) print(GREEN("\n Ground Truth: ") + groundTruths(cell)(group).peak().getOrElse("None"))
print("\n") print("\n")
}) })
}) })
//println(sensors)
//println(groundTruths)
} }
} }

View File

@@ -69,6 +69,30 @@ package object evalUtil {
} }
} }
package object consoleUtil {
private val resetColor = "\u001b[0m"
sealed case class Color(value: String) {
override def toString: String = value
def apply(text: String): String = {
value + text + resetColor
}
}
object Color {
object BLACK extends Color("\u001b[30m")
object RED extends Color("\u001b[31m")
object GREEN extends Color("\u001b[32m")
object YELLOW extends Color("\u001b[33m")
object BLUE extends Color("\u001b[34m")
object MAGENTA extends Color("\u001b[35m")
object CYAN extends Color("\u001b[36m")
object WHITE extends Color("\u001b[37m")
object RESET extends Color(resetColor)
val values = Seq(BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET)
}
}
package object debugUtil { package object debugUtil {
sealed case class DebugType(name: String, level: Int) sealed case class DebugType(name: String, level: Int)
@@ -81,7 +105,7 @@ package object debugUtil {
object DEBUG extends DebugType("DEBUG", 4) // Debug messages object DEBUG extends DebugType("DEBUG", 4) // Debug messages
val values = Seq(ERROR, WARNING, NOTICE, INFO, DEBUG) val values = Seq(ERROR, WARNING, NOTICE, INFO, DEBUG)
} }
val level: Int = DebugType.DEBUG.level val level: Int = DebugType.INFO.level
def currentMethodName: String = Thread.currentThread.getStackTrace()(2).getMethodName def currentMethodName: String = Thread.currentThread.getStackTrace()(2).getMethodName
def currentMethodCallerName: String = Thread.currentThread.getStackTrace()(3).getMethodName def currentMethodCallerName: String = Thread.currentThread.getStackTrace()(3).getMethodName