deleted lib, realized graphic building

This commit is contained in:
ZhigalskiiIvan 2023-03-30 16:15:22 +03:00
parent 0bc2c199d6
commit 39451d99ab
30 changed files with 29 additions and 12 deletions

View File

@ -8,10 +8,15 @@ version = '1.0-SNAPSHOT'
repositories { repositories {
mavenCentral() mavenCentral()
} }
dependencies { dependencies {
implementation("org.jetbrains.lets-plot:lets-plot-kotlin:4.0.0") implementation("org.jetbrains.lets-plot:lets-plot-kotlin:4.0.0")
implementation("org.jetbrains.lets-plot:lets-plot-batik:3.1.0")
implementation("org.jetbrains.lets-plot:lets-plot-jfx:3.1.0")
implementation("org.slf4j:slf4j-nop:1.7.29")
implementation("org.jetbrains.lets-plot:lets-plot-image-export:3.1.0")
testImplementation 'org.jetbrains.kotlin:kotlin-test' testImplementation 'org.jetbrains.kotlin:kotlin-test'
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,12 +1,12 @@
import java.io.File import java.io.File
import kotlin.system.exitProcess import kotlin.system.exitProcess
import org.jetbrains.letsPlot.* import org.jetbrains.letsPlot.*
import org.jetbrains.letsPlot.geom.geomBar import org.jetbrains.letsPlot.export.ggsave
import org.jetbrains.letsPlot.intern.Plot import org.jetbrains.letsPlot.geom.*
import kotlin.reflect.typeOf import kotlin.reflect.typeOf
/** Singleton object which gives statistics of saved texts. /** Gives statistics of saved texts.
*/ */
class StatisticBuilder { class StatisticBuilder {
@ -36,12 +36,11 @@ class StatisticBuilder {
"console" -> printStatisticsInConsole(text.getName(), wordsCountsMap.toMap()) "console" -> printStatisticsInConsole(text.getName(), wordsCountsMap.toMap())
"graphic" -> buildGraphic(text.getName(), wordsCountsMap.toMap()) "graphic" -> buildGraphic(text.getName(), wordsCountsMap.toMap())
"both" -> { "both" -> {
buildGraphic(text.getName(), wordsCountsMap.toMap())
printStatisticsInConsole(text.getName(), wordsCountsMap.toMap()) printStatisticsInConsole(text.getName(), wordsCountsMap.toMap())
buildGraphic(text.getName(), wordsCountsMap.toMap())
} }
} }
} }
/** It builds bar chart with data of mapOfSentenceNumToItsSize. /** It builds bar chart with data of mapOfSentenceNumToItsSize.
@ -50,10 +49,25 @@ class StatisticBuilder {
*/ */
private fun buildGraphic(textName: String, mapOfSentenceNumToItsSize: Map<Int, Int>) { private fun buildGraphic(textName: String, mapOfSentenceNumToItsSize: Map<Int, Int>) {
val plot: Plot = val data = mapOf(
ggplot(mapOfSentenceNumToItsSize) + ggsize(1000, 600) + geomBar { x = "sentence number"; y = "words count" } "words count" to mapOfSentenceNumToItsSize.map { it.value.toFloat() / mapOfSentenceNumToItsSize.size },
)
TODO("вил би сун") val fig = ggplot(data) +
geomBar(
color = "white",
fill = "red"
) { x = "words count" } +
geomArea(
stat = Stat.density(),
color = "white",
fill = "pink",
alpha = 0.4
) { x = "words count" } +
ggsize(1400, 800)
println("Graphic was save in ${ggsave(fig, "$textName.png")}")
fig.show()
} }
@ -361,14 +375,13 @@ class CommandCenter(
private val statisticBuilder: StatisticBuilder private val statisticBuilder: StatisticBuilder
) { ) {
private val exitCommand = Command("exit", ::exit) private val exitCommand = Command("exit", ::exit)
private val addCommand = Command("add text") { textReader.readNewText(textData) } private val addCommand = Command("add text") { textReader.readNewText(textData) }
private val showStatisticsCommand = Command("show statistics") { statisticBuilder.getStatistics(textData) } private val showStatisticsCommand = Command("show statistics") { statisticBuilder.getStatistics(textData) }
private val removeTextCommand = Command("Remove text") { textData.removeText() } private val removeTextCommand = Command("remove text") { textData.removeText() }
private val commandsList = listOf(exitCommand, addCommand, showStatisticsCommand, removeTextCommand) private val commandsList = listOf(exitCommand, addCommand, showStatisticsCommand, removeTextCommand)
val commandsNames = commandsList.map { it.name } private val commandsNames = commandsList.map { it.name }
/** Enumerating of available commands names and functions conjugated /** Enumerating of available commands names and functions conjugated
* with them. * with them.
@ -472,7 +485,6 @@ inline fun <reified T> requestInput(
if (input == "return") return Pair(ReturnCommand(), "") if (input == "return") return Pair(ReturnCommand(), "")
try { try {
// inputT = input to typeOf<T>()
inputT = when (typeOf<T>()) { inputT = when (typeOf<T>()) {
typeOf<Int>() -> input.toInt() typeOf<Int>() -> input.toInt()
typeOf<Double>() -> input.toDouble() typeOf<Double>() -> input.toDouble()