예제 #1
0
파일: lojhandler.cpp 프로젝트: himcc/bnuoj
bool getStatus(string pid,string lang,string & result,string& ce_info,string &tu,string &mu)
{
    int begin=time(NULL);
    string runid;
    tu=mu="0";
    string ts;
    while (true)
    {
        FILE * fp=fopen(tfilename,"w+");
        curl = curl_easy_init();
        if(curl)
        {
            curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
            curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
            curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "loj.cookie");
            string url=(string)"http://www.lightoj.com/volume_usersubmissions.php";
            //cout<<url;
            curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
            res = curl_easy_perform(curl);
            curl_easy_cleanup(curl);
        }
        fclose(fp);
        if (res) return false;
        ts=getResFromFile(tfilename);
        if (ts=="") return false;
        writelog((char *)ts.c_str());
        runid=getRunid(ts);
        result=getResult(ts);
        //cout << result;
        if (result.find("Not")==string::npos
                &&result.find("Running")==string::npos
                &&result.find("Judging")==string::npos
                &&result.find("Queuing")==string::npos
                &&result.find("Compiling")==string::npos
                )
        {
            break;
        }
        if (time(NULL)-begin>MAX_WAIT_TIME) break;
    }
    if (!(result.find("Not")==string::npos
            &&result.find("Running")==string::npos
            &&result.find("Judging")==string::npos
            &&result.find("Queuing")==string::npos
            &&result.find("Compiling")==string::npos)) return false;
    //cout<<runid<<" "<<tu<<" "<<mu<<" "<<result<<endl;
    if (result=="Compilation Error") ce_info=getCEinfo(runid);
    else {
        tu=getUsedTime(ts);
        mu=getUsedMem(ts);
        ce_info="";
    }
    //cout<<ce_info;
    if (result!="Accepted"&&result[result.length()-1]=='d') {
        result.erase(result.end()-2,result.end());
    }
    result=convertResult(result);
    return true;
}
예제 #2
0
bool getStatus(string pid,string lang,string & result,string& ce_info,string &tu,string &mu)
{
	usleep(600000);
    int begin=time(NULL);
    string runid;
    tu=mu="0";
    string ts;
    while (true)
    {
        FILE * fp=fopen(tfilename,"w+");
        curl = curl_easy_init();
        if(curl)
        {
            curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
            curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
            curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "sgu.cookie");
            string url=(string)"http://acm.sgu.ru/status.php?id="+username+"&idmode=1&problem="+pid;
            //cout<<url;
            curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
            res = curl_easy_perform(curl);
            curl_easy_cleanup(curl);
        }
        fclose(fp);
        if (res) return false;
        ts=getResFromFile(tfilename);
        if (ts=="") return false;
        //cout<<ts;
        runid=getRunid(ts);
        result=getResult(ts);
        //cout << result;
        if (result.find("queue")==string::npos
                &&result.find("Running")==string::npos
                &&result.find("Judging")==string::npos
                &&result.find("Queuing")==string::npos
                &&result.find("Waiting")==string::npos
                &&result.find("Compiling")==string::npos
				&&result.length()>4)
        {
            break;
        }
        if (time(NULL)-begin>MAX_WAIT_TIME) break;
    }
    if (!(result.find("queue")==string::npos
            &&result.find("Running")==string::npos
            &&result.find("Judging")==string::npos
            &&result.find("Queuing")==string::npos
            &&result.find("Waiting")==string::npos
            &&result.find("Compiling")==string::npos
			&&result.length()>4)) return false;
    tu=getUsedTime(ts);
    mu=getUsedMem(ts);
    //cout<<runid<<" "<<tu<<" "<<mu<<" "<<result<<endl;
    result=convertResult(result);
    if (result=="Compile Error") ce_info=getCEinfo(runid);
    else ce_info="";
    //cout<<ce_info;
    return true;
}
예제 #3
0
//http://poj.org/status?problem_id=1000&user_id=51isoft&result=&language=
bool getStatus(string pid,string lang,string & result,string& ce_info,string &tu,string &mu) {
	int begin=time(NULL);
	string runid;
	tu=mu="0";
	string ts;
	while (true) {
		FILE * fp=fopen(tfilename,"w+");
		curl = curl_easy_init();
		if(curl) {
			curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
			curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
			curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "pku.cookie");
			string url=(string)"http://poj.org/status?problem_id="+pid+"&user_id="+username+"&language="+lang;
			//cout<<url;
			curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
			res = curl_easy_perform(curl);
			curl_easy_cleanup(curl);
		}
		fclose(fp);
		if (res) return false;
		ts=getLineFromFile(tfilename,3);
		//cout<<ts;
		/*if (ts.find("alert(\"Login failed!)")!=string::npos) return false;
		 */
		if (ts.find("Error Occurred")!=string::npos||ts.find("The page is temporarily unavailable")!=string::npos) return false;
		runid=getRunid(ts);
		result=getResult(ts);
		//cout << result;
		if (result.find("Waiting")==string::npos
				&&result.find("Running")==string::npos
				&&result.find("Judging")==string::npos
				&&result.find("Queuing")==string::npos
				&&result.find("Compiling")==string::npos
				&&result!=""&&result[0]!='\n'&&result[0]!='\t'&&result[0]!='\r'&&result[0]!=' ') {
			break;
		}
		if (time(NULL)-begin>MAX_WAIT_TIME) break;
	}
	if (!(result.find("Waiting")==string::npos
				&&result.find("Running")==string::npos
				&&result.find("Judging")==string::npos
				&&result.find("Queuing")==string::npos
				&&result.find("Compiling")==string::npos
				&&result!=""&&result[0]!='\n'&&result[0]!='\t'&&result[0]!='\r'&&result[0]!=' ')) return false;

	if (result=="Compile Error") {
		result = "Compilation Error";
		ce_info=getCEinfo(runid);
	} else ce_info="";
	if (result=="Accepted") {
		tu=getUsedTime(ts);
		mu=getUsedMem(ts);
	} else if (result[result.length()-1]=='d') {
		//result.erase(result.end()-2,result.end());
	}
	return true;
}
예제 #4
0
void HRBUSTJudger::getStatus() {
//	prepareCurl();
	while (true) {
		stringstream sStream;
		string lang, outer_oj_id;
		char *lang_tmp, *outer_oj_id_tmp;
		sStream << judgeInfo.getLang();
		sStream >> lang;
		sStream << judgeInfo.getId();
		sStream >> outer_oj_id;
		string res_url = "http://acm.hrbust.edu.cn/index.php?m=Status&a=showStatus&problem_id=" + outer_oj_id + "&user_name=acmstep&language=" + lang; 
		curl_easy_setopt(easy_handle, CURLOPT_URL, res_url.c_str());
	cout << "Before performCurl()................." << endl;
		performCurl("tmpfiles/statusdata.html");
	cout << "After performCurl()................." << endl;
		string res, runid, result, time_used, memory_used;
		string html = fileToString("tmpfiles/statusdata.html");
		if (code != CURLE_OK) syslog(LOG_ERR, "getStatus failed.");
		else {
			if (html.find("var is_login=\"\";") != string::npos || !RE2::PartialMatch(html, "(?s)<table class=\"ojlist\".*?<tr.*?(<tr.*?</tr>)", &res)) {
				syslog(LOG_ERR, "[ERROR] HRBUSTJudger: Failed to get status row.");
			}
			if (!RE2::PartialMatch(res, "(?s)<td.*?<td>([0-9]*).*?<td.*?<td.*?>(.*?)</td>", &runid, &result)) {
				syslog(LOG_ERR, "[ERROR] HRBUSTJudger: Fail to get current result.");
			}
			result = convertResult(trim(result));
			cout << "Result is: " << result << endl;
			if (isFinalResult(result)) {
				if (!RE2::PartialMatch(res, "(?s)>([0-9]*)ms.*?>([0-9]*)k", &time_used, &memory_used)) {
					syslog(LOG_ERR, "[ERROR] HRBUSTJudger: Failed to parse details from status row.");
				}
				cout << "0---------------------------------" << endl;
				cout << "Time used: " << time_used << " Memory_used: " << memory_used<< endl;
				judgeResult.setCodeId(judgeInfo.getCodeId());
				judgeResult.setRunId(atoi(trim(runid).c_str()));
				judgeResult.setJudgeStatus(status_table[result]);
				judgeResult.setRunTime(atoi(trim(time_used).c_str()));
				judgeResult.setRunMemory(atoi(trim(memory_used).c_str()));

				cout << "[Result] Get JudgeStatus: " << judgeResult.getJudgeStatus() << endl;
				if (judgeResult.getJudgeStatus() == OJ_CE) {
					judgeResult.setErrorInfo(getCEinfo());
				} else {
					judgeResult.setErrorInfo("NULL");
				}
				break;
			} else {
				usleep(5000);
			}
		}
	}
}
예제 #5
0
파일: fzuhandler.cpp 프로젝트: himcc/bnuoj
//http://acm.fzu.edu.cn/log.php?pid=1000&user=bnuvjudge&language=1
bool getStatus(string pid,string lang,string & result,string& ce_info,string &tu,string &mu) {
    int begin=time(NULL);
    string runid;
    tu=mu="0";
    string ts;
    while (true) {
        FILE * fp=fopen(tfilename,"w+");
        curl = curl_easy_init();
        if(curl) {
            curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
            curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
            curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "fzu.cookie");
            string url=(string)"http://acm.fzu.edu.cn/log.php?user="******"&pid="+pid;
            //cout<<url<<endl;
            curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
            res = curl_easy_perform(curl);
            curl_easy_cleanup(curl);
        }
        fclose(fp);
        if (res) return false;
        ts=getResFromFile(tfilename);
        //cout<<ts;
        if (ts.find("Error Occurred")!=string::npos||ts.find("The page is temporarily unavailable")!=string::npos) return false;
        runid=getRunid(ts);
        result=getResult(ts);
        //cout << result;
        if (result.find("Waiting")==string::npos
            &&result.find("Running")==string::npos
            &&result.find("Judging")==string::npos
            &&result.find("Queuing")==string::npos
            &&result.find("Compiling")==string::npos) {
            break;
        }
        if (time(NULL)-begin>MAX_WAIT_TIME) break;
    }
    if (!(result.find("Waiting")==string::npos
            &&result.find("Running")==string::npos
            &&result.find("Judging")==string::npos
            &&result.find("Queuing")==string::npos
            &&result.find("Compiling")==string::npos)) return false;
    result=convertResult(result);
    if (result=="Compile Error") ce_info=getCEinfo(runid);
    else ce_info="";
    if (result=="Accepted") {
        tu=getUsedTime(ts);
        mu=getUsedMem(ts);
    }
    return true;
}
예제 #6
0
//http://acm.nbut.cn/Problem/status.xhtml?username=bnuvjudge&problemid=1000&language=1
bool getStatus(string pid,string lang,string & result,string& ce_info,string &tu,string &mu) {
    int begin=time(NULL);
    string runid;
    tu=mu="0";
    string ts;
    while (true) {
        FILE * fp=fopen(tfilename,"w+");
        curl = curl_easy_init();
        if(curl) {
            curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
            curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
            curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "nbut.cookie");
            string url=(string)"http://acm.nbut.cn/Problem/status.xhtml?username="******"&problemid="+pid+"&language="+lang;
            //cout<<url<<endl;
            curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
            res = curl_easy_perform(curl);
            curl_easy_cleanup(curl);
        }
        fclose(fp);
        if (res) return false;
        ts=getResFromFile(tfilename);
        //cout<<ts;
        if (ts.find("Error Occurred")!=string::npos||ts.find("The page is temporarily unavailable")!=string::npos) return false;
        runid=getRunid(ts);
        result=getResult(ts);
        //cout << result;
        if (result.find("WAITING")==string::npos
            &&result.find("RUNNING")==string::npos
            &&result.find("JUDGING")==string::npos
            &&result.find("QUEUING")==string::npos
            &&result.find("COMPILING")==string::npos) {
            break;
        }
        if (time(NULL)-begin>MAX_WAIT_TIME) break;
    }
    if (!(result.find("WAITING")==string::npos
            &&result.find("RUNNING")==string::npos
            &&result.find("JUDGING")==string::npos
            &&result.find("QUEUING")==string::npos
            &&result.find("COMPILING")==string::npos)) return false;
    result=convertResult(result);
    if (result=="Compile Error") ce_info=getCEinfo(runid);
    else ce_info="";
    tu=getUsedTime(ts);
    mu=getUsedMem(ts);
    return true;
}
예제 #7
0
//http://acm.hdu.edu.cn/status.php?first=&pid=1000&user=bnuvjudge&lang=1&status=0
bool getStatus(string pid,string lang,string & result,string& ce_info,string &tu,string &mu) {
    int begin=time(NULL);
    string runid=getRealRunid();
    //cout<<runid;
    tu=mu="0";
    string ts;
    while (true) {
        if (time(NULL)-begin>MAX_WAIT_TIME) break;
        FILE * fp=fopen(tfilename,"w+");
        curl = curl_easy_init();
        if(curl) {
            curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
            curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
            curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "uvalive.cookie");
            curl_easy_setopt(curl, CURLOPT_USERAGENT, "curl");
            string url=(string)"http://livearchive.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=9";
            curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
            res = curl_easy_perform(curl);
            curl_easy_cleanup(curl);
        }
        fclose(fp);
        if (res) return false;
        ts=getFirstFromFile(tfilename);
        if (ts.find("<b>One or more following ERROR(s) occurred.")!=string::npos||ts.find("The page is temporarily unavailable")!=string::npos) return false;
        writelog((char *)ts.c_str());
        writelog((char *)(runid+"\n").c_str());
        if (runid!=getRunid(ts)) continue;
        result=getResult(ts);
        //cout << result <<endl;
        if (result.find("Waiting")==string::npos
            &&result.find("Running")==string::npos
            &&result.find("Judging")==string::npos
            &&result.find("judge")==string::npos
            &&result.find("Queuing")==string::npos
            &&result.find("queue")==string::npos
            &&result.find("Compiling")==string::npos
            &&result.find("Received")==string::npos
            &&result.find("Linking")==string::npos
            &&result.find("Submission error")==string::npos
            &&result!=""&&result[0]!='\t'&&result[0]!=' ') {
            break;
        }
    }
    if (!(result.find("Waiting")==string::npos
            &&result.find("Running")==string::npos
            &&result.find("Judging")==string::npos
            &&result.find("judge")==string::npos
            &&result.find("Queuing")==string::npos
            &&result.find("queue")==string::npos
            &&result.find("Compiling")==string::npos
            &&result.find("Linking")==string::npos
            &&result.find("Received")==string::npos
            &&result.find("Submission error")==string::npos
            &&result!=""&&result[0]!='\t'&&result[0]!=' ')) return false;
    if (result=="Compilation error") {
        result="Compile Error";
        ce_info=getCEinfo(runid);
    }
    else ce_info="";
    tu=getUsedTime(ts);
    mu=getUsedMem(ts);
    if (mu=="") mu="0";
    if (result!="Accepted"&&result[result.length()-1]=='d') {
        result.erase(result.end()-2,result.end());
    }
    for (int i=0;i<result.length();i++) {
        if (result[i]==' ') {
            if (result[i+1]>='a'&&result[i+1]<='z') result[i+1]+='A'-'a';
        }
    }
    return true;
}
예제 #8
0
/**
 * Send a submit to remote, and store the judge result
 * @param bott      Submit info
 * @param filename  File store the result
 */
