-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
129 lines (114 loc) · 4.54 KB
/
main.cpp
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* This file is part of NFLdecisionTree. It creates decision trees to classify
situations within NFL football games, and displays the plays historically
called in those situations given a set of opponents.
Copyright (C) 2013 Ezra Erb
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3 as published
by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
I'd appreciate a note if you find this program useful or make
updates. Please contact me through LinkedIn (my profile also has
a link to the code depository)
*/
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include"baseException.h"
#include"singlePlay.h"
#include"playIndexSet.h"
#include"playStats.h"
#include"dataStore.h"
#include"playLoader.h"
#include"decisionNode.h"
using std::cout;
using std::endl;
using std::vector;
using std::string;
using std::ofstream;
int main(int argc, char **argv)
{
ofstream resultFile;
try {
PlayLoader loader("..\\Data");
DataStore data;
/* Extract the teams from the input. Order is given below */
bool validInput = false;
bool usSimiliar = false;
if (argc == 3)
validInput = true;
else if (argc >= 5) {
/* Third argument must be either -u for teams similiar to us or
-o for teams similiar to opponent */
string flag(argv[3]); // Argv[0] contains the program name
if (flag == string("-u")) {
validInput = true;
usSimiliar = true;
}
else if (flag == string("-o"))
validInput = true;
} // Four or more arguments
if (!validInput) {
cout << "Invalid arguments. US OPPONENT [-u] [SIMILIAR US TEAMS] [-o] [SIMILIAR OTHER TEAMS]" << endl;
exit(1);
} // Invalid input
string thisTeam(argv[1]);
string otherTeam(argv[2]);
vector <string> thisSimiliar;
vector <string> otherSimiliar;
if (argc >= 5) {
int argIndex;
for (argIndex = 4; argIndex < argc; argIndex++) {
string newTeam(argv[argIndex]);
if (usSimiliar) {
if (newTeam == string("-o"))
usSimiliar = false;
else
thisSimiliar.push_back(newTeam);
} // Teams similiar to us
else {
if (newTeam == string("-u"))
usSimiliar = true;
else
otherSimiliar.push_back(newTeam);
} // Teams similiar to opponent
} // Loop through arguments
} // More than two teams specified
loader.loadPlays(thisTeam, otherTeam, thisSimiliar, otherSimiliar, 3, data);
PlayIndexSet dataView(data.getIndexes());
DecisionNode tree(dataView, data.getPlaySummaryStats());
tree.pruneTree();
// Output the final decision tree
resultFile.open("result.txt");
if (resultFile.is_open()) {
// Generate header
resultFile << "Us:" << thisTeam << " Opponent: " << otherTeam << " ";
if (!thisSimiliar.empty()) {
resultFile << "Similiar to Us:";
vector<string>::iterator index;
for (index = thisSimiliar.begin(); index != thisSimiliar.end(); index++)
resultFile << *index << " ";
}
if (!otherSimiliar.empty()) {
resultFile << "Similiar to Other:";
vector<string>::iterator index;
for (index = otherSimiliar.begin(); index != otherSimiliar.end(); index++)
resultFile << *index << " ";
}
resultFile << endl;
resultFile << tree << endl;
resultFile.close();
}
} // Try block
catch (exception& e) { // Catch by reference so virtual methods work properly
cout << "Exception: " << e.what() << " thrown" << endl;
if (resultFile.is_open())
resultFile.close();
exit(1);
} // Catch block
}