소스 검색

Minor refactoring

Vadik Sirekanyan 4 년 전
부모
커밋
90ec2b1fde
4개의 변경된 파일19개의 추가작업 그리고 16개의 파일을 삭제
  1. 1 0
      .gitignore
  2. 3 0
      build.gradle.kts
  3. 13 14
      src/main/kotlin/com/sirekanyan/andersrobot/LetsPlot.kt
  4. 2 2
      src/main/kotlin/com/sirekanyan/andersrobot/config/Config.kt

+ 1 - 0
.gitignore

@@ -3,3 +3,4 @@
 /build
 /build
 /bot.properties
 /bot.properties
 /bot.properties.debug
 /bot.properties.debug
+/lets-plot-images

+ 3 - 0
build.gradle.kts

@@ -32,6 +32,9 @@ dependencies {
 
 
 application {
 application {
     mainClassName = "com.sirekanyan.andersrobot.Main"
     mainClassName = "com.sirekanyan.andersrobot.Main"
+    if (hasProperty("debug")) {
+        applicationDefaultJvmArgs = listOf("-Ddebug")
+    }
 }
 }
 
 
 tasks {
 tasks {

+ 13 - 14
src/main/kotlin/com/sirekanyan/andersrobot/LetsPlot.kt

@@ -37,28 +37,27 @@ fun plotForecast(forecast: Forecast, locale: Locale): Plot {
             scaleXContinuous("", breaks = xBreaks, labels = xLabels) +
             scaleXContinuous("", breaks = xBreaks, labels = xLabels) +
             scaleYContinuous("", breaks = yBreaks, format = "{d}°C") +
             scaleYContinuous("", breaks = yBreaks, format = "{d}°C") +
             geomVLine(data = mapOf("x" to xBreaks), linetype = "dotted") { xintercept = "x" } +
             geomVLine(data = mapOf("x" to xBreaks), linetype = "dotted") { xintercept = "x" } +
-            geomHLine(data = mapOf("y" to yBreaks), linetype = "dotted", color = Color.GRAY) { yintercept = "y" }
+            geomHLine(data = mapOf("y" to yBreaks), linetype = "dotted") { yintercept = "y" }
 }
 }
 
 
-private fun xBreaks(now: Long, times: List<Long>, offset: ZoneOffset): List<Long> {
-    val start = now.toLocalDateTime(offset).toLocalDate()
-    val end = times.maxOrNull()!!.toLocalDateTime(offset).toLocalDate()
+private fun xBreaks(now: Long, values: List<Long>, offset: ZoneOffset): List<Long> {
+    var br = now.toLocalDateTime(offset).toLocalDate().plusDays(1)
+    val end = checkNotNull(values.maxOrNull()).toLocalDateTime(offset).toLocalDate()
     val breaks = mutableListOf<Long>()
     val breaks = mutableListOf<Long>()
-    var b = start.plusDays(1)
-    while (b <= end) {
-        breaks.add(b.toEpochSecond(LocalTime.MIN, offset))
-        b = b.plusDays(1)
+    while (br <= end) {
+        breaks.add(br.toEpochSecond(LocalTime.MIN, offset))
+        br = br.plusDays(1)
     }
     }
     return breaks
     return breaks
 }
 }
 
 
-private fun yBreaks(temps: List<Double>): List<Int> {
-    var b = floor(checkNotNull(temps.minOrNull()) / 5).toInt() * 5
-    val end = ceil(checkNotNull(temps.maxOrNull()) / 5).toInt() * 5
+private fun yBreaks(values: List<Double>): List<Int> {
+    var br = floor(checkNotNull(values.minOrNull()) / 5).toInt() * 5
+    val end = ceil(checkNotNull(values.maxOrNull()) / 5).toInt() * 5
     val breaks = mutableListOf<Int>()
     val breaks = mutableListOf<Int>()
-    while (b <= end) {
-        breaks.add(b)
-        b += 5
+    while (br <= end) {
+        breaks.add(br)
+        br += 5
     }
     }
     return breaks
     return breaks
 }
 }

+ 2 - 2
src/main/kotlin/com/sirekanyan/andersrobot/config/Config.kt

@@ -3,8 +3,8 @@ package com.sirekanyan.andersrobot.config
 import java.io.File
 import java.io.File
 import java.util.*
 import java.util.*
 
 
-private const val DEBUG_SUFFIX = ""
-private const val CONFIG_FILE = "bot.properties$DEBUG_SUFFIX"
+private val IS_DEBUG = System.getProperty("debug") != null
+private val CONFIG_FILE = if (IS_DEBUG) "bot.properties.debug" else "bot.properties"
 
 
 object Config {
 object Config {