-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameDataAdapter.cpp
More file actions
116 lines (95 loc) · 2.26 KB
/
Copy pathGameDataAdapter.cpp
File metadata and controls
116 lines (95 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "GameDataAdapter.hpp"
#include "Team.hpp"
#include "Game.hpp"
#include "CSVParser.hpp"
#include <map>
#include <cstdlib>
#include <string>
#include <cassert>
using namespace std;
GameDataAdapter::GameDataAdapter(string season)
{
seasonName = season;
_gamesCount = 0;
_good = true;
CSVParser seasonsData("data/seasons.csv");
if(seasonsData.fail()) {
_error = "Failed to open file data/seasons.csv";
_good = false;
return;
}
seasonsData.skip();
string seasonId = "";
while(seasonsData.good()) {
std::vector<string> row = seasonsData.next();
if(row.size())
// cout << row[0] << " " << row[1];
if(row.size() && row[1] == seasonName) {
seasonId = row[0];
}
}
if (seasonId == "")
{
_error = "Unknown season";
_good = false;
return;
}
// cout << "Season " << seasonId << endl;
std::map<int, Team *> teams;
CSVParser teamsData("data/teams.csv");
if(teamsData.fail()) {
_error = "Failed to open file data/teams.csv";
_good = false;
return;
}
teamsData.skip();
while(teamsData.good()) {
std::vector<string> row;
// cout << "Attempt read" << endl;
row = teamsData.next();
// cout << row.size() << endl;
int id = atoi(row[0].c_str());
teams[id] = new Team(id, row[1]);
// cout << id << row[1] << endl;
}
CSVParser gamesData("data/regular_tourney_combined_results.csv");
if(gamesData.fail()) {
_error = "Failed to open file data/regular_tourney_combined_results.csv";
_good = false;
return;
}
gamesData.skip();
// cout << "Reading game data" << endl;
int gamesCount = 0;
while(gamesData.good()) {
std::vector<string> row;
row = gamesData.next();
if(row.size() && row[0] == seasonId) {
// cout << teams[atoi(row[2].c_str())]->name() << " vs " << teams[atoi(row[4].c_str())]->name() << endl;
Game *game = new Game(teams[atoi(row[2].c_str())], teams[atoi(row[4].c_str())], atoi(row[3].c_str()), atoi(row[5].c_str()), row[6].c_str()[0]);
assert(game != NULL);
gamesCount++;
}
}
_gamesCount = gamesCount;
_teams = teams;
}
std::map<int, Team *> GameDataAdapter::getData()
{
return _teams;
}
int GameDataAdapter::getGamesCount()
{
return _gamesCount;
}
bool GameDataAdapter::good()
{
return _good;
}
std::string GameDataAdapter::error()
{
return _error;
}
GameDataAdapter::~GameDataAdapter()
{
}