mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Extracted some logic to the core Predictor.kt class
This commit is contained in:
1 parent
b5da3d3ac4
commit
04c4ef25d2
3 files changed
+52
-59
No files matched your search
+9
-23
@@ -41,9 +41,16 @@ class PassesViewModel @Inject constructor(
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
predictor.passes.collect { passes ->
|
||||
predictor.calculatedPasses.collect { passes ->
|
||||
passesProcessing?.cancelAndJoin()
|
||||
passesProcessing = viewModelScope.launch { tickPasses(passes) }
|
||||
passesProcessing = viewModelScope.launch {
|
||||
while (isActive) {
|
||||
val time = System.currentTimeMillis()
|
||||
val newPasses = predictor.processPasses(passes, time)
|
||||
_passes.postValue(DataState.Success(newPasses))
|
||||
delay(1000)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,25 +77,4 @@ class PassesViewModel @Inject constructor(
|
||||
settings.setHoursAhead(hoursAhead)
|
||||
settings.setMinElevation(minElevation)
|
||||
}
|
||||
|
||||
private suspend fun tickPasses(passes: List<SatPass>) = withContext(Dispatchers.Default) {
|
||||
var currentPasses = passes
|
||||
while (isActive) {
|
||||
val timeNow = System.currentTimeMillis()
|
||||
currentPasses.forEach { pass ->
|
||||
if (!pass.isDeepSpace) {
|
||||
val timeStart = pass.aosTime
|
||||
if (timeNow > timeStart) {
|
||||
val deltaNow = timeNow.minus(timeStart).toFloat()
|
||||
val deltaTotal = pass.losTime.minus(timeStart).toFloat()
|
||||
pass.progress = ((deltaNow / deltaTotal) * 100).toInt()
|
||||
}
|
||||
}
|
||||
}
|
||||
currentPasses = currentPasses.filter { it.progress < 100 }
|
||||
val passesCopy = currentPasses.map { it.copy() }
|
||||
_passes.postValue(DataState.Success(passesCopy))
|
||||
delay(1000)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,7 @@ class RadarViewModel @Inject constructor(
|
||||
val orientation: LiveData<Triple<Float, Float, Float>> = _orientation
|
||||
|
||||
fun getPass(catNum: Int, aosTime: Long) = liveData {
|
||||
predictor.passes.collect { passes ->
|
||||
predictor.calculatedPasses.collect { passes ->
|
||||
val pass = passes.find { it.catNum == catNum && it.aosTime == aosTime }
|
||||
pass?.let { satPass ->
|
||||
emit(satPass)
|
||||
@@ -105,21 +105,13 @@ class RadarViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun processTransmitters(satPass: SatPass) {
|
||||
private fun processTransmitters(pass: SatPass) {
|
||||
viewModelScope.launch {
|
||||
val transmitters = dataRepository.getTransmitters(satPass.catNum)
|
||||
val transmitters = dataRepository.getTransmitters(pass.catNum)
|
||||
while (isActive) {
|
||||
val satPos = predictor.getSatPos(satPass.satellite, stationPos, Date().time)
|
||||
val copiedList = transmitters.map { it.copy() }
|
||||
copiedList.forEach { transmitter ->
|
||||
transmitter.downlink?.let {
|
||||
transmitter.downlink = satPos.getDownlinkFreq(it)
|
||||
}
|
||||
transmitter.uplink?.let {
|
||||
transmitter.uplink = satPos.getUplinkFreq(it)
|
||||
}
|
||||
}
|
||||
_transmitters.postValue(copiedList.map { it.copy() })
|
||||
val time = System.currentTimeMillis()
|
||||
val list = predictor.processRadios(pass.satellite, stationPos, transmitters, time)
|
||||
_transmitters.postValue(list)
|
||||
delay(1000)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user