Skip to content

Commit

Permalink
statistics_dialog: Change the hits table format to "1703.2 + 42 | 93.6"
Browse files Browse the repository at this point in the history
  • Loading branch information
jostephd committed Jul 9, 2019
1 parent 1c19e8c commit 7b78a8c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 4 additions & 2 deletions data/gui/window/statistics_dialog.cfg
Expand Up @@ -547,7 +547,8 @@

{_GUI_DAMAGE_STATS_LIST
(_ "Damage") damage_this_turn_header stats_list_damage damage_type damage_overall damage_this_turn
(_"stats dialog^Amount of hitpoints (actual / expected)")
(_"stats dialog^The first number is the expected number of hitpoints.
The sum (or difference) of the two numbers is the actual number of hitpoints.")
(_"stats dialog^Ratio of actual to expected")}
[/column]

Expand All @@ -564,7 +565,8 @@

{_GUI_DAMAGE_STATS_LIST
(_ "Hits") hits_this_turn_header stats_list_hits hits_type hits_overall hits_this_turn
(_"stats dialog^Number of hits (actual / expected)")
(_"stats dialog^The first number is the expected number of hits.
The sum (or difference) of the two numbers is the actual number of hits.")
(_"stats dialog^Estimate of how much randomness of battles favored or disfavored this side.
Values between 0 and 50 suggest the number of hits was less than expected.
Values between 50 and 100 suggest the number of hits was more than expected.")}
Expand Down
13 changes: 11 additions & 2 deletions src/gui/dialogs/statistics_dialog.cpp
Expand Up @@ -129,6 +129,15 @@ void statistics_dialog::add_stat_row(window& window, const std::string& type, co
main_stat_table_.push_back(&value);
}

// Generate the string for the "A + B" column of the damage and hits tables.
static std::ostream& write_actual_and_expected(std::ostream& str, const long long actual, const double expected)
{
// This is displayed as a sum or difference, not as "actual/expected", to prevent the string in the next column, str2.str(), from being mistaken for the result of the division.
str << expected << (actual >= expected ? " + " : "")
<< static_cast<unsigned int>(std::round(std::abs(expected - actual)));
return str;
}

void statistics_dialog::add_damage_row(
window& window,
const std::string& type,
Expand All @@ -154,7 +163,7 @@ void statistics_dialog::add_damage_row(
const auto damage_str = [shift](long long damage, long long expected) {
const long long shifted = ((expected * 20) + shift) / (2 * shift);
std::ostringstream str;
str << damage << " / " << static_cast<double>(shifted) * 0.1;
write_actual_and_expected(str, damage, static_cast<double>(shifted) * 0.1);
return str.str();
};
item["label"] = damage_str(damage, expected);
Expand Down Expand Up @@ -211,7 +220,7 @@ static hitrate_table_element tally(const statistics::stats::hitrate_map& by_cth,
}

std::ostringstream str, str2;
str << overall_hits << " / " << expected_hits;
write_actual_and_expected(str, overall_hits, expected_hits);

// Compute the a priori probability of this actual result, by simulating many attacks against a single defender.
{
Expand Down

0 comments on commit 7b78a8c

Please sign in to comment.