void VirtualJudger::judge(Bott * bott, string filename) {
  // login
  if (!logged_in) { // Not logged in, try login
    clearCookies();
    login();
    log("Logged in.");
    logged_in = true;
  }

  // submit
  int submit_status = submit(bott);
  if (submit_status == SUBMIT_OTHER_ERROR) {
    // first time fail, blame login status...
    log((string) "Submit error. Assume not logged in.");
    logged_in = false;
    clearCookies();
    login();
    log("Logged in.");
    logged_in = true;
    submit_status = submit(bott);
    if (submit_status == SUBMIT_OTHER_ERROR) {
      // second time fail, blame frequency
      if (info->GetOj() == "CodeChef") {
        // CodeChef's restriction is harsh... 30 seconds cool down required
        log("Submit error. Assume should sleep for a while, "
            "sleeping 30 seconds.");
        sleep(30);
      } else {
        log("Submit error. Assume should sleep for a while, sleeping " +
            intToString(VirtualJudger::SLEEP_INTERVAL) + " seconds.");
        sleep(VirtualJudger::SLEEP_INTERVAL);
      }
      submit_status = submit(bott);
    }
  } else if (submit_status == SUBMIT_INVALID_LANGUAGE &&
      (info->GetOj() == "SPOJ" || info->GetOj() == "CodeChef") &&
      convertLanguage(bott->Getlanguage()) == "41") {
    // Special HACK for Invalid Language on SPOJ/CodeChef, since they have two
    // C++ types and each covers a certain subset of problems
    log((string) "Try another C++ for SPOJ/CodeChef");
    bott->Setlanguage(1);
    submit_status = submit(bott);
  }
  if (submit_status != SUBMIT_OTHER_ERROR) log("Submitted.");

  // check submit status
  sleep(1); // sleep 1 second, just in case remote status table is not refreshed
  Bott * result;
  if (submit_status == SUBMIT_NORMAL) {
    // get status
    result = getStatus(bott);
    result->Setrunid(bott->Getrunid());
    if (result->Getresult() == "Compile Error") {
      try {
        result->Setce_info(getCEinfo(result));
      } catch (...) {
        log("Failed to get CE info, use empty one instead.");
        result->Setce_info("");
      }
    }
  } else {
    result = new Bott;
    result->Setrunid(bott->Getrunid());
    switch (submit_status) {
      case SUBMIT_SAME_CODE:
        generateSpecialResult(result, "Judge Error (Same Code)");
        break;
      case SUBMIT_INVALID_LANGUAGE:
        generateSpecialResult(result, "Judge Error (Invalid Language)");
        break;
      case SUBMIT_COMPILE_ERROR:
        generateSpecialResult(result, "Compile Error");
        break;
      default:
        log("Submit Error.");
        generateSpecialResult(result, "Judge Error");
    }
  }
  result->Setout_filename(filename);
  result->save();
  log("Done judging. Result: " + result->Getresult() + ", remote runid: " +
      result->Getremote_runid());
  delete result;
}
예제 #9
0
파일: test.cpp 프로젝트: jie414341055/toj
//http://acm.hdu.edu.cn/status.php?first=&pid=1000&user=tjuvjudge&lang=1&status=0
bool getStatus(string pid,string lang,string & result,string& ce_info,string &tu,string &mu) {
	int begin=time(NULL);
	string runid;
	tu=mu="0";
	string ts;
	int tried=0;
	while (true) {
		FILE * fp=fopen(tfilename,"w+");
		curl = curl_easy_init();
		if(curl) {
			curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
			curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
			curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "hdu.cookie");
			string url=(string)"http://acm.hdu.edu.cn/status.php?first=&pid="+pid+"&user="******"&lang=&status=0";
			//cout<<url;
			curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
			res = curl_easy_perform(curl);
			curl_easy_cleanup(curl);
		}
		fclose(fp);
		if (res) return false;
		ts=getLineFromFile(tfilename,77);
		//cout<<ts;
		//writelog((char *)ts.c_str());
		/*if (ts.find("alert(\"Login failed!)")!=string::npos) return false;
		 */
		if (ts.find("Connect(0) to MySQL Server failed.")!=string::npos||ts.find("<b>One or more following ERROR(s) occurred.")!=string::npos||ts.find("<h2>The requested URL could not be retrieved</h2>")!=string::npos||ts.find("PHP: Maximum execution time of")!=string::npos) {
			tried++;
			if (tried>=MAX_TRY_TIME) return false;
			continue;
		}
		runid=getRunid(ts);
		result=getResult(ts);
		/* minjie */
		db_client.update("toj.Status",
				BSON("run_ID" << temp.runid),
				BSON("$set" << BSON("result"<<result)),
				true, false);
				//upsert, multi
		
		cout << result<<endl<<runid<<endl;
		if (result.find("Waiting")==string::npos
				&&result.find("Running")==string::npos
				&&result.find("Judging")==string::npos
				&&result.find("Queuing")==string::npos
				&&result.find("Compiling")==string::npos
				&&result.find("\n")&&result!="") {
			break;
		}
		/* minjie */
		//if (time(NULL)-begin>30) sleep(500);
		if (time(NULL)-begin>MAX_WAIT_TIME) break;
	}
	if (!(result.find("Waiting")==string::npos
				&&result.find("Running")==string::npos
				&&result.find("Judging")==string::npos
				&&result.find("Queuing")==string::npos
				&&result.find("Compiling")==string::npos)) return false;

	if(result=="Compilation Error") ce_info = getCEinfo(runid);
	else	ce_info="";
	tu=getUsedTime(ts);
	mu=getUsedMem(ts);

	/* minjie update Status */
	db_client.update("toj.Status",
			BSON("run_ID" << temp.runid),
			BSON("$set" << BSON("vrun_ID" << runid << "oj" << "HDU" << "result"<<result<<"time_used"<<tu<<"mem_used"<<mu<<"ce_info"<<ce_info)),
			true, false);
	/* minjie update User */
	db_client.update("toj.User",
			BSON("username" << temp.user),
			BSON("$inc"<<BSON("total_submit"<<1)),
			false,true);
			//upsert,multi

	if(result == "Accepted") {
		db_client.update("toj.User",
				BSON("username" << temp.user),
				BSON("$inc"<<BSON("total_ac"<<1)),
				false,true);

		/* update speed */
		bson::bo obj = db_client.findOne("toj.Status",
				BSON("username" << temp.user << "pid" << temp.pid << "speed" << 51));
		bool fast = false;
		if(obj.isEmpty()) fast = true;
		else {
			int time_used = boost::lexical_cast<int>(obj.getStringField("time_used"));
			int mem_used = boost::lexical_cast<int>(obj.getStringField("mem_used"));
			int now_tu = boost::lexical_cast<int>(tu);
			int now_mu = boost::lexical_cast<int>(mu);
			if(now_tu < time_used || (now_tu == time_used && now_mu < mem_used))
				fast = true;
		}
		if(fast) {
			db_client.update("toj.Status",
					BSON("username" << temp.user << "pid" << temp.pid),
					BSON("$set" << BSON("speed" << 50)),
					true, false);
			db_client.update("toj.Status",
					BSON("run_ID" << temp.runid),
					BSON("$set" << BSON("speed" << 51)),
					true, false);
		}
	}

	/* minjie update Problem */
	db_client.update("toj.Problem",
			BSON("pid" << temp.pid),
			BSON("$inc"<<BSON("total_submit"<<1)),
			false,true);
			//upsert,multi
	string dbresult;
	switch(result[0]) {
		case 'A': 	dbresult = "total_ac";
			  	break;
		case 'W': 	dbresult = "total_wa";
			  	break;
		case 'P': 	dbresult = "total_pe";
			  	break;
		case 'C': 	dbresult = "total_ce";
			  	break;
		case 'R': 	dbresult = "total_re";
			  	break;
		case 'T': 	dbresult = "total_tle";
			  	break;
		case 'M': 	dbresult = "total_mle";
			  	break;
		case 'O': 	dbresult = "total_ole";
			  	break;
		default:  	dbresult = "total_other";
			  	break;
	}

	db_client.update("toj.Problem",
			BSON("pid" << temp.pid),
			BSON("$inc"<<BSON(dbresult<<1)),
			false,true);
			//upsert,multi

	return true;
}
예제 #10
0
//http://acm.hdu.edu.cn/status.php?first=&pid=1000&user=bnuvjudge&lang=1&status=0
bool getStatus(string pid,string lang,string & result,string& ce_info,string &tu,string &mu) {
	int begin=time(NULL);
	string runid;
	tu=mu="0";
	string ts;
	int tried=0;
	while (true) {
		FILE * fp=fopen(tfilename,"w+");
		curl = curl_easy_init();
		if(curl) {
			curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
			curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
			curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "hdu.cookie");
			string url=(string)"http://acm.hdu.edu.cn/status.php?first=&pid="+pid+"&user="******"&lang=&status=0";
			//cout<<url;
			curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
			res = curl_easy_perform(curl);
			curl_easy_cleanup(curl);
		}
		fclose(fp);
		if (res) return false;
		ts=getLineFromFile(tfilename,77);
		//cout<<ts;
		//writelog((char *)ts.c_str());
		/*if (ts.find("alert(\"Login failed!)")!=string::npos) return false;
		 */
		if (ts.find("Connect(0) to MySQL Server failed.")!=string::npos||ts.find("<b>One or more following ERROR(s) occurred.")!=string::npos||ts.find("<h2>The requested URL could not be retrieved</h2>")!=string::npos||ts.find("PHP: Maximum execution time of")!=string::npos) {
			tried++;
			if (tried>=MAX_TRY_TIME) return false;
			continue;
		}
		runid=getRunid(ts);
		result=getResult(ts);
		cout << result<<endl<<runid<<endl;
		if (result.find("Waiting")==string::npos
				&&result.find("Running")==string::npos
				&&result.find("Judging")==string::npos
				&&result.find("Queuing")==string::npos
				&&result.find("Compiling")==string::npos
				&&result.find("\n")&&result!="") {
			break;
		}
		if (time(NULL)-begin>MAX_WAIT_TIME) break;
	}
	if (!(result.find("Waiting")==string::npos
				&&result.find("Running")==string::npos
				&&result.find("Judging")==string::npos
				&&result.find("Queuing")==string::npos
				&&result.find("Compiling")==string::npos)) return false;
	if (result=="Compilation Error") {
		//result="Compile Error";
		ce_info=getCEinfo(runid);
	}
	else ce_info="";
	tu=getUsedTime(ts);
	mu=getUsedMem(ts);
	/*
	if (result != "Accepted" && result[result.length()-1] == 'd') {
		result.erase(result.end()-2,result.end());
	}
	*/
	return true;
}