mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Fixed csv data parser bug, now showing correct data
This commit is contained in:
1 parent
738aa1132a
commit
f48a46d0e4
2 files changed
+14
-9
No files matched your search
@@ -82,12 +82,13 @@ class DataParser(private val parserDispatcher: CoroutineDispatcher) {
|
||||
val year = values[2].substring(0, 4)
|
||||
val month = values[2].substring(5, 7)
|
||||
val dayOfMonth = values[2].substring(8, 10)
|
||||
val day = getDayOfYear(year.toInt(), month.toInt(), dayOfMonth.toInt())
|
||||
val hour = values[2].substring(11, 13).toInt() * 3600000000 // microseconds in one hour
|
||||
val min = values[2].substring(14, 16).toInt() * 60000000 // microseconds in one minute
|
||||
val sec = values[2].substring(17, 19).toInt() * 1000000 // microseconds in one second
|
||||
val microsec = values[2].substring(20, 26).toInt()
|
||||
val frac = ((hour + min + sec + microsec) / 86400000000.0).toString()
|
||||
val dayInt = getDayOfYear(year.toInt(), month.toInt(), dayOfMonth.toInt())
|
||||
val day = if (dayInt < 10) "00$dayInt" else if (dayInt < 100) "0$dayInt" else "$dayInt"
|
||||
val hour = values[2].substring(11, 13).toInt() * 3600000 // ms in one hour
|
||||
val min = values[2].substring(14, 16).toInt() * 60000 // ms in one minute
|
||||
val sec = values[2].substring(17, 19).toInt() * 1000 // ms in one second
|
||||
val ms = values[2].substring(20, 26).toInt() / 1000.0 // microseconds to ms
|
||||
val frac = ((hour + min + sec + ms) / 86400000.0).toString()
|
||||
val epoch = "${year.substring(2)}$day${frac.substring(1)}".toDouble()
|
||||
val meanmo = values[3].toDouble()
|
||||
val eccn = values[4].toDouble()
|
||||
@@ -151,9 +152,7 @@ class DataParser(private val parserDispatcher: CoroutineDispatcher) {
|
||||
var dayOfYear = dayOfMonth
|
||||
// If leap year increment Feb days
|
||||
if (((year / 4 == 0) && (year / 100 != 0)) || (year / 400 == 0)) daysArray[1]++
|
||||
for (i in 0 until month - 1) {
|
||||
dayOfYear += daysArray[i]
|
||||
}
|
||||
for (i in 0 until month - 1) { dayOfYear += daysArray[i] }
|
||||
return dayOfYear
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ class DataParserTest {
|
||||
private val validCSVStream = """
|
||||
OBJECT_NAME,OBJECT_ID,EPOCH,MEAN_MOTION,ECCENTRICITY,INCLINATION,RA_OF_ASC_NODE,ARG_OF_PERICENTER,MEAN_ANOMALY,EPHEMERIS_TYPE,CLASSIFICATION_TYPE,NORAD_CAT_ID,ELEMENT_SET_NO,REV_AT_EPOCH,BSTAR,MEAN_MOTION_DOT,MEAN_MOTION_DDOT
|
||||
ISS (ZARYA),1998-067A,2021-11-16T12:28:09.322176,15.48582035,.0004694,51.6447,309.4881,203.6966,299.8876,0,U,25544,999,31220,.31985E-4,.1288E-4,0
|
||||
FLTSATCOM 8 (USA 46),1989-077A,2022-01-07T11:37:38.074080,1.00273350,.0001114,12.9044,1.3272,91.5769,260.4200,0,U,20253,999,24434,0,-.85E-6,0
|
||||
""".trimIndent().byteInputStream()
|
||||
private val invalidCSVStream = """
|
||||
ISS (ZARYA),1998-067A,2021-11-16T12:28:09.322176,15.48582035,.0004694,51.6447,309.4881,203.6966,299.8876,0,U,25544,999,31220,.31985E-4,.1288E-4,0
|
||||
@@ -39,6 +40,9 @@ class DataParserTest {
|
||||
ISS (ZARYA)
|
||||
1 25544U 98067A 21320.51955234 .00001288 00000+0 31985-4 0 9990
|
||||
2 25544 51.6447 309.4881 0004694 203.6966 299.8876 15.48582035312205
|
||||
FLTSATCOM 8 (USA 46)
|
||||
1 20253U 89077A 22007.48446845 -.00000085 00000+0 00000+0 0 9999
|
||||
2 20253 12.9044 1.3272 0001114 91.5769 260.4200 1.00273350244345
|
||||
""".trimIndent().byteInputStream()
|
||||
private val invalidTLEStream = """
|
||||
1 25544U 98067A 21320.51955234 .00001288 00000+0 31985-4 0 9990
|
||||
@@ -79,6 +83,8 @@ class DataParserTest {
|
||||
fun `Given valid data streams parsed results match`() = runBlockingTest {
|
||||
val csvResult = dataParser.parseCSVStream(validCSVStream)
|
||||
val tleResult = dataParser.parseTLEStream(validTLEStream)
|
||||
println(csvResult)
|
||||
println(tleResult)
|
||||
assert(csvResult == tleResult)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user