-
Notifications
You must be signed in to change notification settings - Fork 0
/
GradeSnap.cpp
274 lines (210 loc) · 7.43 KB
/
GradeSnap.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
//#include "GradeSnap.h"
//#include <wx\wx.h>
/*
class BasicApplication : public wxApp
{
public:
virtual bool OnInit();
};
class BasicFrame : public wxFrame
{
public:
BasicFrame( const wxChar *title, int xpos, int ypos, int width, int height );
~BasicFrame();
};
IMPLEMENT_APP(BasicApplication)
bool BasicApplication::OnInit()
{
BasicFrame *frame = new BasicFrame(_T("Basic"), 50, 50, 450, 300);
frame->Show(TRUE);
SetTopWindow(frame);
return TRUE;
}
BasicFrame::BasicFrame( const wxChar *title, int xpos, int ypos, int width, int height)
: wxFrame( (wxFrame*) NULL, -1, title, wxPoint(xpos, ypos), wxSize(width, height) )
{
}
BasicFrame::~BasicFrame()
{
}
*/
/*
#include <iostream>
using namespace std;
int main ( int argc, char* argv[] ) {
// Beta Testing algorithm
cout << "Welcome to GradeSnap!" << endl << endl;
// Gets number of questions on exam
int numVerify = 0;
int numQuestions = 5;
char numQChar[ 4 ];
while( numVerify == 0 ) {
cout << "How many questions will there be on this exam? (1-50): ";
cin >> numQChar;
cout << endl;
numQuestions = atoi( numQChar );
if ( numQuestions < 1 || numQuestions > 50 ) {
cout << "Oops! -- Number of questions entered incorrectly. " <<
"Will be discarded. -- " << endl << endl;
} else {
numVerify++;
}
}
// Gets the key file name
int fileVerify = 0;
string keyFilename = "s2-2.jpeg";
while ( fileVerify == 0 ) {
keyFilename = "";
cout << "Please enter the name of the key file (with file extension): ";
cin >> keyFilename;
cout << endl;
transform( keyFilename.begin(), keyFilename.end(), keyFilename.begin(), tolower );
// Checking for proper names and extensions
// Index of the dot for extension
int dotIndex = keyFilename.find( '.' );
// Return false if no dot '.'
if ( dotIndex == -1 ) {
if ( keyFilename.compare( "end" ) != 0 ) {
cout << "Oops! -- Bad file input. Will be discarded -- " << endl << endl;
}
} else {
// Checks if the extension is allowed
string extension = keyFilename.substr( dotIndex, ( keyFilename.size() - dotIndex ) );
if ( ( extension.compare( ".jpg" ) == 0 )
|| ( extension.compare( ".bmp" ) == 0 )
|| ( extension.compare( ".dib" ) == 0 )
|| ( extension.compare( ".jpeg" ) == 0 )
|| ( extension.compare( ".jpe" ) == 0 )
|| ( extension.compare( ".png" ) == 0 )
|| ( extension.compare( ".pbm" ) == 0 )
|| ( extension.compare( ".pgm" ) == 0 )
|| ( extension.compare( ".ppm" ) == 0 )
|| ( extension.compare( ".sr" ) == 0 )
|| ( extension.compare( ".ras" ) == 0 )
|| ( extension.compare( ".tff" ) == 0 )
|| ( extension.compare( ".tiff" ) == 0 ) ) {
//Checks if the file actually now exists
FILE * kFile;
kFile = fopen( keyFilename.c_str(), "r" );
if ( kFile != NULL ) {
fileVerify++;
} else {
cout << "Oops! -- Bad file input. Will be discarded -- "
<< endl << endl;
}
kFile = 0;
} else {
cout << "Oops! -- Bad file input. Will be discarded -- "
<< endl << endl;
}
}
}
// Gets student exam filenames
vector< string > studentExamFilenames;
//studentExamFilenames.push_back( "s2-2.jpeg" );
string testFilename;
string end( "end" );
// Continue to take in student exam filenames
cout << "Entering student exam file names. " <<
"Type 'end' (no quotes), hit enter to finish" << endl << endl;
while ( testFilename.compare( end ) != 0 ) {
testFilename = "";
cout << "Please test file name with file extension: ";
cin >> testFilename;
cout << endl;
// Turns the filename to lower-case
transform( testFilename.begin(), testFilename.end(), testFilename.begin(), tolower );
// Checking for proper names and extensions
// Index of the dot for extension
int dotIndex = testFilename.find( '.' );
// Return false if no dot '.'
if ( dotIndex == -1 ) {
if ( testFilename.compare( "end" ) != 0 ) {
cout << "Oops! -- Bad file input. Will be discarded -- " << endl << endl;
}
} else {
// Checks if the extension is allowed
string extension = testFilename.substr( dotIndex, ( testFilename.size() - dotIndex ) );
if ( ( extension.compare( ".jpg" ) == 0 )
|| ( extension.compare( ".bmp" ) == 0 )
|| ( extension.compare( ".dib" ) == 0 )
|| ( extension.compare( ".jpeg" ) == 0 )
|| ( extension.compare( ".jpe" ) == 0 )
|| ( extension.compare( ".png" ) == 0 )
|| ( extension.compare( ".pbm" ) == 0 )
|| ( extension.compare( ".pgm" ) == 0 )
|| ( extension.compare( ".ppm" ) == 0 )
|| ( extension.compare( ".sr" ) == 0 )
|| ( extension.compare( ".ras" ) == 0 )
|| ( extension.compare( ".tff" ) == 0 )
|| ( extension.compare( ".tiff" ) == 0 ) ) {
//Checks if the file actually now exists
FILE * tFile;
tFile = fopen( testFilename.c_str(), "r" );
if ( tFile != NULL ) {
studentExamFilenames.push_back( testFilename );
} else {
cout << "Oops! -- Bad file input. Will be discarded -- "
<< endl << endl;
}
tFile = 0;
} else {
cout << "Oops! -- Bad file input. Will be discarded -- "
<< endl << endl;
}
}
}
//Checks to see if there was no file name entered
if ( studentExamFilenames.size() == 0 ) {
cout << "No student exam filenames entered. "
<< "Program will now close." << endl;
int stop = 1;
cout << "Press any key and enter to exit ";
cin >> stop;
return( 1 );
}
DBManager::db_init();
// TODO clear the database for testing purposes (LATER-ish)
// --- TOP LEVEL ----
int classID = 1;
int assignmentID = DBManager::makeDataObject( "Assignment", numQChar );
// Create key, link to assignment, set filename
int keyID = DBManager::makeDataObject( "Student", keyFilename );
DBManager::linkAToB( "LinkerStudentAssignment", assignmentID, "AssignmentID",
keyID, "StudentID" );
DBManager::setLinkedValues( "LinkerStudentAssignment", keyID, assignmentID,
"StudentID", "AssignmentID", "key", "YES" );
DBManager::setLinkedValues( "LinkerStudentAssignment", keyID, assignmentID,
"StudentID", "AssignmentID", "filename", keyFilename );
// Pair for use in the model
pair< int, string > keyFilePair( keyID, keyFilename );
// Vector of pairs for the student IDs and filenames
vector< pair< int, string > > studentFilePairs;
// Vector of student IDs
vector< int > studentIDs;
// Gets student IDs by setting them to be in the DB and finding their ID
// Links the necessary student data and pushes their info into the pair vector
for( unsigned int i = 0; i < studentExamFilenames.size(); i++ ) {
string name = studentExamFilenames.at( i );
// Extracts information about the studentID and places corresponding
// student data into the database
int sID = DBManager::makeDataObject( "Student", name );
DBManager::linkAToB( "LinkerStudentAssignment", assignmentID, "AssignmentID",
sID, "StudentID" );
DBManager::linkAToB( "LinkerClassStudent", classID, "ClassID", sID, "StudentID" );
DBManager::setLinkedValues( "LinkerStudentAssignment", sID, assignmentID,
"StudentID", "AssignmentID", "filename", name );
// Pushes student ID and name to the student pair vector
studentFilePairs.push_back( pair< int, string >( sID, name ) );
studentIDs.push_back( sID );
}
GradeSnapModel gsm;
gsm.evaluateImage( assignmentID, classID, keyFilePair, studentFilePairs, numQuestions );
gsm.printResults( assignmentID, classID, keyID, studentIDs );
gsm.getStats( assignmentID, classID, keyID, studentIDs );
int x;
cin >> x;
DBManager::db_close();
return 0;
}
*/