Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagohm committed Jun 19, 2024
2 parents 764ae13 + 6f848ab commit 66b2f8e
Show file tree
Hide file tree
Showing 205 changed files with 23,462 additions and 18,772 deletions.
16 changes: 14 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
.PHONY: build install
.PHONY: api desktop build install

build:
ifeq ($(OS),Windows_NT)
api:
gradlew.bat api:bootJar

desktop:
cd desktop && npm run electron:build
else
api:
./gradlew api:bootJar

desktop:
cd desktop && npm run electron:build:deb

install:
sudo dpkg -i desktop/release/nebulosa_0.1.0_amd64.deb
endif

build: api desktop
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ data class TPPATask(
)

private val alignment = ThreePointPolarAlignment(solver, longitude, latitude)
private val cameraCaptureTask = CameraCaptureTask(camera, cameraRequest, exposureMaxRepeat = 1)
private val cameraCaptureTask = CameraCaptureTask(camera, cameraRequest, mount = mount)
private val settleDelayTask = DelayTask(SETTLE_TIME)
private val mountMoveState = BooleanArray(3)
private val elapsedTime = Stopwatch()
Expand Down Expand Up @@ -110,10 +110,10 @@ data class TPPATask(
rightAscension = mount?.rightAscension ?: 0.0
declination = mount?.declination ?: 0.0

camera.snoop(camera.snoopedDevices.filter { it !is Mount } + mount)

cancellationToken.listenToPause(this)

cameraCaptureTask.initialize(cancellationToken)

while (!cancellationToken.isCancelled) {
if (cancellationToken.isPaused) {
pausing.set(false)
Expand Down Expand Up @@ -151,7 +151,7 @@ data class TPPATask(
sendEvent(TPPAState.EXPOSURING)

// CAPTURE.
cameraCaptureTask.execute(cancellationToken)
cameraCaptureTask.executeOnce(cancellationToken)

if (cancellationToken.isCancelled || savedImage == null) {
break
Expand Down Expand Up @@ -236,6 +236,8 @@ data class TPPATask(
}
}

cameraCaptureTask.finalize(cancellationToken)

pausing.set(false)
cancellationToken.unlistenToPause(this)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package nebulosa.api.atlas

import nebulosa.api.notifications.NotificationEvent

sealed interface SatelliteUpdateNotificationEvent : NotificationEvent.System {

data object Started : SatelliteUpdateNotificationEvent, NotificationEvent.Info {

override val body = "Satellite database is being updated"
}

data class Finished(private val numberOfSatellites: Int) : SatelliteUpdateNotificationEvent, NotificationEvent.Success {

override val body = "Satellite database was updated: $numberOfSatellites satellites"
}
}
11 changes: 3 additions & 8 deletions api/src/main/kotlin/nebulosa/api/atlas/SatelliteUpdateTask.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package nebulosa.api.atlas

import nebulosa.api.messages.MessageService
import nebulosa.api.notifications.NotificationEvent
import nebulosa.api.preferences.PreferenceService
import nebulosa.log.loggerFor
import okhttp3.OkHttpClient
Expand All @@ -19,12 +18,6 @@ class SatelliteUpdateTask(
private val messageService: MessageService,
) : Runnable {

data class UpdateFinished(val numberOfSatellites: Int) : NotificationEvent {

override val type = "SATELLITE.UPDATE_FINISHED"
override val body = "%d satellites was updated".format(numberOfSatellites)
}

@Scheduled(fixedDelay = UPDATE_INTERVAL, timeUnit = TimeUnit.MILLISECONDS)
override fun run() {
checkIsOutOfDateAndUpdate()
Expand Down Expand Up @@ -52,6 +45,8 @@ class SatelliteUpdateTask(
private fun updateTLEs(): Boolean {
satelliteRepository.deleteAll()

messageService.sendMessage(SatelliteUpdateNotificationEvent.Started)

val data = HashMap<Long, SatelliteEntity>(16384)
val tasks = ArrayList<CompletableFuture<*>>(SatelliteGroupType.entries.size)

Expand All @@ -66,7 +61,7 @@ class SatelliteUpdateTask(
return satelliteRepository
.save(data.values)
.also { LOG.info("{} satellites updated", it.size) }
.also { messageService.sendMessage(UpdateFinished(it.size)) }
.also { messageService.sendMessage(SatelliteUpdateNotificationEvent.Finished(it.size)) }
.isNotEmpty()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package nebulosa.api.atlas

import nebulosa.api.notifications.NotificationEvent

sealed interface SkyAtlasUpdateNotificationEvent : NotificationEvent.System {

data object Started : SkyAtlasUpdateNotificationEvent, NotificationEvent.Info {

override val body = "Sky Atlas database is being updated"
}

data class Finished(private val version: String) : SkyAtlasUpdateNotificationEvent, NotificationEvent.Success {

override val body = "Sky Atlas database was updated: $version"
}

data object Failed : SkyAtlasUpdateNotificationEvent, NotificationEvent.Error {

override val body = "Sky Atlas database update failed"
}
}
98 changes: 30 additions & 68 deletions api/src/main/kotlin/nebulosa/api/atlas/SkyAtlasUpdateTask.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package nebulosa.api.atlas

import nebulosa.api.messages.MessageService
import nebulosa.api.notifications.NotificationEvent
import nebulosa.api.preferences.PreferenceService
import nebulosa.log.loggerFor
import okhttp3.OkHttpClient
Expand All @@ -19,92 +18,55 @@ class SkyAtlasUpdateTask(
private val messageService: MessageService,
) : Runnable {

data object UpdateStarted : NotificationEvent {

override val type = "SKY_ATLAS.UPDATE_STARTED"
override val body = "Sky Atlas database is being updated"
}

data class ProgressChanged(val progress: Int) : NotificationEvent {

override val type = "SKY_ATLAS.PROGRESS_CHANGED"
override val body = "Sky Atlas database is updating"
override val silent = true
}

data object UpdateFinished : NotificationEvent {

override val type = "SKY_ATLAS.UPDATE_FINISHED"
override val body = "Sky Atlas database was updated"
}

data object UpdateFailed : NotificationEvent {

override val type = "SKY_ATLAS.UPDATE_FINISHED"
override val body = "Sky Atlas database update failed"
override val severity = NotificationEvent.Severity.ERROR
}

@Scheduled(fixedDelay = Long.MAX_VALUE, timeUnit = TimeUnit.SECONDS)
override fun run() {
var needsUpdate = false
var request = Request.Builder().get().url(VERSION_URL).build()

try {
httpClient.newCall(request).execute().use { response ->
if (response.isSuccessful) {
val newestVersion = response.body!!.string().trim()

if (newestVersion != preferenceService.getText(VERSION_KEY) || simbadEntityRepository.isEmpty()) {
needsUpdate = true
httpClient.newCall(request).execute().use { response ->
if (response.isSuccessful) {
val newestVersion = response.body!!.string().trim()

LOG.info("Sky Atlas database is out of date. Downloading...")
if (newestVersion != preferenceService.getText(VERSION_KEY) || simbadEntityRepository.isEmpty()) {
LOG.info("Sky Atlas database is out of date. Downloading...")

messageService.sendMessage(UpdateStarted)
messageService.sendMessage(SkyAtlasUpdateNotificationEvent.Started)

var finished = false
var finished = false

for (i in 0 until MAX_DATA_COUNT) {
if (finished) break
for (i in 0 until MAX_DATA_COUNT) {
if (finished) break

val url = DATA_URL.format(i)
request = Request.Builder().get().url(url).build()
val url = DATA_URL.format(i)
request = Request.Builder().get().url(url).build()

messageService.sendMessage(ProgressChanged(i))

httpClient.newCall(request).execute().use {
if (it.isSuccessful) {
it.body!!.byteStream().source().use { source ->
SimbadDatabaseReader(source).use { reader ->
for (entity in reader) {
simbadEntityRepository.save(entity)
}
httpClient.newCall(request).execute().use {
if (it.isSuccessful) {
it.body!!.byteStream().source().use { source ->
SimbadDatabaseReader(source).use { reader ->
for (entity in reader) {
simbadEntityRepository.save(entity)
}
}
} else if (it.code == 404) {
finished = true
} else {
messageService.sendMessage(UpdateFailed)

LOG.error("Failed to download. url={}, code={}", url, it.code)
return
}
} else if (it.code == 404) {
finished = true
} else {
messageService.sendMessage(SkyAtlasUpdateNotificationEvent.Failed)

LOG.error("Failed to download. url={}, code={}", url, it.code)
return
}
}
}

preferenceService.putText(VERSION_KEY, newestVersion)
messageService.sendMessage(UpdateFinished)
preferenceService.putText(VERSION_KEY, newestVersion)
messageService.sendMessage(SkyAtlasUpdateNotificationEvent.Finished(newestVersion))

LOG.info("Sky Atlas database was updated. version={}, size={}", newestVersion, simbadEntityRepository.size)
} else {
LOG.info("Sky Atlas database is up to date. version={}, size={}", newestVersion, simbadEntityRepository.size)
}
LOG.info("Sky Atlas database was updated. version={}, size={}", newestVersion, simbadEntityRepository.size)
} else {
LOG.info("Sky Atlas database is up to date. version={}, size={}", newestVersion, simbadEntityRepository.size)
}
}
} finally {
if (needsUpdate) {
messageService.sendMessage(ProgressChanged(100))
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.databind.SerializerProvider
import com.fasterxml.jackson.databind.ser.std.StdSerializer
import nebulosa.curve.fitting.*
import nebulosa.nova.almanac.evenlySpacedNumbers
import nebulosa.math.evenlySpacedNumbers
import org.springframework.stereotype.Component
import kotlin.math.max
import kotlin.math.min
Expand Down
Loading

0 comments on commit 66b2f8e

Please sign in to comment.