Skip to content

Instantly share code, notes, and snippets.

@hmrclt
Created January 9, 2018 16:04
Show Gist options
  • Save hmrclt/2bbf0fb1b02d2d68eaf8b0c491963674 to your computer and use it in GitHub Desktop.
Save hmrclt/2bbf0fb1b02d2d68eaf8b0c491963674 to your computer and use it in GitHub Desktop.
SDIL-prereg
object prereg {
def OptList[A](in: List[A]): List[Option[A]] =
None :: in.toList.map(Some(_))
object GG extends Enumeration { val CT, SA, SDIL = Value }
object Affinity extends Enumeration {
val Agent, Individual, Org_Admin, Org_Assistant, Other = Value
}
object PendingTable extends Enumeration {
val Pending, Overdue, ETMPError = Value
}
sealed trait Outcome
trait Reject extends Outcome
case object AlreadyEnrolled extends Reject
case object PendingEnrollment extends Reject
case class OtherReject(msg: String) extends Reject
case object Unaccounted extends Outcome
case class Error(msg: String) extends Outcome
case class Accept(utr: Boolean) extends Outcome
object AffinityCheck {
import Affinity._
def unapply(in: Option[Affinity.Value]): Option[Boolean] =
in match {
case Some(Individual) | Some(Org_Admin) => Some(true)
case _ => Some(false)
}
}
type Input = (
List[GG.Value],
Option[Affinity.Value],
Boolean,
Boolean,
Option[PendingTable.Value]
)
def outcome(input: Input): Outcome = input match {
case (gg, _, _, _, _) if gg contains GG.SDIL => AlreadyEnrolled
case (_, _, _, _ , Some(PendingTable.ETMPError)) => Error("Failed to submit to ETMP")
case (_, _, false, _, Some(_)) => Error("No ROSM record")
case (_, _, _, _, Some(_)) => PendingEnrollment
case (_, _, _, true, None) => OtherReject("Org enrolled with another user")
case (gg, AffinityCheck(false), _, _, _) => OtherReject("Bad User Type")
case (Nil | List(GG.CT, GG.SA), _, _, _, _) => Accept(false)
case (List(GG.CT) | List(GG.SA), _, _, _, _) => Accept(true)
case _ => Unaccounted
}
def allScenarios: List[Input] = for {
gg <- GG.values.toSet.subsets.map(_.toList).toList
affinity <- OptList(Affinity.values.toList)
rosm <- List(true,false)
etmp <- List(true,false)
pTable <- OptList(PendingTable.values.toList)
} yield {
(gg, affinity, rosm, etmp, pTable)
}
def allScenariosWOutcome = allScenarios.map{x => (x,outcome(x))}
def tablerow(in: Input): String = {
def opt[A](in: Option[A]): String = in match {
case Some(x) => x.toString
case None => "-"
}
def bool(in: Boolean): String =
if (in) "✓" else "-"
in match {
case (gg, affinity, rosm, etmp, pTable) =>
csv(gg.mkString(","), opt(affinity), bool(rosm), bool(etmp), opt(pTable), outcome(in).toString)
}
}
def csv(in: String*): String =
in.map{x => '"'.toString + x + '"'}.mkString(",")
def main(in: Array[String]): Unit = {
val text = {
csv("Gov Gateway","Affinity","ROSM","DES/ETMP","Pending Table","Outcome") ::
allScenarios.map(tablerow)
}.mkString("\n")
import java.io._
val file = new File("outcomes.csv")
val bw = new BufferedWriter(new FileWriter(file))
bw.write(text)
bw.close()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment