asd
Alejandro Acuña
2024-09-16 816cb391a192e357426312ab8e591fd49d1d242e
servers/enforcement/gost-access-server/src/art/servers/gost/access/controller/Controller_ACCESS_Neural_Detections.java
@@ -18,7 +18,6 @@
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -61,14 +60,17 @@
        {
            try
            {
                System.out.println(getName() + " - 1.RUN");
                if (Shared.isServerEnabled() == true)
                {
                    System.out.println(getName() + " - 2.RUN");
                    update();
                    System.out.println(getName() + " - 3.RUN");
                }
            }
            catch (Exception exception)
            {
                // exception.printStackTrace();
                exception.printStackTrace();
            }
            try 
@@ -97,9 +99,6 @@
    private void update() throws Exception
    {
        while (readDetections() == true);
        {
            try{sleep(100);} catch (Exception e){};
        }
    }
@@ -141,7 +140,6 @@
                if (detectionsCameraLane.size() > 0) detectionsCamera.addAll(detectionsCameraLane);
            }
            // Shared.println(this.getName(), "1.ReadDetections: " + detectionsCamera.size());
            for (AccessEnforcement_Detection detection  : detectionsCamera)
            {
                lastDetectionTimestamp = Math.max(lastDetectionTimestamp, detection.timestamp);
@@ -149,7 +147,6 @@
            }
            this.lastDetection = lastDetectionTimestamp;
            // Shared.println(this.getName(), "2.ReadDetections: " + detectionsCamera.size() + " - " + new Date(this.lastDetection).toString());
            
            
            //  Insert into database and update timestamps
@@ -160,10 +157,6 @@
                {
                    try
                    {
                        // Shared.println(this.getName(), "3.ReadDetections Detection: " + detection);
                        // Shared.println(this.getName(), "4.ReadDetections Detection: " + detection.images);
                        // Shared.println(this.getName(), "5.ReadDetections Detection: " + detection.getLastState());
                        // Shared.println(this.getName(), "5.ReadDetections Detection: " + detection.getLastState().vehicle);
                        if ((detection.images == null) || (detection.images.size() == 0))
                        {
                            getImagesDetectionUC(access, detection);
@@ -171,14 +164,12 @@
                    }
                    catch (Exception e)
                    {
                        // Shared.printstack(this.getName(), e);
                        Shared.printstack(this.getName(), e);
                    }
                    AccessEnforcement_Detection_State detectionState = detection.getLastState();
                    if (detectionState == null) detectionState = new AccessEnforcement_Detection_State();
                    if ((detection.images != null) && (detection.images.size() >= 2))
                    {
                        if (Shared.controllerDetections.hasPermission(detection, detectionState.vehicle.plate) != null)
@@ -188,7 +179,7 @@
                            detectionState.discarded.code = AccessEnforcement_Detection_State_Discarded.DISCARDED_ALLOWED;
                            detectionState.discarded.timestamp = System.currentTimeMillis();
                            detectionState.discarded.user = Shared.getApplicationName();
                            // Shared.printcorrect(getName(),Shared.getMessage("Successful (allowed), plate")  + " = " + detectionState.vehicle.plate + ", " + Shared.getMessage("date") + " = " + formato2.format(detection.timestamp));
                            Shared.printcorrect(getName(),Shared.getMessage("Successful (allowed), plate")  + " = " + detectionState.vehicle.plate + ", " + Shared.getMessage("date") + " = " + formato2.format(detection.timestamp));
                        }
                        else if ((this.detail.detections != null) && (detectionState.vehicle.confidence.floatValue() < this.detail.detections.plateConfidence) &&
                                 (this.detail.detections.enabled == true))
@@ -198,13 +189,13 @@
                            detectionState.discarded.code = AccessEnforcement_Detection_State_Discarded.DISCARDED_LOW_OCR_CONFIDENCE;
                            detectionState.discarded.timestamp = System.currentTimeMillis();
                            detectionState.discarded.user = Shared.getApplicationName();
                            // Shared.printerr(getName(),Shared.getMessage("Low ocr confidence, plate")  + " = " + detectionState.vehicle.plate + ", " + Shared.getMessage("confidence") + " = " + detectionState.vehicle.confidence.floatValue() + ", " + Shared.getMessage("date") + " = " + formato2.format(detection.timestamp));
                            Shared.printerr(getName(),Shared.getMessage("Low ocr confidence, plate")  + " = " + detectionState.vehicle.plate + ", " + Shared.getMessage("confidence") + " = " + detectionState.vehicle.confidence.floatValue() + ", " + Shared.getMessage("date") + " = " + formato2.format(detection.timestamp));
                        }
                        else
                        {
                            detectionState.state = AccessEnforcement_Detection_State.STATE_REVISION_PENDING;
                            detectionState.timestamp = System.currentTimeMillis();
                            // Shared.printcorrect(getName(),Shared.getMessage("Successful (revision pending), plate")  + " = " + detectionState.vehicle.plate + ", " + Shared.getMessage("date") + " = " + formato2.format(detection.timestamp));
                            Shared.printcorrect(getName(),Shared.getMessage("Successful (revision pending), plate")  + " = " + detectionState.vehicle.plate + ", " + Shared.getMessage("date") + " = " + formato2.format(detection.timestamp));
                        }
                    }
                    else
