From ba84104c45419b8de8861f8b9505068df3627465 Mon Sep 17 00:00:00 2001 From: tiagohm Date: Thu, 22 Aug 2024 19:02:28 -0300 Subject: [PATCH] [api][desktop]: Fix Sky Atlas manual date & time ephemeris --- .../nebulosa/api/atlas/SkyAtlasController.kt | 24 +++++++++---------- .../nebulosa/api/atlas/SkyAtlasService.kt | 24 +++++++++---------- desktop/src/app/atlas/atlas.component.html | 4 ++-- desktop/src/app/atlas/atlas.component.ts | 10 ++++++-- desktop/src/shared/services/api.service.ts | 20 ++++++++-------- 5 files changed, 44 insertions(+), 38 deletions(-) diff --git a/api/src/main/kotlin/nebulosa/api/atlas/SkyAtlasController.kt b/api/src/main/kotlin/nebulosa/api/atlas/SkyAtlasController.kt index 4d33c76fd..2fd6608b5 100644 --- a/api/src/main/kotlin/nebulosa/api/atlas/SkyAtlasController.kt +++ b/api/src/main/kotlin/nebulosa/api/atlas/SkyAtlasController.kt @@ -38,10 +38,10 @@ class SkyAtlasController( @GetMapping("sun/altitude-points") fun altitudePointsOfSun( @LocationParam location: Location, - @DateAndTimeParam date: LocalDate, + @DateAndTimeParam dateTime: LocalDateTime, @RequestParam(required = false, defaultValue = "1") @Valid @Min(1) stepSize: Int, @RequestParam(required = false, defaultValue = "false") fast: Boolean, - ) = skyAtlasService.altitudePointsOfSun(location, date, stepSize, fast) + ) = skyAtlasService.altitudePointsOfSun(location, dateTime, stepSize, fast) @GetMapping("moon/position") fun positionOfMoon( @@ -53,10 +53,10 @@ class SkyAtlasController( @GetMapping("moon/altitude-points") fun altitudePointsOfMoon( @LocationParam location: Location, - @DateAndTimeParam date: LocalDate, + @DateAndTimeParam dateTime: LocalDateTime, @RequestParam(required = false, defaultValue = "1") @Valid @Min(1) stepSize: Int, @RequestParam(required = false, defaultValue = "false") fast: Boolean, - ) = skyAtlasService.altitudePointsOfMoon(location, date, stepSize, fast) + ) = skyAtlasService.altitudePointsOfMoon(location, dateTime, stepSize, fast) @GetMapping("planets/{code}/position") fun positionOfPlanet( @@ -70,10 +70,10 @@ class SkyAtlasController( fun altitudePointsOfPlanet( @PathVariable code: String, @LocationParam location: Location, - @DateAndTimeParam date: LocalDate, + @DateAndTimeParam dateTime: LocalDateTime, @RequestParam(required = false, defaultValue = "1") @Valid @Min(1) stepSize: Int, @RequestParam(required = false, defaultValue = "false") fast: Boolean, - ) = skyAtlasService.altitudePointsOfPlanet(location, code, date, stepSize, fast) + ) = skyAtlasService.altitudePointsOfPlanet(location, code, dateTime, stepSize, fast) @GetMapping("minor-planets") fun searchMinorPlanet(@RequestParam @Valid @NotBlank text: String) = skyAtlasService.searchMinorPlanet(text) @@ -96,9 +96,9 @@ class SkyAtlasController( fun altitudePointsOfSkyObject( @PathVariable id: Long, @LocationParam location: Location, - @DateAndTimeParam date: LocalDate, + @DateAndTimeParam dateTime: LocalDateTime, @RequestParam(required = false, defaultValue = "1") @Valid @Min(1) stepSize: Int, - ) = skyAtlasService.altitudePointsOfSkyObject(location, id, date, stepSize) + ) = skyAtlasService.altitudePointsOfSkyObject(location, id, dateTime, stepSize) @GetMapping("sky-objects") fun searchSkyObject( @@ -130,9 +130,9 @@ class SkyAtlasController( fun altitudePointsOfSatellite( satellite: SatelliteEntity, @LocationParam location: Location, - @DateAndTimeParam date: LocalDate, + @DateAndTimeParam dateTime: LocalDateTime, @RequestParam(required = false, defaultValue = "1") @Valid @Min(1) stepSize: Int, - ) = skyAtlasService.altitudePointsOfSatellite(location, satellite, date, stepSize) + ) = skyAtlasService.altitudePointsOfSatellite(location, satellite, dateTime, stepSize) @GetMapping("satellites") fun searchSatellites( @@ -144,9 +144,9 @@ class SkyAtlasController( @GetMapping("twilight") fun twilight( @LocationParam location: Location, - @DateAndTimeParam date: LocalDate, + @DateAndTimeParam dateTime: LocalDateTime, @RequestParam(required = false, defaultValue = "false") fast: Boolean, - ) = skyAtlasService.twilight(location, date, fast) + ) = skyAtlasService.twilight(location, dateTime, fast) @GetMapping("moon/phase") fun moonPhase( diff --git a/api/src/main/kotlin/nebulosa/api/atlas/SkyAtlasService.kt b/api/src/main/kotlin/nebulosa/api/atlas/SkyAtlasService.kt index 09ef7334b..cfb037731 100644 --- a/api/src/main/kotlin/nebulosa/api/atlas/SkyAtlasService.kt +++ b/api/src/main/kotlin/nebulosa/api/atlas/SkyAtlasService.kt @@ -124,7 +124,7 @@ class SkyAtlasService( return satelliteRepository.search(text.ifBlank { null }, groups, id) } - fun twilight(location: GeographicCoordinate, date: LocalDate, fast: Boolean = false): Twilight { + fun twilight(location: GeographicCoordinate, dateTime: LocalDateTime, fast: Boolean = false): Twilight { val civilDusk = doubleArrayOf(0.0, 0.0) val nauticalDusk = doubleArrayOf(0.0, 0.0) val astronomicalDusk = doubleArrayOf(0.0, 0.0) @@ -133,7 +133,7 @@ class SkyAtlasService( val nauticalDawn = doubleArrayOf(0.0, 0.0) val civilDawn = doubleArrayOf(0.0, 0.0) - val ephemeris = bodyEphemeris(if (fast) VSOP87E.SUN else SUN, location, LocalDateTime.of(date, LocalTime.now(SystemClock)), true) + val ephemeris = bodyEphemeris(if (fast) VSOP87E.SUN else SUN, location, dateTime, true) val range = evenlySpacedNumbers(0.0, (ephemeris.size - 1).toDouble(), ephemeris.size) val result = findDiscrete(range, TwilightDiscreteFunction(ephemeris), 1.0) @@ -158,35 +158,35 @@ class SkyAtlasService( ) } - fun altitudePointsOfSun(location: GeographicCoordinate, date: LocalDate, stepSize: Int, fast: Boolean = false): List { - val ephemeris = bodyEphemeris(if (fast) VSOP87E.SUN else SUN, location, LocalDateTime.of(date, LocalTime.now(SystemClock)), true) + fun altitudePointsOfSun(location: GeographicCoordinate, dateTime: LocalDateTime, stepSize: Int, fast: Boolean = false): List { + val ephemeris = bodyEphemeris(if (fast) VSOP87E.SUN else SUN, location, dateTime, true) return altitudePointsOfBody(ephemeris, stepSize) } - fun altitudePointsOfMoon(location: GeographicCoordinate, date: LocalDate, stepSize: Int, fast: Boolean = false): List { - val ephemeris = bodyEphemeris(if (fast) FAST_MOON else MOON, location, LocalDateTime.of(date, LocalTime.now(SystemClock)), true) + fun altitudePointsOfMoon(location: GeographicCoordinate, dateTime: LocalDateTime, stepSize: Int, fast: Boolean = false): List { + val ephemeris = bodyEphemeris(if (fast) FAST_MOON else MOON, location, dateTime, true) return altitudePointsOfBody(ephemeris, stepSize) } fun altitudePointsOfPlanet( - location: GeographicCoordinate, code: String, date: LocalDate, + location: GeographicCoordinate, code: String, dateTime: LocalDateTime, stepSize: Int, fast: Boolean = false ): List { val target: Any = VSOP87E.entries.takeIf { fast }?.find { "${it.target}" == code } ?: code - val ephemeris = bodyEphemeris(target, location, LocalDateTime.of(date, LocalTime.now(SystemClock)), true) + val ephemeris = bodyEphemeris(target, location, dateTime, true) return altitudePointsOfBody(ephemeris, stepSize) } - fun altitudePointsOfSkyObject(location: GeographicCoordinate, id: Long, date: LocalDate, stepSize: Int): List { + fun altitudePointsOfSkyObject(location: GeographicCoordinate, id: Long, dateTime: LocalDateTime, stepSize: Int): List { val target = cachedSimbadEntities[id] ?: simbadEntityRepository.find(id) ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Cannot found sky object: [$id]") cachedSimbadEntities[id] = target - val ephemeris = bodyEphemeris(target, location, LocalDateTime.of(date, LocalTime.now(SystemClock)), true) + val ephemeris = bodyEphemeris(target, location, dateTime, true) return altitudePointsOfBody(ephemeris, stepSize) } - fun altitudePointsOfSatellite(location: GeographicCoordinate, satellite: SatelliteEntity, date: LocalDate, stepSize: Int): List { - val ephemeris = bodyEphemeris("TLE@${satellite.tle}", location, LocalDateTime.of(date, LocalTime.now(SystemClock)), true) + fun altitudePointsOfSatellite(location: GeographicCoordinate, satellite: SatelliteEntity, dateTime: LocalDateTime, stepSize: Int): List { + val ephemeris = bodyEphemeris("TLE@${satellite.tle}", location, dateTime, true) return altitudePointsOfBody(ephemeris, stepSize) } diff --git a/desktop/src/app/atlas/atlas.component.html b/desktop/src/app/atlas/atlas.component.html index 1043d2989..9eccdb077 100644 --- a/desktop/src/app/atlas/atlas.component.html +++ b/desktop/src/app/atlas/atlas.component.html @@ -873,8 +873,8 @@
this.moon.phase = res) + void this.api.moonPhase(dateTime).then((res) => (this.moon.phase = res)) const position = await this.api.positionOfMoon(dateTime, location) Object.assign(this.moon.position, position) } diff --git a/desktop/src/shared/services/api.service.ts b/desktop/src/shared/services/api.service.ts index 9958f0c91..1e63e22df 100644 --- a/desktop/src/shared/services/api.service.ts +++ b/desktop/src/shared/services/api.service.ts @@ -452,8 +452,8 @@ export class ApiService { } altitudePointsOfSun(dateTime: Date, location?: Location, fast: boolean = false) { - const date = extractDate(dateTime) - const query = this.http.query({ date, fast, hasLocation: location?.id || true }) + const [date, time] = extractDateTime(dateTime) + const query = this.http.query({ date, time, fast, hasLocation: location?.id || true }) return this.http.get<[number, number][]>(`sky-atlas/sun/altitude-points?${query}`) } @@ -464,8 +464,8 @@ export class ApiService { } altitudePointsOfMoon(dateTime: Date, location?: Location, fast: boolean = false) { - const date = extractDate(dateTime) - const query = this.http.query({ date, fast, hasLocation: location?.id || true }) + const [date, time] = extractDateTime(dateTime) + const query = this.http.query({ date, time, fast, hasLocation: location?.id || true }) return this.http.get<[number, number][]>(`sky-atlas/moon/altitude-points?${query}`) } @@ -476,8 +476,8 @@ export class ApiService { } altitudePointsOfPlanet(code: string, dateTime: Date, location?: Location, fast: boolean = false) { - const date = extractDate(dateTime) - const query = this.http.query({ date, fast, hasLocation: location?.id || true }) + const [date, time] = extractDateTime(dateTime) + const query = this.http.query({ date, time, fast, hasLocation: location?.id || true }) return this.http.get<[number, number][]>(`sky-atlas/planets/${encodeURIComponent(code)}/altitude-points?${query}`) } @@ -488,8 +488,8 @@ export class ApiService { } altitudePointsOfSkyObject(simbad: DeepSkyObject, dateTime: Date, location?: Location) { - const date = extractDate(dateTime) - const query = this.http.query({ date, hasLocation: location?.id || true }) + const [date, time] = extractDateTime(dateTime) + const query = this.http.query({ date, time, hasLocation: location?.id || true }) return this.http.get<[number, number][]>(`sky-atlas/sky-objects/${simbad.id}/altitude-points?${query}`) } @@ -511,8 +511,8 @@ export class ApiService { } altitudePointsOfSatellite(satellite: Satellite, dateTime: Date, location?: Location) { - const date = extractDate(dateTime) - const query = this.http.query({ date, hasLocation: location?.id || true }) + const [date, time] = extractDateTime(dateTime) + const query = this.http.query({ date, time, hasLocation: location?.id || true }) return this.http.get<[number, number][]>(`sky-atlas/satellites/${satellite.id}/altitude-points?${query}`) }