update socket

This commit is contained in:
2020-02-07 15:56:40 +07:00
parent 6aefd96212
commit 5417531e83
2 changed files with 61 additions and 6 deletions

View File

@@ -62,12 +62,14 @@ const db = makeDb(config);
var currentIn = [];
var currentOut = [];
var maxCompare = 5;
var maxFalse = 3;
var maxFalse = 0;
var falseIn = 0;
var falseOut = 0;
exports.SaveLogs = async function (req, res) {
var io = req.app.get('socketio');
var today = new Date();
var currentDate = today.getDate();
var currentMonth = today.getMonth() + 1;
@@ -126,14 +128,37 @@ exports.SaveLogs = async function (req, res) {
if (query_plate_raw.length > 0) {
vehicleInfo = {"status": true, "data": query_plate_raw[0]};
if (req.body.type == "in") {
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', {
id: newLogs.insertId,
vehicleInfo: query_plate_raw[0],
type: "in",
image: plateSaved,
time: currentTimestamp
});
}
if (req.body.type == "out") {
var checkIn = await db.query("SELECT * FROM logs WHERE vehicle_id=" + query_plate_raw[0].id + " AND time_out=0 ORDER BY time_in DESC LIMIT 0,1");
if (checkIn.length > 0) {
await db.query("UPDATE logs SET `plate_image_out`='" + plateSaved + "',`frame_image_out`='" + frameSaved + "',`time_out`=" + currentTimestamp + " WHERE id=" + checkIn[0].id);
io.emit('logs', {
id: checkIn[0].id,
vehicleInfo: query_plate_raw[0],
type: "out",
image: plateSaved,
time: currentTimestamp,
logs: checkIn[0]
});
} else {
await db.query("INSERT INTO logs(`vehicle_id`,`plate_image_out`,`frame_image_out`,`time_out`) VALUES ('" + query_plate_raw[0].id + "','" + plateSaved + "','" + frameSaved + "'," + currentTimestamp + ")");
var newLogs = await db.query("INSERT INTO logs(`vehicle_id`,`plate_image_out`,`frame_image_out`,`time_out`) VALUES ('" + query_plate_raw[0].id + "','" + plateSaved + "','" + frameSaved + "'," + currentTimestamp + ")");
io.emit('logs', {
id: newLogs.insertId,
vehicleInfo: query_plate_raw[0],
type: "out",
image: plateSaved,
time: currentTimestamp,
logs: false
});
}
}
} else {
@@ -141,14 +166,37 @@ exports.SaveLogs = async function (req, res) {
if (query_plate_levenshtein.length > 0) {
vehicleInfo = {"status": true, "data": query_plate_levenshtein[0]};
if (req.body.type == "in") {
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', {
id: newLogs.insertId,
vehicleInfo: query_plate_levenshtein[0],
type: "in",
image: plateSaved,
time: currentTimestamp
});
}
if (req.body.type == "out") {
var checkIn = await db.query("SELECT * FROM logs WHERE vehicle_id=" + query_plate_levenshtein[0].id + " AND time_out=0 ORDER BY time_in DESC LIMIT 0,1");
if (checkIn.length > 0) {
await db.query("UPDATE logs SET `plate_image_out`='" + plateSaved + "',`frame_image_out`='" + frameSaved + "',`time_out`=" + currentTimestamp + " WHERE id=" + checkIn[0].id);
io.emit('logs', {
id: checkIn[0].id,
vehicleInfo: query_plate_levenshtein[0],
type: "out",
image: plateSaved,
time: currentTimestamp,
logs: checkIn[0]
});
} else {
await db.query("INSERT INTO logs(`vehicle_id`,`plate_image_out`,`frame_image_out`,`time_out`) VALUES ('" + query_plate_levenshtein[0].id + "','" + plateSaved + "','" + frameSaved + "'," + currentTimestamp + ")");
var newLogs = await db.query("INSERT INTO logs(`vehicle_id`,`plate_image_out`,`frame_image_out`,`time_out`) VALUES ('" + query_plate_levenshtein[0].id + "','" + plateSaved + "','" + frameSaved + "'," + currentTimestamp + ")");
io.emit('logs', {
id: newLogs.insertId,
vehicleInfo: query_plate_levenshtein[0],
type: "out",
image: plateSaved,
time: currentTimestamp,
logs: false
});
}
}
} else {