Removing uneeded file.
[and.git] / PC^2 / pc2board / samps / pc2 / ex / SampleScoreboardClient.java
blobf219e2750d708c120a258cfa4f4ddd721b3272e9
1 package pc2.ex;
3 import javax.swing.*;
4 import java.io.*;
5 import pc2.PC2Log;
6 import pc2.PC2ini;
7 /**
8 * Sample Scoreboard Client Abstract Class, extends {@link ScoreboardClient}.
9 */
10 public class SampleScoreboardClient extends ScoreboardClient {
11 // used by printRow to print out all the problem statistics
12 private long numProblems=0;
13 //
14 private String fileName=null;
15 private Object printingLock=new Object();
16 /**
17 * SampleScoreboardClient constructor comment.
18 * @exception java.rmi.RemoteException The exception description.
20 public SampleScoreboardClient() throws java.rmi.RemoteException {
21 super();
23 /**
24 * handleClientRefresh method comment.
26 public void handleClientRefresh() {}
27 /**
28 * Each time a new run is submitted to a PC<SUP>2</SUP> Server
29 * this method is called passing run information and files to this
30 * method.
31 * <P>
32 * Note: one can extract the files from {@link RunInfoAndFiles} using
33 * {@link RunInfoAndFiles#writeUserFile(int,String)}
36 public void handleNewRun(RunInfoAndFiles run) {}
37 /**
38 * Each time a run is judged this method will be invoked with
39 * the run and judgement info.
42 public void handleRunJudged(RunInfoAndFiles run, boolean isSolved, String judgement) {
43 printHTML();
45 /**
46 * Invoked when run is judged
48 * @param run pc2.ex.RunInfoAndFiles
50 public void handleRunStatusUpdated(RunInfoAndFiles run) {}
51 /**
52 * Indicates when contest settings have changed
54 public void handleSettingsUpdated() {
55 printHTML();
57 /**
58 * When a judge un checks out (returns a run without judging) this is invoked
60 * @see RunInfoAndFiles
61 * @param run pc2.ex.RunInfoAndFiles
63 public void handleUNCheckedOutRun(RunInfoAndFiles run) {}
64 /**
65 * Starts the application.
66 * @param args java.lang.String[]
68 public static void main(String[] args) {
69 SampleScoreboardClient sc = null;
70 try {
71 sc = new SampleScoreboardClient();
72 } catch (Exception e){
73 PC2Log.message("error in new SampleClient()",e);
74 System.exit(12);
76 // This sets the debug level for the log according to pc2v8.ini
77 if (new PC2ini().containsKey("client.debugLevel")) {
78 String temp=PC2ini.getKey("client.debugLevel");
79 try {
80 int value=new Integer(temp).intValue();
81 PC2Log.setDebugLevel(value);
82 } catch (NumberFormatException nfe) {
87 if (args != null && args.length > 0) {
88 sc.fileName=args[0];
90 String loginId = "board1";
91 // siteId of 0 means any site
93 try {
94 if (! sc.loginToPC2("127.0.0.1", pc2.PC2Constants.DEFAULT_PC2_PORT, 0, loginId, loginId))
96 PC2Log.message("Could not login as "+loginId);
97 JFrame frame = new JFrame("Invisible JFrame... ooh");
98 JOptionPane.showMessageDialog
100 frame,
101 "Could not login as "+loginId,
102 "Login failure",
103 JOptionPane.INFORMATION_MESSAGE
105 System.exit(5);
108 } catch (Exception exc) {
109 PC2Log.message("Exception ",exc);
113 // print scoreboard at start
114 sc.printHTML();
115 String sentinel = "stopboard";
116 PC2Log.message("Create file named '"+sentinel+"' to exit client.");
117 Thread loopy = new Thread ();
118 try {
120 for (;;)
122 // PC2Log.message("remaining "+(max-count));
123 loopy.sleep(1000);
124 loopy.yield();
125 java.io.File f = new java.io.File(sentinel);
126 if (f.exists())
128 f.deleteOnExit();
129 System.out.println("found "+sentinel+", exiting ");
130 sc.logoff();
131 System.exit(4);
135 } catch (Exception ex) {
136 PC2Log.message("Funny bugger aren't you ",ex);
139 if (sc.logoffPC2())
141 PC2Log.message("Logged out.");
142 System.exit(0);
146 * Insert the method's description here.
147 * Creation date: (8/14/2002 3:29:52 PM)
148 * @param os java.io.PrintWriter
150 private void printHeader(PrintWriter os) {
151 if (os == null) {
152 os=new PrintWriter(System.out,true);
154 os.println("<html>");
155 os.println("<head><title>"+this.getClass().getName()+"</title><head>");
156 os.println("<body>");
157 os.println("<table>");
158 os.print("<tr>");
159 os.print("<th><strong><u>Rank</u></strong></th>");
160 os.print("<th><strong><u>Name</u></strong></th>");
161 os.print("<th><strong><u>Solved</u></strong></th>");
162 os.print("<th><strong><u>Score</u></strong></th>");
163 // now all per problem stuff
164 String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
165 for(int j=0;j < numProblems;j++) {
166 os.print("<th>&nbsp;&nbsp;&nbsp;&nbsp;<u><strong>"+alphabet.charAt(j % 26)+"</u></strong>&nbsp;&nbsp;&nbsp;&nbsp;</th>");
168 os.print("</tr>");
169 os.println();
172 * Insert the method's description here.
173 * Creation date: (8/20/02 5:53:33 PM)
175 private void printHTML() {
176 try {
177 synchronized (printingLock) {
178 PC2Log.message("print scoreboard begin");
179 ClientScoreData[] sd = null;
180 ProblemScoreData psd = null;
181 PrintWriter pout = null;
182 if (fileName != null) {
183 pout = new PrintWriter(new FileOutputStream(fileName), true);
184 } else {
185 pout = new PrintWriter(System.out, true);
187 numProblems = getNumProblems();
188 printHeader(pout);
190 if (getNumTeamAccounts() > 0) {
191 sd = getStandings();
192 if (sd == null) {
193 // no standings
194 PC2Log.message("no standings ?!?");
196 for (int i = 0; i < sd.length; i++) {
197 printRow(pout, sd[i]);
199 } else {
200 PC2Log.message("No teams defined");
202 printTrailer(pout);
203 PC2Log.message("print scoreboard end");
205 } catch (Exception e) {
206 PC2Log.message("printHTML()", e);
210 * Insert the method's description here.
211 * Creation date: (8/14/2002 3:29:52 PM)
212 * @param os java.io.PrintWriter
213 * @param csd pc2.ex.ClientScoreData
215 private void printRow(PrintWriter os, ClientScoreData csd) {
216 if (os == null) {
217 os=new PrintWriter(System.out,true);
219 if (csd == null) {
220 PC2Log.message("printRow no ClientScoreData to print");
221 } else {
222 os.print("<tr>");
223 os.print("<td>"+csd.getRank()+"</td>");
224 os.print("<td>"+csd.getTeamName()+"</td>");
225 os.print("<td>"+csd.getNumberOfSolvedProblems()+"</td>");
226 os.print("<td>"+csd.getScore()+"</td>");
227 // now all per problem stuff
228 String stats="";
229 ProblemScoreData psd=null;
230 for(int j=1;j <= numProblems;j++) {
231 psd=csd.getProblemScoreData(j);
232 if (psd.isSolved()) {
233 stats=psd.getAttempts()+"/"+psd.getSolutionTime();
234 } else {
235 stats=psd.getAttempts()+"/--";
237 os.print("<td>"+stats+"</td>");
239 os.print("</tr>");
240 os.println();
244 * Insert the method's description here.
245 * Creation date: (8/14/2002 3:29:52 PM)
246 * @param os java.io.PrintWriter
248 private void printTrailer(PrintWriter os) {
249 if (os == null) {
250 os=new PrintWriter(System.out,true);
252 os.println("</table>");
253 os.println("</body>");
254 os.println("</html>");