Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stats tracker #33782

Merged
merged 11 commits into from
Sep 4, 2019
Merged

Add stats tracker #33782

merged 11 commits into from
Sep 4, 2019

Conversation

jbytheway
Copy link
Contributor

Summary

SUMMARY: Infrastructure "Add new object to track event statistics for use in calculating scores"

Purpose of change

The next step towards #4173 (scores and achievements).

Replace the existing stats class (used for player::lifetime_stats) with a more generic solution.

Describe the solution

Add a new stats_tracker class which counts all events sent to the event bus.

Add new event types for the events needed to compute the stats from lifetime_stats.

So far it has some simple APIs to count events and compute the sum of values from events. This is used to compute the values previously stored in player::lifetime_stats.

The lifetime_stats was also used for the torsion ratchet CBM and related CBMs. I switched them to use randomized updates at the same average frequency (I think this is more correct anyway; I think there were corner cases where you could cause the power to increase every turn).

Describe alternatives you've considered

More features will be needed to make this sufficiently functional for achievements, because we can't afford to do an O(n) recomputation every time an event occurs. I have plans to add "live-updated" statistics that can track various specific values of interest with O(1) updates.

But for the lifetime stats (and for scores in general), this is good enough.

I think the "number of moves" statistic is dubious. I'm not sure exactly what sorts of moves it's counting. But it should be the same as it used to be, in any case. If we want to make it more correct, that can go in a separate PR.

This is now more general than kills_tracker, so we could probably retire kills_tracker, but I don't plan to do that. It's convenient to have all that code and it's associated GUI in one place.

The "damage taken" and "damage healed" stats don't seem hugely interesting to me, so I considered just removing them, but I didn't want to lose functionality (and I can imagine some fun achievements involving them).

Additional context

There are potential memory and save file size concerns with tracking all these stats as I am. So far I think the events that are present shouldn't explode too badly (we have one count for each distinct set of parameter values for every event type). If it starts to be a problem we could blacklist certain events or fields from the stats_tracker.

Uses the new features added in #33742.

The hp_part case I added to cata_variant isn't actually used in the final version, but having it doesn't hurt.

@ZhilkinSerg ZhilkinSerg added [C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style Code: Tests Measurement, self-control, statistics, balancing. labels Sep 3, 2019
range_hash is a hash for using e.g. containers as keys in unordered_maps.

auto_hash is a hash function that chooses automatically between std::hash
and cata::tuple_hash depending on the hashed type.
This is a typedef for the map type used to store the event data.  Adding
it because the underlying type seems likely to change in the future.
This sums the value of a particular field in events satisfying a
criterion.
Previously each player object contained some lifetime_stats about tiles
moved, etc.  Replace all that with the newly added stats_tracker
functionality.

One side-effect is that muscle-powered bionics now recharge at random
intervals, rather than regularly, but should have the same average
charge rates.
This is supposed to be in the standard library in C++14 but gcc 5.3
lacks it.
@ZhilkinSerg ZhilkinSerg merged commit 9df45a3 into CleverRaven:master Sep 4, 2019
@jbytheway jbytheway deleted the stats_tracker branch September 4, 2019 11:15
misterprimus pushed a commit to misterprimus/Cataclysm-DDA that referenced this pull request Sep 21, 2019
* Added auto_hash and range_hash

range_hash is a hash for using e.g. containers as keys in unordered_maps.

auto_hash is a hash function that chooses automatically between std::hash
and cata::tuple_hash depending on the hashed type.

* Add event::data_type

This is a typedef for the map type used to store the event data.  Adding
it because the underlying type seems likely to change in the future.

* Add a simple stats_tracker that counts events

* Add stats_tracker to game

* Serialize stats_tracker

* Add hp_part case for cata_variant

* Add (and use) a character_takes_damage event

* Add stats_tracker::total

This sums the value of a particular field in events satisfying a
criterion.

* Replace lifetime_stats with stats_tracker

Previously each player object contained some lifetime_stats about tiles
moved, etc.  Replace all that with the newly added stats_tracker
functionality.

One side-effect is that muscle-powered bionics now recharge at random
intervals, rather than regularly, but should have the same average
charge rates.

* Some comments to help explain stats_tracker

* Add std::hash specialization for event_type

This is supposed to be in the standard library in C++14 but gcc 5.3
lacks it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style Code: Tests Measurement, self-control, statistics, balancing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants