All Downloads are FREE. Search and download functionalities are using the official Maven repository.

lucuma.itc.IntegrationTimeResult.scala Maven / Gradle / Ivy

There is a newer version: 0.22.3
Show newest version
// Copyright (c) 2016-2023 Association of Universities for Research in Astronomy, Inc. (AURA)
// For license information see LICENSE or https://opensource.org/licenses/BSD-3-Clause

package lucuma.itc

import io.circe.*
import io.circe.syntax.*
import lucuma.core.data.Zipper
import lucuma.core.data.ZipperCodec.given
import lucuma.core.syntax.string.*
import lucuma.itc.search.ObservingMode

sealed trait IntegrationTimeError extends RuntimeException {
  def message: String
}

case class SourceTooBright(halfWellTime: BigDecimal) extends IntegrationTimeError
    derives Encoder.AsObject {
  val message: String = f"Source too bright, well half filled in $halfWellTime%.2f seconds"
}

/** Generic calculation error */
case class CalculationError(msg: List[String]) extends IntegrationTimeError
    derives Encoder.AsObject {
  val message: String = msg.mkString("\n")
}

object CalculationError {
  def apply(msg: String): CalculationError = CalculationError(List(msg))
}

case class IntegrationTimeCalculationResult(
  serverVersion: String,
  dataVersion:   String,
  mode:          ObservingMode,
  results:       Zipper[IntegrationTime]
)

object IntegrationTimeCalculationResult:
  given Encoder[IntegrationTimeCalculationResult] =
    r =>
      Json
        .obj(
          "serverVersion" -> r.serverVersion.asJson,
          "dataVersion"   -> r.dataVersion.asJson,
          "mode"          -> r.mode.asJson
        )
        .deepMerge(r.results.asJson)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy