compare with 10 plate
This commit is contained in:
parent
ae07cb58d7
commit
b56d26d5c1
|
@ -59,8 +59,8 @@ function levenshtein(a, b) {
|
||||||
}
|
}
|
||||||
const db = makeDb(config);
|
const db = makeDb(config);
|
||||||
|
|
||||||
var currentIn = {"plate": "", "time": 0};
|
var currentIn = [];
|
||||||
var currentOut = {"plate": "", "time": 0};
|
var currentOut = [];
|
||||||
|
|
||||||
exports.SaveLogs = async function (req, res) {
|
exports.SaveLogs = async function (req, res) {
|
||||||
|
|
||||||
|
@ -87,32 +87,54 @@ exports.SaveLogs = async function (req, res) {
|
||||||
var canSaveLogs = true;
|
var canSaveLogs = true;
|
||||||
var vehicleInfo = {"status": false};
|
var vehicleInfo = {"status": false};
|
||||||
|
|
||||||
if (req.body.type === "in" && (currentTimestamp - currentIn.time) < 600) {
|
if (req.body.type === "in") {
|
||||||
if (req.body.plate === currentIn.plate) {
|
for (var i = 0; i < currentIn.length; i++) {
|
||||||
canSaveLogs = false;
|
if ((currentTimestamp - currentIn[i].time) < 600) {
|
||||||
} else if (levenshtein(req.body.plate, currentIn.plate) < 2) {
|
if (req.body.plate === currentIn[i].plate) {
|
||||||
canSaveLogs = false;
|
canSaveLogs = false;
|
||||||
|
} else if (levenshtein(req.body.plate, currentIn[i].plate) < 3) {
|
||||||
|
canSaveLogs = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (req.body.type === "out" && (currentTimestamp - currentOut.time) < 600) {
|
if (req.body.type === "out") {
|
||||||
if (req.body.plate === currentOut.plate) {
|
for (var i = 0; i < currentOut.length; i++) {
|
||||||
canSaveLogs = false;
|
if ((currentTimestamp - currentOut[i].time) < 600) {
|
||||||
} else if (levenshtein(req.body.plate, currentOut.plate) < 2) {
|
if (req.body.plate === currentOut[i].plate) {
|
||||||
canSaveLogs = false;
|
canSaveLogs = false;
|
||||||
|
} else if (levenshtein(req.body.plate, currentOut[i].plate) < 3) {
|
||||||
|
canSaveLogs = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (req.body.type == "in") {
|
if (req.body.type == "in") {
|
||||||
console.log("req: ", req.body.plate, "\t type: ", req.body.type, " \t compare: ", currentIn.plate, "\t save: ", canSaveLogs);
|
var lists = [];
|
||||||
|
for (var i = 0; i < currentIn.length; i++) {
|
||||||
|
lists.push(currentIn[i].plate);
|
||||||
|
}
|
||||||
|
console.log("req: ", req.body.plate, " ", req.body.type, " ", lists, " ", canSaveLogs);
|
||||||
}
|
}
|
||||||
if (req.body.type == "out") {
|
if (req.body.type == "out") {
|
||||||
console.log("req: ", req.body.plate, "\t type: ", req.body.type, " \t compare: ", currentOut.plate, "\t save: ", canSaveLogs);
|
var lists = [];
|
||||||
|
for (var i = 0; i < currentOut.length; i++) {
|
||||||
|
lists.push(currentOut[i].plate);
|
||||||
|
}
|
||||||
|
console.log("req: ", req.body.plate, " ", req.body.type, " ", lists, " ", canSaveLogs);
|
||||||
}
|
}
|
||||||
if (canSaveLogs) {
|
if (canSaveLogs) {
|
||||||
if (req.body.type === "in") {
|
if (req.body.type === "in") {
|
||||||
currentIn = {"plate": req.body.plate, "time": currentTimestamp};
|
if (currentIn.length >= 10) {
|
||||||
|
currentIn.shift();
|
||||||
|
}
|
||||||
|
currentIn.push({"plate": req.body.plate, "time": currentTimestamp});
|
||||||
}
|
}
|
||||||
if (req.body.type === "out") {
|
if (req.body.type === "out") {
|
||||||
currentOut = {"plate": req.body.plate, "time": currentTimestamp};
|
if (currentOut.length >= 10) {
|
||||||
|
currentOut.shift();
|
||||||
|
}
|
||||||
|
currentOut.push({"plate": req.body.plate, "time": currentTimestamp});
|
||||||
}
|
}
|
||||||
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 + "'");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user