This commit is contained in:
dongpd 2020-02-11 11:03:25 +07:00
parent 5417531e83
commit e7cfe25ceb

View File

@ -98,7 +98,7 @@ exports.SaveLogs = async function (req, res) {
if ((currentTimestamp - currentIn[i].time) < 600) { if ((currentTimestamp - currentIn[i].time) < 600) {
if (req.body.plate === currentIn[i].plate) { if (req.body.plate === currentIn[i].plate) {
canSaveLogs = false; canSaveLogs = false;
} else if (levenshtein(req.body.plate, currentIn[i].plate) < 3) { } else if (levenshtein(req.body.plate, currentIn[i].plate) < 2) {
canSaveLogs = false; canSaveLogs = false;
} }
} }
@ -109,7 +109,7 @@ exports.SaveLogs = async function (req, res) {
if ((currentTimestamp - currentOut[i].time) < 600) { if ((currentTimestamp - currentOut[i].time) < 600) {
if (req.body.plate === currentOut[i].plate) { if (req.body.plate === currentOut[i].plate) {
canSaveLogs = false; canSaveLogs = false;
} else if (levenshtein(req.body.plate, currentOut[i].plate) < 3) { } else if (levenshtein(req.body.plate, currentOut[i].plate) < 2) {
canSaveLogs = false; canSaveLogs = false;
} }
} }
@ -117,6 +117,7 @@ exports.SaveLogs = async function (req, res) {
} }
if (canSaveLogs) { if (canSaveLogs) {
var currentPlate = "";
var fileName = req.body.plate + "_" + currentTimestamp + ".png"; var fileName = req.body.plate + "_" + currentTimestamp + ".png";
var plateSaved = currentYear + "/" + currentMonth + "/" + currentDate + "/" + req.body.type + "/plate/" + fileName; var plateSaved = currentYear + "/" + currentMonth + "/" + currentDate + "/" + req.body.type + "/plate/" + fileName;
var frameSaved = currentYear + "/" + currentMonth + "/" + currentDate + "/" + req.body.type + "/frame/" + fileName; var frameSaved = currentYear + "/" + currentMonth + "/" + currentDate + "/" + req.body.type + "/frame/" + fileName;
@ -127,6 +128,7 @@ exports.SaveLogs = async function (req, res) {
var query_plate_raw = await db.query("SELECT * FROM vehicle WHERE plate='" + req.body.plate + "'"); var query_plate_raw = await db.query("SELECT * FROM vehicle WHERE plate='" + req.body.plate + "'");
if (query_plate_raw.length > 0) { if (query_plate_raw.length > 0) {
vehicleInfo = {"status": true, "data": query_plate_raw[0]}; vehicleInfo = {"status": true, "data": query_plate_raw[0]};
currentPlate = query_plate_raw[0].plate;
if (req.body.type == "in") { if (req.body.type == "in") {
var newLogs = await db.query("INSERT INTO logs(`vehicle_id`,`plate_image_in`,`frame_image_in`,`time_in`) VALUES ('" + query_plate_raw[0].id + "','" + plateSaved + "','" + frameSaved + "'," + currentTimestamp + ")"); var newLogs = await db.query("INSERT INTO logs(`vehicle_id`,`plate_image_in`,`frame_image_in`,`time_in`) VALUES ('" + query_plate_raw[0].id + "','" + plateSaved + "','" + frameSaved + "'," + currentTimestamp + ")");
io.emit('logs', { io.emit('logs', {
@ -162,9 +164,10 @@ exports.SaveLogs = async function (req, res) {
} }
} }
} else { } else {
var query_plate_levenshtein = await db.query("SELECT * FROM `vehicle` WHERE LENGTH(`plate`)=" + req.body.plate.length + " AND levenshtein('" + req.body.plate + "', `plate`) BETWEEN 0 AND 1 LIMIT 0,1"); var query_plate_levenshtein = await db.query("SELECT * FROM `vehicle` WHERE LENGTH(`plate`)>=" + req.body.plate.length + " AND levenshtein('" + req.body.plate + "', `plate`) BETWEEN 0 AND 1 LIMIT 0,1");
if (query_plate_levenshtein.length > 0) { if (query_plate_levenshtein.length > 0) {
vehicleInfo = {"status": true, "data": query_plate_levenshtein[0]}; vehicleInfo = {"status": true, "data": query_plate_levenshtein[0]};
currentPlate = query_plate_levenshtein[0].plate;
if (req.body.type == "in") { if (req.body.type == "in") {
var newLogs = await db.query("INSERT INTO logs(`vehicle_id`,`plate_image_in`,`frame_image_in`,`time_in`) VALUES ('" + query_plate_levenshtein[0].id + "','" + plateSaved + "','" + frameSaved + "'," + currentTimestamp + ")"); var newLogs = await db.query("INSERT INTO logs(`vehicle_id`,`plate_image_in`,`frame_image_in`,`time_in`) VALUES ('" + query_plate_levenshtein[0].id + "','" + plateSaved + "','" + frameSaved + "'," + currentTimestamp + ")");
io.emit('logs', { io.emit('logs', {
@ -200,6 +203,7 @@ exports.SaveLogs = async function (req, res) {
} }
} }
} else { } else {
currentPlate = req.body.plate;
if (req.body.type == "in") { if (req.body.type == "in") {
if (falseIn < maxFalse) { if (falseIn < maxFalse) {
vehicleInfo = {"status": false}; vehicleInfo = {"status": false};
@ -239,12 +243,12 @@ exports.SaveLogs = async function (req, res) {
for (var i = 0; i < currentIn.length; i++) { for (var i = 0; i < currentIn.length; i++) {
lists.push(currentIn[i].plate); lists.push(currentIn[i].plate);
} }
console.log("req: ", req.body.plate, " ", req.body.type, " ", lists, " ", vehicleInfo.status); console.log("req: ", req.body.plate, " ", currentPlate, " ", req.body.type, " ", lists, " ", vehicleInfo.status);
if (vehicleInfo.status) { if (vehicleInfo.status) {
if (currentIn.length >= maxCompare) { if (currentIn.length >= maxCompare) {
currentIn.shift(); currentIn.shift();
} }
currentIn.push({"plate": req.body.plate, "time": currentTimestamp}); currentIn.push({"plate": currentPlate, "time": currentTimestamp});
} }
} }
if (req.body.type === "out") { if (req.body.type === "out") {
@ -252,12 +256,12 @@ exports.SaveLogs = async function (req, res) {
for (var i = 0; i < currentOut.length; i++) { for (var i = 0; i < currentOut.length; i++) {
lists.push(currentOut[i].plate); lists.push(currentOut[i].plate);
} }
console.log("req: ", req.body.plate, " ", req.body.type, " ", lists, " ", vehicleInfo.status); console.log("req: ", req.body.plate, " ", currentPlate, " ", req.body.type, " ", lists, " ", vehicleInfo.status);
if (vehicleInfo.status) { if (vehicleInfo.status) {
if (currentOut.length >= maxCompare) { if (currentOut.length >= maxCompare) {
currentOut.shift(); currentOut.shift();
} }
currentOut.push({"plate": req.body.plate, "time": currentTimestamp}); currentOut.push({"plate": currentPlate, "time": currentTimestamp});
} }
} }
res.send(vehicleInfo); res.send(vehicleInfo);