Skip to content

Commit

Permalink
wip scatter plot as separate, finetuning
Browse files Browse the repository at this point in the history
  • Loading branch information
meikpiep committed Sep 14, 2024
1 parent 0e05a21 commit 2d5319d
Show file tree
Hide file tree
Showing 29 changed files with 228 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ class StatisticsActivity : AppCompatActivity() {
val fragment =
StatisticsMultiDiagramFragment(
scatterPlotDiagramFragment,
difficultyDiagramFragment,
// difficultyDiagramFragment,
durationDiagramFragment,
)

multiDiagramFragment = fragment
ft.replace(binding.multiDiagramFrame!!.id, fragment)
} else {
binding.scatterPlotCardView?.let { ft.replace(it.id, scatterPlotDiagramFragment) }
binding.overallDifficultyCardView?.let { ft.replace(it.id, difficultyDiagramFragment) }
binding.overallDurationCardView?.let { ft.replace(it.id, durationDiagramFragment) }
}

binding.overallStreaksCardView.let { ft.replace(it.id, streaksDiagramFragment) }
binding.overallDifficultyCardView?.let { ft.replace(it.id, difficultyDiagramFragment) }
binding.overallStreaksCardView?.let { ft.replace(it.id, streaksDiagramFragment) }

ft.commit()
}
Expand Down Expand Up @@ -104,7 +104,7 @@ class StatisticsActivity : AppCompatActivity() {
binding.multiDiagramFrame?.visibility = View.INVISIBLE
binding.overallDifficultyCardView?.visibility = View.INVISIBLE
binding.overallDurationCardView?.visibility = View.INVISIBLE
binding.overallStreaksCardView.visibility = View.INVISIBLE
binding.overallStreaksCardView?.visibility = View.INVISIBLE
}

private fun solveRate(): Double =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@ class StatisticsMultiDiagramFragment() : Fragment(R.layout.fragment_statistics_m
lateinit var binding: FragmentStatisticsMultiDiagramBinding

private var scatterPlotDiagramFragment: StatisticsScatterPlotDiagramFragment? = null
private var difficultyDiagramFragment: StatisticsDifficultyDiagramFragment? = null
private var durationDiagramFragment: StatisticsDurationDiagramFragment? = null

constructor(
scatterPlotDiagramFragment: StatisticsScatterPlotDiagramFragment,
difficultyDiagramFragment: StatisticsDifficultyDiagramFragment,
durationDiagramFragment: StatisticsDurationDiagramFragment,
) : this() {
this.scatterPlotDiagramFragment = scatterPlotDiagramFragment
this.difficultyDiagramFragment = difficultyDiagramFragment
this.durationDiagramFragment = durationDiagramFragment
}

Expand All @@ -36,9 +33,6 @@ class StatisticsMultiDiagramFragment() : Fragment(R.layout.fragment_statistics_m
scatterPlotDiagramFragment?.let {
ft.replace(binding.multiDiagramFrameScatterPlot.id, it)
}
difficultyDiagramFragment?.let {
ft.replace(binding.multiDiagramFrameDifficultyPlot.id, it)
}
durationDiagramFragment?.let {
ft.replace(binding.multiDiagramFrameDurationPlot.id, it)
}
Expand All @@ -48,13 +42,13 @@ class StatisticsMultiDiagramFragment() : Fragment(R.layout.fragment_statistics_m
if (isChecked) {
binding.multiDiagramFrameScatterPlot.visibility =
if (checkedId == binding.toggleGroupButtonScatterPlot.id) View.VISIBLE else View.GONE
binding.multiDiagramFrameDifficultyPlot.visibility =
if (checkedId == binding.toggleGroupButtonDifficulty.id) View.VISIBLE else View.GONE
binding.multiDiagramFrameDurationPlot.visibility =
if (checkedId == binding.toggleGroupButtonDuration.id) View.VISIBLE else View.GONE
}
}

binding.toggleGroupMultiDiagram.check(binding.toggleGroupButtonScatterPlot.id)

return binding.root
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@ import com.androidplot.util.PixelUtils
import com.androidplot.xy.BoundaryMode
import com.androidplot.xy.LineAndPointFormatter
import com.androidplot.xy.SimpleXYSeries
import com.androidplot.xy.XYGraphWidget
import com.google.android.material.color.MaterialColors
import org.koin.android.ext.android.inject
import org.koin.core.component.KoinComponent
import org.piepmeyer.gauguin.R
import org.piepmeyer.gauguin.Utils
import org.piepmeyer.gauguin.databinding.FragmentStatisticsScatterPlotDiagramBinding
import org.piepmeyer.gauguin.preferences.StatisticsManager
import java.text.FieldPosition
import java.text.Format
import java.text.ParsePosition
import kotlin.math.nextUp
import kotlin.math.roundToInt
import kotlin.time.Duration.Companion.seconds

class StatisticsScatterPlotDiagramFragment :
Fragment(R.layout.fragment_statistics_scatter_plot_diagram),
Expand All @@ -30,6 +38,18 @@ class StatisticsScatterPlotDiagramFragment :
): View {
binding = FragmentStatisticsScatterPlotDiagramBinding.inflate(inflater, parent, false)

if (statisticsManager
.statistics()
.overall.solvedDuration
.isNotEmpty()
) {
createPlot()
}

return binding.root
}

private fun createPlot() {
val series = SimpleXYSeries(null)

statisticsManager
Expand All @@ -39,6 +59,24 @@ class StatisticsScatterPlotDiagramFragment :
.associateWith { statisticsManager.statistics().overall.solvedDifficulty[it.index] }
.forEach { (difficulty, duration) -> series.addLast(difficulty.value, duration) }

val maximumDuration =
statisticsManager
.statistics()
.overall.solvedDuration
.max()
.coerceAtLeast(60)
val roundedMaximumDuration = ((maximumDuration * 1.2) / 60.0).nextUp().roundToInt() * 60

val maximumDifficulty =
statisticsManager
.statistics()
.overall.solvedDifficulty
.max()
.nextUp()
.toInt()
.coerceAtLeast(10)
val roundedMaximumDifficulty = ((maximumDifficulty * 1.2) / 20.0).nextUp().roundToInt() * 20

PixelUtils.init(context)

val formatter = LineAndPointFormatter()
Expand All @@ -49,14 +87,38 @@ class StatisticsScatterPlotDiagramFragment :
MaterialColors.getColor(binding.scatterPlot, com.google.android.material.R.attr.colorSecondary)
formatter.vertexPaint.strokeWidth = 10f * 2.5f

binding.scatterPlot.setDomainBoundaries(0, 80, BoundaryMode.FIXED)
binding.scatterPlot.setRangeBoundaries(0, 100, BoundaryMode.FIXED)
binding.scatterPlot
.setDomainBoundaries(0, roundedMaximumDuration, BoundaryMode.FIXED)
binding.scatterPlot
.setRangeBoundaries(0, roundedMaximumDifficulty, BoundaryMode.FIXED)
binding.scatterPlot.linesPerRangeLabel = 2
binding.scatterPlot.rangeStepValue = 9.0
binding.scatterPlot.linesPerDomainLabel = 2
binding.scatterPlot.domainStepValue = 9.0
binding.scatterPlot.addSeries(series, formatter)

return binding.root
binding.scatterPlot.graph
.getLineLabelStyle(XYGraphWidget.Edge.BOTTOM)
.format =
object : Format() {
override fun format(
obj: Any,
toAppendTo: StringBuffer,
pos: FieldPosition?,
): StringBuffer {
val value = Math.round((obj as Number).toFloat())

return toAppendTo.append(Utils.displayableGameDuration(value.seconds))
}

override fun parseObject(
source: String?,
pos: ParsePosition?,
): Any? {
// unused
return null
}
}

binding.scatterPlot.addSeries(series, formatter)
}
}
75 changes: 55 additions & 20 deletions gauguin-app/src/main/res/layout-land/activity_statistics.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,22 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideLinePuzzleNumbers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.5"/>

