Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
id("org.jlleitschuh.gradle.ktlint") version "12.1.2"
}

version = "1.0.4"
version = "1.0.5"

group = "com.github.kiolk.typingplugin"

Expand Down Expand Up @@ -35,15 +35,9 @@ dependencies {
intellijPlatform {
pluginConfiguration {
name = "Typing Training"
description =
"""
Improved stability and usability.
- Added ability to drag typing dialog to any position on the screen.
- Improved stability.
""".trimIndent()
changeNotes =
"""
- Added ability to drag typing dialog to any position on the screen.
- Fixed incorrect representation of the time on the final statistic dialog.
- Improved stability.
""".trimIndent()
ideaVersion {
Expand Down
21 changes: 17 additions & 4 deletions src/main/kotlin/com/github/kiolk/typingplugin/ui/TypingDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class TypingDialog(private val project: Project, private val sourceCode: String)

private fun showStatistics() {
val endTime = System.currentTimeMillis()
val totalTimeSeconds = (endTime - startTime) / 1000.0
val totalTimeSeconds = if (startTime != 0L) (endTime - startTime) / 1000.0 else 0.0
val totalTimeMinutes = totalTimeSeconds / 60.0
val totalChars = sourceCode.length
val wpm = if (totalTimeMinutes > 0) (totalChars / 5.0) / totalTimeMinutes else 0.0
Expand All @@ -234,9 +234,22 @@ class TypingDialog(private val project: Project, private val sourceCode: String)
0.0
}

val statsMessage = "Typing Finished!\n\nTime: ${"%.1f".format(
totalTimeSeconds,
)}s\nWPM: ${"%.1f".format(wpm)}\nAccuracy: ${"%.1f".format(accuracy)}%\nErrors: $errorCount"
val timeFormatted = formatTime(totalTimeSeconds)

val statsMessage = "Typing Finished!\n\nTime: $timeFormatted\nWPM: ${"%.1f".format(
wpm,
)}\nAccuracy: ${"%.1f".format(accuracy)}%\nErrors: $errorCount"
Messages.showInfoMessage(project, statsMessage, "Session Summary")
}

companion object {
fun formatTime(totalTimeSeconds: Double): String {
if (totalTimeSeconds >= 60) {
val minutes = totalTimeSeconds.toInt() / 60
val seconds = totalTimeSeconds % 60
return "${minutes}m ${"%.1f".format(seconds)}s"
}
return "${"%.1f".format(totalTimeSeconds)}s"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ class TypingDialogTest : BasePlatformTestCase() {
assertEquals(Color.GREEN, StyleConstants.getForeground(attrsSpace))
}

@Test
fun testFormatTime() {
assertEquals("0.0s", TypingDialog.formatTime(0.0))
assertEquals("30.0s", TypingDialog.formatTime(30.0))
assertEquals("59.9s", TypingDialog.formatTime(59.9))
assertEquals("1m 0.0s", TypingDialog.formatTime(60.0))
assertEquals("1m 5.4s", TypingDialog.formatTime(65.4))
assertEquals("2m 5.4s", TypingDialog.formatTime(125.4))
assertEquals("10m 0.0s", TypingDialog.formatTime(600.0))
}

private fun simulateType(char: Char) {
val keyEvent = KeyEvent(textPane, KeyEvent.KEY_TYPED, System.currentTimeMillis(), 0, KeyEvent.VK_UNDEFINED, char)
textPane.keyListeners.forEach { it.keyTyped(keyEvent) }
Expand Down
Loading