@@ -214,7 +205,7 @@
                        detectionState.discarded.code = AccessEnforcement_Detection_State_Discarded.DISCARDED_MISSING_PICTURES;
                        detectionState.discarded.timestamp = System.currentTimeMillis();
                        detectionState.discarded.description = detectionState.discarded.getDescription(detectionState.discarded.code);
                        // Shared.printerr(getName(),Shared.getMessage("Missing images, plate")  + " = " + detectionState.vehicle.plate + ", " + Shared.getMessage("date") + " = " + formato2.format(detection.timestamp));
                        Shared.printerr(getName(),Shared.getMessage("Missing images, plate")  + " = " + detectionState.vehicle.plate + ", " + Shared.getMessage("date") + " = " + formato2.format(detection.timestamp));
                    }
                    this.controller.updateDatabaseDetection(information, detection);
@@ -228,7 +219,7 @@
        }
        catch (Exception exception)
        {
            // Shared.printstack(getName(), exception);
            Shared.printstack(getName(), exception);
        }
        return false;
@@ -250,7 +241,7 @@
            SimpleDateFormat formato1 = new SimpleDateFormat("dd/MM/yyyy");
            SimpleDateFormat formato2 = new SimpleDateFormat("HH:mm:ss");
            String url = "https://" + information.neural.connection.address + ":" + information.neural.connection.port + "/art?operation=getDetections";
            String url = "https://" + information.neural.connection.address + "/art?operation=getDetections";
            url += "&from=" + formato1.format(from) + "%20" + formato2.format(from);
            url += "&to=" + formato1.format(to) + "%20" + formato2.format(to);
            url += "&lane=" + lane;
@@ -266,10 +257,9 @@
            url += "&token=" + user + "," + password;
            // Shared.println(this.getName(), "1.URL GetDEtections: " + url);
            Shared.println(this.getName(), "URL: " + url);
            byte[] response = HttpsRequest.requestBytes(url, user, password, new byte[0], 30000, 60000);
            AccessEnforcement_Detection[] ucDetections = Serialization.deserialize(AccessEnforcement_Detection[].class, response);
            // Shared.println(this.getName(), "2.GetDEtections: " + ucDetections.length);
            for (AccessEnforcement_Detection ucDetection : ucDetections)
            {
@@ -284,7 +274,7 @@
                        }
                        catch (Exception e)
                        {
                            // Shared.printstack(this.getName(), e);
                            e.printStackTrace();
                        }
                    }
                }
@@ -293,7 +283,7 @@
        }
        catch (Exception e)
        {
            // Shared.printstack(this.getName(), e);
            Shared.printstack(this.getName(), e);
        }
        return detections;
@@ -360,7 +350,7 @@
            // https://10.106.7.18/art?operation=getImage&incidence=22758&name=overview&token=write,EdubVmde
            // https://10.106.7.18/art?operation=getImage&incidence=22758&name=plate&token=write,EdubVmde
            String urlOverview = "https://" + access.getDeviceInformation().neural.connection.address + ":" + access.getDeviceInformation().neural.connection.port + "/art?operation=getImage";
            String urlOverview = "https://" + access.getDeviceInformation().neural.connection.address + "/art?operation=getImage";
            urlOverview += "&incidence=" + detection.incidence;
            urlOverview += "&name=overview";
@@ -373,9 +363,7 @@
            }
            urlOverview += "&token=" + user + "," + password;
            // Shared.println(this.getName(), "1.GetImages URLOver: " + urlOverview);
            byte[] response = HttpsRequest.requestBytes(urlOverview, user, password, new byte[0], 30000, 60000);
            // Shared.println(this.getName(), "2.GetImages URLOver: " + urlOverview);
            AccessEnforcement_Detection_Image imageOverview = new AccessEnforcement_Detection_Image();
            imageOverview.format = "jpg";
@@ -383,7 +371,7 @@
            imageOverview.data = response;
            accessDetectionImages.add(imageOverview);
            String urlPlate = "https://" + access.getDeviceInformation().neural.connection.address + ":" + access.getDeviceInformation().neural.connection.port + "/art?operation=getImage";
            String urlPlate = "https://" + access.getDeviceInformation().neural.connection.address + "/art?operation=getImage";
            urlPlate += "&incidence=" + detection.incidence;
            urlPlate += "&name=plate";
            urlPlate += "&token=" + user + "," + password;
@@ -398,7 +386,6 @@
        }
        catch (SerializationException e) 
        {
            // Shared.printstack(this.getName(), e);
            if (e.getMessage().indexOf("NoSuchFileException") < 0)
            {
                throw e;
@@ -406,7 +393,6 @@
        } 
        catch (Exception e)
        {
            // Shared.printstack(this.getName(), e);
            throw e;
        }
@@ -512,7 +498,7 @@
        { 
            public void run() 
            {
                // Shared.println(getName(), Shared.getMessage("Total detections in last minute") + " = " + counterDetections);
                Shared.println(getName(), Shared.getMessage("Total detections in last minute") + " = " + counterDetections);
                counterDetections = 0;
            }
        }, delay, 60000, TimeUnit.MILLISECONDS);