mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-03 11:17:25 +00:00
Various tweaks and minor refactoring, fixed issue #84
This commit is contained in:
1 parent
ec553bf429
commit
abb1bd4718
22 files changed
+321
-87
No files matched your search
@@ -56,9 +56,9 @@ class DataRepository(
|
||||
override fun updateFromFile(uri: String) {
|
||||
repositoryScope.launch(exceptionHandler) {
|
||||
_updateState.value = DataState.Loading
|
||||
fileSource.getDataStream(uri)?.let { fileStream ->
|
||||
fileSource.getDataStream(uri)?.let { stream ->
|
||||
delay(updateStateDelay)
|
||||
entrySource.insertEntries(importSatellites(fileStream))
|
||||
entrySource.insertEntries(importSatellites(stream))
|
||||
}
|
||||
_updateState.value = DataState.Success(0L)
|
||||
}
|
||||
@@ -67,23 +67,20 @@ class DataRepository(
|
||||
override fun updateFromWeb(urls: List<String>) {
|
||||
_updateState.value = DataState.Loading
|
||||
repositoryScope.launch(exceptionHandler) {
|
||||
val jobsMap = mutableMapOf<String, Deferred<InputStream?>>()
|
||||
val streamsMap = mutableMapOf<String, InputStream?>()
|
||||
val streams = mutableListOf<InputStream>()
|
||||
val entries = mutableListOf<SatEntry>()
|
||||
urls.forEach { jobsMap[it] = async { remoteSource.getDataStream(it) } }
|
||||
jobsMap.forEach { job -> streamsMap[job.key] = job.value.await() }
|
||||
streamsMap.forEach { stream ->
|
||||
stream.value?.let { inputStream ->
|
||||
val jobs = urls.associateWith { url -> async { remoteSource.getDataStream(url) } }
|
||||
jobs.mapValues { job -> job.value.await() }.forEach { result ->
|
||||
result.value?.let { stream ->
|
||||
when {
|
||||
stream.key.contains("=csv", true) -> {
|
||||
val tles = dataParser.parseCSVStream(inputStream)
|
||||
entries.addAll(tles.map { tle -> SatEntry(tle) })
|
||||
result.key.contains("=csv", true) -> {
|
||||
val orbitalData = dataParser.parseCSVStream(stream)
|
||||
entries.addAll(orbitalData.map { data -> SatEntry(data) })
|
||||
}
|
||||
stream.key.contains(".zip", true) -> {
|
||||
streams.add(ZipInputStream(inputStream).apply { nextEntry })
|
||||
result.key.contains(".zip", true) -> {
|
||||
streams.add(ZipInputStream(stream).apply { nextEntry })
|
||||
}
|
||||
else -> streams.add(inputStream)
|
||||
else -> streams.add(stream)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -113,6 +110,6 @@ class DataRepository(
|
||||
}
|
||||
|
||||
private suspend fun importSatellites(stream: InputStream): List<SatEntry> {
|
||||
return dataParser.parseTLEStream(stream).map { tle -> SatEntry(tle) }
|
||||
return dataParser.parseTLEStream(stream).map { data -> SatEntry(data) }
|
||||
}
|
||||
}
|
||||
@@ -33,13 +33,9 @@ data class OrbitalData(
|
||||
val omegao: Double = argper * DEG2RAD,
|
||||
val xmo: Double = meanan * DEG2RAD,
|
||||
val xno: Double = meanmo * TWO_PI / MIN_PER_DAY,
|
||||
val isDeepspace: Boolean = meanmo < 6.4
|
||||
val orbitalPeriod: Double = MIN_PER_DAY / meanmo,
|
||||
// Space objects are classified as NearEarth (period < 225 min) or DeepSpace (period >= 225 min)
|
||||
val isDeepSpace: Boolean = orbitalPeriod >= 225.0
|
||||
) {
|
||||
|
||||
fun createSat(): Satellite {
|
||||
return when {
|
||||
this.isDeepspace -> DeepSpaceSat(this)
|
||||
else -> NearEarthSat(this)
|
||||
}
|
||||
}
|
||||
fun getSatellite(): Satellite = if (isDeepSpace) DeepSpaceSat(this) else NearEarthSat(this)
|
||||
}
|
||||
@@ -31,5 +31,5 @@ data class SatPass(
|
||||
) {
|
||||
val catNum: Int = satellite.data.catnum
|
||||
val name: String = satellite.data.name
|
||||
val isDeepSpace: Boolean = satellite.data.isDeepspace
|
||||
val isDeepSpace: Boolean = satellite.data.isDeepSpace
|
||||
}
|
||||
@@ -47,7 +47,6 @@ abstract class Satellite(val data: OrbitalData) {
|
||||
private var gsPosTheta = 0.0
|
||||
private var julUTC = 0.0
|
||||
private var perigee = 0.0
|
||||
val orbitalPeriod = 24 * 60 / data.meanmo
|
||||
var qoms24 = 0.0
|
||||
var s4 = 0.0
|
||||
|
||||
@@ -108,7 +107,7 @@ abstract class Satellite(val data: OrbitalData) {
|
||||
}
|
||||
|
||||
private fun calculateSDP4orSGP4(tsince: Double) {
|
||||
if (data.isDeepspace) (this as DeepSpaceSat).calculateSDP4(tsince)
|
||||
if (data.isDeepSpace) (this as DeepSpaceSat).calculateSDP4(tsince)
|
||||
else (this as NearEarthSat).calculateSGP4(tsince)
|
||||
}
|
||||
|
||||
|
||||
@@ -118,13 +118,13 @@ class SatelliteManager(private val defaultDispatcher: CoroutineDispatcher) : ISa
|
||||
private fun Satellite.getPasses(pos: GeoPos, time: Long, hours: Int): List<SatPass> {
|
||||
val passes = mutableListOf<SatPass>()
|
||||
val endDate = time + hours * 60L * 60L * 1000L
|
||||
val quarterOrbitMin = (this.orbitalPeriod / 4.0).toInt()
|
||||
val quarterOrbitMin = (this.data.orbitalPeriod / 4.0).toInt()
|
||||
var startDate = time
|
||||
var shouldRewind = true
|
||||
var lastAosDate: Long
|
||||
var count = 0
|
||||
if (this.willBeSeen(pos)) {
|
||||
if (this.data.isDeepspace) {
|
||||
if (this.data.isDeepSpace) {
|
||||
passes.add(getGeoPass(this, pos, time))
|
||||
} else {
|
||||
do {
|
||||
@@ -160,7 +160,7 @@ class SatelliteManager(private val defaultDispatcher: CoroutineDispatcher) : ISa
|
||||
}
|
||||
|
||||
private fun getLeoPass(sat: Satellite, pos: GeoPos, time: Long, rewind: Boolean): SatPass {
|
||||
val quarterOrbitMin = (sat.orbitalPeriod / 4.0).toInt()
|
||||
val quarterOrbitMin = (sat.data.orbitalPeriod / 4.0).toInt()
|
||||
var calendarTimeMillis = time
|
||||
var elevation: Double
|
||||
var maxElevation = 0.0
|
||||
|
||||
Reference in new issue
Block a user