Skip to content

Instantly share code, notes, and snippets.

@Pitbi
Created September 21, 2012 21:41
Show Gist options
  • Save Pitbi/3764096 to your computer and use it in GitHub Desktop.
Save Pitbi/3764096 to your computer and use it in GitHub Desktop.
DEBUG: TypeError: Cannot read property 'value' of undefined
at _asyncMap (/home/pitbi/Projects/RaceLive/node_modules/async/lib/async.js:185:23)
at async.forEachSeries.iterate (/home/pitbi/Projects/RaceLive/node_modules/async/lib/async.js:108:13)
at async.forEachSeries.iterate (/home/pitbi/Projects/RaceLive/node_modules/async/lib/async.js:119:25)
at _asyncMap (/home/pitbi/Projects/RaceLive/node_modules/async/lib/async.js:187:17)
at async.series.results (/home/pitbi/Projects/RaceLive/node_modules/async/lib/async.js:491:34)
at async.forEach (/home/pitbi/Projects/RaceLive/node_modules/async/lib/async.js:94:25)
at bestLapSearch (/home/pitbi/Projects/RaceLive/lib/rfactor_xml_parser.js:188:19)
at async.forEach (/home/pitbi/Projects/RaceLive/node_modules/async/lib/async.js:86:13)
at Array.forEach (native)
at _forEach (/home/pitbi/Projects/RaceLive/node_modules/async/lib/async.js:26:24)
DEBUG: Program node server.js exited with code 1
DEBUG: Starting child process with 'node server.js'
RFactorXmlParser.prototype._loadDriveSession = function _loadDriveSession(callback) {
var self = this;
var drivers = self.xml.find("//Driver");
var dateText = self.xml.get("/rFactorXML/RaceResults/TimeString").text();
var dateMatches = /^(\d{4})\/(\d{2})\/(\d{2}) (\d\d):(\d\d):(\d\d)/.exec(dateText);
var date = new Date(dateMatches[1], dateMatches[2], dateMatches[3], dateMatches[4], dateMatches[5], dateMatches[6]);
Qualification.findOne({date: date}).exec(function (err, existingQualification) {
if (err)
return callback(err);
if(!existingQualification) {
var qualification = new Qualification ({date: date, track: self.track.id, mod: self.mod.id});
drivers.forEach(function (driver) {
var driverName = driver.get("Name").text();
var driverBestLap = self._parseDriveTime(driver.get("BestLapTime").text());
var driverCar = driver.get("CarType").text();
var driverPosition = driver.get("Position").text();
var laps = driver.find("Lap");
Driver.findOne({gameName : driverName}).exec(function (err, driverFound) {
if (err)
return callback(err);
if (driverFound) {
var entry = {
driver : driverFound.id,
bestLap : driverBestLap,
car : driverCar,
position: driverPosition,
laps : []
};
async.forEach(laps, lapsSearch, callback);
qualification.entries.push(entry);
function lapsSearch(lap, callback) {
var lapTime = self._parseDriveTime(lap.text());
var lapAttribute = { lapTime: lapTime };
console.log("Prout");
async.forEach(lap.attrs(), lapAttributeSave, callback);
entry.laps.push(lapAttribute);
callback();
}
function lapAttributeSave(lap, callback) {
var name = lap.name();
var value = lap.value();
console.log("VAL", value, name);
lap[name] = value;
callback;
}
var driverBestLaps = driverFound.bestLaps;
var driverBestLapAttributes = {track: self.track.id, mod: self.mod.id, bestLap: driverBestLap, qualification: qualification.id};
console.log("DBBDBDBDB",driverBestLapAttributes);
if (driverBestLaps[0]) {
console.log
async.forEach(driverBestLaps, bestLapSearch, callback)
} else {
console.log("Add whitout preBestLap");
driverFound.bestLaps.push(driverBestLapAttributes);
}
function bestLapSearch(value, callback) {
console.log("");
if (value) {
if (value.track != driverBestLapAttributes.track && value.mod != driverBestLapAttributes.mod) {
driverFound.bestLaps.push(driverBestLapAttributes);
console.log("2");
callback();
} else if (value.track === driverBestLapAttributes.track && value.mod === driverBestLapAttributes.mod && driverBestLapAttributes.bestLap > value.bestLap) {
var index = driverFound.bestLaps.indexOf(driverBestLapAttributes.bestLap);
driverFound.bestLaps[index] = driverBestLapAttributes;
console.log("3");
callback();
} else {
console.log("4");
callback();
}
} else {
callback();
}
};
qualification.save(function (err) {
if (err) {
return callback(err);
} else {
driverFound.save(function (err) {
if (err)
return callback(err);
console.log("SAVE DRIVER");
});
return callback(null, "Qualification Added");
}
});
}
});
});
} else {
return callback(null, "Existing Qualification");
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment