<commit_before>package ca.josephroque.bowlingcompanion.statistics

import android.content.res.Resources
import android.os.Parcel
import ca.josephroque.bowlingcompanion.common.interfaces.KParcelable
import ca.josephroque.bowlingcompanion.statistics.immutable.StatFrame
import ca.josephroque.bowlingcompanion.statistics.immutable.StatGame
import ca.josephroque.bowlingcompanion.statistics.immutable.StatSeries
import ca.josephroque.bowlingcompanion.statistics.list.StatisticListItem
import ca.josephroque.bowlingcompanion.statistics.unit.StatisticsUnit
import java.text.DecimalFormat

/**
 * Copyright (C) 2018 <NAME>
 *
 * A statistic to display.
 */
interface Statistic : StatisticListItem, KParcelable {

    /** String ID of the title of the statistic. */
    val titleId: Int

    /** Value to be displayed by the statistic. */
    val displayValue: String

    /** Optional subtitle to be displayed by the statistic. */
    fun getSubtitle(): String? { return null }

    /** Category that the statistic belongs to. */
    val category: StatisticsCategory

    /** Indicates if a graph can be generated from the statistic. */
    val canBeGraphed: Boolean

    /** Get a primary Y position for a graph entry from the statistic's current state, if available. */
    val primaryGraphY: Float?

    /** Get a secondary Y position for a graph entry from the statistic's current state, if available. */
    val secondaryGraphY: Float?

    /** Label for the primary graph data. */
    val primaryGraphDataLabelId: Int
        get() = titleId

    /** Label for the secondary graph data. */
    val secondaryGraphDataLabelId: Int?

    /** Indicates if this statistic will be modified by a given [StatisticsUnit]. */
    fun isModifiedBy(unit: StatisticsUnit) = false

    /** Modify the statistic given a [StatisticsUnit]. */
    fun modify(unit: StatisticsUnit) {}

    /** Indicates if this statistic will be modified by a given [StatSeries]. */
    fun isModifiedBy(series: StatSeries) = false

    /** Modify the statistic given a [StatSeries]. */
    fun modify(series: StatSeries) {}

    /** Indicates if this statistic will be modified by a given [StatGame]. */
    fun isModifiedBy(game: StatGame) = false

    /** Modify the statistic given a [StatGame]. */
    fun modify(game: StatGame) {}

    /** Indicates if this statistic will be modified by a given [StatFrame]. */
    fun isModifiedBy(frame: StatFrame) = false

    /** Modify the statistic given a [StatFrame]. */
    fun modify(frame: StatFrame) {}

    /** Zero the statistic. */
    fun zero()

    /**
     * Get the title of the statistic.
     *
     * @param resources to get string
     * @return the title from the app resources
     */
    fun getTitle(resources: Resources): String {
        return resources.getString(titleId)
    }

    /** @Override */
    override fun describeContents(): Int {
        return titleId
    }

    companion object {
        /** Displayed value for an empty statistic. */
        const val EMPTY_STATISTIC = "—"
    }
}

/**
 * A statistic with a percentage value.
 */
interface PercentageStatistic : Statistic {

    companion object {
        /** Format percentages consistently. */
        private val formatter = DecimalFormat("#.##")
    }

    /** Numerator of the percentage. */
    var numerator: Int
    /** Denominator of the percentage. */
    var denominator: Int

    /** @Override */
    override val canBeGraphed
        get() = true

    override val primaryGraphY: Float?
        get() = percentage.toFloat()

    override val secondaryGraphY: Float?
        get() = denominator.toFloat()

    /** Get the percentage. */
    val percentage: Double
        get() {
            return if (denominator > 0) {
                numerator.div(denominator.toDouble()).times(100)
            } else {
                0.0
            }
        }

    /** @Override */
    override val displayValue: String
        get() = if (denominator > 0) {
            "${formatter.format(percentage)}% [$numerator/$denominator]"<commit_msg>Show a better value in graph for PercentageStatistic<commit_after>package ca.josephroque.bowlingcompanion.statistics

import android.content.res.Resources
import android.os.Parcel
import ca.josephroque.bowlingcompanion.common.interfaces.KParcelable
import ca.josephroque.bowlingcompanion.statistics.immutable.StatFrame
import ca.josephroque.bowlingcompanion.statistics.immutable.StatGame
import ca.josephroque.bowlingcompanion.statistics.immutable.StatSeries
import ca.josephroque.bowlingcompanion.statistics.list.StatisticListItem
import ca.josephroque.bowlingcompanion.statistics.unit.StatisticsUnit
import java.text.DecimalFormat

/**
 * Copyright (C) 2018 <NAME>
 *
 * A statistic to display.
 */
interface Statistic : StatisticListItem, KParcelable {

    /** String ID of the title of the statistic. */
    val titleId: Int

    /** Value to be displayed by the statistic. */
    val displayValue: String

    /** Optional subtitle to be displayed by the statistic. */
    fun getSubtitle(): String? { return null }

    /** Category that the statistic belongs to. */
    val category: StatisticsCategory

    /** Indicates if a graph can be generated from the statistic. */
    val canBeGraphed: Boolean

    /** Get a primary Y position for a graph entry from the statistic's current state, if available. */
    val primaryGraphY: Float?

    /** Get a secondary Y position for a graph entry from the statistic's current state, if available. */
    val secondaryGraphY: Float?

    /** Label for the primary graph data. */
    val primaryGraphDataLabelId: Int
        get() = titleId

    /** Label for the secondary graph data. */
    val secondaryGraphDataLabelId: Int?

    /** Indicates if this statistic will be modified by a given [StatisticsUnit]. */
    fun isModifiedBy(unit: StatisticsUnit) = false

    /** Modify the statistic given a [StatisticsUnit]. */
    fun modify(unit: StatisticsUnit) {}

    /** Indicates if this statistic will be modified by a given [StatSeries]. */
    fun isModifiedBy(series: StatSeries) = false

    /** Modify the statistic given a [StatSeries]. */
    fun modify(series: StatSeries) {}

    /** Indicates if this statistic will be modified by a given [StatGame]. */
    fun isModifiedBy(game: StatGame) = false

    /** Modify the statistic given a [StatGame]. */
    fun modify(game: StatGame) {}

    /** Indicates if this statistic will be modified by a given [StatFrame]. */
    fun isModifiedBy(frame: StatFrame) = false

    /** Modify the statistic given a [StatFrame]. */
    fun modify(frame: StatFrame) {}

    /** Zero the statistic. */
    fun zero()

    /**
     * Get the title of the statistic.
     *
     * @param resources to get string
     * @return the title from the app resources
     */
    fun getTitle(resources: Resources): String {
        return resources.getString(titleId)
    }

    /** @Override */
    override fun describeContents(): Int {
        return titleId
    }

    companion object {
        /** Displayed value for an empty statistic. */
        const val EMPTY_STATISTIC = "—"
    }
}

/**
 * A statistic with a percentage value.
 */
interface PercentageStatistic : Statistic {

    companion object {
        /** Format percentages consistently. */
        private val formatter = DecimalFormat("#.##")
    }

    /** Numerator of the percentage. */
    var numerator: Int
    /** Denominator of the percentage. */
    var denominator: Int

    /** @Override */
    override val canBeGraphed
        get() = true

    override val primaryGraphY: Float?
        get() = numerator.toFloat()

    override val secondaryGraphY: Float?
        get() = denominator.toFloat()

    /** Get the percentage. */
    val percentage: Double
        get() {
            return if (denominator > 0) {
                numerator.div(denominator.toDouble()).times(100)
            } else {
                0.0
            }
        }

    /** @Override */
    override val displayValue: String
        get() = if (denominator > 0) {
            "${formatter.format(percentage)}% [$numerator/$denominator]"
{'fraction_non_alphanumeric': 0.10098280098280098, 'fraction_numerical': 0.002702702702702703, 'mean_word_length': 2.7516129032258063, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '984084', 'n_tokens_mistral': 2323, 'n_tokens_neox': 2178, 'n_words': 736}