From e01db9fb34ae2382f0e22f5d54c6fb8c78147dae Mon Sep 17 00:00:00 2001 From: Pascal Date: Wed, 29 Jan 2020 01:19:11 -0600 Subject: [PATCH] [fix] fixed bugs in parser - [fix] fixed out of bound error - [fix] fixed ground truth to not requiring "truth" key if parent exist - [fix] fixed group list overwriting itself in groupMapper function --- src/main/scala/scim/components/Parser.scala | 45 ++++++++++++--------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/src/main/scala/scim/components/Parser.scala b/src/main/scala/scim/components/Parser.scala index 9ff70f8..cd56c49 100644 --- a/src/main/scala/scim/components/Parser.scala +++ b/src/main/scala/scim/components/Parser.scala @@ -177,7 +177,7 @@ class SimulationConfigParser(input: Map[String, Any], simulationBehaviours: Simu var current = if(it.hasNext) Some(it.next) else None while(!current.isEmpty) { val next = if(it.hasNext) Some(it.next) else None - for(time <- current.get._1 to (if(!next.isEmpty) next.get._1 else config.duration - 1)) { + for(time <- current.get._1 to (if(!next.isEmpty && next.get._1 < config.duration) next.get._1 else config.duration - 1)) { timeVector(time) = current.get._2 } current = next @@ -212,13 +212,17 @@ class SimulationConfigParser(input: Map[String, Any], simulationBehaviours: Simu } else { debugf(DebugType.WARNING, "Duplicate Ground Truth in Group [%s]. Ignoring Ground Truth: %s", groupString, groundTruthMap.toString()) } - parseTruth(groundTruthMap("truth").asInstanceOf[Vector[Any]]).map(kv => { - if(groundTruthValues.contains(kv._1)) { - groundTruthValues(kv._1)(group) = kv._2 - } else { - groundTruthValues(kv._1) = mutable.Map[Group, Truth](group -> kv._2) - } - }) + if(groundTruthMap.contains("truth")){ + parseTruth(groundTruthMap("truth").asInstanceOf[Vector[Any]]).map(kv => { + if(groundTruthValues.contains(kv._1)) { + groundTruthValues(kv._1)(group) = kv._2 + } else { + groundTruthValues(kv._1) = mutable.Map[Group, Truth](group -> kv._2) + } + }) + } else if(group.parent.isEmpty) { + debugf(DebugType.WARNING, "Sensor Group [%s] has no parent and no ground truth values", groupString) + } } else { debugf(DebugType.WARNING, "Unused Ground Truth in Group [%s] because the Sensor has Parent [%s]. Ignoring Ground Truth: %s", groupString, group.parent.get, groundTruthMap.toString()) } @@ -281,18 +285,21 @@ class SimulationConfigParser(input: Map[String, Any], simulationBehaviours: Simu val groupDone: mutable.HashSet[Group] = mutable.HashSet() def groupMapper(group: Group, count: SensorCount): List[(Group, Sensor, Option[GroundTruth])] = { - if(!behaviourListSensor.contains(group)) { - debugf(DebugType.WARNING, "Group [%s] does not have a behaviour, using default", group.toString()) - behaviourListSensor(group) = Behaviour(BehaviourVector(Vector.tabulate(config.duration)(_ => None))) - } - if(group.parent.isEmpty) { - groupDone.add(group) - List((group, Sensor(group, cell, count, behaviourListSensor(group), config.parSensor, config.sensorThreadPool), - if(behaviourListGroundTruth.contains(group)) Some(GroundTruth(group, Some(behaviourListGroundTruth(group)))) else None)) + if(groupDone.contains(group)) { + // if we've already seen the group, get the list so we can add a depended group + val root = getParentRoot(group, this.groups.toMap) // get root if already added + if(!root.isEmpty) { + groupMap(root.get) + } else { List() } // circular dependency, just return empty list } else { - if(groupDone.contains(group)) { - debugf(DebugType.WARNING, "Circular dependency of groups: [%s]", groupDone.toString()) - List() + if(!behaviourListSensor.contains(group)) { + debugf(DebugType.WARNING, "Group [%s] does not have a behaviour, using default", group.toString()) + behaviourListSensor(group) = Behaviour(BehaviourVector(Vector.tabulate(config.duration)(_ => None))) + } + if(group.parent.isEmpty) { + groupDone.add(group) + List((group, Sensor(group, cell, count, behaviourListSensor(group), config.parSensor, config.sensorThreadPool), + if(behaviourListGroundTruth.contains(group)) Some(GroundTruth(group, Some(behaviourListGroundTruth(group)))) else None)) } else { groupDone.add(group) val parentGroup = this.groups(group.parent.get) // this should really exist at this point