Skip to content

Commit

Permalink
Merge pull request #911 from gemini-hlsw/sys-type
Browse files Browse the repository at this point in the history
Add program type system
  • Loading branch information
cquiroz committed Jun 18, 2024
2 parents c1f61b3 + 8afc227 commit e0abb58
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ThisBuild / tlBaseVersion := "0.99"
ThisBuild / tlBaseVersion := "0.100"
ThisBuild / tlCiReleaseBranches := Seq("master")
ThisBuild / githubWorkflowEnv += "MUNIT_FLAKY_OK" -> "true"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ enum ProgramType(val tag: String, val abbreviation: String) derives Enumerated:
case Library extends ProgramType("library", "LIB")
case Monitoring extends ProgramType("monitoring", "MON")
case Science extends ProgramType("science", "SCI")
case System extends ProgramType("system", "SYS")

object ProgramType {

Expand All @@ -27,4 +28,4 @@ object ProgramType {
given Ordering[ProgramType] =
Order[ProgramType].toOrdering

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,23 @@ object ProgramReference {
Format(s => parse.program.parseAll(s).toOption, _.label)
}

case class System(description: Description) extends ProgramReference {
override def programType: ProgramType = ProgramType.System

override def label: String =
s"${programType.abbreviation}-${description.value}"
}

object System {

given Order[System] =
Order.by(_.description.value)

val fromString: Prism[String, System] =
Prism[String, System](s => parse.system.parseAll(s).toOption)(_.label)

}

object parse {

import lucuma.core.enums.parser.EnumParsers.scienceSubtype
Expand Down Expand Up @@ -216,6 +233,9 @@ object ProgramReference {
Science(proposal, scienceSubtype)
}

val system: Parser[System] =
(string(s"SYS-") *> description).map { description => System(description) }

val programReference: Parser[ProgramReference] =
oneOf(
parse.program.backtrack ::
Expand All @@ -224,7 +244,8 @@ object ProgramReference {
parse.engineering.backtrack ::
parse.example.backtrack ::
parse.library.backtrack ::
parse.monitoring ::
parse.monitoring.backtrack ::
parse.system ::
Nil
)
}
Expand All @@ -251,10 +272,11 @@ object ProgramReference {
case (a @ Library(_, _), b @ Library(_, _)) => Order.compare(a, b)
case (a @ Monitoring(_, _, _), b @ Monitoring(_, _, _)) => Order.compare(a, b)
case (a @ Science(_, _), b @ Science(_, _)) => Order.compare(a, b)
case (a, b) => Order.compare(a.programType, b.programType)
case (a @ System(_), b @ System(_)) => Order.compare(a, b)
case (a, b) => Order.compare(a.programType, b.programType)
}

given Ordering[ProgramReference] =
Order[ProgramReference].toOrdering

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ trait ArbProgramReference extends ArbReference {
val engineeringStrings: Gen[String] =
referenceStrings[Engineering](_.label)

val calibrationLibraryStrings: Gen[String] =
referenceStrings[System](_.label)

given Arbitrary[Example] =
Arbitrary {
arbitrary[Instrument].map(Example.apply)
Expand Down Expand Up @@ -107,6 +110,12 @@ trait ArbProgramReference extends ArbReference {
given Cogen[Monitoring] =
cogSemesterlyInstrument[Monitoring]

given Arbitrary[System] =
Arbitrary(arbitrary[Description].map(System(_)))

given Cogen[System] =
Cogen[Description].contramap(_.description)

val monitoringStrings: Gen[String] =
referenceStrings[Monitoring](_.label)

Expand Down Expand Up @@ -136,7 +145,8 @@ trait ArbProgramReference extends ArbReference {
arbitrary[Example],
arbitrary[Library],
arbitrary[Monitoring],
arbitrary[Science]
arbitrary[Science],
arbitrary[System]
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ final class ProgramReferenceSuite extends munit.DisciplineSuite {
checkAll("Example.fromString", PrismTests(Example.fromString))
checkAll("Library.fromString", PrismTests(Library.fromString))
checkAll("Science.fromString", FormatTests(Science.fromString).formatWith(scienceStrings))
checkAll("System.fromString", PrismTests(System.fromString))

checkAll("ProgramReference", FormatTests(ProgramReference.fromString).formatWith(programReferenceStrings))
checkAll("ProgramReference", FormatTests(ProgramReference.fromString).formatWith(programReferenceStrings))
}

0 comments on commit e0abb58

Please sign in to comment.