<TextView
android:id="@+id/startedstat"
style="@style/TextAppearance.Material3.DisplaySmall"
style="@style/TextAppearance.Material3.DisplayMedium"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="@id/guideLinePuzzleNumbers"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.5"
android:layout_marginBottom="32dp"
android:textAlignment="center"
/>

Expand All @@ -48,21 +56,23 @@
android:layout_height="wrap_content"
android:text="@string/statistics_puzzles_started"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="@id/guideLinePuzzleNumbers"
app:layout_constraintTop_toBottomOf="@id/startedstat"
app:layout_constraintWidth_percent="0.5"
android:textAlignment="center"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
/>

<TextView
android:id="@+id/solvedstat"
style="@style/TextAppearance.Material3.DisplaySmall"
style="@style/TextAppearance.Material3.DisplayMedium"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="@id/guideLinePuzzleNumbers"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.5"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="32dp"
android:textAlignment="center"
/>

Expand All @@ -72,11 +82,11 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/statistics_puzzles_solved"
app:layout_constraintStart_toStartOf="@id/guideLinePuzzleNumbers"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/solvedstat"
app:layout_constraintWidth_percent="0.5"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:textAlignment="center"
/>

Expand All @@ -85,19 +95,33 @@
</com.google.android.material.card.MaterialCardView>

<FrameLayout
android:id="@+id/multiDiagramFrame"
android:id="@+id/overallDifficultyCardView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_gravity="fill"
android:layout_columnWeight="10"
android:layout_columnWeight="4"
android:layout_rowWeight="7"
android:layout_margin="8dp"
android:layout_column="0"
android:layout_columnSpan="10"
android:layout_columnSpan="4"
android:layout_row="3"
android:layout_rowSpan="7"
/>

<FrameLayout
android:id="@+id/multiDiagramFrame"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_gravity="fill"
android:layout_columnWeight="6"
android:layout_rowWeight="6"
android:layout_margin="8dp"
android:layout_column="4"
android:layout_columnSpan="6"
android:layout_row="4"
android:layout_rowSpan="6"
/>

<com.google.android.material.card.MaterialCardView
android:id="@+id/noStatisticsAvailableYetCardView"
style="?attr/materialCardViewFilledStyle"
Expand Down Expand Up @@ -162,14 +186,23 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideLineStreakNumbers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5"/>

<TextView
android:id="@+id/solvedstreak"
style="@style/TextAppearance.Material3.DisplaySmall"
style="@style/TextAppearance.Material3.DisplayMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="@id/guideLineStreakNumbers"
android:layout_marginBottom="32dp"
android:textAlignment="center"
/>

Expand All @@ -183,18 +216,20 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/solvedstreak"
android:textAlignment="center"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
/>

<TextView
android:id="@+id/longeststreak"
style="@style/TextAppearance.Material3.DisplaySmall"
style="@style/TextAppearance.Material3.DisplayMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/labelSolvedstreak"
app:layout_constraintTop_toTopOf="@id/guideLineStreakNumbers"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="32dp"
android:textAlignment="center"
/>

Expand All @@ -207,8 +242,8 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/longeststreak"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:textAlignment="center"
/>

Expand Down
Loading

0 comments on commit 2d5319d

Please sign in to comment.