Commit c549917d authored by Peter van 't Hof's avatar Peter van 't Hof

Adding methods for stats and settings

parent 8aad8df1
......@@ -66,6 +66,12 @@ object SummaryToSqlite extends ToolCommand {
println(Await.result(summary.getPipelines(), Duration.Inf))
Await.result(summary.createStat(runId, pipelineId, None, None, None, """{"bla": "bla"}"""), Duration.Inf)
println(Await.result(summary.getStats(runId = Some(runId), pipelineId = Some(pipelineId), sampleId = Option(None)), Duration.Inf))
println(Await.result(summary.getStat(0,0), Duration.Inf))
db.close()
logger.info("Done")
......
......@@ -37,7 +37,7 @@ class SummaryDb(db: Database) {
List(
runId.map(run.id === _),
runName.map(run.runName === _),
outputDir.map(run.outputDir === _) // not a condition as `criteriaRoast` evaluates to `None`
outputDir.map(run.outputDir === _)
).collect({ case Some(criteria) => criteria }).reduceLeftOption(_ && _).getOrElse(true: Rep[Boolean])
}
db.run(q.result)
......@@ -53,7 +53,7 @@ class SummaryDb(db: Database) {
List(
sampleId.map(sample.id === _),
runId.map(sample.runId === _),
name.map(sample.name === _) // not a condition as `criteriaRoast` evaluates to `None`
name.map(sample.name === _)
).collect({ case Some(criteria) => criteria }).reduceLeftOption(_ && _).getOrElse(true: Rep[Boolean])
}
db.run(q.map(x => (x.id, x.runId, x.name)).result)
......@@ -96,7 +96,7 @@ class SummaryDb(db: Database) {
List(
pipelineId.map(lib.id === _),
runId.map(lib.runId === _),
name.map(lib.name === _) // not a condition as `criteriaRoast` evaluates to `None`
name.map(lib.name === _)
).collect({ case Some(criteria) => criteria }).reduceLeftOption(_ && _).getOrElse(true: Rep[Boolean])
}
db.run(q.map(x => (x.id, x.name, x.runId)).result)
......@@ -113,10 +113,72 @@ class SummaryDb(db: Database) {
moduleId.map(lib.id === _),
runId.map(lib.runId === _),
pipelineId.map(lib.pipelineId === _),
name.map(lib.name === _) // not a condition as `criteriaRoast` evaluates to `None`
name.map(lib.name === _)
).collect({ case Some(criteria) => criteria }).reduceLeftOption(_ && _).getOrElse(true: Rep[Boolean])
}
db.run(q.map(x => (x.id, x.name, x.runId)).result)
}
def createStat(runId: Int, pipelineId: Int, moduleId: Option[Int] = None,
sampleId: Option[Int] = None, libId: Option[Int] = None, content: String) = {
db.run(stats.forceInsert(Stat(runId, pipelineId, moduleId, sampleId, libId, content)))
}
def getStats(runId: Option[Int] = None, pipelineId: Option[Int] = None, moduleId: Option[Option[Int]] = None,
sampleId: Option[Option[Int]] = None, libId: Option[Option[Int]] = None) = {
val q = List(
runId.map(x => (y:Query[Stats, Stats#TableElementType, Seq]) => y.filter(_.runId === x)),
pipelineId.map(x => (y:Query[Stats, Stats#TableElementType, Seq]) => y.filter(_.pipelineId === x)),
moduleId.map(x => (y:Query[Stats, Stats#TableElementType, Seq]) => (if (x.isDefined) y.filter(_.moduleId === x) else y.filter(_.moduleId.isEmpty))),
sampleId.map(x => (y:Query[Stats, Stats#TableElementType, Seq]) => (if (x.isDefined) y.filter(_.sampleId === x) else y.filter(_.sampleId.isEmpty))),
libId.map(x => (y:Query[Stats, Stats#TableElementType, Seq]) => (if (x.isDefined) y.filter(_.libraryId === x) else y.filter(_.libraryId.isEmpty)))
).flatten.foldLeft(stats.subquery)((a,b) => b(a))
db.run(q.result)
}
def getStat(runId: Int, pipelineId: Int, moduleId: Option[Int] = None,
sampleId: Option[Int] = None, libId: Option[Int] = None): Future[Option[Map[String, Any]]] = {
val q = List(
(y:Query[Stats, Stats#TableElementType, Seq]) => y.filter(_.runId === runId),
(y:Query[Stats, Stats#TableElementType, Seq]) => y.filter(_.pipelineId === pipelineId),
(y:Query[Stats, Stats#TableElementType, Seq]) => (if (moduleId.isDefined) y.filter(_.moduleId === moduleId) else y.filter(_.moduleId.isEmpty)),
(y:Query[Stats, Stats#TableElementType, Seq]) => (if (sampleId.isDefined) y.filter(_.sampleId === sampleId) else y.filter(_.sampleId.isEmpty)),
(y:Query[Stats, Stats#TableElementType, Seq]) => (if (libId.isDefined) y.filter(_.libraryId === libId) else y.filter(_.libraryId.isEmpty))
).foldLeft(stats.subquery)((a,b) => b(a))
db.run(q.map(_.content).result).map(_.headOption.map(ConfigUtils.jsonTextToMap))
}
def createSetting(runId: Int, pipelineId: Int, moduleId: Option[Int] = None,
sampleId: Option[Int] = None, libId: Option[Int] = None, content: String) = {
db.run(settings.forceInsert(Setting(runId, pipelineId, moduleId, sampleId, libId, content)))
}
def getSettings(runId: Option[Int] = None, pipelineId: Option[Int] = None, moduleId: Option[Option[Int]] = None,
sampleId: Option[Option[Int]] = None, libId: Option[Option[Int]] = None) = {
val q = List(
runId.map(x => (y:Query[Settings, Settings#TableElementType, Seq]) => y.filter(_.runId === x)),
pipelineId.map(x => (y:Query[Settings, Settings#TableElementType, Seq]) => y.filter(_.pipelineId === x)),
moduleId.map(x => (y:Query[Settings, Settings#TableElementType, Seq]) => (if (x.isDefined) y.filter(_.moduleId === x) else y.filter(_.moduleId.isEmpty))),
sampleId.map(x => (y:Query[Settings, Settings#TableElementType, Seq]) => (if (x.isDefined) y.filter(_.sampleId === x) else y.filter(_.sampleId.isEmpty))),
libId.map(x => (y:Query[Settings, Settings#TableElementType, Seq]) => (if (x.isDefined) y.filter(_.libraryId === x) else y.filter(_.libraryId.isEmpty)))
).flatten.foldLeft(settings.subquery)((a,b) => b(a))
db.run(q.result)
}
def getSetting(runId: Int, pipelineId: Int, moduleId: Option[Int] = None,
sampleId: Option[Int] = None, libId: Option[Int] = None): Future[Option[Map[String, Any]]] = {
val q = List(
(y:Query[Settings, Settings#TableElementType, Seq]) => y.filter(_.runId === runId),
(y:Query[Settings, Settings#TableElementType, Seq]) => y.filter(_.pipelineId === pipelineId),
(y:Query[Settings, Settings#TableElementType, Seq]) => (if (moduleId.isDefined) y.filter(_.moduleId === moduleId) else y.filter(_.moduleId.isEmpty)),
(y:Query[Settings, Settings#TableElementType, Seq]) => (if (sampleId.isDefined) y.filter(_.sampleId === sampleId) else y.filter(_.sampleId.isEmpty)),
(y:Query[Settings, Settings#TableElementType, Seq]) => (if (libId.isDefined) y.filter(_.libraryId === libId) else y.filter(_.libraryId.isEmpty))
).foldLeft(settings.subquery)((a,b) => b(a))
db.run(q.map(_.content).result).map(_.headOption.map(ConfigUtils.jsonTextToMap))
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment