Skip to content

Commit

Permalink
Make each output row a single player of each game
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldoylecs committed Sep 30, 2019
1 parent 77a6b47 commit 5d5ddaa
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
<IncludePath>E:\Library\Development\RocketAnalytics-PlayerStatParser\RocketAnalytics-PlayerStatParser\lib\RocketAnalyticsLib\include\properties;E:\Library\Development\RocketAnalytics-PlayerStatParser\RocketAnalytics-PlayerStatParser\lib\RocketAnalyticsLib\include;E:\Library\Development\RocketAnalytics-PlayerStatParser\RocketAnalytics-PlayerStatParser\include;$(IncludePath)</IncludePath>
<SourcePath>E:\Library\Development\RocketAnalytics-PlayerStatParser\RocketAnalytics-PlayerStatParser\lib\RocketAnalyticsLib\src\properties;E:\Library\Development\RocketAnalytics-PlayerStatParser\RocketAnalytics-PlayerStatParser\src;E:\Library\Development\RocketAnalytics-PlayerStatParser\RocketAnalytics-PlayerStatParser\lib\RocketAnalyticsLib\src;$(SourcePath)</SourcePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<IncludePath>E:\Library\Development\RocketAnalytics-PlayerStatParser\RocketAnalytics-PlayerStatParser\lib\RocketAnalyticsLib\include\properties;E:\Library\Development\RocketAnalytics-PlayerStatParser\RocketAnalytics-PlayerStatParser\lib\RocketAnalyticsLib\include;E:\Library\Development\RocketAnalytics-PlayerStatParser\RocketAnalytics-PlayerStatParser\include;$(IncludePath)</IncludePath>
<SourcePath>E:\Library\Development\RocketAnalytics-PlayerStatParser\RocketAnalytics-PlayerStatParser\lib\RocketAnalyticsLib\src\properties;E:\Library\Development\RocketAnalytics-PlayerStatParser\RocketAnalytics-PlayerStatParser\lib\RocketAnalyticsLib\src;E:\Library\Development\RocketAnalytics-PlayerStatParser\RocketAnalytics-PlayerStatParser\src;$(SourcePath)</SourcePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
Expand Down Expand Up @@ -117,6 +121,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,23 @@ using std::cout;
using std::cin;
using std::clog;
using std::endl;
using std::map;
using std::vector;
using std::pair;
using std::ofstream;
using std::stringstream;

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

vector<vector<Property>> get_stats(vector<Property> properties);
int get_winning_team(vector<Property> properties);
string create_stat_csv(map<string, Player> players);
void set_mvp(vector<Player>& player_records, int winning_team);
vector<vector<Property>> get_stats(const vector<Property>& properties);
int get_winning_team(const vector<Property>& properties);
string create_stat_csv(const vector<Player>& players);

int main() {
const string version = "1.1";
const string version = "1.2";
const string default_file_name = "player_stats";
const string file_extension = ".csv";
map<string, Player> players;
vector<Player> players;
string replay_dir;
string dest_dir;

Expand Down Expand Up @@ -75,23 +76,18 @@ int main() {
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) {
vector<Player> player_stat_records;
for (const 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;
}
player_stat_records.push_back(player);
}
players[highest_score_player.onlineID].mvp += 1;
set_mvp(player_stat_records, winning_team);

players.insert(
players.begin(),
player_stat_records.begin(),
player_stat_records.end());
}

cout << endl;
Expand All @@ -100,8 +96,7 @@ int main() {
cout << "Please enter the output filename (no spaces):" << endl;
cin >> output_file_name;

string output_filepath = dest_dir + "\\" + output_file_name +
file_extension;
string output_filepath = dest_dir + "\\" + output_file_name + file_extension;

ofstream output_file(output_filepath);
output_file << create_stat_csv(players);
Expand All @@ -110,7 +105,25 @@ int main() {
return 0;
}

vector<vector<Property>> get_stats(vector<Property> properties) {
void set_mvp(vector<Player>& player_records, int winning_team) {
Player highest_score_player;

for (auto& player : player_records) {
if (player.team == winning_team &&
player.score > highest_score_player.score) {
highest_score_player = player;
}
}

for (auto& player : player_records) {
if (player.onlineID == highest_score_player.onlineID) {
++player.mvp;
return;
}
}
}

vector<vector<Property>> get_stats(const vector<Property>& properties) {
vector<vector<Property>> stats;
for (Property prop : properties) {
if (prop.get_name() == "PlayerStats") {
Expand All @@ -121,7 +134,7 @@ vector<vector<Property>> get_stats(vector<Property> properties) {
return stats;
}

int get_winning_team(vector<Property> properties) {
int get_winning_team(const vector<Property>& properties) {
int team_0_score = 0;
int team_1_score = 0;
for (Property prop : properties) {
Expand All @@ -135,14 +148,14 @@ int get_winning_team(vector<Property> properties) {
return team_0_score > team_1_score ? 0 : 1;
}

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

int count = 1;
for (auto const&[_, player] : players) {
for (auto const& player : players) {
csv <<
count << ",," <<
player.name << "," <<
Expand Down

0 comments on commit 5d5ddaa

Please sign in to comment.