Fixing the bug, pleeeeease
This commit is contained in:
parent
e942f1e0bc
commit
4cf5f3f449
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,3 +2,5 @@ target
|
|||||||
*.iml
|
*.iml
|
||||||
.idea
|
.idea
|
||||||
data
|
data
|
||||||
|
stars.svg
|
||||||
|
*.log
|
||||||
|
|||||||
@ -58,7 +58,10 @@ class HygParser {
|
|||||||
dec = it[dec].toDouble(),
|
dec = it[dec].toDouble(),
|
||||||
mag = it[mag].toDouble(),
|
mag = it[mag].toDouble(),
|
||||||
absmag = it[absmag].toDouble(),
|
absmag = it[absmag].toDouble(),
|
||||||
properName = it[proper]
|
properName = it[proper],
|
||||||
|
colorIndex = it[ci],
|
||||||
|
bayerFlamsteed = it[bf],
|
||||||
|
constellationAbbreviation = it[con]
|
||||||
)
|
)
|
||||||
}.stream()
|
}.stream()
|
||||||
|
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
data class HygStar(val ra: Double, val dec: Double, val mag: Double, val absmag: Double, val properName: String?)
|
data class HygStar(val ra: Double, val dec: Double, val mag: Double, val absmag: Double, val properName: String?, val colorIndex: String, val bayerFlamsteed: String, val constellationAbbreviation: String)
|
||||||
@ -7,11 +7,14 @@ import com.singulariti.os.ephemeris.domain.Star
|
|||||||
import com.singulariti.os.ephemeris.utils.StarCatalog
|
import com.singulariti.os.ephemeris.utils.StarCatalog
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileReader
|
import java.io.FileReader
|
||||||
|
import java.time.Duration
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.time.ZoneId
|
import java.time.ZoneId
|
||||||
import java.time.ZonedDateTime
|
import java.time.ZonedDateTime
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
import java.util.stream.Stream
|
import java.util.stream.Stream
|
||||||
|
import javax.xml.datatype.DatatypeConstants.HOURS
|
||||||
import kotlin.math.absoluteValue
|
import kotlin.math.absoluteValue
|
||||||
|
|
||||||
|
|
||||||
@ -25,17 +28,26 @@ import kotlin.math.absoluteValue
|
|||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
// set the place and time you want
|
// set the place and time you want
|
||||||
val starPositionCalculator = StarPositionCalculator()
|
val starPositionCalculator = StarPositionCalculator()
|
||||||
|
|
||||||
val observatory = getObservatory()
|
val observatory = getObservatory()
|
||||||
|
|
||||||
// at least get this absolute magnitude (smaller is brighter)
|
// at least get this absolute magnitude (smaller is brighter) 6.5 = human vis
|
||||||
val apparentMagnitudeCutOff = 6.5
|
val apparentMagnitudeCutOff = 7
|
||||||
|
|
||||||
// make the svg file
|
// make the svg file
|
||||||
File("stars.svg").printWriter().use { out ->
|
File("stars.svg").printWriter().use { out ->
|
||||||
|
|
||||||
out.println(""" <svg width="180" height="180">
|
out.println(""" <svg width="180" height="180">
|
||||||
<style>
|
<style>
|
||||||
.properName { font: italic 0.3px sans-serif; stroke-width: 0.01px; stroke: white; fill: black }
|
.properName { font: italic 1px sans-serif; stroke-width: 0.03px; stroke: white; fill: black }
|
||||||
|
.constellationName { font: italic 0.2px sans-serif; stroke-width: 0.03px }
|
||||||
|
.colorClassO5V { fill: #f0f8ff }
|
||||||
|
.colorClassB0V { fill: #f2f6ff }
|
||||||
|
.colorClassA0V { fill: #effbff }
|
||||||
|
.colorClassF0V { fill: #fffffb }
|
||||||
|
.colorClassG0V { fill: #ffffce }
|
||||||
|
.colorClassK0V { fill: #fff8a0 }
|
||||||
|
.colorClassDefault { fill: white }
|
||||||
</style>
|
</style>
|
||||||
<circle cx="90" cy="90" r="90" stroke="white" stroke-width="1" fill="black" />""".trimIndent())
|
<circle cx="90" cy="90" r="90" stroke="white" stroke-width="1" fill="black" />""".trimIndent())
|
||||||
// history.forEach {
|
// history.forEach {
|
||||||
@ -44,11 +56,9 @@ fun main(args: Array<String>) {
|
|||||||
// second attempt
|
// second attempt
|
||||||
val calendarAstronomer = CalendarAstronomer(Date(Instant.parse("2018-10-05T10:15:30.00Z").toEpochMilli()))
|
val calendarAstronomer = CalendarAstronomer(Date(Instant.parse("2018-10-05T10:15:30.00Z").toEpochMilli()))
|
||||||
|
|
||||||
var maxAltitude = Double.NEGATIVE_INFINITY
|
val colorIndices = HashSet<String>()
|
||||||
var minAltitude = Double.POSITIVE_INFINITY
|
|
||||||
|
|
||||||
var maxMagnitude = Double.NEGATIVE_INFINITY
|
val casA = StarCatalog.byIdAndConstellation("a", "cas")
|
||||||
var minMagnitude = Double.POSITIVE_INFINITY
|
|
||||||
|
|
||||||
// read the hyg database...
|
// read the hyg database...
|
||||||
HygParser()
|
HygParser()
|
||||||
@ -59,17 +69,19 @@ fun main(args: Array<String>) {
|
|||||||
}
|
}
|
||||||
.forEach { star ->
|
.forEach { star ->
|
||||||
|
|
||||||
if (star.absmag < minMagnitude)
|
colorIndices.add(star.colorIndex)
|
||||||
minMagnitude = star.absmag
|
|
||||||
if (star.absmag > minMagnitude)
|
val convertDegreesToHoursMinutesSeconds = convertDecimalHoursToHMS(star.ra)
|
||||||
maxMagnitude = star.absmag
|
val convertDegreesToHoursMinutesSeconds1 = convertDecimalHoursToHMS(star.dec)
|
||||||
|
|
||||||
|
println("convertDegreesToHoursMinutesSeconds = ${convertDegreesToHoursMinutesSeconds} ${convertDegreesToHoursMinutesSeconds1}")
|
||||||
|
|
||||||
val star1 = Star(
|
val star1 = Star(
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
convertDegreesToHoursMinutesSeconds(star.ra),
|
convertDegreesToHoursMinutesSeconds,
|
||||||
convertDegreesToHoursMinutesSeconds(star.dec),
|
convertDegreesToHoursMinutesSeconds1,
|
||||||
star.mag.toInt().toString(),
|
star.mag.toInt().toString(),
|
||||||
null,
|
null,
|
||||||
null
|
null
|
||||||
@ -77,6 +89,7 @@ fun main(args: Array<String>) {
|
|||||||
|
|
||||||
// print the star
|
// print the star
|
||||||
println("it = $star")
|
println("it = $star")
|
||||||
|
println(" > star1 = ${star1.ra} ${star1.de}")
|
||||||
|
|
||||||
val position = starPositionCalculator.getPosition(star1, observatory)
|
val position = starPositionCalculator.getPosition(star1, observatory)
|
||||||
// println("position = $position")
|
// println("position = $position")
|
||||||
@ -106,36 +119,64 @@ fun main(args: Array<String>) {
|
|||||||
y += 90
|
y += 90
|
||||||
x += 90
|
x += 90
|
||||||
|
|
||||||
|
// figure out the color
|
||||||
|
val colorClass = if (star.colorIndex.isNotEmpty()) {
|
||||||
|
star.colorIndex.toDouble().let {
|
||||||
|
when {
|
||||||
|
it <= -.33 -> "colorClassO5V"
|
||||||
|
it <= -.3 -> "colorClassB0V"
|
||||||
|
it <= -0.02 -> "colorClassA0V"
|
||||||
|
it <= 0.3 -> "colorClassF0V"
|
||||||
|
it <= 0.58 -> "colorClassG0V"
|
||||||
|
it <= 0.81 -> "colorClassK0V"
|
||||||
|
it <= 1.40 -> "colorClassM0V"
|
||||||
|
else -> "colorClassDefault"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
"colorClassDefault"
|
||||||
|
}
|
||||||
|
|
||||||
// determine the size of the circle -> depending on the apparent magnitude
|
// determine the size of the circle -> depending on the apparent magnitude
|
||||||
val circleR = ((star.mag - apparentMagnitudeCutOff) * -1) * 0.05
|
val circleR = ((star.mag - apparentMagnitudeCutOff) * -1) * 0.05
|
||||||
|
|
||||||
// print it to svg
|
// print it to svg
|
||||||
val random = Random()
|
val random = Random()
|
||||||
out.println("""<circle cx="${x}" cy="${y}" r="$circleR" fill="white"/>""")
|
out.println("""<circle cx="${x}" cy="${y}" r="$circleR" class="$colorClass"/>""")
|
||||||
|
|
||||||
// print name?
|
// print name?
|
||||||
if (star.properName?.isNotEmpty() == true) {
|
if (star.properName?.isNotEmpty() == true) {
|
||||||
out.println("""<text x="$x" y="$y" class="properName">${star.properName}</text>""")
|
out.println("""<text x="$x" y="$y" class="properName">${star.properName}</text>""")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (altitude < minAltitude)
|
if (star.constellationAbbreviation?.isNotEmpty()) {
|
||||||
minAltitude = altitude
|
val col = when (star.constellationAbbreviation) {
|
||||||
if (altitude > maxAltitude)
|
"Dra" -> "red"
|
||||||
maxAltitude = altitude
|
"UMa" -> "green"
|
||||||
|
"Her" -> "blue"
|
||||||
|
else -> "white"
|
||||||
|
}
|
||||||
|
out.println("""<text x="$x" y="$y" class="constellationName" fill="$col" stroke="$col">${star.constellationAbbreviation}</text>""")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// println("skipping star... $altitude")
|
||||||
|
}
|
||||||
|
|
||||||
// filter the stars on altitude
|
// filter the stars on altitude
|
||||||
}
|
}
|
||||||
|
|
||||||
println("minAltitude = ${minAltitude}")
|
val minRaa = HygParser().parse().mapToDouble { star -> star.ra }.min()
|
||||||
println("maxAltitude = ${maxAltitude}")
|
println("minRa = ${minRaa}")
|
||||||
println("minMagnitude = ${minMagnitude}")
|
val maxRaa = HygParser().parse().mapToDouble { star -> star.ra }.max()
|
||||||
println("maxMagnitude = ${maxMagnitude}")
|
println("maxRa = ${maxRaa}")
|
||||||
|
val minDec = HygParser().parse().mapToDouble { star -> star.dec }.min()
|
||||||
|
println("minDec = ${minDec}")
|
||||||
|
val maxDec = HygParser().parse().mapToDouble { star -> star.dec }.max()
|
||||||
|
println("maxDec = ${maxDec}")
|
||||||
|
|
||||||
out.println("</svg>")
|
out.println("</svg>")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -155,23 +196,32 @@ fun dmsToRad(input: String): Double {
|
|||||||
* Default position: gontrodestraat
|
* Default position: gontrodestraat
|
||||||
*/
|
*/
|
||||||
fun getObservatory(name: String = "Default place name", latitude: Double = 51.027930, longitude: Double = 3.753585): Observatory {
|
fun getObservatory(name: String = "Default place name", latitude: Double = 51.027930, longitude: Double = 3.753585): Observatory {
|
||||||
val time = ZonedDateTime.of(2018, 10, 5, 16, 0, 0, 0, ZoneId.of("UTC")) //Date and time in UTC
|
val time = ZonedDateTime.of(2018, 10, 5, 19, 0, 0, 0, ZoneId.of("UTC")) //Date and time in UTC
|
||||||
val place = Place(name, latitude, Pole.NORTH, longitude, Pole.EAST, TimeZone.getTimeZone("Asia/Calcutta"), "", "")
|
val place = Place(name, latitude, Pole.NORTH, longitude, Pole.EAST, TimeZone.getTimeZone("Asia/Calcutta"), "", "")
|
||||||
return Observatory(place, time)
|
return Observatory(place, time)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert 2.39483 degrees to X:Y:Z, X hours, Y minutes, Z seconds
|
* Convert 21.9384 hours to X:Y:Z, X hours, Y minutes, Z seconds
|
||||||
*/
|
*/
|
||||||
fun convertDegreesToHoursMinutesSeconds(degrees: Double): String {
|
fun convertDecimalHoursToHMS(degrees: Double): String {
|
||||||
val hours = Math.floor(degrees).toInt()
|
// what's the sign?
|
||||||
val minutesWithRest = (degrees - hours) * 60
|
val sign = if(degrees<0) "-" else "+"
|
||||||
|
val input = degrees.absoluteValue
|
||||||
|
val hours = Math.floor(input).toInt()
|
||||||
|
val minutesWithRest = (input - hours) * 60
|
||||||
val minutes = Math.floor(minutesWithRest).toInt()
|
val minutes = Math.floor(minutesWithRest).toInt()
|
||||||
val seconds = (minutesWithRest - minutes) * 60
|
val seconds = ((minutesWithRest - minutes) * 60).toInt()
|
||||||
val result = "$hours:$minutes:$seconds"
|
val result = "${sign}$hours:$minutes:$seconds"
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert 25.5 degrees to 25 degrees, 5
|
||||||
|
*/
|
||||||
|
fun convertDecimalDegreesToDMS(degrees: Double): String {
|
||||||
|
return convertDecimalHoursToHMS(degrees)
|
||||||
|
}
|
||||||
|
|
||||||
fun testEphemeris() {
|
fun testEphemeris() {
|
||||||
|
|
||||||
@ -200,3 +250,7 @@ fun getDistanceFromLatLonInKm(lat1: Double, lon1: Double, lat2: Double, lon2: Do
|
|||||||
fun deg2rad(deg: Double): Double {
|
fun deg2rad(deg: Double): Double {
|
||||||
return deg * (Math.PI / 180)
|
return deg * (Math.PI / 180)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun hoursToDms(hours: Double) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
7
src/main/java/TestHoekskes.kt
Normal file
7
src/main/java/TestHoekskes.kt
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fun main(args: Array<String>) {
|
||||||
|
val h = convertDecimalHoursToHMS(-24.0)
|
||||||
|
println("h = ${h}")
|
||||||
|
|
||||||
|
val s = convertDecimalDegreesToDMS(-45.2)
|
||||||
|
println("s = ${s}")
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user