Skip to content
This repository was archived by the owner on May 11, 2020. It is now read-only.

Commit

Permalink
IN PROGRESS - issue ALESIA-9: Fix TestReport test of SESSL's JAMESII …
Browse files Browse the repository at this point in the history
…binding

https://altair.informatik.uni-rostock.de/jira/browse/ALESIA-9
more general container (list ->iterable) in AbstractReport
(grafted from 712c6fc894aa4701e48a5e2ab0155c1ab296762b)
  • Loading branch information
Roland Ewald committed Jul 31, 2013
1 parent bb9e622 commit faabc04
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 29 deletions.
8 changes: 4 additions & 4 deletions sessl-james/src/main/scala/sessl/james/Report.scala
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ trait Report extends AbstractReport {
case v: ScatterPlotView => new ScatterPlotDataView(to2DJavaDoubleArray(v.xData, v.yData),
v.caption, v.title, Array[String](v.xLabel, v.yLabel))
case v: HistogramView => new HistogramDataView(toDoubleArray(v.data), v.caption, v.title, v.xLabel, v.yLabel)
case v: BoxPlotView => new BoxPlotDataView(to2DJavaDoubleArray(v.data.map(_._2): _*),
v.caption, v.title, Array(v.xLabel, v.yLabel), Array(v.data.map(x => x._1): _*))
case v: LinePlotView => new LineChartDataView(to2DJavaDoubleArray(v.data.map(_._2): _*),
v.caption, v.title, Array(v.xLabel, v.yLabel), Array(v.data.map(x => x._1).tail: _*))
case v: BoxPlotView => new BoxPlotDataView(to2DJavaDoubleArray(v.data.toSeq.map(_._2): _*),
v.caption, v.title, Array(v.xLabel, v.yLabel), Array(v.data.toSeq.map(x => x._1): _*))
case v: LinePlotView => new LineChartDataView(to2DJavaDoubleArray(v.data.toSeq.map(_._2): _*),
v.caption, v.title, Array(v.xLabel, v.yLabel), Array(v.data.toSeq.map(x => x._1).tail: _*))
case v: StatisticalTestView =>
val dataPair = new org.jamesii.core.util.misc.Pair[Array[java.lang.Double], Array[java.lang.Double]](toDoubleArray(v.firstData._2), toDoubleArray(v.secondData._2))
new StatisticalTestDataView(dataPair, v.caption, v.firstData._1, v.secondData._1, true, true, StatisticalTestDefinition.KOLMOGOROV_SMIRNOV)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ import org.junit.Assert._
val files = new File(exp.reportName).list.toSet
assertTrue("The directory for raw data, the auxiliary plotting methods, and the report itself should be there", files("raw") && files("plotting.R") && files("report.Rtex"))
val dataFiles = rawDataDir.listFiles
assertTrue("There should be 28 files containing the raw data, and none of them should be empty.", dataFiles.length == 28 && dataFiles.forall(_.length > 0))
assertEquals("There should be non-empty raw data files", 28, dataFiles.filter(_.length > 0).length)
}

}
38 changes: 19 additions & 19 deletions sessl/src/main/scala/sessl/AbstractReport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ trait AbstractReport extends ExperimentConfiguration {
}

