Пояснительная записка (1231610), страница 9
Текст из файла (страница 9)
while( log.index < log.text.length ) {
var tag = log.nextTagText();
if( tag == null ) {
break;
}
if( tag.getTagName() == "challenge" ) {
getProblemsFromFile( problems, log );
}
if( tag.getTagName() == "session" ) {
getTeamFromFile( teams, submits, tag, log );
}
if( tag.getTagName() == "/standings" ) {
break;
}
}
}
function getTeamFromFile( teams, submits, team, log ) {
var name = team.getParamsValue( "party" );
var id = teams.length;
teams.push( new Team( id, name ) );
while( true ) {
var tag = log.nextTagText();
if( tag.getTagName() == "/session" )
break;
getSubmitFromFile( submits, id, tag, log );
}
}
function getSubmitFromFile( submits, teamId, problem, log ) {
var code = problem.getParamsValue( "alias" );
while( true ) {
var tag = log.nextTagText();
if( tag.getTagName() == "/problem" )
break;
var time = Number(tag.getParamsValue( "time" )) / 1000;
var state = ( tag.getParamsValue( "accepted" ) == "yes" ? "accepted" : "no" );
submits.push(new Submit(time, teamId, code, state, 0));
}
}
function getProblemsFromFile( problems, log ) {
while( true ) {
var tag = log.nextTagText();
if( tag.getTagName() == "/challenge" )
break;
var code = tag.getParamsValue( "alias" );
problems.push( new Problem( code ) );
}
}
Листинг А.7 – Файл class Team.js
function Team( id, name ) {
this.id = id;
this.name = name;
this.problemAllSubmit = [];
this.problemSubmit = [];
this.problemSolved = [];
this.problemTime = [];
this.problemSubmits = [];
this.solved = 0;
this.time = 0;
this.submit = [];
this.nextSubmit = 0;
}
Team.prototype.azaza = function() {
alert( "azaza" );
}
Team.prototype.getSolved = function() {
var str = "";
str += this.solved;
return str;
}
Team.prototype.getTime = function() {
var str = "";
str += this.time;
return str;
}
Team.prototype.getVerdict = function( problem ) {
var str = "";
if( this.problemSolved[problem] )
str += "+";
else if( this.problemSubmit[problem] )
str += "-";
else
str += "";
if( this.problemSubmit[problem] )
str += this.problemSubmit[problem];
if( ( this.problemSubmit[problem] || this.problemSolved[problem] ) && showTime ) {
str += "<br>";
str += this.getTimeProblem( problem );
}
return str;
}
Team.prototype.getClassVerdict = function( problem ) {
if( this.id == problemFirstSolved[problem] && this.problemSolved[problem] )
return "tdFirstAccepted";
if( this.problemSolved[problem] )
return "tdAccepted";
if( this.problemAllSubmit[problem] && showSubmit )
return "tdSubmit";
if( this.problemSubmit[problem] )
return "tdReject";
return "tdNull";
}
Team.prototype.getTimeProblem = function( problem ) {
var str = "";
var hour = Math.floor( this.problemTime[problem] / 60 );
var minute = this.problemTime[problem] % 60;
str += hour;
str += ":";
if( minute < 10 )
str += "0";
str += minute;
return str;
}
Team.prototype.addSubmit = function( submit ) {
var problem = problemId.get( submits[submit].problemCode );
if( this.problemSolved[problem] )
return;
if( this.problemSubmits[problem].length )
return this.addAllSubmit( problem );
else
return this.addOneSubmit( submit );
}
Team.prototype.addOneSubmit = function( submit ) {
var problem = problemId.get( submits[submit].problemCode );
this.problemTime[problem] = submits[submit].getTime();
this.problemAllSubmit[problem] --;
problems[problem].addSubmit( submit );
if( submits[submit].state == "accepted" ) {
this.solvedProblem( problem );
return true;
} else {
this.problemSubmit[problem] ++;
return false;
}
}
Team.prototype.addAllSubmit = function( problem ) {
var res = false;
for(var i=0; i<this.problemSubmits[problem].length; i++) {
if( this.addOneSubmit(this.problemSubmits[problem][i]) )
res = true;
}
this.problemSubmits[problem] = [];
return res;
}
Team.prototype.addProblemSubmit = function( submit ) {
var problem = problemId.get( submits[submit].problemCode );
if( this.problemSolved[problem] )
return;
this.problemSubmits[problem].push( submit );
return ( submits[submit].state == "accepted" || this.problemSubmits[problem].length == this.problemAllSubmit[problem] );
}
Team.prototype.solvedProblem = function( problem ) {
this.problemSolved[problem] = true;
this.solved ++;
this.time += this.problemTime[problem];
this.time += 20 * this.problemSubmit[problem];
}
Team.prototype.clearProblemSubmits = function() {
for( var i = 0; i < this.problemSubmits.length; i ++ ) {
for(var j=0; j<this.problemSubmits[i].length; j ++ ) {
var submit = this.problemSubmits[i][j];
submits[submit].checked = false;
}
this.problemSubmits[i] = [];
}
}
Team.prototype.createProblems = function( problems ) {
this.problemAllSubmit = [];
this.problemSubmit = [];
this.problemSolved = [];
this.problemTime = [];
for( var i = 0; i < problems; i ++ ) {
this.problemAllSubmit.push( 0 );
this.problemSubmit.push( 0 );
this.problemSolved.push( false );
this.problemTime.push( 0 );
this.problemSubmits.push( [] );
}
this.solved = 0;
this.time = 0;
}
Team.prototype.getIdPlace = function() {
return this.id + '.' + 'Place';
}
Team.prototype.getIdName = function() {
return this.id + '.' + 'Name';
}
Team.prototype.getIdSolved = function() {
return this.id + '.' + 'Solved';
}
Team.prototype.getIdTime = function() {
return this.id + '.' + 'Time';
}
Team.prototype.getIdProblem = function( problem ) {
return this.id + '.' + problems[problem].code;
}
Team.prototype.getIdSubmit = function() {
return this.submit[this.nextSubmit];
}
Листинг А.8 – Файл class Problem.js
function Problem( code ) {
this.code = code;
this.solved = 0;
this.submit = 0;
}
Problem.prototype.getIdStatistic = function() {
return this.code + ".statistic";
}
Problem.prototype.getSolved = function() {
var str = "";
str += this.solved;
str += "<br>";
str += this.submit;
return str;
}
Problem.prototype.getClassSolved = function() {
if( this.solved == 0 && this.submit == 0 )
return "tdStatistic";
if( this.solved )
return "tdAccepted";
if( this.submit )
return "tdReject";
}
Problem.prototype.addSubmit = function( submit ) {
if( submits[submit].state == "accepted" )
this.solved ++;
this.submit ++;
}
Листинг А.9 – Файл class Submit.js
function Submit( time, teamId, problemCode, state, test ) {
this.time = time;
this.teamId = teamId;
this.problemCode = problemCode;
this.state = state;
this.test = test;
this.checked = false;
}
Submit.prototype.getTime = function() {
return Math.floor(this.time/60) + ( this.time % 60 >= 30 );
}
Листинг А.10 – Файл createTable.js
function createTable() {
var table = document.createElement( "table" );
table.appendChild( createThead() );
table.appendChild( createTbody() );
table.className = "table";
table.id = "table";
var div = document.getElementById( "printTable" );
var oldTable = document.getElementById( "table" );
var newTable = div.appendChild( table );
if( oldTable != null ) {
div.replaceChild( newTable, oldTable );
}
}
function createThead() {
var thead = document.createElement( "thead" );
thead.appendChild( createTrHead() );
thead.appendChild( createTrStatistic() );
var tr = document.createElement( "tr" );
var td = document.createElement( "td" );
td.className = "tdSeparator";
td.setAttribute( "colspan", 4 + problems.length );
tr.appendChild( td );
thead.appendChild( tr );
return thead;
}
function createTrHead() {
var tr = document.createElement( "tr" );
tr.appendChild( createTd( "Place", "", "tdHeadSqr" ) );
tr.appendChild( createTd( "Team name", "", "tdHead" ) );
for( var i = 0; i < problems.length; i ++ ) {
tr.appendChild( createTd( problems[i].code, "", "tdHeadSqr" ) );
}
tr.appendChild( createTd( "=", "", "tdHeadSqr" ) );
tr.appendChild( createTd( "Time", "", "tdHeadSqr" ) );
return tr;
}
function createTrStatistic() {
var tr = document.createElement( "tr" );
tr.appendChild( createTd( "", "", "tdStatistic" ) );
tr.appendChild( createTd( "Accepted<br>Submits", "", "tdStatistic" ) );
for( var i = 0; i < problems.length; i ++ )
tr.appendChild( createTd( "", problems[i].getIdStatistic(), "tdStatistic" ) );
tr.appendChild( createTd( "", "Total", "tdStatistic" ) );
tr.appendChild( createTd( "", "", "tdStatistic" ) );
return tr;
}
function createTh( text, id, className ) {
var th = document.createElement( "th" );
th.innerHTML = text;
//td.appendChild( document.createTextNode( text ) );
th.id = id;
th.className = className;
return th;
}
function createTbody() {
var tbody = document.createElement( "tbody" );
for( var i = 0; i < teams.length; i ++ ) {
var tr = document.createElement( "tr" );
tr.appendChild( createTd( "1", teams[i].getIdPlace(), "tdBody1" ) );
tr.appendChild( createTd( teams[i].name, teams[i].getIdName(), "tdBody1" ) );
for( var j = 0; j < problems.length; j ++ ) {
tr.appendChild( createTd( "", teams[i].getIdProblem( j ), "tdNull" ) );
}
tr.appendChild( createTd( "0", teams[i].getIdSolved(), "tdBody1" ) );
tr.appendChild( createTd( "0", teams[i].getIdTime(), "tdBody1" ) );
tr.id = teams[i].id;
tbody.appendChild( tr );
}
return tbody;
}
function createTd( text, id, className ) {
var td = document.createElement( "td" );
td.innerHTML = text;
//td.appendChild( document.createTextNode( text ) );
td.id = id;
td.className = className;
return td;
}
function createTeams() {
for( var i = 0; i < teams.length; i ++ ) {
teams[i].createProblems( problems.length );
teams[i].submit = [];
teams[i].nextSubmit = 0;
}
for( var i = 0; i < submits.length; i ++ ) {
var team = teamId.get( submits[i].teamId );
var problem = problemId.get( submits[i].problemCode );
if( team == null || problem == null )
continue;
teams[team].submit.push( i );
if( submits[i].state == "accepted" && problemFirstSolved[problem] == -1 ) {
problemFirstSolved[problem] = teams[team].id;
}
}
}
function createTeamsAllSubmit() {
for( var team = 0; team < teams.length; team ++ ) {
for(var problem=0; problem<problems.length; problem++) {
teams[team].problemAllSubmit[problem] = 0;
}
}
for( var i = 0; i < submits.length; i ++ ) {