Skip to content

Commit

Permalink
Add ability to track game MVPs. Currently is based on which team has …
Browse files Browse the repository at this point in the history
…more goals.
  • Loading branch information
michaeldoylecs committed Feb 16, 2018
1 parent 1f703c9 commit 972fc12
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
1 change: 1 addition & 0 deletions RocketAnalytics-PlayerStatParser/src/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace PlayerStatParser {
platform = properties.at(1).get_value_as_string();
onlineID = properties.at(2).get_value_as_string();
team = stoi(properties.at(3).get_value_as_string());
mvp = 0;
score = stoi(properties.at(4).get_value_as_string());
goals = stoi(properties.at(5).get_value_as_string());
assists = stoi(properties.at(6).get_value_as_string());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ using std::stringstream;

namespace filesystem = std::experimental::filesystem::v1;

vector<vector<Property>> get_player_stats(vector<Property> properties);
vector<vector<Property>> get_stats(vector<Property> properties);
int get_winning_team(vector<Property> properties);
string create_stat_csv(map<string, Player> players);

int main() {
Expand Down Expand Up @@ -69,20 +70,29 @@ int main() {
for (filesystem::path path : filesystem::directory_iterator(replay_dir)) {
string replay_path = path.u8string();
cout << "Parsing " << replay_path << "\n";
ReplayFile replay(replay_path);
vector<Property> replay_properties =
replay.get_header().get_properties();

vector<vector<Property>> player_stats = get_stats(replay_properties);
ReplayFile replay(replay_path);
vector<Property> properties = replay.get_header().get_properties();
vector<vector<Property>> player_stats = get_stats(properties);
int winning_team = get_winning_team(properties);
Player highest_score_player;

for (auto player_info : player_stats) {
Player player(player_info);

if (player.team == winning_team &&
player.score > highest_score_player.score) {
highest_score_player = player;
}

if (players.count(player.onlineID)) {
players[player.onlineID] += player;
} else {
players[player.onlineID] = player;
}
}
cout << highest_score_player.name << ": " << highest_score_player.mvp << "\n";
players[highest_score_player.onlineID].mvp += 1;
}

cout << endl;
Expand Down Expand Up @@ -112,10 +122,24 @@ vector<vector<Property>> get_stats(vector<Property> properties) {
return stats;
}

int get_winning_team(vector<Property> properties) {
int team_0_score = 0;
int team_1_score = 0;
for (Property prop : properties) {
if (prop.get_name() == "Team0Score") {
team_0_score = prop.get_value().property_value.int32;
}
else if (prop.get_name() == "Team1Score") {
team_1_score = prop.get_value().property_value.int32;
}
}
return team_0_score > team_1_score ? 0 : 1;
}

string create_stat_csv(map<string, Player> players) {
stringstream csv;
csv << "Player Stats generated by RocketAnalyticsPlayerStatsParser.\n" <<
"Player #,Team,Name,Platform,Steam64,Games Played,MVPs,Score," <<
"Unique ID,Team,Name,Platform,Online ID,Games Played,MVPs,Score," <<
"Goals,Assists,Saves,Shots\n";

int count = 1;
Expand Down

0 comments on commit 972fc12

Please sign in to comment.