@@ -26,6 +26,8 @@ import kotlinx.coroutines.joinAll
26
26
import kotlinx.coroutines.launch
27
27
import kotlinx.coroutines.withContext
28
28
import kotlinx.coroutines.yield
29
+ import java.time.ZoneId
30
+ import java.time.ZonedDateTime
29
31
import kotlin.time.Duration
30
32
import kotlin.time.Duration.Companion.microseconds
31
33
import kotlin.time.Duration.Companion.milliseconds
@@ -39,6 +41,9 @@ private val cleanupScope = CoroutineScope(Dispatchers.IO)
39
41
const val BENCHMARK_WINDOW = 100
40
42
const val BENCHMARK_TIMEOUT_SECONDS = 5
41
43
const val BENCHMARK_TIMEOUT_OVERRIDE_ENV = " BENCHMARK_TIMEOUT_SECONDS"
44
+
45
+ var plotFlag = true
46
+
42
47
suspend fun main (args : Array <String >) {
43
48
logger.log(AocLogger .Main ) { " starting advent of code" }
44
49
AocDay .load()
@@ -59,6 +64,7 @@ suspend fun main(args: Array<String>) {
59
64
return @forEach
60
65
}
61
66
when (arg) {
67
+ " --no-plot" -> plotFlag = false
62
68
" all" -> addAll(AocDay .getAll().days())
63
69
" latest" -> AocDay .getAll(mostRecentYear).days().maxOrNull()?.also { add(it) }
64
70
else -> {
@@ -161,8 +167,10 @@ suspend fun runDay(day: Day) {
161
167
}
162
168
}
163
169
164
- cleanupScope.launch(start = CoroutineStart .LAZY ) {
165
- BenchmarkProgressPlotter (day).plot()
170
+ if (plotFlag) {
171
+ cleanupScope.launch(start = CoroutineStart .LAZY ) {
172
+ BenchmarkProgressPlotter (day).plot()
173
+ }
166
174
}
167
175
}
168
176
@@ -245,8 +253,10 @@ private suspend fun benchmark(
245
253
.microseconds
246
254
val lastBest = Results .getLastSubmittedBenchmarkResult(puzzle)
247
255
Results .send(BenchmarkResult (average, durations.size.toLong(), puzzle))
248
- cleanupScope.launch(start = CoroutineStart .LAZY ) {
249
- BenchmarkWindowPlotter (puzzle, BENCHMARK_WINDOW , durations).plot()
256
+ if (plotFlag) {
257
+ cleanupScope.launch(start = CoroutineStart .LAZY ) {
258
+ BenchmarkWindowPlotter (puzzle, BENCHMARK_WINDOW , durations).plot()
259
+ }
250
260
}
251
261
val styledCommand =
252
262
(TextStyles .italic + TextColors .blue)(" /aoc_benchmark day:${puzzle.day} part:${puzzle.part} time_milliseconds:${average.inWholeMicroseconds / 1000.0 } " )
@@ -261,12 +271,27 @@ private suspend fun benchmark(
261
271
} else if (average == lastSubmittedDuration) {
262
272
" ${TextColors .gray(" stayed the same" )} "
263
273
} else {
264
- " "
274
+ null
265
275
}
266
- } ? : " ${TextColors .brightBlue(" new(?)" )} "
276
+ }
277
+ val canReportWithDiscord = puzzle.year == ZonedDateTime .now(ZoneId .of(" CET" )).year
267
278
logger.log(
268
279
puzzle
269
- ) { " averaged at ${TextColors .brightWhite(average.toString())}$improvementText , report with: $styledCommand " }
280
+ ) {
281
+ buildString {
282
+ append(" averaged at ${TextColors .brightWhite(average.toString())} " )
283
+
284
+ if (improvementText != null ) {
285
+ append(improvementText)
286
+ } else if (canReportWithDiscord) {
287
+ append(" ${TextColors .brightBlue(" new(?)" )} " )
288
+ }
289
+
290
+ if (canReportWithDiscord) {
291
+ append(" , report with: $styledCommand " )
292
+ }
293
+ }
294
+ }
270
295
} catch (e: NotImplementedError ) {
271
296
logger.error(e = null , puzzle) { " not implemented" }
272
297
} catch (e: AocDay .DayNotReleasedException ) {
0 commit comments