Commit cc77bd23 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Improve typing

parent c549917d
...@@ -126,26 +126,28 @@ class SummaryDb(db: Database) { ...@@ -126,26 +126,28 @@ class SummaryDb(db: Database) {
def getStats(runId: Option[Int] = None, pipelineId: Option[Int] = None, moduleId: Option[Option[Int]] = None, 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) = { sampleId: Option[Option[Int]] = None, libId: Option[Option[Int]] = None) = {
val q = List( val l: List[Option[Query[Stats, Stats#TableElementType, Seq] => Query[Stats, Stats#TableElementType, Seq]]] = List(
runId.map(x => (y:Query[Stats, Stats#TableElementType, Seq]) => y.filter(_.runId === x)), runId.map(x => y => y.filter(_.runId === x)),
pipelineId.map(x => (y:Query[Stats, Stats#TableElementType, Seq]) => y.filter(_.pipelineId === x)), pipelineId.map(x => y => 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))), moduleId.map(x => y => (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))), sampleId.map(x => y => (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))) libId.map(x => y => (if (x.isDefined) y.filter(_.libraryId === x) else y.filter(_.libraryId.isEmpty)))
).flatten.foldLeft(stats.subquery)((a,b) => b(a)) )
val q = l.flatten.foldLeft(stats.subquery)((a,b) => b(a))
db.run(q.result) db.run(q.result)
} }
def getStat(runId: Int, pipelineId: Int, moduleId: Option[Int] = None, def getStat(runId: Int, pipelineId: Int, moduleId: Option[Int] = None,
sampleId: Option[Int] = None, libId: Option[Int] = None): Future[Option[Map[String, Any]]] = { sampleId: Option[Int] = None, libId: Option[Int] = None): Future[Option[Map[String, Any]]] = {
val q = List( val l: List[Query[Stats, Stats#TableElementType, Seq] => Query[Stats, Stats#TableElementType, Seq]] = List(
(y:Query[Stats, Stats#TableElementType, Seq]) => y.filter(_.runId === runId), y => y.filter(_.runId === runId),
(y:Query[Stats, Stats#TableElementType, Seq]) => y.filter(_.pipelineId === pipelineId), y => y.filter(_.pipelineId === pipelineId),
(y:Query[Stats, Stats#TableElementType, Seq]) => (if (moduleId.isDefined) y.filter(_.moduleId === moduleId) else y.filter(_.moduleId.isEmpty)), y => (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 => (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)) y => (if (libId.isDefined) y.filter(_.libraryId === libId) else y.filter(_.libraryId.isEmpty))
).foldLeft(stats.subquery)((a,b) => b(a)) )
val q = l.foldLeft(stats.subquery)((a,b) => b(a))
db.run(q.map(_.content).result).map(_.headOption.map(ConfigUtils.jsonTextToMap)) db.run(q.map(_.content).result).map(_.headOption.map(ConfigUtils.jsonTextToMap))
} }
...@@ -157,27 +159,29 @@ class SummaryDb(db: Database) { ...@@ -157,27 +159,29 @@ class SummaryDb(db: Database) {
def getSettings(runId: Option[Int] = None, pipelineId: Option[Int] = None, moduleId: Option[Option[Int]] = None, 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) = { sampleId: Option[Option[Int]] = None, libId: Option[Option[Int]] = None) = {
val q = List( val l: List[Option[Query[Settings, Settings#TableElementType, Seq] => Query[Settings, Settings#TableElementType, Seq]]] = List(
runId.map(x => (y:Query[Settings, Settings#TableElementType, Seq]) => y.filter(_.runId === x)), runId.map(x => y => y.filter(_.runId === x)),
pipelineId.map(x => (y:Query[Settings, Settings#TableElementType, Seq]) => y.filter(_.pipelineId === x)), pipelineId.map(x => y => 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))), moduleId.map(x => y => (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))), sampleId.map(x => y => (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))) libId.map(x => y => (if (x.isDefined) y.filter(_.libraryId === x) else y.filter(_.libraryId.isEmpty)))
).flatten.foldLeft(settings.subquery)((a,b) => b(a)) )
val q = l.flatten.foldLeft(settings.subquery)((a,b) => b(a))
db.run(q.result) db.run(q.result)
} }
def getSetting(runId: Int, pipelineId: Int, moduleId: Option[Int] = None, def getSetting(runId: Int, pipelineId: Int, moduleId: Option[Int] = None,
sampleId: Option[Int] = None, libId: Option[Int] = None): Future[Option[Map[String, Any]]] = { sampleId: Option[Int] = None, libId: Option[Int] = None): Future[Option[Map[String, Any]]] = {
val q = List( val l: List[Query[Settings, Settings#TableElementType, Seq] => Query[Settings, Settings#TableElementType, Seq]] = List(
(y:Query[Settings, Settings#TableElementType, Seq]) => y.filter(_.runId === runId), _.filter(_.runId === runId),
(y:Query[Settings, Settings#TableElementType, Seq]) => y.filter(_.pipelineId === pipelineId), _.filter(_.pipelineId === pipelineId),
(y:Query[Settings, Settings#TableElementType, Seq]) => (if (moduleId.isDefined) y.filter(_.moduleId === moduleId) else y.filter(_.moduleId.isEmpty)), y => (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 => (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)) y => (if (libId.isDefined) y.filter(_.libraryId === libId) else y.filter(_.libraryId.isEmpty))
).foldLeft(settings.subquery)((a,b) => b(a)) )
val q = l.foldLeft(settings.subquery)((a,b) => b(a))
db.run(q.map(_.content).result).map(_.headOption.map(ConfigUtils.jsonTextToMap)) 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