Skip to content

Commit

Permalink
statistics_dialog: Show the actual (empirical) CTH.
Browse files Browse the repository at this point in the history
  • Loading branch information
jostephd committed Jul 9, 2019
1 parent 84c6467 commit 6220f71
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
9 changes: 3 additions & 6 deletions data/gui/window/statistics_dialog.cfg
Expand Up @@ -566,12 +566,9 @@ The sum (or difference) of the two numbers in parentheses is the actual number o

{_GUI_DAMAGE_STATS_LIST
(_ "Hits") hits_this_turn_header stats_list_hits hits_type hits_overall hits_this_turn
(_"stats dialog^Difference of actual outcome to expected outcome, as a percentage.
The first number in parentheses is the expected number of hits.
The sum (or difference) of the two numbers in parentheses 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.")}
# The tooltips are in statistics_dialog::add_hits_row because dynamic data is appended to them
""
""}
[/column]

[/row]
Expand Down
21 changes: 19 additions & 2 deletions src/gui/dialogs/statistics_dialog.cpp
Expand Up @@ -201,6 +201,8 @@ struct hitrate_table_element
std::string hitrate_str;
// The string with the a priori probability of that result
std::string pvalue_str;
// The tooltip of the table cell - shows the actual (empirical) CTH
std::string tooltip;
};

// Return the strings to use in the "Hits" table, showing actual and expected number of hits.
Expand All @@ -210,14 +212,19 @@ static hitrate_table_element tally(const statistics::stats::hitrate_map& by_cth,
double expected_hits = 0;
unsigned int overall_strikes = 0;

std::ostringstream str, str2, tooltip;

tooltip << '\n' << '\n' << _("Actual hit rates, by chance to hit:");
for(const auto& i : by_cth) {
int cth = i.first;
overall_hits += i.second.hits;
expected_hits += (cth * 0.01) * i.second.strikes;
overall_strikes += i.second.strikes;
tooltip << "\n" << cth << "%: "
<< get_probability_string(i.second.hits/static_cast<double>(i.second.strikes))
<< "% (N=" << i.second.strikes << ")";
}

std::ostringstream str, str2;
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 Expand Up @@ -293,7 +300,7 @@ static hitrate_table_element tally(const statistics::stats::hitrate_map& by_cth,
}
}

return hitrate_table_element{str.str(), str2.str()};
return hitrate_table_element{str.str(), str2.str(), tooltip.str()};
}

void statistics_dialog::add_hits_row(
Expand All @@ -315,6 +322,11 @@ void statistics_dialog::add_hits_row(
data.emplace("hits_type", item);

element = tally(by_cth, more_is_better);
item["tooltip"] = _(
"stats dialog^Difference of actual outcome to expected outcome, as a percentage.\n"
"The first number in parentheses is the expected number of hits.\n"
"The sum (or difference) of the two numbers in parentheses is the actual number of hits.")
+ element.tooltip;
item["label"] = element.hitrate_str;
data.emplace("hits_overall", item);
item["label"] = element.pvalue_str;
Expand All @@ -325,6 +337,11 @@ void statistics_dialog::add_hits_row(
this_turn_header.set_label(_("This Turn"));

element = tally(turn_by_cth, more_is_better);
item["tooltip"] = _(
"stats dialog^Estimate of how much randomness of battles favored or disfavored this side.\n"
"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.")
+ element.tooltip;
item["label"] = element.hitrate_str;
data.emplace("hits_this_turn", item);
item["label"] = element.pvalue_str;
Expand Down

0 comments on commit 6220f71

Please sign in to comment.