/** Converts data items to a common format that can be used for line plots. */
private[this] def convertToLinePlotData(data: Iterable[Any]): List[(String, List[_])] = data.head match {
private[this] def convertToLinePlotData(data: Iterable[Any]): Seq[(String, Iterable[_])] = data.head match {
case tuple: (_, _) => ("Time", tuple._2.asInstanceOf[Trajectory].map(_._1)) :: data.toList.flatMap(toNamedList)
case trajectory: List[_] => ("Time", trajectory.asInstanceOf[Trajectory].map(_._1)) :: data.toList.flatMap(toNamedList)
case trajectory: Iterable[_] => ("Time", trajectory.asInstanceOf[Trajectory].map(_._1)) :: data.toList.flatMap(toNamedList)
case _ => data.toList.flatMap(toNamedList)
}

Expand All @@ -175,22 +175,22 @@ trait AbstractReport extends ExperimentConfiguration {
*/
def reportTable(data: Any*)(caption: String = "") = {
val namedData = data.flatMap(toNamedList)
val tableData = namedData.map(x => x._1 :: x._2.map(_.toString))
currentSection.childs += TableView(tableData.toList, caption, currentSection)
val tableData = namedData.map(x => x._1 :: x._2.map(_.toString).toList)
currentSection.childs += TableView(tableData, caption, currentSection)
}

/** Converts an object of a suitable type into a tuple (name, list of values)*/
private[this] def toNamedList(data: Any): Seq[(String, List[_])] = {
private[this] def toNamedList(data: Any): Seq[(String, Iterable[_])] = {
data match {
//Because of type erasure, we have to match the types of the list content separately
case tuple: (_, _) => tuple._2.asInstanceOf[List[_]].head match {
case tuple: (_, _) => tuple._2.asInstanceOf[Iterable[_]].head match {
case t: (_, _) => Seq((tuple._1.toString, tuple._2.asInstanceOf[Trajectory].map(_._2)))
case _ => Seq((tuple._1.toString, tuple._2.asInstanceOf[List[_]]))
case _ => Seq((tuple._1.toString, tuple._2.asInstanceOf[Iterable[_]]))
}
case seq: Seq[_] => seq.head match {
case t: (_, _) => seq.asInstanceOf[Seq[(_, List[Double])]].map(tuple => (tuple._1.toString, tuple._2))
case nestedSeq: Seq[_] => seq.asInstanceOf[Seq[Seq[Double]]].map(rawData => ("", rawData.toList))
case n: Number => Seq(("", seq.asInstanceOf[Seq[Number]].map(_.doubleValue()).toList))
case t: (_, _) => seq.asInstanceOf[Seq[(_, Iterable[Double])]].map(tuple => (tuple._1.toString, tuple._2))
case nestedSeq: Seq[_] => seq.asInstanceOf[Seq[Iterable[_]]].map(rawData => ("", rawData))
case n: Number => Seq(("", seq.asInstanceOf[Iterable[Number]].map(_.doubleValue()).toList))
}
case _ => throw new IllegalArgumentException("Entity '" + data + "' cannot be converted to a tuple (name, list of values).")
}
Expand All @@ -205,18 +205,18 @@ trait AbstractReport extends ExperimentConfiguration {
protected def topmostElements = rootSection.children

/** Checks whether the elements in the list are numeric. */
private def dataIsNumeric(values: List[_]): Boolean = {
private def dataIsNumeric(values: Iterable[_]): Boolean = {
val typesOK = typesConform(classOf[Number], values)
if (!typesOK)
logger.warn("Some elements to be plotted are not numbers, hence this plot view is skipped: " + values)
typesOK
}

/** Checks whether the elements in all given lists are numeric. */
private def dataAreNumeric(data: List[_]*): Boolean = data.forall(dataIsNumeric)
private def dataAreNumeric(data: Iterable[_]*): Boolean = data.forall(dataIsNumeric)

/** Converts a list of Any into a list of Double.*/
private def toDoubleList(values: List[_]) = values.asInstanceOf[List[Number]].map(_.doubleValue())
private def toDoubleList(values: Iterable[_]) = values.asInstanceOf[Iterable[Number]].map(_.doubleValue()).toSeq

/** Needs to be realized by concrete implementations*/
def generateReport(results: ExperimentResults): Unit
Expand Down Expand Up @@ -251,19 +251,19 @@ protected case class ReportSectionNode(name: String, description: String, parent
trait DataView extends ReportNode

/** Display a scatter plot. */
case class ScatterPlotView(xData: List[Double], yData: List[Double], title: String, caption: String, xLabel: String, yLabel: String, parent: ReportSection) extends DataView
case class ScatterPlotView(xData: Iterable[Double], yData: Iterable[Double], title: String, caption: String, xLabel: String, yLabel: String, parent: ReportSection) extends DataView

/** Display a histogram. */
case class HistogramView(data: List[Double], title: String, caption: String, xLabel: String, yLabel: String, parent: ReportSection) extends DataView
case class HistogramView(data: Iterable[Double], title: String, caption: String, xLabel: String, yLabel: String, parent: ReportSection) extends DataView

/** Display a box plot. */
case class BoxPlotView(data: List[(String, List[Double])], title: String, caption: String, xLabel: String, yLabel: String, parent: ReportSection) extends DataView
case class BoxPlotView(data: Iterable[(String, Iterable[Double])], title: String, caption: String, xLabel: String, yLabel: String, parent: ReportSection) extends DataView

/** Display a line plot. */
case class LinePlotView(data: List[(String, List[Double])], title: String, caption: String, xLabel: String, yLabel: String, parent: ReportSection) extends DataView
case class LinePlotView(data: Iterable[(String, Iterable[Double])], title: String, caption: String, xLabel: String, yLabel: String, parent: ReportSection) extends DataView

/** Display the results of a statistical test. */
case class StatisticalTestView(firstData: (String, List[Double]), secondData: (String, List[Double]), caption: String, testMethod: Option[TwoPairedStatisticalTest], parent: ReportSection) extends DataView
case class StatisticalTestView(firstData: (String, Iterable[Double]), secondData: (String, Iterable[Double]), caption: String, testMethod: Option[TwoPairedStatisticalTest], parent: ReportSection) extends DataView

/** Display the results in a table. */
case class TableView(data: List[List[String]], caption: String, parent: ReportSection) extends DataView
case class TableView(data: Seq[Seq[String]], caption: String, parent: ReportSection) extends DataView
4 changes: 2 additions & 2 deletions sessl/src/main/scala/sessl/util/MiscUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ object MiscUtils extends Logging {
* the values
* @return true, if all elements in the sequence are of this kind
*/
def typesConform(clazz: java.lang.Class[_], values: Seq[Any]): Boolean =
def typesConform(clazz: java.lang.Class[_], values: Iterable[Any]): Boolean =
filterByConformantType(clazz, values).isEmpty

/** Filters a list by the type of its elements.
Expand All @@ -87,7 +87,7 @@ object MiscUtils extends Logging {
* the values
* @return the sequence of elements with non-conforming types
*/
def filterByConformantType(clazz: java.lang.Class[_], values: Seq[Any]) = values.filter(x => !clazz.isAssignableFrom(x.getClass))
def filterByConformantType(clazz: java.lang.Class[_], values: Iterable[Any]) = values.filter(x => !clazz.isAssignableFrom(x.getClass))

/** Gets the value or, if it is empty, gets default instead.
*
Expand Down
5 changes: 2 additions & 3 deletions sessl/src/main/scala/sessl/util/ScalaToJava.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ object ScalaToJava {
def toDoubleArray(values: Iterable[Double]): Array[java.lang.Double] = values.map(_.asInstanceOf[java.lang.Double]).toArray

/** Convert list to (transposed) nested array. */
def to2DTransposedJavaStringArray(valueLists: List[String]*): Array[Array[java.lang.String]] = {
def to2DTransposedJavaStringArray(valueLists: Seq[String]*): Array[Array[java.lang.String]] = {
if (valueLists.length == 0)
return Array.ofDim(0)

val rv: Array[Array[java.lang.String]] = Array.ofDim(valueLists.head.length)
for (i <- valueLists.head.indices)
rv(i) = Array.ofDim(valueLists.length)
Expand All @@ -66,7 +65,7 @@ object ScalaToJava {
}

/** Convert list to nested array. */
def to2DJavaDoubleArray(valueLists: List[Double]*) = {
def to2DJavaDoubleArray(valueLists: Iterable[Double]*) = {
val rv: Array[Array[java.lang.Double]] = Array.ofDim(valueLists.length)
for (i <- valueLists.indices)
rv(i) = toDoubleArray(valueLists(i))
Expand Down

0 comments on commit faabc04

Please sign in to comment.