-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate.txt
344 lines (274 loc) · 12.1 KB
/
generate.txt
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
//put all the method to generate the HTML for user
import java.sql.*;
import java.util.*;
import java.io.*;
class generate{
public static void startGame()throws Exception{
Class.forName("com.mysql.jdbc.Driver");
Connection con= DriverManager.getConnection("jdbc:mysql://localhost/jlj?user=root");
Statement instruction = con.createStatement();
ResultSet resultat = instruction.executeQuery("update user u set u.modes=1 where u.modes=0");// change all the user exist now to the modes 1 which is play mode
makeSchedule();
File file=new File("start.html");
PrintWriter output=new PrintWriter(file);
output.print("");//put html code here and if you wish put the output.print() as more as possible
output.close();
con.close();
}
/* public static void loginPage(userLogin e)throws Exception{
if(e.existUser){
//goto the user page
}
else {
//goto other fault page
}
}*/
public static void randomSick()throws Exception{
}
public static void makeSchedule()throws Exception{
Class.forName("com.mysql.jdbc.Driver");
Connection con= DriverManager.getConnection("jdbc:mysql://localhost/jlj?user=root");
Statement instruction = con.createStatement();
ResultSet resultat = instruction.executeQuery("SELECT u.username from user u order by u.lossdata");
resultat.next();
ArrayList<String> userResult=new ArrayList<String>();
while(resultat.next()){
userResult.add(resultat.getString(1));}
int n=userResult.size();
int [][] matchTable;
if(userResult.size()%2!=0){
n++;
matchTable=doSchedule(n);
}
else
matchTable=doSchedule(n);
instruction.executeQuery("DROP TABLE IF EXISTS schedule");
String excuteString="CREATE TABLE schedule ( username CHAR(20) NOT NULL, ";
for(int i=0;i<n;++i)
excuteString+="week"+(i+1)+" CHAR(20), ";
excuteString+="PRIMARY KEY (username), FOREIGN KEY (username) REFERENCES user (username))";
instruction.executeQuery(excuteString);
if(userResult.size()!=n){
for(int i=0;i<n;++i){
String theString="INSERT INTO schedule VALUES ("+userResult.get(i);
for(int j=0;j<n-1;++j){
if(matchTable[i][j]==userResult.size())
theString+=",break";
else
theString+=","+userResult.get(matchTable[i][j]);
}
theString+=")";
instruction.executeQuery(theString);
}
}
else {
for(int i=0;i<n;++i){
String theString="INSERT INTO schedule VALUES ("+userResult.get(i);
for(int j=0;j<n-1;++j){
theString+=","+userResult.get(matchTable[i][j]);
}
theString+=")";
instruction.executeQuery(theString);
}
}
con.close();
}
private static int[][] doSchedule(int n){
return roundRobin.get(n);
}
/* Set<Integer> checkSet=new HashSet<Integer>();
MyList[] allMatch=new MyList[n/2];
for(int i=0;i<allMatch.length;++i)
allMatch[i]=new MyList();
int matchSize=n*(n-1)/2;
int difference=1;
while(difference<n/2+1){*/
/* int one=0;
int two=difference;
Game myGame=new Game(n);
while(true){
myGame.setValue(one,two);
if(checkSet.contains(myGame.hashing()))
break;
checkSet.add(myGame.hashing());
allMatch[difference-1].add(new Game(n,one,two));
one=(one+1)%n;
two=(two+1)%n;
}
difference++;
}*/
/*int[][] matchTable=new int[n][n-1];
for(int i=0;i<matchTable.length;++i)
for(int j=0;j<matchTable[i].length;++j)
matchTable[i][j]=-1;
int index=n/2-1;
int date=0;
while(!allMatch[index].isEmpty()){
Game myGame=allMatch[index].get(0);
matchTable[myGame.getFirst()][date]=myGame.getSecond();
matchTable[myGame.getSecond()][date]=myGame.getFirst();
allMatch[index].remove(0);
}
if(n>2){
index--;
while(date<n-2){
date=date+1;
int in=index;
ArrayList<Integer> allUser=reset(n);
while(!allUser.isEmpty()){
for(int i=0;i<matchTable.length;++i){
for(int j=0;j<matchTable[0].length;++j)
System.out.print(matchTable[i][j]);
System.out.println();
}
System.out.println();
int matchIndex=0;
while(allMatch[in].isEmpty())
in--;
while(!allMatch[in].isEmpty() && matchIndex<allMatch[in].size()){
Game myGame=allMatch[in].get(matchIndex);
if(conflict(matchTable,myGame,date)){
if(differ(allUser,in)<in){
in=differ(allUser,in);
break;
}
matchIndex++;
}
else {
matchTable[myGame.getFirst()][date]=myGame.getSecond();
matchTable[myGame.getSecond()][date]=myGame.getFirst();
allMatch[in].remove(matchIndex);
allUser.remove(allUser.indexOf(myGame.getFirst()));
allUser.remove(allUser.indexOf(myGame.getSecond()));
}
}
/* while(!allUser.isEmpty()){
int min=allUser.get(0);
int max=allUser.get(allUser.size()-1);
in=max-min-1;
Game myGame=new Game(n,min,max);
if(!conflict(matchTable,myGame,date)){
matchTable[min][date]=max;
matchTable[max][date]=min;
allMatch[in].remove(allMatch[in].indexAs(myGame));
}
else {
boolean getDone=false;
while(!getDone){
min++;
in=max-min-1;
myGame=new Game(n,min,max);
if(!conflict(matchTable,myGame,date)){
matchTable[min][date]=max;
matchTable[max][date]=min;
allMatch[in].remove(allMatch[in].indexAs(myGame));
getDone=true;
}
}
}
}
}
if(allMatch[index].isEmpty())
index--;
}
}
}*/
/*return allMatch;
}*/
private static ArrayList<Integer> reset(int n){
ArrayList<Integer> allUser=new ArrayList<Integer>();
for(int i=0;i<n;++i)
allUser.add(i);
return allUser;
}
private static boolean conflict(int[][] a,Game b,int date){
return (a[b.getFirst()][date]!=-1 || a[b.getSecond()][date]!=-1);
}
private static int differ(ArrayList<Integer> a,int in){
if(a.size()==0)
return in;
int max=a.get(0);
int min=a.get(0);
for(int i=0;i<a.size();++i){
if(a.get(i)<min)
min=a.get(i);
if(a.get(i)>max)
max=a.get(i);
}
return max-min-1;
}
public static ResultSet showAllSchedule()throws Exception{
Class.forName("com.mysql.jdbc.Driver");
Connection con= DriverManager.getConnection("jdbc:mysql://localhost/jlj?user=root");
Statement instruction = con.createStatement();
ResultSet resultat = instruction.executeQuery("SELECT * from schedule");
con.close();
return resultat;
}
public static ResultSet showAvaPlayers()throws Exception{
Class.forName("com.mysql.jdbc.Driver");
Connection con= DriverManager.getConnection("jdbc:mysql://localhost/jlj?user=root");
Statement instruction = con.createStatement();
ResultSet resultat = instruction.executeQuery("SELECT * from players p where p.availability=0");// change all the user exist now to the modes 1 which is play mode
con.close();
return resultat;
}
public static ResultSet showAllPlayers()throws Exception{
Class.forName("com.mysql.jdbc.Driver");
Connection con= DriverManager.getConnection("jdbc:mysql://localhost/jlj?user=root");
Statement instruction = con.createStatement();
ResultSet resultat = instruction.executeQuery("SELECT * from players");
con.close();
return resultat;
}
public static ResultSet updateWeekStats(String name,double passTD,double passyards,double interceptions,double rushTD,double rushyards,double fumbles,double receivingTD,double receivingyards,double pointsallowed,double turnovers,double sacks,double defensiveTD,double fl40,double fg40,double ml40,double mg40,double pat,double mpat)throws Exception{
Class.forName("com.mysql.jdbc.Driver");
Connection con= DriverManager.getConnection("jdbc:mysql://localhost/jlj?user=root");
Statement instruction = con.createStatement();
double total=passTD+passyards+interceptions+rushTD+rushyards+fumbles+receivingTD+receivingyards+pointsallowed+turnovers+sacks+defensiveTD+fl40+fg40+ml40+mg40+pat+mpat;
ResultSet resultat = instruction.executeQuery("UPDATE weeklystats w SET passTD="+passTD+",passyards="+passyards+",interceptions="+interceptions+",rushTD="+rushTD+",rushyards="+rushyards+",fumbles="+fumbles+",receivingTD="+receivingTD+",receivingyards="+receivingyards+",pointsallowed="+pointsallowed+",turnovers="+turnovers+",sacks="+sacks+",defensiveTD="+defensiveTD+",fieldgoalless40="+fl40+",fieldgoalgreater40="+fg40+",missedfieldgoaless40="+ml40+",missedfieldgoalgreater40="+mg40+",PAT="+pat+",missedPAT="+mpat+",calpoints="+total+" where w.name='"+name+"'");//
con.close();
return resultat;
}
public static ResultSet showRank()throws Exception{
Class.forName("com.mysql.jdbc.Driver");
Connection con= DriverManager.getConnection("jdbc:mysql://localhost/jlj?user=root");
Statement instruction = con.createStatement();
ResultSet resultat = instruction.executeQuery("SELECT u.teamname,u.windata FROM user u order by u.lossdata");
con.close();
return resultat;
}
public static ResultSet showWin(String user1,String user2)throws Exception{
Class.forName("com.mysql.jdbc.Driver");
Connection con= DriverManager.getConnection("jdbc:mysql://localhost/jlj?user=root");
Statement instruction = con.createStatement();
ResultSet resultat =instruction.executeQuery("SELECT u.username,u.windata from user u order by u.lossdata");
con.close();
return resultat;
}
public static void startNextWeek()throws Exception{
Class.forName("com.mysql.jdbc.Driver");
Connection con= DriverManager.getConnection("jdbc:mysql://localhost/jlj?user=root");
Statement instruction = con.createStatement();
instruction.executeQuery("update totalstats t,weeklystats w set t.passTD=t.passTD+w.passTD,t.passyards=t.passyards+w.passyards,t.interceptions=t.interceptions+w.interceptions,t.rushTD=t.rushTD+w.rushTD,t.rushyards=t.rushyards+w.rushyards,t.fumbles=t.fumbles+w.fumbles,t.receivingTD=t.receivingTD+w.receivingTD,t.receivingyards=t.receivingyards+w.receivingyards,t.pointsallowed=t.pointsallowed+w.pointsallowed,t.turnovers=t.turnovers+w.turnovers,t.sacks=t.sacks+w.sacks,t.defensiveTD=t.defensiveTD+w.defensiveTD,t.fieldgoalless40=t.fieldgoalless40+w.fieldgoalless40,t.fieldgoalgreater40=t.fieldgoalgreater40+w.fieldgoalgreater40,t.missedfieldgoaless40=t.missedfieldgoaless40+w.missedfieldgoaless40,t.missedfieldgoalgreater40=t.missedfieldgoalgreater40+w.missedfieldgoalgreater40,t.PAT=t.PAT+w.PAT,t.missedPAT=t.missedPAT+w.missedPAT,t.calpoints=t.calpoints+w.calpoints where t.name=w.name");
calWin();
con.close();
}
public static void setInjury(String name,String types)throws Exception{
Class.forName("com.mysql.jdbc.Driver");
Connection con= DriverManager.getConnection("jdbc:mysql://localhost/jlj?user=root");
Statement instruction = con.createStatement();
ResultSet resultat = instruction.executeQuery("update players p set p.injury='"+types+"' where p.name='"+name+"'");
con.close();
}
//to let the system to determine which people will go first in the selection
public static ResultSet determineSelection()throws Exception{
Class.forName("com.mysql.jdbc.Driver");
Connection con= DriverManager.getConnection("jdbc:mysql://localhost/jlj?user=root");
Statement instruction = con.createStatement();
ResultSet resultat = instruction.executeQuery("select u.username from user u oreder by lossdata");
con.close();
return resultat;
}
public static void calWin()throws Exception{}
}