Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagohm committed Oct 23, 2023
2 parents cb956f8 + 8f29923 commit d8e9143
Show file tree
Hide file tree
Showing 101 changed files with 2,055 additions and 774 deletions.
5 changes: 2 additions & 3 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import org.springframework.boot.gradle.tasks.bundling.BootJar

plugins {
kotlin("jvm")
id("org.springframework.boot") version "3.1.4"
id("org.springframework.boot") version "3.1.5"
id("io.spring.dependency-management") version "1.1.3"
kotlin("plugin.spring")
kotlin("kapt")
Expand Down Expand Up @@ -32,8 +32,7 @@ dependencies {
implementation(libs.eventbus)
implementation(libs.apache.codec)
implementation(libs.rx)
// implementation(libs.sqlite)
runtimeOnly(files("$projectDir/libs/sqlite-jdbc-3.43.0.0.jar"))
implementation(libs.sqlite)
implementation(libs.flyway)
implementation("org.springframework.boot:spring-boot-starter")
implementation("org.springframework.boot:spring-boot-starter-web")
Expand Down
Binary file modified api/data/dsos.json.gz
Binary file not shown.
Binary file modified api/data/stars.json.gz
Binary file not shown.
1 change: 0 additions & 1 deletion api/libs/.gitignore

This file was deleted.

18 changes: 0 additions & 18 deletions api/libs/README.md

This file was deleted.

Binary file removed api/libs/sqlite-jdbc-3.43.0.0.jar
Binary file not shown.
14 changes: 12 additions & 2 deletions api/src/main/kotlin/nebulosa/api/atlas/AtlasController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class AtlasController(

@GetMapping("stars")
fun searchStar(
@RequestParam @Valid @NotBlank text: String,
@RequestParam(required = false, defaultValue = "") text: String,
@RequestParam(required = false, defaultValue = "") rightAscension: String,
@RequestParam(required = false, defaultValue = "") declination: String,
@RequestParam(required = false, defaultValue = "0.0") radius: Double,
Expand All @@ -117,6 +117,11 @@ class AtlasController(
constellation, magnitudeMin, magnitudeMax, type,
)

@GetMapping("stars/types")
fun starTypes(): List<SkyObjectType> {
return atlasService.starTypes
}

@GetMapping("dsos/{dso}/position")
fun positionOfDSO(
@EntityBy dso: DeepSkyObjectEntity,
Expand All @@ -138,7 +143,7 @@ class AtlasController(

@GetMapping("dsos")
fun searchDSO(
@RequestParam @Valid @NotBlank text: String,
@RequestParam(required = false, defaultValue = "") text: String,
@RequestParam(required = false, defaultValue = "") rightAscension: String,
@RequestParam(required = false, defaultValue = "") declination: String,
@RequestParam(required = false, defaultValue = "0.0") radius: Double,
Expand All @@ -151,6 +156,11 @@ class AtlasController(
constellation, magnitudeMin, magnitudeMax, type,
)

@GetMapping("dsos/types")
fun dsoTypes(): List<SkyObjectType> {
return atlasService.dsoTypes
}

@GetMapping("satellites/{satellite}/position")
fun positionOfSatellite(
@EntityBy satellite: SatelliteEntity,
Expand Down
18 changes: 13 additions & 5 deletions api/src/main/kotlin/nebulosa/api/atlas/AtlasService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class AtlasService(
private val positions = HashMap<LocationEntity, GeographicPosition>()
@Volatile private var sunImage = ByteArray(0)

val starTypes by lazy { starRepository.types() }

val dsoTypes by lazy { deepSkyObjectRepository.types() }

fun imageOfSun(output: HttpServletResponse) {
output.contentType = "image/png"
output.outputStream.write(sunImage)
Expand Down Expand Up @@ -154,7 +158,7 @@ class AtlasService(
}

fun altitudePointsOfSatellite(location: LocationEntity, satellite: SatelliteEntity, date: LocalDate, stepSize: Int): List<DoubleArray> {
val ephemeris = bodyEphemeris("TLE@$${satellite.tle}", location, LocalDateTime.of(date, LocalTime.now()))
val ephemeris = bodyEphemeris("TLE@${satellite.tle}", location, LocalDateTime.of(date, LocalTime.now()))
return altitudePointsOfBody(ephemeris, stepSize)
}

Expand All @@ -181,10 +185,11 @@ class AtlasService(
magnitudeMin: Double = -SkyObject.UNKNOWN_MAGNITUDE, magnitudeMax: Double = SkyObject.UNKNOWN_MAGNITUDE,
type: SkyObjectType? = null,
) = starRepository.search(
text,
text.replace(INVALID_DSO_CHARS, "").replace("][", "").ifBlank { null },
rightAscension, declination, radius,
constellation,
magnitudeMin.clampMagnitude(), magnitudeMax.clampMagnitude(), type
magnitudeMin.clampMagnitude(), magnitudeMax.clampMagnitude(), type,
Pageable.ofSize(5000),
)

fun searchDSO(
Expand All @@ -194,10 +199,11 @@ class AtlasService(
magnitudeMin: Double = -SkyObject.UNKNOWN_MAGNITUDE, magnitudeMax: Double = SkyObject.UNKNOWN_MAGNITUDE,
type: SkyObjectType? = null,
) = deepSkyObjectRepository.search(
text,
text.replace(INVALID_DSO_CHARS, "").replace("][", "").ifBlank { null },
rightAscension, declination, radius,
constellation,
magnitudeMin.clampMagnitude(), magnitudeMax.clampMagnitude(), type
magnitudeMin.clampMagnitude(), magnitudeMax.clampMagnitude(), type,
Pageable.ofSize(5000),
)

@Scheduled(fixedDelay = 15, timeUnit = TimeUnit.MINUTES)
Expand All @@ -224,6 +230,8 @@ class AtlasService(
private const val SUN = "10"
private const val MOON = "301"

@JvmStatic private val INVALID_DSO_CHARS = Regex("[^\\w\\-\\s\\[\\].+]+")

@JvmStatic
private fun Double.clampMagnitude(): Double {
return if (this in -29.9..29.9) this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ interface DeepSkyObjectRepository : JpaRepository<DeepSkyObjectEntity, Long> {
type: SkyObjectType? = null,
pageable: Pageable = Pageable.unpaged(),
): List<DeepSkyObjectEntity>

@Query("SELECT DISTINCT dso.type FROM DeepSkyObjectEntity dso")
fun types(): List<SkyObjectType>
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import kotlin.io.path.outputStream

@Component
@ThreadedTask
class IERSThreadedTask(
class IERSUpdateTask(
private val dataPath: Path,
private val httpClient: OkHttpClient,
) : Runnable {
Expand Down Expand Up @@ -49,6 +49,6 @@ class IERSThreadedTask(

companion object {

@JvmStatic private val LOG = loggerFor<IERSThreadedTask>()
@JvmStatic private val LOG = loggerFor<IERSUpdateTask>()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import java.util.concurrent.CompletableFuture

@Component
@ThreadedTask
class SatelliteThreadedTask(
class SatelliteUpdateTask(
private val httpClient: OkHttpClient,
private val configRepository: ConfigRepository,
private val satelliteRepository: SatelliteRepository,
Expand Down Expand Up @@ -104,6 +104,6 @@ class SatelliteThreadedTask(
const val TLE_UPDATED_AT = "TLE_UPDATED_AT"
const val UPDATE_INTERVAL = 1000L * 60 * 60 * 24 // 1 day

@JvmStatic private val LOG = loggerFor<SatelliteThreadedTask>()
@JvmStatic private val LOG = loggerFor<SatelliteUpdateTask>()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import kotlin.io.path.inputStream

@Component
@ThreadedTask
class AtlasDatabaseThreadedTask(
class SkyAtlasUpdateTask(
private val objectMapper: ObjectMapper,
private val configRepository: ConfigRepository,
private val starsRepository: StarRepository,
Expand All @@ -29,6 +29,8 @@ class AtlasDatabaseThreadedTask(
val databaseVersion = configRepository.text(DATABASE_VERSION_KEY)

if (databaseVersion != DATABASE_VERSION) {
LOG.info("Star/DSO database is out of date. currentVersion={}, newVersion={}", databaseVersion, DATABASE_VERSION)

starsRepository.deleteAllInBatch()
deepSkyObjectRepository.deleteAllInBatch()

Expand Down Expand Up @@ -97,9 +99,9 @@ class AtlasDatabaseThreadedTask(

companion object {

const val DATABASE_VERSION = "2023.10.05"
const val DATABASE_VERSION = "2023.10.18"
const val DATABASE_VERSION_KEY = "DATABASE_VERSION"

@JvmStatic private val LOG = loggerFor<AtlasDatabaseThreadedTask>()
@JvmStatic private val LOG = loggerFor<SkyAtlasUpdateTask>()
}
}
3 changes: 3 additions & 0 deletions api/src/main/kotlin/nebulosa/api/atlas/StarRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ interface StarRepository : JpaRepository<StarEntity, Long> {
type: SkyObjectType? = null,
pageable: Pageable = Pageable.unpaged(),
): List<StarEntity>

@Query("SELECT DISTINCT star.type FROM StarEntity star")
fun types(): List<SkyObjectType>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package nebulosa.api.atlas.ephemeris
import nebulosa.horizons.HorizonsElement
import nebulosa.horizons.HorizonsQuantity
import nebulosa.horizons.HorizonsService
import nebulosa.horizons.NonUniqueObjectException
import nebulosa.log.loggerFor
import nebulosa.nova.position.GeographicPosition
import nebulosa.sbd.SmallBody
import org.springframework.stereotype.Service
Expand Down Expand Up @@ -44,7 +46,7 @@ class HorizonsEphemerisProvider(private val horizonsService: HorizonsService) :
startTime, endTime,
extraPrecision = true,
quantities = QUANTITIES,
)
).execute()
}
is String -> {
if (target.startsWith("TLE@")) {
Expand All @@ -55,24 +57,39 @@ class HorizonsEphemerisProvider(private val horizonsService: HorizonsService) :
startTime, endTime,
extraPrecision = true,
quantities = QUANTITIES,
)
).execute()
} else {
horizonsService
.observer(
target,
position.longitude, position.latitude, position.elevation,
startTime, endTime,
extraPrecision = true,
quantities = QUANTITIES,
)
try {
horizonsService
.observer(
target,
position.longitude, position.latitude, position.elevation,
startTime, endTime,
extraPrecision = true,
quantities = QUANTITIES,
).execute()
} catch (e: NonUniqueObjectException) {
LOG.warn("non unique object. target={}, matches={}", target, e.recordItems)

horizonsService
.observer(
"$target;CAP;NOFRAG".replace(";;", ";"),
position.longitude, position.latitude, position.elevation,
startTime, endTime,
extraPrecision = true,
quantities = QUANTITIES,
).execute()
}
}
}
else -> return emptyList()
}.execute().body() ?: emptyList()
}.body() ?: emptyList()
}

companion object {

@JvmStatic private val LOG = loggerFor<HorizonsEphemerisProvider>()

@JvmStatic private val QUANTITIES = arrayOf(
HorizonsQuantity.ASTROMETRIC_RA, HorizonsQuantity.ASTROMETRIC_DEC,
HorizonsQuantity.APPARENT_RA, HorizonsQuantity.APPARENT_DEC,
Expand Down
11 changes: 11 additions & 0 deletions api/src/main/kotlin/nebulosa/api/image/CoordinateInterpolation.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package nebulosa.api.image

import java.time.LocalDateTime

@Suppress("ArrayInDataClass")
data class CoordinateInterpolation(
val ma: DoubleArray,
val md: DoubleArray,
val x0: Int, val y0: Int, val x1: Int, val y1: Int,
val delta: Int, val date: LocalDateTime?,
)
5 changes: 5 additions & 0 deletions api/src/main/kotlin/nebulosa/api/image/ImageController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,9 @@ class ImageController(
downsampleFactor, pathOrUrl, apiKey,
)
}

@GetMapping("coordinate-interpolation")
fun coordinateInterpolation(@RequestParam path: Path): CoordinateInterpolation? {
return imageService.coordinateInterpolation(path)
}
}
Loading

0 comments on commit d8e9143

Please sign in to comment.