2005-01-20 23:22:22 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
2003-08-14 00:02:15 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation;
|
|
|
|
// either version 2.1 of the License, or (at your option) any later version.
|
2003-08-14 00:02:15 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This software is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
2003-08-14 00:02:15 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
|
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2003-08-14 00:02:15 +00:00
|
|
|
|
2003-09-20 17:38:13 +00:00
|
|
|
// Code to facilitate writing validators.
|
|
|
|
// Can be used as the basis for a validator that accepts everything
|
|
|
|
// (see validate_trivial.C),
|
|
|
|
// or that requires strict or fuzzy equality.
|
|
|
|
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2003-09-20 17:38:13 +00:00
|
|
|
|
2003-10-21 04:06:55 +00:00
|
|
|
#include "error_numbers.h"
|
2003-08-14 00:02:15 +00:00
|
|
|
#include "parse.h"
|
2004-08-06 11:42:41 +00:00
|
|
|
#include "util.h"
|
2005-01-02 08:01:27 +00:00
|
|
|
#include "filesys.h"
|
2004-04-08 08:15:23 +00:00
|
|
|
|
|
|
|
#include "sched_util.h"
|
|
|
|
#include "sched_config.h"
|
|
|
|
#include "sched_msgs.h"
|
2006-06-10 21:29:51 +00:00
|
|
|
#include "validator.h"
|
2003-10-21 04:06:55 +00:00
|
|
|
#include "validate_util.h"
|
2003-08-14 00:02:15 +00:00
|
|
|
|
2004-06-30 18:17:21 +00:00
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
|
2006-10-28 18:25:35 +00:00
|
|
|
#if 0
|
2003-08-14 00:02:15 +00:00
|
|
|
// get the name of a result's (first) output file
|
|
|
|
//
|
2004-08-06 11:42:41 +00:00
|
|
|
int get_output_file_path(RESULT const& result, string& path_str) {
|
2006-10-28 18:25:35 +00:00
|
|
|
char buf[256], path[1024];
|
2003-08-14 00:02:15 +00:00
|
|
|
|
2005-04-18 17:54:03 +00:00
|
|
|
if (!parse_str(result.xml_doc_out, "<name>", buf, sizeof(buf))) {
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
2005-09-23 21:09:00 +00:00
|
|
|
dir_hier_path(buf, config.upload_dir, config.uldl_dir_fanout, path);
|
2004-08-06 11:42:41 +00:00
|
|
|
path_str = path;
|
2003-08-14 00:02:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2006-10-28 18:25:35 +00:00
|
|
|
#endif
|
2003-08-14 00:02:15 +00:00
|
|
|
|
2006-10-28 18:25:35 +00:00
|
|
|
static int parse_filename(XML_PARSER& xp, string& name) {
|
|
|
|
char tag[256];
|
|
|
|
bool is_tag, found=false;
|
|
|
|
while (!xp.get(tag, sizeof(tag), is_tag)) {
|
|
|
|
if (!is_tag) continue;
|
|
|
|
if (!strcmp(tag, "/file")) {
|
|
|
|
return found?0:ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
if (xp.parse_string(tag, "name", name)) {
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int get_output_file_path(RESULT const& result, string& path_str) {
|
|
|
|
char tag[256], path[1024];
|
|
|
|
bool is_tag;
|
|
|
|
string name;
|
|
|
|
MIOFILE mf;
|
2006-11-07 04:05:05 +00:00
|
|
|
mf.init_buf_read((char*)(result.xml_doc_out));
|
2006-10-28 18:25:35 +00:00
|
|
|
XML_PARSER xp(&mf);
|
|
|
|
while (!xp.get(tag, sizeof(tag), is_tag)) {
|
|
|
|
if (!is_tag) continue;
|
|
|
|
if (!strcmp(tag, "file")) {
|
|
|
|
int retval = parse_filename(xp, name);
|
|
|
|
if (retval) return retval;
|
|
|
|
dir_hier_path(name.c_str(), config.upload_dir, config.uldl_dir_fanout, path);
|
|
|
|
path_str = path;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int get_output_file_paths(RESULT const& result, vector<string>& paths) {
|
|
|
|
char tag[256], path[1024];
|
|
|
|
bool is_tag;
|
|
|
|
MIOFILE mf;
|
|
|
|
string name;
|
2006-11-07 04:05:05 +00:00
|
|
|
mf.init_buf_read((char*)(result.xml_doc_out));
|
2006-10-28 18:25:35 +00:00
|
|
|
XML_PARSER xp(&mf);
|
|
|
|
paths.clear();
|
|
|
|
while (!xp.get(tag, sizeof(tag), is_tag)) {
|
|
|
|
if (!is_tag) continue;
|
|
|
|
if (!strcmp(tag, "file")) {
|
|
|
|
int retval = parse_filename(xp, name);
|
|
|
|
if (retval) return retval;
|
|
|
|
dir_hier_path(name.c_str(), config.upload_dir, config.uldl_dir_fanout, path);
|
|
|
|
paths.push_back(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2003-08-14 00:02:15 +00:00
|
|
|
|
2005-03-07 23:15:53 +00:00
|
|
|
#define CREDIT_EPSILON .001
|
|
|
|
|
|
|
|
// If we have N correct results with nonzero claimed credit,
|
|
|
|
// compute a canonical credit as follows:
|
|
|
|
// - if N==0 (all claimed credits are infinitesmal), return CREDIT_EPSILON
|
|
|
|
// - if N==1, return that credit
|
|
|
|
// - if N==2, return min
|
|
|
|
// - if N>2, toss out min and max, return average of rest
|
2003-08-14 00:02:15 +00:00
|
|
|
//
|
2005-03-07 23:15:53 +00:00
|
|
|
double median_mean_credit(vector<RESULT>& results) {
|
|
|
|
int ilow=-1, ihigh=-1;
|
2003-08-14 00:02:15 +00:00
|
|
|
double credit_low = 0, credit_high = 0;
|
2005-03-07 23:15:53 +00:00
|
|
|
int nvalid = 0;
|
|
|
|
unsigned int i;
|
|
|
|
|
2005-03-22 05:30:32 +00:00
|
|
|
for (i=0; i<results.size(); i++) {
|
2005-03-07 23:15:53 +00:00
|
|
|
RESULT& result = results[i];
|
|
|
|
if (result.validate_state != VALIDATE_STATE_VALID) continue;
|
|
|
|
if (result.claimed_credit < CREDIT_EPSILON) continue;
|
|
|
|
if (ilow < 0) {
|
|
|
|
ilow = ihigh = i;
|
|
|
|
credit_low = credit_high = result.claimed_credit;
|
2003-08-14 00:02:15 +00:00
|
|
|
} else {
|
2005-03-07 23:15:53 +00:00
|
|
|
if (result.claimed_credit < credit_low) {
|
|
|
|
ilow = i;
|
|
|
|
credit_low = result.claimed_credit;
|
2003-08-14 00:02:15 +00:00
|
|
|
}
|
2005-03-07 23:15:53 +00:00
|
|
|
if (result.claimed_credit > credit_high) {
|
|
|
|
ihigh = i;
|
|
|
|
credit_high = result.claimed_credit;
|
2003-08-14 00:02:15 +00:00
|
|
|
}
|
|
|
|
}
|
2005-03-07 23:15:53 +00:00
|
|
|
nvalid++;
|
2003-08-14 00:02:15 +00:00
|
|
|
}
|
|
|
|
|
2005-03-07 23:15:53 +00:00
|
|
|
switch(nvalid) {
|
|
|
|
case 0:
|
|
|
|
return CREDIT_EPSILON;
|
|
|
|
case 1:
|
|
|
|
case 2:
|
2003-08-14 00:02:15 +00:00
|
|
|
return credit_low;
|
2005-03-07 23:15:53 +00:00
|
|
|
default:
|
2003-08-14 00:02:15 +00:00
|
|
|
double sum = 0;
|
2005-03-22 05:30:32 +00:00
|
|
|
for (i=0; i<results.size(); i++) {
|
2005-03-10 22:05:42 +00:00
|
|
|
if (i == (unsigned int) ilow) continue;
|
|
|
|
if (i == (unsigned int) ihigh) continue;
|
2005-03-07 23:15:53 +00:00
|
|
|
RESULT& result = results[i];
|
|
|
|
if (result.validate_state != VALIDATE_STATE_VALID) continue;
|
2003-08-14 00:02:15 +00:00
|
|
|
|
2005-03-07 23:15:53 +00:00
|
|
|
sum += result.claimed_credit;
|
2003-08-14 00:02:15 +00:00
|
|
|
}
|
2005-03-07 23:15:53 +00:00
|
|
|
return sum/(nvalid-2);
|
2003-08-14 00:02:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_07049e8a0e = "$Id$";
|