Regalamiunsorriso/decompiled-libs/www/acxent-face-1.0.0/it/acxent/face/Evento.java

3312 lines
155 KiB
Java
Raw Normal View History

2026-04-22 18:41:37 +02:00
package it.acxent.face;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import it.acxent.anag.Clifor;
import it.acxent.common.StatusMsg;
import it.acxent.db.AddImgInterface;
import it.acxent.db.ApplParmFull;
import it.acxent.db.DBAdapter;
import it.acxent.db.ResParm;
import it.acxent.db.WcString;
import it.acxent.dm.FaceDetectionMethod;
import it.acxent.face.api.FaceRecognitionApi;
import it.acxent.face.api.FaceRecognitionApiResult;
import it.acxent.face.callable.FotoFaceRecognizerByModelCallable;
import it.acxent.face.callable.IndexFotoFaceCallable;
import it.acxent.face.callable.Scoring1PuntoFotoCallableOld;
import it.acxent.face.callable.ScoringFaceCallableGson;
import it.acxent.face.dispatcher.EventoProcessingDispatcher;
import it.acxent.face.pc.SaveScoreProcessor;
import it.acxent.face.scoring.SmartFaceScoringQueue;
import it.acxent.log.Log;
import it.acxent.util.FileWr;
import it.acxent.util.SimpleDateFormat;
import it.acxent.util.StringTokenizer;
import it.acxent.util.Timer;
import it.acxent.util.Vectumerator;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.Serializable;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.json.JSONArray;
import org.json.JSONObject;
public class Evento extends _FaceAdapter implements Serializable, AddImgInterface {
private static final long serialVersionUID = 1688718313582L;
public static boolean threadInvioEventoWww = false;
public static final long FLG_TIPO_EVENTO_STANDARD = 0L;
public static final long FLG_TIPO_EVENTO_PIX = 1L;
public static final long DEFAULT_MIN_DIM_FOTO_FACE_EVENTO = 25L;
public static final long DEFAULT_FR_IMAGE_WIDTH = 2560L;
public static final double DEFAULT_DETECT_FACE_CONFIDENT_THRESOLD = 0.7D;
public static final double DEFAULT_SCORE_THRESOLD = 0.6D;
public static final double DEFAULT_SCORE_THRESOLD_SELFIE_SEARCH_MIN = 0.2D;
public static final double DEFAULT_SCORE_THRESOLD_SELFIE_SEARCH2 = 0.6D;
public static final long DEFAULT_SELFIE_RANGE_EXT = 0L;
public static final long DEFAULT_SCORE_SELFIE_N_TARGET = 20L;
public static final long DEFAULT_SCORE_SELFIE_TARGET_THRESOLD = 25L;
public static final long DEFAULT_FLG_DETECT_NUMBERS = 0L;
public static final long DEFAULT_ID_FACE_DETECTION_METHOD_EVENTO_yunet = 14L;
private static final long DEFAULT_NUM_FOTO_NO_SCORE = 2L;
private long id_evento;
private long id_clifor;
private String descrizioneEvento;
private Date dataEvento;
private String codiceEventoCliente;
private long margineFotoDx;
private long margineFotoSx;
private long margineFotoTop;
private long margineFotoBottom;
private long dimMinFotoFaceEvento;
private long frImageWidth;
private long flgDetectNumbers;
private long id_faceRecognizer;
private FaceRecognizer faceRecognizer;
private double detectFaceConfidentThresold;
private double scoreThresold;
private double scoreThresoldSelfieSearch;
private double scoreThresoldSelfieSearch2;
private long currentFaceTarget2;
private long currentPuntofoto2;
private long currentTargetindex7;
private long scoreSelfieNTarget;
private long scoreSelfieTargetThresold;
private long flgProcessingDB;
private Timestamp tsLastProcess;
private long flgTipoEvento;
public static boolean threadCreaPuntiFoto = false;
public static boolean threadIndicizzaPuntiFoto = false;
private String pathEvento;
private Clifor clifor;
private Date dataEventoFine;
private String fileNameExport;
private TreeSet<String> pettoraliTS;
private FaceDetectionMethod faceDetectionMethodEvento;
private long id_faceDetectionMethodEvento;
private long numFotoNoScore;
private long labelCount;
private long codeGara;
private long selfieRangeExt;
private long flgProcessing;
public static boolean threadEventoScoring = false;
public static boolean threadBuildModel = false;
public static boolean threadIndicizzaConModello = false;
public static boolean threadEventoScoringSTOP = false;
public static boolean threadBuildModelSTOP = false;
public static boolean threadIndicizzaConModelloSTOP = false;
public static boolean threadGaraFace = false;
class ThreadDetectFaceFoto extends Thread {
private Evento evento;
public ThreadDetectFaceFoto(Evento l_evento) {
this.evento = l_evento;
if (!Evento.isThreadGaraFace()) {
Evento.threadGaraFace = true;
start();
}
}
public void run() {
boolean debug = false;
String TAG_THREAD_MSG = "DETECT FACE GARA";
Timer timer = new Timer();
timer.start();
ResParm rp = new ResParm(true);
StringBuffer err = new StringBuffer();
int i = 0;
StringBuffer errMsg = new StringBuffer();
int maxNumberOfThread = Evento.this.getParm("MAX_NUMBER_OF_THREAD_INDEXING_SCALING").getNumeroInt();
if (maxNumberOfThread <= 1)
maxNumberOfThread = 10;
if (this.evento.getId_evento() == 0L) {
rp.setMsg("Indicizzazione foto: Bean evento non caricato");
rp.setStatus(false);
Evento.this.handleDebug("Indicizzazione foto: Bean evento non caricato", 2);
} else {
try {
boolean detectNumbers = (this.evento.getFlgDetectNumbers() == 1L);
final ThreadLocal<Integer> callerTaskCount = ThreadLocal.withInitial(() -> 0);
int NUMB_OF_CORES = Runtime.getRuntime().availableProcessors();
int corePoolSize = 4;
int maxPoolSize = NUMB_OF_CORES * 4;
long keepAliveTime = 360L;
int blockingQueueSize = maxPoolSize;
ThreadPoolExecutor pool = new ThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveTime, TimeUnit.SECONDS, new LinkedBlockingQueue(blockingQueueSize), new ThreadPoolExecutor.CallerRunsPolicy() {
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
callerTaskCount.set(Integer.valueOf(callerTaskCount.get() + 1));
super.rejectedExecution(r, e);
}
}) {
protected void afterExecute(Runnable r, Throwable t) {
super.afterExecute(r, t);
if (Thread.currentThread() == Thread.currentThread()) {
int count = callerTaskCount.get();
if (count > 0)
callerTaskCount.set(Integer.valueOf(count - 1));
}
}
};
Vectumerator<Future<ResParm>> vecF = new Vectumerator();
Foto foto = new Foto(Evento.this.getApFull());
FotoCR CR = new FotoCR(Evento.this.getApFull());
CR.setId_evento(this.evento.getId_evento());
CR.setFlgHasFace(0L);
Vectumerator<Foto> vec = foto.findByCR(CR, 1, 1);
long currentFotoSenzaVisi = 0L;
long totFotoSenzaVisi = (long)vec.getTotNumberOfRecords();
long ciclo = 1L;
while (currentFotoSenzaVisi != totFotoSenzaVisi) {
TAG_THREAD_MSG = "INDEX FACE GARA n." + ciclo;
ciclo++;
if (debug)
System.out.println(TAG_THREAD_MSG + " INIZIO TOTFOTOSENZA VISI= " + TAG_THREAD_MSG + " current, prima del ciclo quindi dal 2 sicurmente più grande: " + totFotoSenzaVisi);
currentFotoSenzaVisi = totFotoSenzaVisi;
Vectumerator<PuntoFoto> vecPf = new PuntoFoto(Evento.this.getApFull()).findPuntiFotoByEventoTipoIdx(this.evento.getId_evento(), 0L, 0, 0);
while (vecPf.hasMoreElements()) {
PuntoFoto puntoFoto = (PuntoFoto)vecPf.nextElement();
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "max thread: " + maxNumberOfThread + " - submit ...index FACE foto " +
puntoFoto.getDescrizioneCompleta() + " ...");
if (debug)
System.out.println(TAG_THREAD_MSG + "Attenzione! Thread INDEX FACE FOTO (faccina) punto foto " + TAG_THREAD_MSG + " in esecuzione!!! ");
vec = foto.findByPuntofoto(puntoFoto.getId_puntoFoto());
Foto row = new Foto();
i = 0;
try {
while (vec.hasMoreElements()) {
row = (Foto)vec.nextElement();
i++;
if (row.getNumOfFaces() == 0L) {
row.setId_faceDetectionMethod(0L);
Thread.sleep(20L);
IndexFotoFaceCallable ifc = new IndexFotoFaceCallable(row, detectNumbers, false);
vecF.add(pool.submit(ifc));
if (i % 20 == 0)
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "max thread: " + maxNumberOfThread + " - SUBMIT ...index face foto - " +
row.getFileName() + " - " + puntoFoto.getDescrizioneCompleta() + " - " + i + 1 + " su " +
vec.getTotNumberOfRecords() + " method: " +
row.getFaceDetectionMethodReal().getDescrizione() + " eta: " +
timer.getEta((long)vec.getTotNumberOfRecords(), (long)(i + 1)));
continue;
}
if (i % 20 == 0)
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "max thread: " + maxNumberOfThread + " - SKIP ...index face foto - " +
row.getFileName() + " - " + puntoFoto.getDescrizioneCompleta() + " - " + i + 1 + " su " +
vec.getTotNumberOfRecords() + " method: " +
row.getFaceDetectionMethodReal().getDescrizione() + " eta: " +
timer.getEta((long)vec.getTotNumberOfRecords(), (long)(i + 1)));
}
} catch (Exception e) {
Evento.this.handleDebug(e);
errMsg.append("\nIndicizzazione fallita sul file " + row.getFileName() + "<br>" + e.getMessage());
}
rp.setMsg("Indicizzazione punto foto completata.<br>Numero foto indicizzate:" + i + "<br> - Errori rilevati: " +
errMsg.toString());
rp.setStatus(true);
}
for (int j = 0; j < vecF.getTotNumberOfRecords(); j++) {
Future<ResParm> currentFuture = (Future<ResParm>)vecF.nextElement();
rp = currentFuture.get();
if (!rp.getStatus())
errMsg.append(rp.getErrMsg() + "\n");
System.out.println(currentFuture.get().getMsg() + " ended");
if (i % 20 == 0)
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "max thread: " + maxNumberOfThread + " - face detected on foto " + j + " su " +
vecF.getTotNumberOfRecords() + " eta: " +
timer.getEta((long)vecF.getTotNumberOfRecords(), (long)(j + 1)));
}
vec = foto.findByCR(CR, 1, 1);
totFotoSenzaVisi = (long)vec.getTotNumberOfRecords();
StatusMsg.deleteMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG);
if (debug)
System.out.println(TAG_THREAD_MSG + "FINE CICLO.. CONTROLLO FOTO SENZA VISI: TOTFOTOSENZA VISI= " + TAG_THREAD_MSG + " current,: " + totFotoSenzaVisi);
}
if (debug)
System.out.println(TAG_THREAD_MSG + "USCITO CICLO SENZA VISI.. : TOTFOTOSENZA VISI= " + TAG_THREAD_MSG + " current,: " + totFotoSenzaVisi);
pool.shutdown();
} catch (Exception e) {
err.append("ERRORE!! " + e.getMessage());
err.append("\n");
if (debug) {
System.out.println(TAG_THREAD_MSG + "ERRORE!!!!! exc " + TAG_THREAD_MSG);
e.printStackTrace();
}
}
}
timer.stop();
System.out.println(TAG_THREAD_MSG + " DURATA: " + TAG_THREAD_MSG + " " + timer.getDurata() + "\nerr: " + rp.getMsg());
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "Index face foto concluso: DURATA: " +
timer.getDurata() + "\nRisultato: " + rp.getMsg());
Log.addAltro(Evento.this.getApFull(), "127.0.0.1", 1L, " ThreadDetectFaceFoto: FINE!!! :\n" + timer.getDurata() + "\nRisultato: " +
rp.getMsg() + "\nerr: " + errMsg.toString());
try {
sleep(10000L);
} catch (Exception e) {}
StatusMsg.deleteMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG);
Evento.threadGaraFace = false;
}
public void runOld() {
boolean debug = false;
String TAG_THREAD_MSG = "DETECT FACE GARA";
Timer timer = new Timer();
timer.start();
ResParm rp = new ResParm(true);
StringBuffer err = new StringBuffer();
int i = 0;
StringBuffer errMsg = new StringBuffer();
int maxNumberOfThread = Evento.this.getParm("MAX_NUMBER_OF_THREAD_INDEXING_SCALING").getNumeroInt();
if (maxNumberOfThread <= 1)
maxNumberOfThread = 10;
if (this.evento.getId_evento() == 0L) {
rp.setMsg("Indicizzazione foto: Bean evento non caricato");
rp.setStatus(false);
Evento.this.handleDebug("Indicizzazione foto: Bean evento non caricato", 2);
} else {
try {
boolean detectNumbers = (this.evento.getFlgDetectNumbers() == 1L);
ExecutorService pool = Executors.newFixedThreadPool(maxNumberOfThread);
Vectumerator<Future<ResParm>> vecF = new Vectumerator();
Foto foto = new Foto(Evento.this.getApFull());
FotoCR CR = new FotoCR(Evento.this.getApFull());
CR.setId_evento(this.evento.getId_evento());
CR.setFlgHasFace(0L);
Vectumerator<Foto> vec = foto.findByCR(CR, 1, 1);
long currentFotoSenzaVisi = 0L;
long totFotoSenzaVisi = (long)vec.getTotNumberOfRecords();
long ciclo = 1L;
while (currentFotoSenzaVisi != totFotoSenzaVisi) {
TAG_THREAD_MSG = "INDEX FACE GARA n." + ciclo;
ciclo++;
if (debug)
System.out.println(TAG_THREAD_MSG + " INIZIO TOTFOTOSENZA VISI= " + TAG_THREAD_MSG + " current, prima del ciclo quindi dal 2 sicurmente più grande: " + totFotoSenzaVisi);
currentFotoSenzaVisi = totFotoSenzaVisi;
Vectumerator<PuntoFoto> vecPf = new PuntoFoto(Evento.this.getApFull()).findPuntiFotoByEventoTipoIdx(this.evento.getId_evento(), 0L, 0, 0);
while (vecPf.hasMoreElements()) {
PuntoFoto puntoFoto = (PuntoFoto)vecPf.nextElement();
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "max thread: " + maxNumberOfThread + " - submit ...index FACE foto " +
puntoFoto.getDescrizioneCompleta() + " ...");
if (debug)
System.out.println(TAG_THREAD_MSG + "Attenzione! Thread INDEX FACE FOTO (faccina) punto foto " + TAG_THREAD_MSG + " in esecuzione!!! ");
vec = foto.findByPuntofoto(puntoFoto.getId_puntoFoto());
Foto row = new Foto();
i = 0;
try {
while (vec.hasMoreElements()) {
row = (Foto)vec.nextElement();
i++;
if (row.getNumOfFaces() == 0L) {
row.setId_faceDetectionMethod(0L);
Thread.sleep(20L);
IndexFotoFaceCallable ifc = new IndexFotoFaceCallable(row, detectNumbers, false);
vecF.add(pool.submit(ifc));
if (i % 20 == 0)
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "max thread: " + maxNumberOfThread + " - SUBMIT ...index face foto - " +
row.getFileName() + " - " + puntoFoto.getDescrizioneCompleta() + " - " + i + 1 + " su " +
vec.getTotNumberOfRecords() + " method: " +
row.getFaceDetectionMethodReal().getDescrizione() + " eta: " +
timer.getEta((long)vec.getTotNumberOfRecords(), (long)(i + 1)));
continue;
}
if (i % 20 == 0)
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "max thread: " + maxNumberOfThread + " - SKIP ...index face foto - " +
row.getFileName() + " - " + puntoFoto.getDescrizioneCompleta() + " - " + i + 1 + " su " +
vec.getTotNumberOfRecords() + " method: " +
row.getFaceDetectionMethodReal().getDescrizione() + " eta: " +
timer.getEta((long)vec.getTotNumberOfRecords(), (long)(i + 1)));
}
} catch (Exception e) {
Evento.this.handleDebug(e);
errMsg.append("\nIndicizzazione fallita sul file " + row.getFileName() + "<br>" + e.getMessage());
}
rp.setMsg("Indicizzazione punto foto completata.<br>Numero foto indicizzate:" + i + "<br> - Errori rilevati: " +
errMsg.toString());
rp.setStatus(true);
}
for (int j = 0; j < vecF.getTotNumberOfRecords(); j++) {
Future<ResParm> currentFuture = (Future<ResParm>)vecF.nextElement();
rp = currentFuture.get();
if (!rp.getStatus())
errMsg.append(rp.getErrMsg() + "\n");
System.out.println(currentFuture.get().getMsg() + " ended");
if (i % 20 == 0)
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "max thread: " + maxNumberOfThread + " - face detected on foto " + j + " su " +
vecF.getTotNumberOfRecords() + " eta: " +
timer.getEta((long)vecF.getTotNumberOfRecords(), (long)(j + 1)));
}
vec = foto.findByCR(CR, 1, 1);
totFotoSenzaVisi = (long)vec.getTotNumberOfRecords();
StatusMsg.deleteMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG);
if (debug)
System.out.println(TAG_THREAD_MSG + "FINE CICLO.. CONTROLLO FOTO SENZA VISI: TOTFOTOSENZA VISI= " + TAG_THREAD_MSG + " current,: " + totFotoSenzaVisi);
}
if (debug)
System.out.println(TAG_THREAD_MSG + "USCITO CICLO SENZA VISI.. : TOTFOTOSENZA VISI= " + TAG_THREAD_MSG + " current,: " + totFotoSenzaVisi);
pool.shutdown();
} catch (Exception e) {
err.append("ERRORE!! " + e.getMessage());
err.append("\n");
if (debug) {
System.out.println(TAG_THREAD_MSG + "ERRORE!!!!! exc " + TAG_THREAD_MSG);
e.printStackTrace();
}
}
}
timer.stop();
System.out.println(TAG_THREAD_MSG + " DURATA: " + TAG_THREAD_MSG + " " + timer.getDurata() + "\nerr: " + rp.getMsg());
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "Index face foto concluso: DURATA: " +
timer.getDurata() + "\nRisultato: " + rp.getMsg());
Log.addAltro(Evento.this.getApFull(), "127.0.0.1", 1L, " ThreadDetectFaceFoto: FINE!!! :\n" + timer.getDurata() + "\nRisultato: " +
rp.getMsg() + "\nerr: " + errMsg.toString());
try {
sleep(10000L);
} catch (Exception e) {}
StatusMsg.deleteMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG);
Evento.threadGaraFace = false;
}
}
class ThreadCreaPuntiFoto extends Thread {
private boolean indicizza = false;
private Evento evento;
private long id_users;
private String TAG_THREAD_MSG = "CREA PUNTI FOTO";
public ThreadCreaPuntiFoto(Evento evento, boolean indicizza, long id_users) {
if (!Evento.isThreadCreaPuntiFotoAttivo()) {
Evento.threadCreaPuntiFoto = true;
this.evento = evento;
this.indicizza = indicizza;
this.id_users = id_users;
start();
}
}
public void run() {
boolean debug = false;
Timestamp start = new Timestamp(Calendar.getInstance().getTimeInMillis());
DBAdapter.printDebug(debug, "##############\nCREA PUNTI FOTO\nSTART: " + start.toString());
ResParm rp = new ResParm(true);
StringBuffer err = new StringBuffer();
StringBuilder sb = new StringBuilder();
int i = 0;
int se1 = 10;
int se2 = 100;
ApplParmFull ap = this.evento.getApFull();
StatusMsg.updateMsgByTag(Evento.this.getApFull(), this.TAG_THREAD_MSG, "Thread CREA PUNTI FOTO in esecuzione ....");
String dirBase = this.evento.getPathBaseFoto() + this.evento.getPathBaseFoto();
if (new File(dirBase).exists()) {
File dir = new File(dirBase);
try {
processaDirectoryRicorsivamente(dir, dirBase, this.evento, this.indicizza, this.id_users);
StatusMsg.updateMsgByTag(Evento.this.getApFull(), this.TAG_THREAD_MSG, "Creazione punto foto evento " +
this.evento.getDescrizione() + " ok!");
} catch (Exception e) {
Evento.this.handleDebug(e);
}
}
Timestamp stop = new Timestamp(Calendar.getInstance().getTimeInMillis());
DBAdapter.printDebug(debug, "STOP: " + start.toString());
SimpleDateFormat dfMS = new SimpleDateFormat("HH:mm:ss ");
DBAdapter.printDebug(debug, "DURATA: " + dfMS.format(new Time(stop.getTime() - start.getTime() - 3600000L)) + "Risultato import:\n" +
rp.getMsg() + "\n\nIMPORT CREA PUNTI FOTO concluso\n****************");
StatusMsg.updateMsgByTag(Evento.this.getApFull(), this.TAG_THREAD_MSG, "Thread CREA PUNTI FOTO in esecuzione ....");
try {
sleep(8000L);
} catch (Exception e) {}
StatusMsg.deleteMsgByTag(Evento.this.getApFull(), this.TAG_THREAD_MSG);
Evento.threadCreaPuntiFoto = false;
}
public void runUnLivello() {
boolean debug = false;
Timestamp start = new Timestamp(Calendar.getInstance().getTimeInMillis());
DBAdapter.printDebug(debug, "##############\nCREA PUNTI FOTO 1 lvl\nSTART: " + start.toString());
ResParm rp = new ResParm(true);
StringBuffer err = new StringBuffer();
StringBuilder sb = new StringBuilder();
int i = 0;
int se1 = 10;
int se2 = 100;
ApplParmFull ap = this.evento.getApFull();
StatusMsg.updateMsgByTag(Evento.this.getApFull(), this.TAG_THREAD_MSG, "Thread CREA PUNTI FOTO in esecuzione ....");
String dirBase = this.evento.getPathBaseFoto() + this.evento.getPathBaseFoto();
if (new File(dirBase).exists()) {
File dir = new File(dirBase);
File[] puntiFotos = dir.listFiles();
File thePuntoFotoDir = null;
try {
for (int j = 0; j < puntiFotos.length; j++) {
thePuntoFotoDir = puntiFotos[j];
String theDir = thePuntoFotoDir.getAbsolutePath();
if (new File(theDir).isDirectory()) {
String path = theDir.substring(dirBase.length());
PuntoFoto pf = new PuntoFoto(ap);
pf.findByEventoPath(this.evento.getId_evento(), path);
if (pf.getDBState() == 0) {
StatusMsg.updateMsgByTag(Evento.this.getApFull(), this.TAG_THREAD_MSG, "Creazione punto foto " + path);
pf.setId_evento(this.evento.getId_evento());
pf.setPathRelativoFoto(path);
pf.setDescrizione(path.replace("/", ""));
rp = pf.save();
if (rp.getStatus() &&
this.indicizza) {
StatusMsg.updateMsgByTag(Evento.this.getApFull(), this.TAG_THREAD_MSG, "Indicizzazione punto foto " + path + "....");
pf.indexFoto(this.id_users, this.TAG_THREAD_MSG);
}
}
}
}
StatusMsg.updateMsgByTag(Evento.this.getApFull(), this.TAG_THREAD_MSG, "Creazione punto foto evento " +
this.evento.getDescrizione() + " ok!");
} catch (Exception e) {
Evento.this.handleDebug(e);
}
}
Timestamp stop = new Timestamp(Calendar.getInstance().getTimeInMillis());
DBAdapter.printDebug(debug, "STOP: " + start.toString());
SimpleDateFormat dfMS = new SimpleDateFormat("HH:mm:ss ");
DBAdapter.printDebug(debug, "DURATA: " + dfMS.format(new Time(stop.getTime() - start.getTime() - 3600000L)) + "Risultato import:\n" +
rp.getMsg() + "\n\nIMPORT CREA PUNTI FOTO concluso\n****************");
StatusMsg.updateMsgByTag(Evento.this.getApFull(), this.TAG_THREAD_MSG, "Thread CREA PUNTI FOTO in esecuzione ....");
try {
sleep(8000L);
} catch (Exception e) {}
StatusMsg.deleteMsgByTag(Evento.this.getApFull(), this.TAG_THREAD_MSG);
Evento.threadCreaPuntiFoto = false;
}
private void processaDirectoryRicorsivamente(File directory, String dirBase, Evento evento, boolean indicizza, long id_users) {
if (directory == null || !directory.exists() || !directory.isDirectory())
return;
File[] files = directory.listFiles();
if (files == null || files.length == 0) {
creazioneEIndicizzazionePuntoFoto(directory, dirBase, evento, indicizza, id_users);
return;
}
boolean haSubDir = false;
for (File file : files) {
if (file.isDirectory()) {
haSubDir = true;
break;
}
}
if (!haSubDir) {
creazioneEIndicizzazionePuntoFoto(directory, dirBase, evento, indicizza, id_users);
} else {
for (File file : files) {
if (file.isDirectory()) {
if (evento.getFlgTipoEvento() == 1L && directory.getAbsolutePath().length() > dirBase.length()) {
creazioneEIndicizzazionePuntoFoto(directory, dirBase, evento, indicizza, id_users);
return;
}
processaDirectoryRicorsivamente(file, dirBase, evento, indicizza, id_users);
}
}
}
}
private void creazioneEIndicizzazionePuntoFoto(File directory, String dirBase, Evento evento, boolean indicizza, long id_users) {
String theDir = directory.getAbsolutePath();
String path = theDir.substring(dirBase.length());
StatusMsg.updateMsgByTag(Evento.this.getApFull(), this.TAG_THREAD_MSG, "Creazione punto foto " + path);
PuntoFoto pf = new PuntoFoto(Evento.this.getApFull());
pf.findByEventoPath(evento.getId_evento(), path);
ResParm rp = new ResParm(true);
if (pf.getDBState() == 0) {
pf.setId_evento(evento.getId_evento());
pf.setPathRelativoFoto(path);
pf.setDescrizione(path.replace("/", ""));
rp = pf.save();
}
if (rp.getStatus() &&
indicizza) {
StatusMsg.updateMsgByTag(Evento.this.getApFull(), this.TAG_THREAD_MSG, "Indicizzazione punto foto " + path + "....");
pf.indexFoto(id_users, this.TAG_THREAD_MSG);
}
}
}
class ThreadIndicizzaPuntiFoto extends Thread {
private Evento evento;
private long id_users;
public ThreadIndicizzaPuntiFoto(Evento evento, long id_users) {
if (!Evento.isThreadIndicizzaPuntiFotoAttivo()) {
Evento.threadIndicizzaPuntiFoto = true;
this.evento = evento;
this.id_users = id_users;
start();
}
}
public void run() {
boolean debug = false;
String TAG_THREAD_MSG = "INDICIZZA EVENTO";
Timer timer = new Timer();
timer.start();
System.out.println("##############\nINDICIZZA EVENTO\nSTART: " + String.valueOf(timer.getTStart()));
ResParm rp = new ResParm(true);
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "..... in esecuzione ....");
Vectumerator<PuntoFoto> vec = this.evento.getPuntiFoto(0, 0);
while (vec.hasMoreElements()) {
PuntoFoto rowPf = (PuntoFoto)vec.nextElement();
DBAdapter.println(rowPf.getDescrizione());
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "Indicizzazione punto foto " +
rowPf.getDescrizioneCompleta() + "....");
rowPf.indexFoto(this.id_users, TAG_THREAD_MSG);
}
timer.stop();
System.out.println("DURATA: " + timer.getDurataHourMin() + "Risultato import:\n" + rp.getMsg() + "\n\nINDICIZZAZIONE PUNTI EVENTO concluso\n****************");
try {
sleep(8000L);
} catch (Exception e) {}
StatusMsg.deleteMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG);
Evento.threadIndicizzaPuntiFoto = false;
Log.addAltro(Evento.this.getApFull(), "127.0.0.1", 1L, " INDICIZZA EVENTO: FINE!!! \n" + timer.getDurata() + "\nRisultato: " + rp.getMsg());
}
}
class ThreadIndexFaceFotoOld extends Thread {
private Evento evento;
public ThreadIndexFaceFotoOld(Evento l_evento) {
this.evento = l_evento;
if (!Evento.isThreadGaraFace()) {
Evento.threadGaraFace = true;
start();
}
}
public void run() {
boolean debug = false;
String TAG_THREAD_MSG = "INDEX FACE GARA";
Timer timer = new Timer();
timer.start();
ResParm rp = new ResParm(true);
StringBuffer err = new StringBuffer();
StringBuilder sb = new StringBuilder();
int i = 0;
if (this.evento.getId_evento() == 0L) {
rp.setMsg("Indicizzazione foto: Bean evento non caricato");
rp.setStatus(false);
Evento.this.handleDebug("Indicizzazione foto: Bean evento non caricato", 2);
} else {
try {
Vectumerator<PuntoFoto> vecPf = new PuntoFoto(Evento.this.getApFull()).findPuntiFotoByEventoTipoIdx(this.evento.getId_evento(), 0L, 0, 0);
while (vecPf.hasMoreElements()) {
PuntoFoto puntoFoto = (PuntoFoto)vecPf.nextElement();
StatusMsg.updateMsgByTag(Evento.this.getApFull(), "INDEX FACE GARA", "...index FACE foto " +
puntoFoto.getDescrizioneCompleta() + " ...");
if (debug)
System.out.println("INDEX FACE GARAAttenzione! Thread INDEX FACE FOTO (faccina) punto foto " +
puntoFoto.getDescrizioneCompleta() + " in esecuzione!!! ");
int totFoto = 0;
StringBuffer errMsg = new StringBuffer();
String dirFoto = puntoFoto.getParm("PATHFOTO_FACE").getTesto() + puntoFoto.getParm("PATHFOTO_FACE").getTesto();
Foto foto = new Foto(Evento.this.getApFull());
Vectumerator<Foto> vec = foto.findByPuntofoto(puntoFoto.getId_puntoFoto());
sb = new StringBuilder();
Foto row = new Foto();
i = 0;
try {
while (vec.hasMoreElements()) {
row = (Foto)vec.nextElement();
i++;
rp = Foto.loadFacesByFaceRecognition(row,
(this.evento.getFlgDetectNumbers() == 1L), false);
if (!rp.getStatus())
errMsg.append(rp.getErrMsg() + " " + rp.getErrMsg() + "\n");
StatusMsg.updateMsgByTag(Evento.this.getApFull(), "INDEX FACE GARA", "...index face foto - " +
row.getFileName() + " - " + puntoFoto.getDescrizioneCompleta() + " - " + i + 1 + " su " +
vec.getTotNumberOfRecords() + " eta: " +
timer.getEta((long)vec.getTotNumberOfRecords(), (long)(i + 1)));
}
} catch (Exception e) {
Evento.this.handleDebug(e);
errMsg.append("\nIndicizzazione fallita sul file " + row.getFileName() + "<br>" + e.getMessage());
}
rp.setMsg("Indicizzazione punto foto completata.<br>Numero foto indicizzate:" + i + "<br> - Errori rilevati: " +
errMsg.toString());
rp.setStatus(true);
}
} catch (Exception e) {
err.append("ERRORE!! " + e.getMessage());
err.append("\n");
}
}
timer.stop();
System.out.println("INDEX FACE GARA DURATA: " + timer.getDurata() + " " + rp.getMsg());
StatusMsg.updateMsgByTag(Evento.this.getApFull(), "INDEX FACE GARA", "Index face foto concluso: DURATA: " +
timer.getDurata() + "\nRisultato: " + rp.getMsg());
try {
sleep(10000L);
} catch (Exception e) {}
StatusMsg.deleteMsgByTag(Evento.this.getApFull(), "INDEX FACE GARA");
Evento.threadGaraFace = false;
}
}
class ThreadEventoScoring extends Thread {
private Evento evento;
private int fase;
private static final int FASE_ALL = 0;
private static final int FASE_SCORING_FACE_PF_1 = 1;
private static final int FASE_SCORING_TARGET_PF_2 = 2;
private static final int FASE_SCORING_FACE_SENZA_SCORING_3 = 3;
private static final int FASE_SCORING_GLOBALE_5 = 5;
private static final int FASE_SCORING_PF_N_FOTO_6 = 6;
private static final int FASE_SCORING_GLOBALE_7 = 7;
public ThreadEventoScoring(Evento l_evento, int l_fase) {
this.evento = l_evento;
this.fase = l_fase;
if (!Evento.isthreadEventoScoring()) {
Evento.threadEventoScoring = true;
Evento.threadEventoScoringSTOP = false;
SmartFaceScoringQueue smartFaceScoringQueue = SmartFaceScoringQueue.getInstance(this.evento.getApFull());
smartFaceScoringQueue.setStopScoring(false);
start();
}
}
public void run() {
boolean debug = false;
ResParm rp = new ResParm(true);
String TAG_THREAD_MSG = "EVENTO SCORING F." + this.fase + " Ev.: " + this.evento.getId_evento();
Timer timer = new Timer();
timer.start();
if (this.fase == 1 || this.fase == 0) {
rp = fase1ScoringPuntifoto(TAG_THREAD_MSG);
} else if (this.fase == 2 || this.fase == 0) {
rp.append(fase2RaggruppaScoringTarget(TAG_THREAD_MSG));
} else if (this.fase == 3 || this.fase == 0) {
rp.append(fase3ScoringFaceSenzaScoringPerEvento(TAG_THREAD_MSG));
} else if (this.fase == 5) {
rp.append(fase5ScoringDirettoSuFotoFace(TAG_THREAD_MSG));
} else if (this.fase == 6) {
rp.append(fase6ScoringDirettoSuFotoFaceNfoto(TAG_THREAD_MSG));
} else if (this.fase == 6) {
rp.append(fase6ScoringDirettoSuFotoFaceNfoto(TAG_THREAD_MSG));
} else if (this.fase == 7) {
rp.append(fase7ScoringTargetSuTargetMergeAggressivo(TAG_THREAD_MSG));
}
timer.stop();
DBAdapter.printDebug(debug, TAG_THREAD_MSG + " *******DURATA TOTALE********: " + TAG_THREAD_MSG);
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "Concluso: DURATA TOTALE: " +
timer.getDurataHourMin() + "\nRisultato: " + rp.getMsg());
try {
sleep(4000L);
} catch (Exception e) {}
StatusMsg.deleteMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG);
Evento.threadEventoScoring = false;
Evento.threadEventoScoringSTOP = false;
SmartFaceScoringQueue smartFaceScoringQueue = SmartFaceScoringQueue.getInstance(this.evento.getApFull());
smartFaceScoringQueue.setStopScoring(false);
}
private ResParm fase2RaggruppaScoringTarget(String TAG_THREAD_MSG) {
boolean debug = false;
StringBuffer errMsg = new StringBuffer();
ResParm rp = new ResParm(true);
TAG_THREAD_MSG = TAG_THREAD_MSG + " FASE 2";
int STEP_STATUS_MSG = 300;
Timer timer = new Timer();
timer.start();
long lastidxFotoTarget = 0L;
int maxNumberOfThread = Evento.this.getParm("MAX_NUMBER_OF_THREAD_SCORING_LVL_2").getNumeroInt();
int NUM_QUERY_CALLABLE = Evento.this.getParm("NUM_QUERY_CALLABLE_LVL_2").getNumeroInt();
if (maxNumberOfThread <= 0)
maxNumberOfThread = 200;
if (NUM_QUERY_CALLABLE <= 0)
NUM_QUERY_CALLABLE = 95;
ExecutorService pool = Executors.newFixedThreadPool(maxNumberOfThread);
Vectumerator<Future<ResParm>> vecF = new Vectumerator();
String targetDir = Evento.this.getParm("PATHFOTO_FACE").getTesto() + Evento.this.getParm("PATHFOTO_FACE").getTesto();
File targetDirFile = new File(targetDir);
if (!targetDirFile.exists())
targetDirFile.mkdirs();
double confDetectLevel = this.evento.getDetectFaceConfidentThresold();
long dysType = Evento.this.getParm("ZOO_YUNET_SCORING_DYS_TYPE").getNumeroLong();
PuntoFoto firstPuntoFoto = null;
Vectumerator<FaceScore> vecFsTargetMain = DBAdapter.AB_EMPTY_VECTUMERATOR;
HashSet<Long> hsPuntiFoto = new HashSet<>();
FaceScore fs = new FaceScore(Evento.this.getApFull());
int targetUniti = 0;
Timer timerPf = new Timer();
int i = 0;
Vectumerator<PuntoFoto> vecPf = this.evento.getPuntiFoto(0, 0);
int numPf = 0;
int totPf = vecPf.getTotNumberOfRecords();
String etaTot = ".......";
while (vecPf.hasMoreElements() && !Evento.threadEventoScoringSTOP) {
String etaPf = ".......";
timerPf.start();
PuntoFoto puntofoto = (PuntoFoto)vecPf.nextElement();
if (puntofoto.getFlgStatoScoring() == -1L)
continue;
if (puntofoto.getFlgStatoScoring() == 2L) {
hsPuntiFoto.add(Long.valueOf(puntofoto.getId_puntoFoto()));
if (firstPuntoFoto == null)
firstPuntoFoto = puntofoto;
if (debug)
System.out.println(TAG_THREAD_MSG + " PUNTO FOTO: " + TAG_THREAD_MSG + " STATO_SCORING_FASE2 aggiungo a hs target main il puntofoto " + puntofoto.getDescrizione());
continue;
}
if (puntofoto.getFlgStatoScoring() != 1L)
continue;
if (debug)
System.out.println(TAG_THREAD_MSG + " PUNTO FOTO: " + TAG_THREAD_MSG + " STATO_SCORING_FASE1 puntofoto da processare " + puntofoto.getDescrizione());
if (firstPuntoFoto == null) {
hsPuntiFoto.add(Long.valueOf(puntofoto.getId_puntoFoto()));
if (debug)
System.out.println(TAG_THREAD_MSG + " PUNTO FOTO: " + TAG_THREAD_MSG + " STATO_SCORING_FASE1 aggiungo a hs target main il puntofoto iniziale " + puntofoto.getDescrizione() + " e vado avanti....");
}
puntofoto.setFlgStatoScoring(22L);
puntofoto.save();
vecFsTargetMain = fs.findTargetByPuntiFoto(hsPuntiFoto);
if (debug)
System.out.println(TAG_THREAD_MSG + " PUNTO FOTO: " + TAG_THREAD_MSG + " vecFsTargetMain len: " + puntofoto.getDescrizione());
int totFsTargetMain = vecFsTargetMain.getTotNumberOfRecords();
JsonArray jsonQuery = new JsonArray();
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, " pf: " + puntofoto.getDescrizione() + " query target scoring .... current pf:" + etaPf + " TOTALE: " + etaTot);
Vectumerator<FaceScore> vecFsQuery = fs.findTargetByPuntofoto(puntofoto.getId_puntoFoto());
int totFsQuery = vecFsQuery.getTotNumberOfRecords();
int j = 0;
LinkedHashMap<Long, JsonObject> lhpFsQuery = new LinkedHashMap<>();
while (vecFsQuery.hasMoreElements() && !Evento.threadEventoScoringSTOP) {
FaceScore fsQuery = (FaceScore)vecFsQuery.nextElement();
if (j % STEP_STATUS_MSG == 0)
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "max thread: " + maxNumberOfThread + " qsize:" + NUM_QUERY_CALLABLE + " pf: " +
puntofoto.getDescrizione() + " hspf target size:" +
hsPuntiFoto.size() + " target uniti: " + targetUniti + " main " + i + "/" + totFsTargetMain + " scoring target n. " + j + "/" + totFsQuery + " preparazione hash table query invio per scoring ..... PF:" + etaPf + " TOTALE: " + etaTot);
JsonObject jsonQueryRow = new JsonObject();
jsonQueryRow.addProperty("id", Long.valueOf(fsQuery.getId_fotoFace()));
jsonQueryRow.addProperty("path", fsQuery.getFotoFace().getFacePath());
jsonQueryRow.addProperty("md5", fsQuery.getFotoFace().getMd5());
jsonQueryRow.addProperty("type", "face");
lhpFsQuery.put(Long.valueOf(fsQuery.getId_fotoFace()), jsonQueryRow);
j++;
}
i = 0;
int aggiustaEtaTarget = 0;
HashSet<FaceScore> hsFaceScoreTrovati = new HashSet<>();
if (this.evento.getCurrentPuntofoto2() == puntofoto.getId_puntoFoto() && this.evento.getCurrentFaceTarget2() > 0L &&
this.evento.getCurrentFaceTarget2() > (long)i) {
vecFsTargetMain.setIndex((int)this.evento.getCurrentFaceTarget2());
i = (int)this.evento.getCurrentFaceTarget2();
aggiustaEtaTarget = (int)this.evento.getCurrentFaceTarget2();
}
while (vecFsTargetMain.hasMoreElements() && !Evento.threadEventoScoringSTOP) {
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "max thread: " + maxNumberOfThread + " qsize:" + NUM_QUERY_CALLABLE + " pf: " +
puntofoto.getDescrizione() + " hspf target size:" +
hsPuntiFoto.size() + " target uniti: " + targetUniti + " main " + i + "/" + totFsTargetMain + " current pf:" + etaPf + " TOTALE: " + etaTot + " " +
String.valueOf(DBAdapter.getTimestamp()));
FaceScore fsTargetMain = (FaceScore)vecFsTargetMain.nextElement();
JsonObject jsonData = new JsonObject();
JsonObject jsonTarget = new JsonObject();
jsonTarget.addProperty("path", fsTargetMain.getFotoFace().getFacePath());
jsonTarget.addProperty("md5", fsTargetMain.getFotoFace().getMd5());
String targetType = "face";
jsonTarget.addProperty("type", targetType);
jsonData.addProperty("dis_type", Long.valueOf(dysType));
jsonData.addProperty("conf_threshold", Double.valueOf(confDetectLevel));
jsonData.add("target", (JsonElement)jsonTarget);
totFsQuery = lhpFsQuery.size();
j = 0;
jsonQuery = new JsonArray();
LinkedHashMap<Long, JsonObject> lhpFsQueryCopy = new LinkedHashMap<>(lhpFsQuery);
for (JsonObject jsonQueryRow : lhpFsQueryCopy.values()) {
if (jsonQueryRow.get("id").getAsLong() != fsTargetMain.getId_fotoFace()) {
if (j % STEP_STATUS_MSG == 0)
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "max thread: " + maxNumberOfThread + " qsize:" + NUM_QUERY_CALLABLE + " pf: " +
puntofoto.getDescrizione() + " hspf target size:" + hsPuntiFoto.size() + " target uniti: " + targetUniti + " main " + i + "/" + totFsTargetMain + " scoring target n. " + j + "/" + totFsQuery + " preparazione invio per scoring tramite hashmap .... current pf:" + etaPf + " TOTALE: " + etaTot);
if (j > 0 && j % NUM_QUERY_CALLABLE == 0) {
String threadMsg = "max thread: " + maxNumberOfThread + " qsize:" + NUM_QUERY_CALLABLE + " pf: " +
puntofoto.getDescrizione() + " hspf target size:" + hsPuntiFoto.size() + " target uniti: " + targetUniti + " main " + i + "/" + totFsTargetMain + " scoring target n. " + j + "/" + totFsQuery + " preparazione invio per scoring tramite hashmap .... current pf:" + etaPf + " TOTALE: " + etaTot;
JsonObject jsonDataCallable = jsonData.deepCopy();
jsonDataCallable.add("query", (JsonElement)jsonQuery);
ScoringFaceCallableGson ifc = new ScoringFaceCallableGson(this.evento, jsonDataCallable, targetDir, true);
vecF.add(pool.submit(ifc));
jsonQuery = new JsonArray();
}
jsonQuery.add((JsonElement)jsonQueryRow);
}
j++;
}
if (jsonQuery.size() > 0) {
String threadMsg = "max thread: " + maxNumberOfThread + " qsize:" + NUM_QUERY_CALLABLE + " pf: " +
puntofoto.getDescrizione() + " hspf target size:" + hsPuntiFoto.size() + " target uniti: " + targetUniti + " main " + i + "/" + totFsTargetMain + " scoring target n. " + j + "/" + totFsQuery + " preparazione invio per scoring tramite hashmap .... current pf:" + etaPf + " TOTALE: " + etaTot;
JsonObject jsonDataCallable = jsonData.deepCopy();
jsonDataCallable.add("query", (JsonElement)jsonQuery);
ScoringFaceCallableGson ifc = new ScoringFaceCallableGson(this.evento, jsonDataCallable, targetDir, true);
vecF.add(pool.submit(ifc));
}
try {
for (int fidx = 0; fidx < vecF.getTotNumberOfRecords(); fidx++) {
Future<ResParm> currentFuture = (Future<ResParm>)vecF.nextElement();
rp = currentFuture.get();
if (j % STEP_STATUS_MSG == 0)
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "max thread: " + maxNumberOfThread + " qsize:" + NUM_QUERY_CALLABLE + " pf: " +
puntofoto.getDescrizione() + " hspf target size:" + hsPuntiFoto.size() + " target uniti: " + targetUniti + " main " + i + "/" + totFsTargetMain + " scoring target n. " + j + "/" + totFsQuery + " future " + fidx + "/" +
vecF.getTotNumberOfRecords() + " .... current pf:" + etaPf + " TOTALE: " + etaTot);
if (!rp.getStatus()) {
errMsg.append(rp.getErrMsg() + "\n");
} else {
HashSet<FaceScore> hsFs = (HashSet<FaceScore>)rp.getReturnObj();
if (hsFs != null) {
for (FaceScore fsTargetSul2 : hsFs) {
if (debug)
System.out.println("******************************** fase2RaggruppaScoringTarget: FS UNITI.... LI TOLGO DA HASHMAP: CURRENT LSH SIZE: " +
lhpFsQuery.size());
rp = fs.unisciTarget(fsTargetMain.getId_fotoFace(), fsTargetSul2.getId_fotoFace2());
targetUniti++;
lhpFsQuery.remove(Long.valueOf(fsTargetSul2.getId_fotoFace2()));
if (debug)
System.out.println("******************************** fase2RaggruppaScoringTarget: FS UNITI.... NUOVA LSH SIZE: " +
lhpFsQuery.size());
}
hsFaceScoreTrovati.addAll(hsFs);
}
}
}
} catch (Exception e) {
e.printStackTrace();
rp.setStatus(false);
rp.setMsg("Eccezione vecfuture: " + e.getMessage());
}
i++;
lastidxFotoTarget = (long)i;
etaPf = timerPf.getEta((long)(totFsTargetMain - aggiustaEtaTarget), (long)(i - aggiustaEtaTarget));
}
if (Evento.threadEventoScoringSTOP) {
puntofoto.setFlgStatoScoring(1L);
} else {
puntofoto.setFlgStatoScoring(2L);
}
puntofoto.save();
this.evento.setCurrentFaceTarget2(lastidxFotoTarget - 1L);
this.evento.setCurrentPuntofoto2(puntofoto.getId_puntoFoto());
this.evento.save();
if (firstPuntoFoto == null) {
firstPuntoFoto = puntofoto;
} else {
hsPuntiFoto.add(Long.valueOf(puntofoto.getId_puntoFoto()));
}
timerPf.stop();
numPf++;
etaTot = timer.getEta((long)totPf, (long)numPf);
}
pool.shutdown();
SaveScoreProcessor ssProcessor = SaveScoreProcessor.getInstance(Evento.this.getApFull(), 10);
ssProcessor.shutdown();
timer.stop();
if (debug)
System.out.println("******************************** fase2RaggruppaScoringTarget: FINE!!!: " + timer.getDurata());
StatusMsg.deleteMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG);
Log.addAltro(Evento.this.getApFull(), "127.0.0.1", 1L, " fase2RaggruppaScoringTarget: FINE!!! Targetuniti: " + targetUniti + "\n" +
timer.getDurata());
return rp;
}
public void runPfxPf() {
boolean debug = false;
String TAG_THREAD_MSG = "EVENTO SCORING ID: " + this.evento.getId_evento();
Timer timer = new Timer();
timer.start();
ResParm rp = new ResParm(true);
Foto foto = new Foto(Evento.this.getApFull());
FotoCR fCR = new FotoCR(Evento.this.getApFull());
fCR.setFlgWithFaces(1L);
fCR.setFlgFotoOrFace(0L);
FotoCR fCRquery = new FotoCR(Evento.this.getApFull());
fCRquery.setFlgWithFaces(1L);
fCRquery.setFlgFotoOrFace(0L);
FotoFace currentFaceTarget = new FotoFace(Evento.this.getApFull());
FotoFaceCR ffCRTarget = new FotoFaceCR(Evento.this.getApFull());
FotoFace currentFaceQuery = new FotoFace(Evento.this.getApFull());
FotoFaceCR ffCRQuery = new FotoFaceCR(Evento.this.getApFull());
FaceScore fs = new FaceScore(Evento.this.getApFull());
boolean scoringDone = false;
long fotoCount = 0L;
long faceCount = 0L;
long faceTrovataCount = 0L;
StringBuffer errMsg = new StringBuffer();
String targetDir = Evento.this.getParm("PATHFOTO_FACE").getTesto() + Evento.this.getParm("PATHFOTO_FACE").getTesto();
File targetDirFile = new File(targetDir);
if (!targetDirFile.exists())
targetDirFile.mkdirs();
int numFotoNoScore = (int)this.evento.getNumFotoNoScore();
Vectumerator<PuntoFoto> vecPf = this.evento.getPuntiFoto(0, 0);
while (vecPf.hasMoreElements() && !Evento.threadEventoScoringSTOP) {
PuntoFoto puntofoto = (PuntoFoto)vecPf.nextElement();
if (puntofoto.getFlgStatoScoring() == 1L)
continue;
if (debug)
System.out.println("THREADSCORING1: PUNTO FOTO:" + puntofoto.getDescrizione());
fotoCount = 0L;
fCR.setId_puntoFoto(puntofoto.getId_puntoFoto());
fCRquery.setId_puntoFoto(puntofoto.getId_puntoFoto());
Vectumerator<Foto> vecFoto = foto.findByCR(fCR, 0, 0);
while (vecFoto.hasMoreElements() && !Evento.threadEventoScoringSTOP) {
Foto currentFoto = (Foto)vecFoto.nextElement();
fotoCount++;
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "Punto foto " +
puntofoto.getDescrizione() + " foto " + currentFoto.getFileName() + " foto " + fotoCount + "/" +
vecFoto.getTotNumberOfRecords() + " face n. " + faceCount + " face trovate n. " + faceTrovataCount + " " +
timer.getEta((long)vecFoto.getTotNumberOfRecords(), fotoCount));
if (debug)
System.out.println("THREADSCORING2: Punto foto ciclo currentfoto pf " + puntofoto.getDescrizione() + " target foto " +
currentFoto.getFileName() + " n. foto target " + fotoCount + "/" +
vecFoto.getTotNumberOfRecords() + " n. face " + faceCount + " face trovate n. " + faceTrovataCount + " " +
timer.getEta((long)vecFoto.getTotNumberOfRecords(), fotoCount));
Vectumerator<FotoFace> vecFotoFace = currentFoto.getFotoFaces();
while (vecFotoFace.hasMoreElements()) {
currentFaceTarget = (FotoFace)vecFotoFace.nextElement();
if (!fs.hasFaceLegami(currentFaceTarget.getId_fotoFace())) {
faceCount++;
if (debug)
System.out.println("THREADSCORING3: Punto foto ciclo currenttargetface pf " +
puntofoto.getDescrizione() + " target foto " + currentFoto.getFileName() + " foto " + fotoCount + "/" +
vecFoto.getTotNumberOfRecords() + " face n. " + faceCount + " face trovate n. " + faceTrovataCount + " " +
timer.getEta((long)vecFoto.getTotNumberOfRecords(), fotoCount));
fCRquery.setFileNameFrom(currentFoto.getFileName());
if (numFotoNoScore == 0) {
vecFotoQuery = foto.findByCR(fCRquery, 0, 0);
if (debug)
System.out.println("THREADSCORING3.1: Punto foto ciclo currenttargetface pf " +
puntofoto.getDescrizione() + " target ffoto " +
currentFoto.getFileName() + " foto " + fotoCount + "/" +
vecFoto.getTotNumberOfRecords() + " face n. " + faceCount + " face trovate n. " + faceTrovataCount + " " +
timer.getEta((long)vecFoto.getTotNumberOfRecords(), fotoCount));
continue;
}
if (debug)
System.out.println("THREADSCORING3.2: Punto foto ciclo currenttargetface pf " +
puntofoto.getDescrizione() + " foto " + currentFoto.getFileName() + " foto " + fotoCount + "/" +
vecFoto.getTotNumberOfRecords() + " face n. " + faceCount + " face trovate n. " + faceTrovataCount + " " +
timer.getEta((long)vecFoto.getTotNumberOfRecords(), fotoCount));
Vectumerator<Foto> vecFotoQuery = foto.findByCR(fCRquery, 1, 20 + numFotoNoScore);
long fotoSenzaFacciaTrovata = 0L;
while (vecFotoQuery.hasMoreElements() && fotoSenzaFacciaTrovata < (long)numFotoNoScore) {
Foto currentFotoQuery = (Foto)vecFotoQuery.nextElement();
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "Punto foto " +
puntofoto.getDescrizione() + " target foto " + currentFoto.getFileName() + " query foto " +
currentFotoQuery.getFileName() + " n. foto target " + fotoCount + "/" +
vecFoto.getTotNumberOfRecords() + " n. face " + faceCount + " n. face trovate " + faceTrovataCount + " " +
timer.getEta((long)vecFoto.getTotNumberOfRecords(), fotoCount));
if (debug)
System.out.println("THREADSCORING4: Punto foto ciclo \ncurrentFotoQuery" +
currentFotoQuery.getFileName() + "\npf " + puntofoto.getDescrizione() + " target ffoto " +
currentFoto.getFileName() + " foto " + fotoCount + "/" + vecFoto.getTotNumberOfRecords() + " face n. " + faceCount + " face trovate n. " + faceTrovataCount + " fotoSenzaFacciaTrovata:" + fotoSenzaFacciaTrovata + " " +
timer.getEta((long)vecFoto.getTotNumberOfRecords(), fotoCount));
boolean facciaTrovata = false;
Vectumerator<FotoFace> vecFotoFaceQuery = currentFotoQuery.getFotoFaces();
while (vecFotoFaceQuery.hasMoreElements() && !facciaTrovata) {
currentFaceQuery = (FotoFace)vecFotoFaceQuery.nextElement();
scoringDone = false;
if (!fs.hasFaceLegami(currentFaceQuery.getId_fotoFace())) {
if (debug)
System.out.println("THREADSCORING5: Punto foto ciclo currentFotoQuery + facescoring \ncurrentFaceTarget" +
currentFaceTarget.getFileName() + " \ncurrentFaceQuery " +
currentFaceQuery.getFileName() + "\npf " + puntofoto.getDescrizione() + " foto " +
currentFoto.getFileName() + " target foto " + fotoCount + "/" +
vecFoto.getTotNumberOfRecords() + " face n. " + faceCount + " face trovate n. " + faceTrovataCount + " fotoSenzaFacciaTrovata:" + fotoSenzaFacciaTrovata + " " +
timer.getEta((long)vecFoto.getTotNumberOfRecords(), fotoCount));
float scoring = currentFaceTarget.getFaceScoring(currentFaceQuery, true);
if (debug)
System.out.println("THREADSCORING6: Punto foto ciclo currentFotoQuery + FACESCORING FATTO \ncurrentFaceTarget" +
currentFaceTarget.getFileName() + " \ncurrentFaceQuery " +
currentFaceQuery.getFileName() + "\npf " + puntofoto.getDescrizione() + " target foto " +
currentFoto.getFileName() + " foto " + fotoCount + "/" +
vecFoto.getTotNumberOfRecords() + " face n. " + faceCount + " face trovate n. " + faceTrovataCount + " fotoSenzaFacciaTrovata:" + fotoSenzaFacciaTrovata + " " +
timer.getEta((long)vecFoto.getTotNumberOfRecords(), fotoCount));
if (scoring > 0.0F) {
facciaTrovata = true;
scoringDone = true;
faceTrovataCount++;
if (debug)
System.out.println("THREADSCORING7: Punto foto ciclo currentFotoQuery + FACESCORING TROVATO\ncurrentFaceTarget" +
currentFaceTarget.getFileName() + " \ncurrentFaceQuery " +
currentFaceQuery.getFileName() + "\n" + puntofoto.getDescrizione() + " target foto " +
currentFoto.getFileName() + " foto " + fotoCount + "/" +
vecFoto.getTotNumberOfRecords() + " face n. " + faceCount + " face trovate n. " + faceTrovataCount + " fotoSenzaFacciaTrovata:" + fotoSenzaFacciaTrovata + " " +
timer.getEta((long)vecFoto.getTotNumberOfRecords(), fotoCount));
}
}
}
if (facciaTrovata) {
fotoSenzaFacciaTrovata = 0L;
continue;
}
fotoSenzaFacciaTrovata++;
}
}
}
if (scoringDone) {
foto.setFlgFaceScoringDone(1L);
foto.save();
}
}
}
if (Evento.threadEventoScoringSTOP) {
rp.setMsg("Evento Scoring STOP MANUALE!.<br>Numero foto:" + fotoCount + " facce: " + faceCount + " facce trovate: " + faceTrovataCount + "<br> - Errori rilevati: " +
errMsg.toString());
} else {
rp.setMsg("Evento Scoring completato.<br>Numero foto: " + fotoCount + " facce: " + faceCount + " facce trovate: " + faceTrovataCount + "<br> - Errori rilevati: " +
errMsg.toString());
}
rp.setStatus(true);
timer.stop();
System.out.println(TAG_THREAD_MSG + " DURATA: " + TAG_THREAD_MSG + " " + timer.getDurata());
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "Concluso: DURATA: " + timer.getDurata() + "\nRisultato: " + rp.getMsg());
try {
sleep(4000L);
} catch (Exception e) {}
StatusMsg.deleteMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG);
Evento.threadEventoScoring = false;
}
private ResParm fase1ScoringPuntifoto(String TAG_THREAD_MSG) {
boolean debug = true;
Timer timer = new Timer();
timer.start();
ResParm rp = new ResParm(true);
long fotoCount = 0L;
long faceCount = 0L;
long faceTrovataCount = 0L;
StringBuffer errMsg = new StringBuffer();
String targetDir = Evento.this.getParm("PATHFOTO_FACE").getTesto() + Evento.this.getParm("PATHFOTO_FACE").getTesto();
File targetDirFile = new File(targetDir);
if (!targetDirFile.exists())
targetDirFile.mkdirs();
FaceScore fs = new FaceScore(Evento.this.getApFull());
Vectumerator<PuntoFoto> vecPf = this.evento.getPuntiFoto(0, 0);
int maxNumberOfThreadPf = Evento.this.getParm("MAX_NUMBER_OF_THREAD_PF_SCORING_LVL_1").getNumeroInt();
if (maxNumberOfThreadPf < 1)
maxNumberOfThreadPf = vecPf.getTotNumberOfRecords();
ExecutorService pool = Executors.newFixedThreadPool(maxNumberOfThreadPf);
Vectumerator<Future<ResParm>> vecF = new Vectumerator();
while (vecPf.hasMoreElements() && !Evento.threadEventoScoringSTOP) {
PuntoFoto puntofoto = (PuntoFoto)vecPf.nextElement();
if (puntofoto.getFlgStatoScoring() != 0L)
continue;
if (debug)
DBAdapter.printDebug(TAG_THREAD_MSG + " PF:" + TAG_THREAD_MSG + " evento id: " + puntofoto.getDescrizione());
fotoCount = 0L;
Scoring1PuntoFotoCallableOld ifc = new Scoring1PuntoFotoCallableOld(this.evento, puntofoto, TAG_THREAD_MSG + " pf: " + TAG_THREAD_MSG);
vecF.add(pool.submit(ifc));
puntofoto.setFlgStatoScoring(11L);
puntofoto.save();
}
try {
for (int j = 0; j < vecF.getTotNumberOfRecords(); j++) {
Future<ResParm> currentFuture = (Future<ResParm>)vecF.nextElement();
rp = currentFuture.get();
if (!rp.getStatus())
errMsg.append(rp.getErrMsg() + "\n");
DBAdapter.printDebug(currentFuture.get().getMsg() + " ended");
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "max thread: " + maxNumberOfThreadPf + " reading future..... " + j + 1 + "/" +
vecF.getTotNumberOfRecords() + 1);
PuntoFoto pfFinito = (PuntoFoto)currentFuture.get().getReturnObj();
if (!Evento.threadEventoScoringSTOP) {
pfFinito.setFlgStatoScoring(1L);
} else {
pfFinito.setFlgStatoScoring(0L);
}
pfFinito.save();
}
} catch (Exception e) {
e.printStackTrace();
rp.setStatus(false);
rp.setMsg("Eccezione vecfuture: " + e.getMessage());
}
if (rp.getStatus()) {
faceTrovataCount = fs.getTotoFaceScoreByEvento(this.evento.getId_evento());
if (Evento.threadEventoScoringSTOP) {
rp.setMsg("Evento Scoring STOP MANUALE!.<br>Numero foto:" + fotoCount + " facce: " + faceCount + " facce trovate: " + faceTrovataCount + "<br> - Errori rilevati: " +
errMsg.toString());
} else {
rp.setMsg("Evento Scoring completato.<br>Numero foto: " + fotoCount + " facce: " + faceCount + " facce trovate: " + faceTrovataCount + "<br> - Errori rilevati: " +
errMsg.toString());
}
rp.setStatus(true);
}
pool.shutdown();
timer.stop();
DBAdapter.printDebug(true, TAG_THREAD_MSG + " DURATA: " + TAG_THREAD_MSG + " " + timer.getDurata());
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "Concluso fase 1: DURATA: " +
timer.getDurata() + "\nRisultato: " + rp.getMsg());
try {
sleep(3000L);
} catch (Exception e) {}
StatusMsg.deleteMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG);
Log.addAltro(Evento.this.getApFull(), "127.0.0.1", 1L, " fase1ScoringPuntifoto: FINE!!! :\n" +
timer.getDurata() + "\nRisultato: " + rp.getMsg());
return rp;
}
@Deprecated
private ResParm fase5ScoringDirettoSuFotoFace(String TAG_THREAD_MSG) {
boolean debug = false;
ResParm rp = new ResParm(true);
TAG_THREAD_MSG = TAG_THREAD_MSG + " GLOBALE 5";
int STEP_STATUS_MSG = 100;
Timer timer = new Timer();
timer.start();
String targetDir = Evento.this.getParm("PATHFOTO_FACE").getTesto() + Evento.this.getParm("PATHFOTO_FACE").getTesto();
File targetDirFile = new File(targetDir);
if (!targetDirFile.exists())
targetDirFile.mkdirs();
double confDetectLevel = this.evento.getDetectFaceConfidentThresold();
long dysType = Evento.this.getParm("ZOO_YUNET_SCORING_DYS_TYPE").getNumeroLong();
FaceRecognitionApi frApi = new FaceRecognitionApi(Evento.this.getApFull());
FaceScore fs = new FaceScore(Evento.this.getApFull());
int totScores = 0;
FotoFace ff = new FotoFace(Evento.this.getApFull());
int j = 0;
Vectumerator<FotoFace> vecFf = ff.findByEvento(this.evento.getId_evento(), 1, 1);
LinkedHashMap<Long, FotoFace> lhpFfTarget = new LinkedHashMap<>(vecFf.getTotNumberOfRecords());
LinkedHashMap<Long, JSONObject> lhpFfQuery = new LinkedHashMap<>(vecFf.getTotNumberOfRecords());
Timer timerHt = new Timer();
timerHt.start();
int pageRows = 20000;
int pagenumber = 1;
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, " query page " + pagenumber + " foto-face in corso .....");
while ((vecFf = ff.findByEvento(this.evento.getId_evento(), pagenumber, pageRows)).hasMoreElements()) {
int totFf = vecFf.getTotNumberOfRecords();
while (vecFf.hasMoreElements() && !Evento.threadEventoScoringSTOP) {
j++;
FotoFace rowFf = (FotoFace)vecFf.nextElement();
if (j % STEP_STATUS_MSG == 0)
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, " preparazione hash table target e query " + j + "/" + totFf + " ....." +
timerHt.getEta((long)totFf, (long)j));
lhpFfTarget.put(Long.valueOf(rowFf.getId_fotoFace()), rowFf);
JSONObject jsonQueryRow = new JSONObject();
jsonQueryRow.put("id", rowFf.getFacePath());
jsonQueryRow.put("path", rowFf.getFacePath());
jsonQueryRow.put("md5", rowFf.getMd5());
jsonQueryRow.put("type", "face");
lhpFfQuery.put(Long.valueOf(rowFf.getId_fotoFace()), jsonQueryRow);
}
pagenumber++;
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, " query page " + pagenumber + " foto-face in corso .....");
}
timerHt.stop();
JSONArray jsonQuery = new JSONArray();
boolean nuovoJsonQuery = true;
int i = 0;
int totFftarget = lhpFfTarget.size();
for (FotoFace ffTarget : lhpFfTarget.values()) {
if (Evento.threadEventoScoringSTOP)
break;
i++;
lhpFfQuery.remove(Long.valueOf(ffTarget.getId_fotoFace()));
JSONObject jsonData = new JSONObject();
JSONObject jsonTarget = new JSONObject();
jsonTarget.put("path", ffTarget.getFacePath());
jsonTarget.put("md5", ffTarget.getMd5());
String targetType = "face";
jsonTarget.put("type", targetType);
jsonData.put("dis_type", dysType);
jsonData.put("conf_threshold", confDetectLevel);
jsonData.put("target", jsonTarget);
if (nuovoJsonQuery) {
jsonQuery = new JSONArray();
int totFfQuery = lhpFfQuery.size();
j = 0;
for (JSONObject jsonQueryRow : lhpFfQuery.values()) {
j++;
if (j % STEP_STATUS_MSG == 0)
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, " scores trovati: " + totScores + " preparazione tramite hashmap del json query per scoring " + j + "/" + totFfQuery + " ...." +
timer.getEta((long)totFfQuery, (long)j) + " totale: " +
timer.getEta((long)totFftarget, (long)i));
jsonQuery.put(jsonQueryRow);
}
nuovoJsonQuery = false;
}
jsonData.put("query", jsonQuery);
if (Evento.threadEventoScoringSTOP)
break;
String jsonDataFileName = targetDir + "jsonDataScoring_" + targetDir + ".json";
String jsonResFileName = targetDir + "jsonDataScoring_" + targetDir + "_res.json";
jsonData.put("debug", "fase5ScoringDirettoSuFotoFace");
FileWr fw = new FileWr(jsonDataFileName, false);
try {
fw.writeLine(jsonData.toString(4));
fw.closeFile();
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, " scores trovati: " + totScores + " tot query face " +
jsonQuery.length() + " della foto " +
ffTarget.getFoto().getFileName() + " chiamata API " + i + "/" + totFftarget + " .... totale: " +
timer.getEta((long)totFftarget, (long)i));
FaceRecognitionApiResult frar = frApi.__scoring(jsonDataFileName, jsonResFileName);
if (frar.isOk()) {
if (debug)
System.out.println("******************************** fase5ScoringDirettoSuFotoFace: json reponse: ");
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, " scores trovati: " + totScores + " tot query face " +
jsonQuery.length() + " della foto " +
ffTarget.getFoto().getFileName() + " elaborazione scoring " + i + "/" + totFftarget + " .... totale: " +
timer.getEta((long)totFftarget, (long)i));
rp = fs.elaboraScoringResult(frar.getJSONObjectResult(), this.evento, true);
if (rp.getStatus()) {
HashSet<FaceScore> hsFs = (HashSet<FaceScore>)rp.getReturnObj();
for (FaceScore fsTargetSul2 : hsFs) {
totScores++;
if (debug)
System.out.println("******************************** fase5ScoringDirettoSuFotoFace: RITORNO DA API.... LI TOLGO DA HASHMAP: CURRENT LSHTARGET SIZE: " +
lhpFfTarget.size() + " CURRENT LHPFQUERY SIZE: " + lhpFfQuery.size());
lhpFfTarget.remove(Long.valueOf(fsTargetSul2.getId_fotoFace2()));
lhpFfQuery.remove(Long.valueOf(fsTargetSul2.getId_fotoFace2()));
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, " scores trovati: " + totScores + " tot query face " +
jsonQuery.length() + " della foto " +
ffTarget.getFoto().getFileName() + " PULIZIA LHPF CON SCORING TROVATO " + i + "/" + totFftarget + " .... totale: " +
timer.getEta((long)totFftarget, (long)i));
if (debug)
System.out.println("******************************** fase5ScoringDirettoSuFotoFace: RITORNO DA API.... LI TOLGO DA HASHMAP: NUOVA LSHTARGET SIZE: " +
lhpFfTarget.size() + " NUOVA LHPFQUERY SIZE: " + lhpFfQuery.size());
nuovoJsonQuery = true;
}
}
}
} catch (Exception e) {
if (debug)
System.out.println("******************************** fase5ScoringDirettoSuFotoFace: ex: " + e.getMessage());
e.printStackTrace();
Evento.this.handleDebug(e);
}
}
SaveScoreProcessor ssProcessor = SaveScoreProcessor.getInstance(Evento.this.getApFull(), 10);
ssProcessor.shutdown();
timer.stop();
if (debug)
System.out.println("******************************** fase5ScoringDirettoSuFotoFace: FINE!!!: " + timer.getDurata());
StatusMsg.deleteMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG);
return rp;
}
private ResParm fase6ScoringDirettoSuFotoFaceNfoto(String TAG_THREAD_MSG) {
boolean debug = false;
ResParm rp = new ResParm(true);
long nFotoDopo = 3L;
TAG_THREAD_MSG = TAG_THREAD_MSG + " G6 >3 foto";
int STEP_STATUS_MSG = 100;
Timer timer = new Timer();
timer.start();
double scoreThresold = this.evento.getScoreThresold();
String targetDir = Evento.this.getParm("PATHFOTO_FACE").getTesto() + Evento.this.getParm("PATHFOTO_FACE").getTesto();
File targetDirFile = new File(targetDir);
if (!targetDirFile.exists())
targetDirFile.mkdirs();
double confDetectLevel = this.evento.getDetectFaceConfidentThresold();
long dysType = Evento.this.getParm("ZOO_YUNET_SCORING_DYS_TYPE").getNumeroLong();
FaceRecognitionApi frApi = new FaceRecognitionApi(Evento.this.getApFull());
FaceScore fs = new FaceScore(Evento.this.getApFull());
int totTargetUniti = 0;
int iPf = 0;
int iFacesTarget = 0;
Vectumerator<PuntoFoto> vecPf = this.evento.getPuntiFoto(0, 0);
Timer timerPf = new Timer();
int numPf = 0;
int totPf = vecPf.getTotNumberOfRecords();
while (vecPf.hasMoreElements() && !Evento.threadEventoScoringSTOP) {
iPf++;
timerPf.start();
PuntoFoto puntofoto = (PuntoFoto)vecPf.nextElement();
iFacesTarget = 0;
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "punto foto:" +
puntofoto.getId_puntoFoto() + " (" + iPf + "/" + vecPf.getTotNumberOfRecords() + ") target uniti: " + totTargetUniti + " QUERY TARGET PUNTOFOTO ...... totale: " +
timer.getEta((long)vecPf.getTotNumberOfRecords(), (long)iPf));
Vectumerator<FaceScore> vecFsTarget = fs.findTargetByPuntofoto(puntofoto.getId_puntoFoto());
while (vecFsTarget.hasMoreElements() && !Evento.threadEventoScoringSTOP) {
iFacesTarget++;
FaceScore fsTarget = (FaceScore)vecFsTarget.nextElement();
Vectumerator<FaceScore> vecFsQuery = fs.findTargetByPuntofotoNFace(puntofoto.getId_puntoFoto(), fsTarget.getFoto().getFileName(), 3L);
JsonArray jsonQueryA = new JsonArray();
int j = 0;
while (vecFsQuery.hasMoreElements() && !Evento.threadEventoScoringSTOP) {
j++;
FaceScore fsQuery = (FaceScore)vecFsQuery.nextElement();
JsonObject jsonQueryRow = new JsonObject();
jsonQueryRow.addProperty("path", fsQuery.getFotoFace().getFacePath());
jsonQueryRow.addProperty("md5", fsQuery.getFotoFace().getMd5());
jsonQueryRow.addProperty("type", "face");
jsonQueryA.add((JsonElement)jsonQueryRow);
if (j % 50 == 0)
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "punto foto:" +
puntofoto.getId_puntoFoto() + " (" + iPf + "/" + vecPf.getTotNumberOfRecords() + ") target uniti: " + totTargetUniti + " QUERY TARGET PUNTOFOTO ...... " + j + "/" +
vecFsQuery.getTotNumberOfRecords() + " totale: " +
timer.getEta((long)vecPf.getTotNumberOfRecords(), (long)iPf));
}
JsonObject jsonData = new JsonObject();
JsonObject jsonTarget = new JsonObject();
jsonTarget.addProperty("path", fsTarget.getFotoFace().getFacePath());
jsonTarget.addProperty("md5", fsTarget.getFotoFace().getMd5());
String targetType = "face";
jsonTarget.addProperty("type", targetType);
jsonData.addProperty("dis_type", Long.valueOf(dysType));
jsonData.addProperty("conf_threshold", Double.valueOf(confDetectLevel));
jsonData.add("target", (JsonElement)jsonTarget);
jsonData.add("query", (JsonElement)jsonQueryA);
if (Evento.threadEventoScoringSTOP)
break;
String jsonDataFileName = targetDir + "jsonDataScoring_" + targetDir + ".json";
String jsonResFileName = targetDir + "jsonDataScoring_" + targetDir + "_res.json";
jsonData.addProperty("debug", "fase6ScoringDirettoSuFotoFaceNfoto");
FileWr fw = new FileWr(jsonDataFileName, false);
try {
fw.writeLine(DBAdapter.gsonToString(jsonData));
fw.closeFile();
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "punto foto:" +
puntofoto.getId_puntoFoto() + " (" + iPf + "/" + vecPf.getTotNumberOfRecords() + ") target uniti: " + totTargetUniti + " tot query face " +
jsonQueryA.size() + " chiamata API " + iFacesTarget + "/" +
vecFsTarget.getTotNumberOfRecords() + " .... current PF: " +
timerPf.getEta((long)vecFsTarget.getTotNumberOfRecords(), (long)iFacesTarget) + " totale: " +
timer.getEta((long)vecPf.getTotNumberOfRecords(), (long)iPf));
FaceRecognitionApiResult frar = frApi.__scoring(jsonDataFileName, jsonResFileName);
if (frar.isOk()) {
if (debug)
System.out.println("******************************** fase6ScoringDirettoSuFotoFaceNfoto: json reponse: ");
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "punto foto:" +
puntofoto.getId_puntoFoto() + " (" + iPf + "/" + vecPf.getTotNumberOfRecords() + ") target uniti: " + totTargetUniti + " tot query face " +
jsonQueryA.size() + " ELABORO SCORING " + iFacesTarget + "/" +
vecFsTarget.getTotNumberOfRecords() + " .... current PF: " +
timerPf.getEta((long)vecFsTarget.getTotNumberOfRecords(), (long)iFacesTarget) + " totale: " +
timer.getEta((long)vecPf.getTotNumberOfRecords(), (long)iPf));
rp = fs.elaboraScoringResultGson(frar.getJsonObjectResult(), this.evento, true);
if (rp.getStatus()) {
HashSet<FaceScore> hsFs = (HashSet<FaceScore>)rp.getReturnObj();
for (FaceScore fsTargetSul2 : hsFs) {
totTargetUniti++;
rp = fs.unisciTarget(fsTarget.getId_fotoFace(), fsTargetSul2.getId_fotoFace2());
if (debug)
System.out.println("******************************** fase6ScoringDirettoSuFotoFaceNfoto: RITORNO DA API....faccio l'unione dei target...");
}
}
}
} catch (Exception e) {
if (debug)
System.out.println("******************************** fase6ScoringDirettoSuFotoFaceNfoto: ex: " +
e.getMessage());
e.printStackTrace();
Evento.this.handleDebug(e);
}
}
}
SaveScoreProcessor ssProcessor = SaveScoreProcessor.getInstance(Evento.this.getApFull(), 10);
ssProcessor.shutdown();
timer.stop();
if (debug)
System.out.println("******************************** fase6ScoringDirettoSuFotoFaceNfoto: FINE!!!: " + timer.getDurata());
StatusMsg.deleteMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG);
return rp;
}
private ResParm fase3ScoringFaceSenzaScoringPerEvento(String TAG_THREAD_MSG) {
boolean debug = false;
StringBuffer errMsg = new StringBuffer();
ResParm rp = new ResParm(true);
int STEP_STATUS_MSG = 20;
Timer timer = new Timer();
timer.start();
int maxNumberOfThread = Evento.this.getParm("MAX_NUMBER_OF_THREAD_SCORING_LVL_2").getNumeroInt();
int NUM_QUERY_CALLABLE = Evento.this.getParm("NUM_QUERY_CALLABLE_LVL_2").getNumeroInt();
if (maxNumberOfThread <= 0)
maxNumberOfThread = 200;
if (NUM_QUERY_CALLABLE <= 0)
NUM_QUERY_CALLABLE = 95;
ExecutorService pool = Executors.newFixedThreadPool(maxNumberOfThread);
Vectumerator<Future<ResParm>> vecF = new Vectumerator();
String targetDir = Evento.this.getParm("PATHFOTO_FACE").getTesto() + Evento.this.getParm("PATHFOTO_FACE").getTesto();
File targetDirFile = new File(targetDir);
if (!targetDirFile.exists())
targetDirFile.mkdirs();
double confDetectLevel = this.evento.getDetectFaceConfidentThresold();
long dysType = Evento.this.getParm("ZOO_YUNET_SCORING_DYS_TYPE").getNumeroLong();
int idxQuery = 0;
int faceOrfanoAssegnato = 0;
LinkedHashMap<Long, JsonObject> lhpFsQuery = new LinkedHashMap<>();
HashSet<FaceScore> hsFaceScoreTrovati = new HashSet<>();
FaceScore fs = new FaceScore(Evento.this.getApFull());
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "QUERY TARGET X EVENTO......");
Vectumerator<FaceScore> vecFsTarget = fs.findTargetByEvento(this.evento.getId_evento(), -1L);
int i = 0;
int startIndex = 0;
if (startIndex < 0) {
startIndex = 0;
} else if (startIndex >= vecFsTarget.getTotNumberOfRecords()) {
startIndex = vecFsTarget.getTotNumberOfRecords();
}
vecFsTarget.setIndex(startIndex);
while (vecFsTarget.hasMoreElements() && !Evento.threadEventoScoringSTOP) {
FaceScore currentFs = (FaceScore)vecFsTarget.nextElement();
if (i % STEP_STATUS_MSG == 0)
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "max thread: " + maxNumberOfThread + " qsize:" + NUM_QUERY_CALLABLE + " punto foto:" +
currentFs.getFoto().getPuntoFoto().getDescrizione() + " (" + i + "/" +
vecFsTarget.getTotNumberOfRecords() + ") CICLO PREPARAZIONE HASH TABLE TARGET E QUERY..... ETA preparazione: " +
timer.getEta((long)vecFsTarget.getTotNumberOfRecords(), (long)i));
JsonObject jsonQueryRow = new JsonObject();
jsonQueryRow.addProperty("id", Long.valueOf(currentFs.getId_fotoFace()));
jsonQueryRow.addProperty("path", currentFs.getFotoFace().getFacePath());
jsonQueryRow.addProperty("md5", currentFs.getFotoFace().getMd5());
jsonQueryRow.addProperty("type", "face");
lhpFsQuery.put(Long.valueOf(currentFs.getId_fotoFace()), jsonQueryRow);
i++;
}
FotoFace ff = new FotoFace(Evento.this.getApFull());
i = 0;
String etaTot = ".......";
Vectumerator<FotoFace> vecFotoFace;
while ((vecFotoFace = ff.findNoScoreByEvento(this.evento.getId_evento(), 1, 20)).hasMoreElements() && !Evento.threadEventoScoringSTOP) {
while (vecFotoFace.hasMoreElements() && !Evento.threadEventoScoringSTOP) {
FotoFace currentFf = (FotoFace)vecFotoFace.nextElement();
JsonObject fsTargetMainJO = new JsonObject();
fsTargetMainJO.addProperty("id", Long.valueOf(currentFf.getId_fotoFace()));
fsTargetMainJO.addProperty("path", currentFf.getFacePath());
fsTargetMainJO.addProperty("md5", currentFf.getMd5());
fsTargetMainJO.addProperty("type", "face");
if (Evento.threadEventoScoringSTOP)
break;
if (i % STEP_STATUS_MSG == 0)
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "max thread: " + maxNumberOfThread + " qsize:" + NUM_QUERY_CALLABLE + " orfano assegnato:" + faceOrfanoAssegnato + " target face n. " + i + "/" +
vecFotoFace.getTotNumberOfRecords() + " PRAPARAZIONE TARGET E QUERY PER INVIO.... ---> " + etaTot);
JsonObject jsonData = new JsonObject();
jsonData.addProperty("dis_type", Long.valueOf(dysType));
jsonData.addProperty("conf_threshold", Double.valueOf(confDetectLevel));
jsonData.add("target", (JsonElement)fsTargetMainJO);
idxQuery = 0;
JsonArray jsonQuery = new JsonArray();
for (JsonObject jsonQueryRow : lhpFsQuery.values()) {
if (Evento.threadEventoScoringSTOP)
break;
if (idxQuery % STEP_STATUS_MSG == 0)
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "max thread: " + maxNumberOfThread + " qsize:" + NUM_QUERY_CALLABLE + " orfano assegnato: " + faceOrfanoAssegnato + " target face n. " + i + "/" +
vecFotoFace.getTotNumberOfRecords() + " CICLO PREPARAZIONE QUERY..... " + idxQuery + "/" +
lhpFsQuery.size() + " ---> " + etaTot);
if (idxQuery > 0 && idxQuery % NUM_QUERY_CALLABLE == 0) {
String threadMsg = "max thread: " + maxNumberOfThread + " qsize:" + NUM_QUERY_CALLABLE + " orfano assegnato: " + faceOrfanoAssegnato + " target face n. " + i + "/" +
vecFotoFace.getTotNumberOfRecords() + " callable..... " + idxQuery + "/" +
lhpFsQuery.size() + " ---> " + etaTot;
JsonObject jsonDataCallable = jsonData.deepCopy();
jsonDataCallable.add("query", (JsonElement)jsonQuery);
ScoringFaceCallableGson ifc = new ScoringFaceCallableGson(this.evento, jsonDataCallable, targetDir, false);
vecF.add(pool.submit(ifc));
jsonQuery = new JsonArray();
}
jsonQuery.add((JsonElement)jsonQueryRow);
idxQuery++;
}
if (jsonQuery.size() > 0) {
String threadMsg = "max thread: " + maxNumberOfThread + " qsize:" + NUM_QUERY_CALLABLE + " orfano assegnato: " + faceOrfanoAssegnato + " target face n. " + i + "/" +
vecFotoFace.getTotNumberOfRecords() + " ULTIMA callable..... " + idxQuery + "/" +
lhpFsQuery.size() + " ---> " + etaTot;
JsonObject jsonDataCallable = jsonData.deepCopy();
jsonDataCallable.add("query", (JsonElement)jsonQuery);
ScoringFaceCallableGson ifc = new ScoringFaceCallableGson(this.evento, jsonDataCallable, targetDir, false);
vecF.add(pool.submit(ifc));
}
try {
for (int fidx = 0; fidx < vecF.getTotNumberOfRecords(); fidx++) {
Future<ResParm> currentFuture = (Future<ResParm>)vecF.nextElement();
rp = currentFuture.get();
if (idxQuery % STEP_STATUS_MSG == 0)
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "max thread: " + maxNumberOfThread + " qsize:" + NUM_QUERY_CALLABLE + " orfano assegnato: " + faceOrfanoAssegnato + " target face n. " + i + "/" +
vecFotoFace.getTotNumberOfRecords() + " FUTURE..... " + fidx + "/" +
vecF.getTotNumberOfRecords() + " ---> " + etaTot);
if (!rp.getStatus()) {
errMsg.append(rp.getErrMsg() + "\n");
} else {
HashSet<FaceScore> hsFs = (HashSet<FaceScore>)rp.getReturnObj();
if (hsFs != null)
hsFaceScoreTrovati.addAll(hsFs);
}
}
if (hsFaceScoreTrovati != null) {
faceOrfanoAssegnato++;
double maxScore = 0.0D;
FaceScore currentFs = null;
if (debug)
System.out.println("******************************** fase3ScoringFaceSenzaScoringPerEvento:tutti gli score trovati. Devo mantenere quello + grande: CURRENT hsFaceScoreTrovati SIZE: " +
hsFaceScoreTrovati.size());
for (FaceScore fsTrovato : hsFaceScoreTrovati) {
if ((double)fsTrovato.getScore() > maxScore) {
maxScore = (double)fsTrovato.getScore();
currentFs = fsTrovato;
}
if (debug)
System.out.println("******************************** fase3ScoringFaceSenzaScoringPerEvento:tutti gli score trovati. Devo mantenere quello + grande: currentScore=" + maxScore + " currentTarget: " +
fsTrovato.getId_fotoFace2());
}
if (maxScore > 0.0D) {
long l_id_temp = currentFs.getId_fotoFace();
currentFs.setId_fotoFace(currentFs.getId_fotoFace2());
currentFs.setId_fotoFace2(l_id_temp);
currentFs.save();
faceOrfanoAssegnato++;
}
}
pool.shutdown();
} catch (Exception e) {
e.printStackTrace();
rp.setStatus(false);
rp.setMsg("Eccezione vecfuture: " + e.getMessage());
}
i++;
etaTot = timer.getEta((long)vecFsTarget.getTotNumberOfRecords(), (long)i);
}
}
SaveScoreProcessor ssProcessor = SaveScoreProcessor.getInstance(Evento.this.getApFull(), 10);
ssProcessor.shutdown();
timer.stop();
if (debug)
System.out.println("******************************** fase3ScoringFaceSenzaScoringPerEvento: FINE!!!: " + timer.getDurata());
Log.addAltro(Evento.this.getApFull(), "127.0.0.1", 1L, " fase3ScoringFaceSenzaScoringPerEvento: FINE!!!" +
timer.getDurata() + "\nRisultato: " + rp.getMsg());
StatusMsg.deleteMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG);
return rp;
}
private ResParm fase7ScoringTargetSuTargetPerEvento(String TAG_THREAD_MSG) {
FaceScore currentFs;
boolean debug = false;
boolean debug2 = false;
boolean debug3 = true;
DBAdapter.printDebug(debug2, "START");
SmartFaceScoringQueue smartFaceScoringQueue = SmartFaceScoringQueue.getInstance(Evento.this.getApFull());
StringBuffer errMsg = new StringBuffer();
int priority = 1;
ResParm rp = new ResParm(true);
int STEP_STATUS_MSG = 100;
Timer timer = new Timer();
Timer timerTarget = new Timer();
long currentTargetTime = 0L;
double currentTargetVelox = 0.0D, actualTargetVelox = 0.0D;
String targetDir = Evento.this.getParm("PATHFOTO_FACE").getTesto() + Evento.this.getParm("PATHFOTO_FACE").getTesto();
File targetDirFile = new File(targetDir);
if (!targetDirFile.exists())
targetDirFile.mkdirs();
double confDetectLevel = this.evento.getDetectFaceConfidentThresold();
long dysType = Evento.this.getParm("ZOO_YUNET_SCORING_DYS_TYPE").getNumeroLong();
int targetUniti = 0;
int targetProcessati = 0;
FaceScore fs = new FaceScore(Evento.this.getApFull());
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "QUERY TARGET X EVENTO......");
Vectumerator<FaceScore> vecFsTarget = fs.findTargetByEvento(this.evento.getId_evento(), -1L);
long i = 0L;
long startIndex = (long)(int)this.evento.getCurrentTargetindex7();
long totTarget = (long)vecFsTarget.getTotNumberOfRecords();
long confrontiStartindex = (startIndex - 1L) * startIndex / 2L;
long totConfrontiDaFare = (totTarget - 1L) * totTarget / 2L;
long totConfrontiFatti = 0L;
long totConfrontiCheSalto = 0L;
JsonArray jsonQuery = new JsonArray();
JsonObject jsonData = new JsonObject();
jsonData.addProperty("dis_type", Long.valueOf(dysType));
jsonData.addProperty("conf_threshold", Double.valueOf(confDetectLevel));
if (vecFsTarget.hasMoreElements()) {
currentFs = (FaceScore)vecFsTarget.nextElement();
JsonObject jsonQueryRow = new JsonObject();
jsonQueryRow.addProperty("id", Long.valueOf(currentFs.getId_fotoFace()));
jsonQueryRow.addProperty("path", currentFs.getFotoFace().getFacePath());
jsonQueryRow.addProperty("md5", currentFs.getFotoFace().getMd5());
jsonQueryRow.addProperty("type", "face");
i++;
jsonQuery.add((JsonElement)jsonQueryRow);
} else {
currentFs = new FaceScore(Evento.this.getApFull());
}
String eta = "....";
JsonObject jsonTarget = null;
while (vecFsTarget.hasMoreElements() && !Evento.threadEventoScoringSTOP) {
if (i > startIndex || i % (long)STEP_STATUS_MSG == 0L)
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "actualTargetVelox: " +
Evento.this.getNf().format(actualTargetVelox) + " targ./sec currentTargetTime: " + currentTargetTime + " sec. currentTargetVelox: " +
Evento.this.getNf().format(currentTargetVelox) + " conf/sec punto foto:" +
currentFs.getFoto().getPuntoFoto().getDescrizione() + " (" + i + "/" +
vecFsTarget.getTotNumberOfRecords() + ") target uniti: " + targetUniti + " ..... ETA: " + eta + "\n" +
smartFaceScoringQueue.getStatus());
currentFs = (FaceScore)vecFsTarget.nextElement();
jsonTarget = new JsonObject();
jsonTarget.addProperty("id", Long.valueOf(currentFs.getId_fotoFace()));
jsonTarget.addProperty("path", currentFs.getFotoFace().getFacePath());
jsonTarget.addProperty("md5", currentFs.getFotoFace().getMd5());
jsonTarget.addProperty("type", "face");
if (i > startIndex) {
targetProcessati++;
if (!timer.isStarted())
timer.start();
timerTarget.start();
jsonData.add("target", (JsonElement)jsonTarget);
DBAdapter.printDebug(debug2, "scoring target:" + currentFs.getId_fotoFace() + " jsonQuery.size(): " + jsonQuery.size());
JsonArray jsonQueryCopy = jsonQuery.deepCopy();
JsonObject jsonTargetCopy = jsonTarget.deepCopy();
DBAdapter.printDebug(debug3, "1.. inizio scoring - " + smartFaceScoringQueue.getStatus());
Vectumerator<Future<ResParm>> vecF = smartFaceScoringQueue.faceScoring(this.evento, jsonQueryCopy, jsonTargetCopy, confDetectLevel, priority);
DBAdapter.printDebug(debug3, "8. future arrivato");
DBAdapter.printDebug(debug3, "8.1 vecF.getTotNumberOfRecords(): " + vecF.getTotNumberOfRecords());
DBAdapter.printDebug(debug2, "FUTURE start vecF.getTotNumberOfRecords():" + vecF.getTotNumberOfRecords());
for (int fidx = 0; fidx < vecF.getTotNumberOfRecords(); fidx++) {
Future<ResParm> currentFuture = (Future<ResParm>)vecF.nextElement();
if (currentFuture == null) {
rp.setStatus(false);
rp.setMsg("Errore: Future null per indice " + fidx);
DBAdapter.printDebug(debug3, "8.null Errore: Future null per indice " + fidx);
} else {
try {
rp = currentFuture.get(45L, TimeUnit.SECONDS);
} catch (TimeoutException e) {
DBAdapter.printDebug(debug3, "8.3 Errore Timeout su future index " + fidx + ", ignorando.");
} catch (InterruptedException e) {
DBAdapter.printDebug(debug3, "8.4 Errore Interruzione rilevata, terminazione del ciclo.");
Thread.currentThread().interrupt();
} catch (ExecutionException e) {
DBAdapter.printDebug(debug3, "8.5 Errore durante l'esecuzione del task " + fidx + ": " + e.getMessage());
e.printStackTrace();
} catch (Exception e) {
DBAdapter.printDebug(debug3, "8.6 Errore generico su future index " + fidx + ": " + e.getMessage());
e.printStackTrace();
}
if (!rp.getStatus()) {
DBAdapter.printDebug((debug || debug2), " errore future: " + rp.getMsg());
errMsg.append(rp.getErrMsg() + "\n");
DBAdapter.printDebug(debug3, "8.7 errore future: " + rp.getMsg());
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "currentTargetTime: " + currentTargetTime + " sec. punto foto:" +
currentFs.getFoto().getPuntoFoto().getDescrizione() + " (" + i + "/" +
vecFsTarget.getTotNumberOfRecords() + ") target uniti: " + targetUniti + "/" + targetProcessati + " future: " + fidx + "/" +
vecF.getTotNumberOfRecords() + " - " + eta + "\n" +
smartFaceScoringQueue.getStatus());
} else {
HashSet<FaceScore> hsFs = (HashSet<FaceScore>)rp.getReturnObj();
Set<String> md5ToRemove = new HashSet<>();
if (hsFs != null) {
if (debug || debug2)
DBAdapter.printDebug(debug, "FS UNITI.... LI TOLGO DA HASHMAP: CURRENT LSH SIZE: " + hsFs.size());
int hsIdx = 0;
for (FaceScore fsTargetSul2 : hsFs) {
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "actualTargetVelox: " +
Evento.this.getNf().format(actualTargetVelox) + " targ./sec currentTargetTime: " + currentTargetTime + " sec. currentTargetVelox: " +
Evento.this.getNf().format(currentTargetVelox) + " conf/sec punto foto:" +
currentFs.getFoto().getPuntoFoto().getDescrizione() + " (" + i + "/" +
vecFsTarget.getTotNumberOfRecords() + ") target uniti: " + targetUniti + "/" + targetProcessati + " future: " + fidx + "/" +
vecF.getTotNumberOfRecords() + " unisci target " + hsIdx + "/" +
hsFs.size() + " - " + eta + "\n" + smartFaceScoringQueue.getStatus());
rp = fs.unisciTarget(jsonTarget.get("id").getAsLong(),
fsTargetSul2.getId_fotoFace2());
targetUniti++;
md5ToRemove.add(fsTargetSul2.getFotoFace2().getMd5());
hsIdx++;
}
if (md5ToRemove.size() > 0) {
DBAdapter.printDebug(debug, " MD5 DA RIMUOVERE...... : ");
for (int j = jsonQuery.size() - 1; j >= 0; j--) {
JsonObject item = jsonQuery.get(j).getAsJsonObject();
String currentMd5 = item.get("md5").getAsString();
if (md5ToRemove.contains(currentMd5)) {
jsonQuery.remove(j);
DBAdapter.printDebug(debug, " rimosso : " + currentMd5);
}
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "actualTargetVelox: " +
Evento.this.getNf().format(actualTargetVelox) + " targ./sec currentTargetTime: " + currentTargetTime + " sec. currentTargetVelox: " +
Evento.this.getNf().format(currentTargetVelox) + " conf/sec punto foto:" +
currentFs.getFoto().getPuntoFoto().getDescrizione() + " (" + i + "/" +
vecFsTarget.getTotNumberOfRecords() + ") target uniti: " + targetUniti + "/" + targetProcessati + " future: " + fidx + "/" +
vecF.getTotNumberOfRecords() + " rimuovo md5 " + j + "/" +
jsonQuery.size() + " - " + eta + "\n\n" +
smartFaceScoringQueue.getStatus());
}
} else {
DBAdapter.printDebug(debug, " NIENTE DA RIMUOVERE : ");
}
DBAdapter.printDebug(debug, " fine ciclo rimuovo md5! ");
DBAdapter.printDebug(debug, " nuova query ripulita dei target trovati. jsonQuery.size: " +
jsonQuery.size());
}
}
}
}
DBAdapter.printDebug(debug3, "9. future finito faccio shutdown ");
DBAdapter.printDebug(debug2, "FUTURE STOP. faccio shutdown ");
smartFaceScoringQueue.poolShutdown();
DBAdapter.printDebug(debug3, "11. shutdown concluso ");
DBAdapter.printDebug(debug, "jsonQuery.size(): " + jsonQuery.size() + " tctccs cf " + totConfrontiDaFare + "-" + totConfrontiCheSalto + " totofatti:" + totConfrontiFatti);
}
jsonQuery.add((JsonElement)jsonTarget);
if (this.evento.getCurrentTargetindex7() < i)
this.evento.updateCurrentTargetindex7(i);
i++;
if (i > startIndex + 1L) {
timerTarget.stop();
totConfrontiFatti = (i - 1L) * i / 2L;
totConfrontiCheSalto = ((long)vecFsTarget.getTotNumberOfRecords() - i) * (long)targetUniti;
eta = timer.getEta(totConfrontiDaFare - totConfrontiCheSalto - confrontiStartindex, totConfrontiFatti - confrontiStartindex);
if (currentTargetTime == 0L) {
currentTargetTime = timerTarget.getDurataSecLong();
currentTargetVelox = (double)jsonQuery.size() / (double)timerTarget.getDurataMilliSec() * 1000.0D;
}
actualTargetVelox = (double)(totConfrontiFatti - confrontiStartindex) / (double)timer.getDurataMilliSec() * 1000.0D;
DBAdapter.printDebug(debug2, "FUTURE STOP currentTargetVelox: " + currentTargetVelox + " actualTargetVelox: " + actualTargetVelox + " currentTargetTime: " + currentTargetTime);
}
}
long lastidxFaceTarget = i - 1L;
this.evento.setCurrentTargetindex7(lastidxFaceTarget);
this.evento.save();
timer.stop();
DBAdapter.printDebug(debug, " FINE!!!: " + timer.getDurata());
StatusMsg.deleteMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG);
Log.addAltro(Evento.this.getApFull(), "127.0.0.1", 1L, " fase7ScoringTargetSuTargetPerEvento: FINE!!! Targetuniti:" + targetUniti + "/" + targetProcessati + " currentTargetVelox: " +
Evento.this.getNf().format(currentTargetVelox) + " conf/sec currentTargetTime: " + currentTargetTime + " sec.\n" +
timer.getDurata() + "\nRisultato: " + rp.getMsg());
return rp;
}
private ResParm fase7ScoringTargetSuTargetMergeAggressivo(String TAG_THREAD_MSG) {
FaceScore currentFs;
boolean debug = true;
boolean debug2 = true;
boolean debug3 = true;
DBAdapter.printDebug(debug2, "# 1 # START");
SmartFaceScoringQueue smartFaceScoringQueue = SmartFaceScoringQueue.getInstance(Evento.this.getApFull());
Foto foto = new Foto(Evento.this.getApFull());
StringBuffer errMsg = new StringBuffer();
int priority = 1;
ResParm rp = new ResParm(true);
int STEP_STATUS_MSG = 100;
Timer timer = new Timer();
Timer timerTarget = new Timer();
long currentTargetTime = 0L;
double currentTargetVelox = 0.0D, actualTargetVelox = 0.0D;
String targetDir = Evento.this.getParm("PATHFOTO_FACE").getTesto() + Evento.this.getParm("PATHFOTO_FACE").getTesto();
File targetDirFile = new File(targetDir);
if (!targetDirFile.exists())
targetDirFile.mkdirs();
double confDetectLevel = this.evento.getDetectFaceConfidentThresold();
long dysType = Evento.this.getParm("ZOO_YUNET_SCORING_DYS_TYPE").getNumeroLong();
int targetUniti = 0;
int targetProcessati = 0;
FaceScore fs = new FaceScore(Evento.this.getApFull());
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "1. QUERY TARGET X EVENTO......");
Vectumerator<FaceScore> vecFsTarget = fs.findTargetByEvento(this.evento.getId_evento(), 2L);
timer.start();
long i = 0L;
long startIndex = 0L;
long totTarget = (long)vecFsTarget.getTotNumberOfRecords();
JsonArray jsonQuery = new JsonArray();
JsonObject jsonData = new JsonObject();
jsonData.addProperty("dis_type", Long.valueOf(dysType));
jsonData.addProperty("conf_threshold", Double.valueOf(confDetectLevel));
JsonObject jsonTarget = null;
if (vecFsTarget.hasMoreElements()) {
currentFs = (FaceScore)vecFsTarget.nextElement();
jsonTarget = new JsonObject();
jsonTarget.addProperty("id", Long.valueOf(currentFs.getId_fotoFace()));
jsonTarget.addProperty("id_foto", Long.valueOf(currentFs.getFotoFace().getId_foto()));
jsonTarget.addProperty("path", currentFs.getFotoFace().getFacePath());
jsonTarget.addProperty("md5", currentFs.getFotoFace().getMd5());
jsonTarget.addProperty("type", "face");
} else {
currentFs = new FaceScore(Evento.this.getApFull());
}
String eta = "....";
String puntoFotoDesc = "";
long l_id_fotoTarget = 0L;
while (vecFsTarget.hasMoreElements() && !Evento.threadEventoScoringSTOP) {
puntoFotoDesc = currentFs.getFotoFace2().getFoto().getPuntoFoto().getDescrizione();
currentFs = (FaceScore)vecFsTarget.nextElement();
if (i % (long)STEP_STATUS_MSG == 0L)
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "2. creazione query globale: current punto foto:" + puntoFotoDesc + " (" + i + "/" +
vecFsTarget.getTotNumberOfRecords() + ")");
JsonObject jsonQueryRow = new JsonObject();
jsonQueryRow.addProperty("id", Long.valueOf(currentFs.getId_fotoFace()));
jsonQueryRow.addProperty("id_foto", Long.valueOf(currentFs.getFotoFace().getId_foto()));
jsonQueryRow.addProperty("path", currentFs.getFotoFace().getFacePath());
jsonQueryRow.addProperty("md5", currentFs.getFotoFace().getMd5());
jsonQueryRow.addProperty("type", "face");
i++;
jsonQuery.add((JsonElement)jsonQueryRow);
}
long totConfrontiFatti = 0L;
long totConfrontiTarget = 0L;
long totMd5Toremove = 0L;
double mediaMd5ToRemove = 0.0D;
i = 0L;
long l_id_curretFoto = 0L;
while (jsonQuery.size() > 0 && !Evento.threadEventoScoringSTOP) {
timerTarget.start();
i++;
totConfrontiTarget = (long)jsonQuery.size();
totConfrontiFatti += (long)jsonQuery.size();
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "3 MAIN. actualTargetVelox: " +
Evento.this.getNf().format(actualTargetVelox) + " targ./sec currentTargetTime: " + currentTargetTime + " sec. currentTargetVelox: " +
Evento.this.getNf().format(currentTargetVelox) + " conf/sec punto foto:" + puntoFotoDesc + " (" + i + "/" +
jsonQuery.size() + ") target uniti: " + targetUniti + " mediaMd5ToRemove: " + mediaMd5ToRemove + " ..... ETA: " + eta + "\n" +
smartFaceScoringQueue.getStatus());
AppStats.setScoring7CurrentTargetVelox(currentTargetVelox);
AppStats.setScoring7ETA(eta);
targetProcessati++;
jsonData.add("target", (JsonElement)jsonTarget);
DBAdapter.printDebug(debug2, "# 2 # scoring target: " +
currentFs.getId_fotoFace() + " jsonQuery.size(): " + jsonQuery.size());
JsonArray jsonQueryCopy = jsonQuery.deepCopy();
JsonObject jsonTargetCopy = jsonTarget.deepCopy();
DBAdapter.printDebug(debug3, "# 4 # inizio scoring - " + smartFaceScoringQueue.getStatus());
Vectumerator<Future<ResParm>> vecF = smartFaceScoringQueue.faceScoring(this.evento, jsonQueryCopy, jsonTargetCopy, confDetectLevel, priority);
DBAdapter.printDebug(debug3, "# 4 # future arrivato");
DBAdapter.printDebug(debug3, "# 5 # vecF.getTotNumberOfRecords(): " + vecF.getTotNumberOfRecords());
DBAdapter.printDebug(debug2, "# 6 # FUTURE start vecF.getTotNumberOfRecords():" + vecF.getTotNumberOfRecords());
Set<String> md5ToRemove = new HashSet<>();
for (int fidx = 0; fidx < vecF.getTotNumberOfRecords(); fidx++) {
Future<ResParm> currentFuture = (Future<ResParm>)vecF.nextElement();
if (currentFuture == null) {
rp.setStatus(false);
rp.setMsg("Errore: Future null per indice " + fidx);
DBAdapter.printDebug(debug3, "# 7 # null Errore: Future null per indice " + fidx);
} else {
try {
rp = currentFuture.get(45L, TimeUnit.SECONDS);
} catch (TimeoutException e) {
DBAdapter.printDebug(debug3, "# 8 # Errore Timeout su future index " + fidx + ", ignorando.");
} catch (InterruptedException e) {
DBAdapter.printDebug(debug3, "# 9 # Errore Interruzione rilevata, terminazione del ciclo.");
Thread.currentThread().interrupt();
} catch (ExecutionException e) {
DBAdapter.printDebug(debug3, "# 10 # Errore durante l'esecuzione del task " + fidx + ": " + e.getMessage());
e.printStackTrace();
} catch (Exception e) {
DBAdapter.printDebug(debug3, "# 11 # Errore generico su future index " + fidx + ": " + e.getMessage());
e.printStackTrace();
}
if (!rp.getStatus()) {
DBAdapter.printDebug((debug || debug2), "# 12 # errore future: " + rp.getMsg());
errMsg.append(rp.getErrMsg() + "\n");
DBAdapter.printDebug(debug3, "# 13 # errore future: " + rp.getMsg());
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "4 FUTURE. currentTargetTime: " + currentTargetTime + " sec. punto foto:" + puntoFotoDesc + " (" + i + "/" +
jsonQuery.size() + ") target uniti: " + targetUniti + " mediaMd5ToRemove: " + mediaMd5ToRemove + " future: " + fidx + "/" +
vecF.getTotNumberOfRecords() + " - " + eta + "\n" +
smartFaceScoringQueue.getStatus());
AppStats.setScoring7CurrentTargetVelox(currentTargetVelox);
AppStats.setScoring7ETA(eta);
} else {
HashSet<FaceScore> hsFs = (HashSet<FaceScore>)rp.getReturnObj();
if (hsFs != null) {
if (debug || debug2)
DBAdapter.printDebug(debug, "# 14 # FS UNITI.... LI TOLGO DA HASHMAP se LSH SIZE>0 ===> CURRENT LSH SIZE: " +
hsFs.size());
int hsIdx = 0;
for (FaceScore fsTargetSul2 : hsFs) {
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "5 CLEAN MD5. actualTargetVelox: " +
Evento.this.getNf().format(actualTargetVelox) + " targ./sec currentTargetTime: " + currentTargetTime + " sec. currentTargetVelox: " +
Evento.this.getNf().format(currentTargetVelox) + " conf/sec punto foto:" + puntoFotoDesc + " (" + i + "/" +
jsonQuery.size() + ") target uniti: " + targetUniti + "/" + targetProcessati + " mediaMd5ToRemove: " + mediaMd5ToRemove + " future: " + fidx + "/" +
vecF.getTotNumberOfRecords() + " unisci target " + hsIdx + "/" + hsFs.size() + " - " + eta + "\n" +
smartFaceScoringQueue.getStatus());
rp = fs.unisciTarget(jsonTarget.get("id").getAsLong(),
fsTargetSul2.getId_fotoFace2());
targetUniti++;
md5ToRemove.add(fsTargetSul2.getFotoFace2().getMd5());
hsIdx++;
}
}
}
}
}
DBAdapter.printDebug(debug3, "# 15 # . ciclo future finito faccio shutdown ");
if (md5ToRemove.size() > 0) {
JsonArray newJsonQuery = new JsonArray();
jsonTarget = null;
DBAdapter.printDebug(debug, "# 16 # MD5 DA RIMUOVERE:" +
md5ToRemove.size() + " ...... : creo newJsonQuery e lo copio su jsonQuery ");
for (int j = jsonQuery.size() - 1; j >= 0; j--) {
JsonObject item = jsonQuery.get(j).getAsJsonObject();
String currentMd5 = item.get("md5").getAsString();
if (!md5ToRemove.contains(currentMd5)) {
if (jsonTarget == null) {
DBAdapter.printDebug(debug, "# 17 # nuovo target : " + currentMd5);
jsonTarget = item;
} else {
newJsonQuery.add((JsonElement)item);
DBAdapter.printDebug(false, "# 19 # newJsonQuery.add jsonQuery size:" + jsonQuery.size() + " newJsonQuery size : " +
newJsonQuery.size());
}
} else {
DBAdapter.printDebug(debug, "# 20 # rimosso : " + currentMd5);
}
}
if (l_id_curretFoto == 0L) {
l_id_curretFoto = l_id_fotoTarget;
} else if (l_id_curretFoto != l_id_fotoTarget) {
foto.findByPrimaryKey(l_id_curretFoto);
foto.updateCurrentFlgFaceScoringDone(3L);
DBAdapter.printDebug(true, "# XXXX # updateCurrentFlgFaceScoringDone FACE_SCORING_DONE_GLOBAL_3 FOTO " +
foto.getFileName() + " id: " + foto.getId_foto());
l_id_curretFoto = l_id_fotoTarget;
}
jsonQuery = newJsonQuery.deepCopy();
jsonTarget = jsonQuery.get(0).getAsJsonObject();
jsonQuery.remove(0);
l_id_fotoTarget = jsonTarget.get("id_foto").getAsLong();
} else {
DBAdapter.printDebug(debug, "# 21 # NIENTE DA RIMUOVERE estraggo target e tolgo primo elemento a query ");
jsonTarget = jsonQuery.get(0).getAsJsonObject();
jsonQuery.remove(0);
}
totMd5Toremove += (long)md5ToRemove.size();
mediaMd5ToRemove = (double)(totMd5Toremove / i);
DBAdapter.printDebug(debug, "# 22 # fine ciclo rimozione md5! totMd5Toremove: " + totMd5Toremove + " cicli i: " + i + " mediaMd5ToRemove: " + mediaMd5ToRemove);
DBAdapter.printDebug(debug, "# 23 # nuova query ripulita dei target trovati. jsonQuery.size: " + jsonQuery.size());
DBAdapter.printDebug(debug2, "# 24 # FUTURE STOP. faccio shutdown ");
smartFaceScoringQueue.poolShutdown();
DBAdapter.printDebug(debug3, "# 25 #. shutdown concluso ");
DBAdapter.printDebug(debug, "# 26 # tot confronti fatti:" + totConfrontiFatti);
if (this.evento.getCurrentTargetindex7() < i)
this.evento.updateCurrentTargetindex7(i);
timerTarget.stop();
if (currentTargetTime == 0L) {
currentTargetTime = timerTarget.getDurataSecLong();
currentTargetVelox = (double)totConfrontiTarget / (double)timerTarget.getDurataMilliSec() * 1000.0D;
}
long numeroQueryRimanenti = (long)jsonQuery.size();
long stimaConfrontiDaFare = Evento.stimaConfrontiMergeAggressivo(numeroQueryRimanenti, mediaMd5ToRemove);
eta = timer.getEta(stimaConfrontiDaFare, totConfrontiFatti);
actualTargetVelox = (double)totConfrontiFatti / (double)timer.getDurataMilliSec() * 1000.0D;
DBAdapter.printDebug(debug2, "# 27 # FUTURE STOP currentTargetVelox: " + currentTargetVelox + " actualTargetVelox: " + actualTargetVelox + " currentTargetTime: " + currentTargetTime);
}
long lastidxFaceTarget = i - 1L;
this.evento.setCurrentTargetindex7(lastidxFaceTarget);
this.evento.save();
timer.stop();
DBAdapter.printDebug(debug, "# 28 # FINE!!!: " + timer.getDurata());
StatusMsg.deleteMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG);
Log.addAltro(Evento.this.getApFull(), "127.0.0.1", 1L, " fase7ScoringTargetSuTargetPerEvento: FINE!!! Target uniti/processati:" + targetUniti + "/" + targetProcessati + " mediaMd5ToRemove: " + mediaMd5ToRemove + " currentTargetVelox: " +
Evento.this.getNf().format(currentTargetVelox) + " conf/sec currentTargetTime: " + currentTargetTime + " sec.\n" +
timer.getDurata() + "\nRisultato: " +
rp.getMsg());
return rp;
}
}
class ThreadBuildModel extends Thread {
private Evento evento;
private int fase;
private static final int FASE_0 = 0;
private static final int FASE_1 = 1;
public ThreadBuildModel(Evento l_evento, int l_fase) {
this.evento = l_evento;
this.fase = l_fase;
if (!Evento.threadBuildModel) {
Evento.threadBuildModel = true;
Evento.threadBuildModelSTOP = false;
start();
}
}
public void run() {
ResParm rp = new ResParm(true);
String TAG_THREAD_MSG = "BUILD MODEL. ID: " + this.evento.getId_evento();
Timer timer = new Timer();
timer.start();
if (this.fase == 0) {
TAG_THREAD_MSG = "UPDATE LABELS ID: " + this.evento.getId_evento();
rp = updateLabels0(TAG_THREAD_MSG);
} else if (this.fase == 1) {
TAG_THREAD_MSG = "BUILD MODEL. ID: " + this.evento.getId_evento();
rp.append(buildModello1(TAG_THREAD_MSG));
}
timer.stop();
System.out.println(TAG_THREAD_MSG + " *******DURATA TOTALE********: " + TAG_THREAD_MSG);
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "Concluso: DURATA TOTALE: " +
timer.getDurata() + "\nRisultato: " + rp.getMsg());
try {
sleep(4000L);
} catch (Exception e) {}
StatusMsg.deleteMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG);
Evento.threadBuildModel = false;
}
private ResParm updateLabels0(String TAG_THREAD_MSG) {
boolean debug = false;
StringBuffer errMsg = new StringBuffer();
ResParm rp = new ResParm(true);
int STEP_STATUS_MSG = 20;
int totTrainingImagesWithLabel = 0;
Timer timer = new Timer();
timer.start();
String recognizerCode = this.evento.getFaceRecognizer().getCodice();
if (recognizerCode.isEmpty()) {
rp.setStatus(false);
rp.setMsg("Attenzione! Recognizer non impostato!!!");
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, rp.getMsg());
return rp;
}
FaceScore fs = new FaceScore(Evento.this.getApFull());
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "QUERY TARGET X EVENTO......");
Vectumerator<FaceScore> vecFsTarget = fs.findTargetByEvento(this.evento.getId_evento(), -1L);
if (debug)
System.out.println(String.valueOf(DBAdapter.getNow()) + " updateLabels0 1");
int i = 0;
String eta = " ...";
while (vecFsTarget.hasMoreElements() && !Evento.threadBuildModelSTOP) {
FaceScore currentFs = (FaceScore)vecFsTarget.nextElement();
if (debug)
System.out.println(String.valueOf(DBAdapter.getNow()) + " updateLabels0 2");
if (i % STEP_STATUS_MSG == 0)
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "punto foto:" +
currentFs.getFoto().getPuntoFoto().getDescrizione() + " (" + i + "/" +
vecFsTarget.getTotNumberOfRecords() + ")CICLO PREPARAZIONE TRAINING IMAGES..... tot training images with label: " + totTrainingImagesWithLabel + " eta: " + eta);
rp.setStatus(true);
FotoFace ffLabel = currentFs.getFotoFace();
if (ffLabel.getLabel() == 0L) {
if (debug)
System.out.println(String.valueOf(DBAdapter.getNow()) + " updateLabels0 3");
rp = ffLabel.addNewLabelFr(recognizerCode);
if (debug)
System.out.println("updateLabels0 4 rp: " + rp.getMsg());
}
currentFs.setFotoFace(null);
System.out.println(String.valueOf(DBAdapter.getNow()) + " updateLabels0 4.5 ff e label: " + String.valueOf(DBAdapter.getNow()) + " - " + ffLabel.getId_fotoFace() + " rp: " +
ffLabel.getLabel() + " " + rp.getStatus());
if (rp.getStatus()) {
totTrainingImagesWithLabel++;
if (debug)
System.out.println(String.valueOf(DBAdapter.getNow()) + " updateLabels0 5");
Vectumerator<FaceScore> vecFsQuery = fs.findQueryByFace(currentFs.getId_fotoFace(), 0, 0);
while (vecFsQuery.hasMoreElements()) {
FaceScore fsQuery = (FaceScore)vecFsQuery.nextElement();
fsQuery.getFotoFace2().setLabel(ffLabel.getLabel());
fsQuery.getFotoFace2().setLabelMd5(ffLabel.getLabelMd5());
fsQuery.getFotoFace2().setFlgTrainingLock(1L);
fsQuery.getFotoFace2().setFlgTrainingOk(1L);
fsQuery.getFotoFace2().setTsTrainingFaceInviata(null);
fsQuery.getFotoFace2().save();
totTrainingImagesWithLabel++;
}
}
i++;
eta = timer.getEta((long)vecFsTarget.getTotNumberOfRecords(), (long)i);
if (debug)
System.out.println(String.valueOf(DBAdapter.getNow()) + " updateLabels0 6");
}
if (debug)
System.out.println(String.valueOf(DBAdapter.getNow()) + " updateLabels0 7");
timer.stop();
if (debug)
System.out.println(String.valueOf(DBAdapter.getNow()) + " ******************************** updateLabels0: FINE!!!: " + String.valueOf(DBAdapter.getNow()));
StatusMsg.deleteMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG);
return rp;
}
private ResParm buildModello1(String TAG_THREAD_MSG) {
boolean debug = false;
ResParm rp = new ResParm(true);
Timer timer = new Timer();
timer.start();
String recognizerCode = this.evento.getFaceRecognizer().getCodice();
if (recognizerCode.isEmpty()) {
rp.setStatus(false);
rp.setMsg("Attenzione! Recognizer non impostato!!!");
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, rp.getMsg());
return rp;
}
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "......");
FotoFace ff = new FotoFace(Evento.this.getApFull());
FotoCR CR = new FotoCR(Evento.this.getApFull());
CR.setId_evento(this.evento.getId_evento());
CR.setId_faceRecognizer(this.evento.getId_faceRecognizer());
CR.setFlgWithFaces(1L);
CR.setFlgFotoOrFace(0L);
CR.setFlgLabel0(0L);
if (debug)
System.out.println("buildModello1 8");
rp = ff.trainingByCR(CR, TAG_THREAD_MSG, true, false);
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "FINE TRAINING: " + rp.getMsg());
if (debug)
System.out.println("buildModello1 9");
try {
sleep(5000L);
} catch (Exception e) {}
timer.stop();
if (debug)
System.out.println("******************************** buildModello2: FINE!!!: " + timer.getDurata());
StatusMsg.deleteMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG);
return rp;
}
}
class ThreadIndicizzaConModello extends Thread {
private Evento evento;
private static final int FASE_0 = 0;
private static final int FASE_1 = 1;
public ThreadIndicizzaConModello(Evento l_evento) {
this.evento = l_evento;
if (!Evento.threadIndicizzaConModello) {
Evento.threadIndicizzaConModello = true;
Evento.threadIndicizzaConModelloSTOP = false;
start();
}
}
public void run() {
ResParm rp = new ResParm(true);
String TAG_THREAD_MSG = "IDX EVENTO " + this.evento.getId_evento() + " MODEL " + this.evento.getFaceRecognizer().getCodice();
Timer timer = new Timer();
timer.start();
rp = indicizzaConModelloDyn(TAG_THREAD_MSG);
timer.stop();
System.out.println(TAG_THREAD_MSG + " *******DURATA TOTALE********: " + TAG_THREAD_MSG);
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "Concluso: DURATA TOTALE: " +
timer.getDurata() + "\nRisultato: " + rp.getMsg());
try {
sleep(4000L);
} catch (Exception e) {}
StatusMsg.deleteMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG);
Evento.threadBuildModel = false;
}
private ResParm indicizzaConModelloFixed(String TAG_THREAD_MSG) {
boolean debug = false;
StringBuilder errMsg = new StringBuilder();
ResParm rp = new ResParm(true);
if (debug)
System.out.println("******************************** indicizzaConModello: INIZIO!!!: " + String.valueOf(DBAdapter.getNowTs()));
Timer timer = new Timer();
String recognizerCode = this.evento.getFaceRecognizer().getCodice();
if (recognizerCode.isEmpty()) {
rp.setStatus(false);
rp.setMsg("Attenzione! Recognizer non impostato!!!");
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, rp.getMsg());
return rp;
}
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "......");
FotoFace ff = new FotoFace(Evento.this.getApFull());
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "QUERY FOTO FACE SENZA LABEL.....: ");
Vectumerator<FotoFace> vecFf = ff.findByEventoNoLabel(this.evento.getId_evento(), 0, 0);
timer.start();
int i = 0;
String eta = " .........";
int NUMB_OF_THREADS = Runtime.getRuntime().availableProcessors();
ExecutorService executorService = Executors.newFixedThreadPool(NUMB_OF_THREADS);
List<Future<ResParm>> futures = new ArrayList<>();
while (vecFf.hasMoreElements() && !Evento.threadIndicizzaConModelloSTOP) {
FotoFace row = (FotoFace)vecFf.nextElement();
FotoFaceRecognizerByModelCallable task = new FotoFaceRecognizerByModelCallable(row, this.evento.getFaceRecognizer());
futures.add(executorService.submit(task));
if (i % 20 == 0)
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "recognizing threads: " + NUMB_OF_THREADS + " ... " + i + "/" +
vecFf.getTotNumberOfRecords() + eta);
eta = timer.getEta((long)vecFf.getTotNumberOfRecords(), (long)i);
i++;
}
for (Future<ResParm> future : futures) {
try {
rp = future.get();
if (rp.getStatus())
errMsg.append(rp.getErrMsg()).append("\n");
} catch (InterruptedException|ExecutionException e) {
e.printStackTrace();
}
}
executorService.shutdown();
DBAdapter.sleepInSecond(10);
timer.stop();
if (debug)
System.out.println("******************************** indicizzaConModello: FINE!!!: " + timer.getDurata());
StatusMsg.deleteMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG);
return rp;
}
private ResParm indicizzaConModelloDyn(String TAG_THREAD_MSG) {
boolean debug = false;
StringBuilder errMsg = new StringBuilder();
ResParm rp = new ResParm(true);
if (debug)
System.out.println("******************************** indicizzaConModello: INIZIO!!!: " + String.valueOf(DBAdapter.getNowTs()));
Timer timer = new Timer();
Timer timerF = new Timer();
String recognizerCode = this.evento.getFaceRecognizer().getCodice();
if (recognizerCode.isEmpty()) {
rp.setStatus(false);
rp.setMsg("Attenzione! Recognizer non impostato!!!");
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, rp.getMsg());
return rp;
}
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "......");
FotoFace ff = new FotoFace(Evento.this.getApFull());
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "QUERY FOTO FACE SENZA LABEL.....: ");
Vectumerator<FotoFace> vecFf = ff.findByEventoNoLabel(this.evento.getId_evento(), 0, 0);
timer.start();
int i = 0;
String eta = " .........";
final ThreadLocal<Integer> callerTaskCount = ThreadLocal.withInitial(() -> 0);
int NUMB_OF_CORES = Runtime.getRuntime().availableProcessors();
int corePoolSize = 4;
int maxPoolSize = NUMB_OF_CORES * 4;
long keepAliveTime = 360L;
int blockingQueueSize = maxPoolSize;
ThreadPoolExecutor executorService = new ThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveTime, TimeUnit.SECONDS, new LinkedBlockingQueue(blockingQueueSize), new ThreadPoolExecutor.CallerRunsPolicy() {
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
callerTaskCount.set(Integer.valueOf(callerTaskCount.get() + 1));
super.rejectedExecution(r, e);
}
}) {
protected void afterExecute(Runnable r, Throwable t) {
super.afterExecute(r, t);
if (Thread.currentThread() == Thread.currentThread()) {
int count = callerTaskCount.get();
if (count > 0)
callerTaskCount.set(Integer.valueOf(count - 1));
}
}
};
List<Future<ResParm>> futures = new ArrayList<>();
while (vecFf.hasMoreElements() && !Evento.threadIndicizzaConModelloSTOP) {
FotoFace row = (FotoFace)vecFf.nextElement();
FotoFaceRecognizerByModelCallable task = new FotoFaceRecognizerByModelCallable(row, this.evento.getFaceRecognizer());
futures.add(executorService.submit(task));
while (executorService.getQueue().size() >= blockingQueueSize - 1) {
DBAdapter.sleepInSecond(5);
if (Evento.threadIndicizzaConModelloSTOP)
break;
}
if (i % 20 == 0) {
int j = executorService.getActiveCount();
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "recognizing. cores: " + NUMB_OF_CORES + " maxPoolSize:" + maxPoolSize + " current threads number: " + j + " task in coda: " +
executorService.getQueue().size() + " task sul thread attuale: " +
String.valueOf(callerTaskCount.get()) + " ... " + i + "/" + vecFf.getTotNumberOfRecords() + " " + eta);
}
eta = timer.getEta((long)vecFf.getTotNumberOfRecords(), (long)i);
i++;
}
i = 0;
eta = " .........";
timerF.start();
int activeThreads = executorService.getActiveCount();
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG + "_F", "FUTURE TASKS. cores: " + NUMB_OF_CORES + " maxPoolSize:" + maxPoolSize + " current threads number: " + activeThreads + " task in coda: " +
executorService.getQueue().size() + " task sul thread attuale: " + String.valueOf(callerTaskCount.get()) + " ... " + i + "/" +
futures.size() + " " + eta);
for (Future<ResParm> future : futures) {
if (Evento.threadIndicizzaConModelloSTOP)
break;
try {
if (i % 20 == 0) {
activeThreads = executorService.getActiveCount();
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG + "_F", "FUTURE TASKS. cores: " + NUMB_OF_CORES + " maxPoolSize:" + maxPoolSize + " current threads number: " + activeThreads + " task in coda: " +
executorService.getQueue().size() + " task sul thread attuale: " +
String.valueOf(callerTaskCount.get()) + " ... " + i + "/" + futures.size() + " " + eta);
}
rp = future.get();
if (rp.getStatus())
errMsg.append(rp.getErrMsg()).append("\n");
} catch (InterruptedException|ExecutionException e) {
e.printStackTrace();
}
eta = timerF.getEta((long)futures.size(), (long)i);
i++;
}
executorService.shutdown();
try {
if (!executorService.awaitTermination(60L, TimeUnit.SECONDS))
executorService.shutdownNow();
} catch (InterruptedException e) {
executorService.shutdownNow();
}
timer.stop();
timerF.stop();
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG + "_F", "FUTURE TASKS. cores: " + NUMB_OF_CORES + " maxPoolSize:" + maxPoolSize + " FINE!!! ... " +
timerF.getDurata());
StatusMsg.updateMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG, "recognizing. cores: " + NUMB_OF_CORES + " maxPoolSize:" + maxPoolSize + " FINE!!!!: " +
timer.getDurata());
DBAdapter.sleepInSecond(10);
if (debug)
System.out.println("******************************** indicizzaConModello: FINE!!!: " + timer.getDurata());
StatusMsg.deleteMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG);
StatusMsg.deleteMsgByTag(Evento.this.getApFull(), TAG_THREAD_MSG + "_F");
return rp;
}
}
class null extends ThreadPoolExecutor.CallerRunsPolicy {
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
callerTaskCount.set(Integer.valueOf(callerTaskCount.get() + 1));
super.rejectedExecution(r, e);
}
}
class null extends ThreadPoolExecutor {
null(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, RejectedExecutionHandler handler) {
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, handler);
}
protected void afterExecute(Runnable r, Throwable t) {
super.afterExecute(r, t);
if (Thread.currentThread() == Thread.currentThread()) {
int count = callerTaskCount.get();
if (count > 0)
callerTaskCount.set(Integer.valueOf(count - 1));
}
}
}
public Evento(ApplParmFull newApplParmFull) {
super(newApplParmFull);
}
public Evento() {}
public void setId_evento(long newId_evento) {
this.id_evento = newId_evento;
}
public void setId_clifor(long newId_clifor) {
this.id_clifor = newId_clifor;
setClifor(null);
}
public void setDescrizioneEvento(String newDescrizione) {
this.descrizioneEvento = newDescrizione;
}
public void setDataEvento(Date newDataGara) {
this.dataEvento = newDataGara;
}
public void setCodiceEventoCliente(String newCodiceEventoCliente) {
this.codiceEventoCliente = newCodiceEventoCliente;
}
public long getId_evento() {
return this.id_evento;
}
public long getId_clifor() {
return this.id_clifor;
}
public Date getDataEvento() {
return this.dataEvento;
}
public String getCodiceEventoCliente() {
return (this.codiceEventoCliente == null) ? "" : this.codiceEventoCliente.trim();
}
public void setClifor(Clifor newClifor) {
this.clifor = newClifor;
}
public Clifor getClifor() {
this.clifor = (Clifor)getSecondaryObject((DBAdapter)this.clifor, Clifor.class, getId_clifor());
return this.clifor;
}
protected ResParm checkDeleteCascade() {
return new ResParm(true);
}
protected void deleteCascade() {}
public Vectumerator<Evento> findByCR(EventoCR CR, int pageNumber, int pageRows) {
String s_Sql_Find = "select A.* from EVENTO AS A";
String s_Sql_Order = " order by A.dataEvento desc";
WcString wc = new WcString();
if (CR.getId_evento() > 0L) {
wc.addWc("A.id_evento=" + CR.getId_evento());
} else {
if (!CR.getSearchTxt().trim().isEmpty()) {
StringTokenizer st = new StringTokenizer(CR.getSearchTxt().trim(), " ");
StringBuffer txt = new StringBuffer("(");
while (st.hasMoreTokens()) {
String token = st.nextToken();
txt.append("(A.descrizioneEvento like '%" + token + "%')");
if (st.hasMoreTokens())
txt.append(" and ");
}
txt.append(")");
wc.addWc(txt.toString());
}
if (!CR.getDescrizione().isEmpty())
wc.addWc("A.descrizione like '%" + CR.getDescrizione() + "%'");
if (CR.getAnno() > 0L) {
wc.addWc("A.dataEvento>=?");
wc.addWc("A.dataEvento<=?");
}
if (CR.getDataDa() != null)
wc.addWc("(A.dataEvento>=? or A.dataEventoFine>=?)");
if (CR.getDataA() != null)
wc.addWc("(A.dataEvento<=? or A.dataEventoFine<=?)");
}
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
if (CR.getId_evento() == 0L) {
int numData = 1;
if (CR.getAnno() > 0L) {
stmt.setDate(numData, DBAdapter.getFirstOfYear((int)CR.getAnno()));
numData++;
stmt.setDate(numData, DBAdapter.getLastOfYear((int)CR.getAnno()));
numData++;
}
if (CR.getDataDa() != null) {
stmt.setDate(numData, CR.getDataDa());
numData++;
stmt.setDate(numData, CR.getDataDa());
numData++;
}
if (CR.getDataA() != null) {
stmt.setDate(numData, CR.getDataA());
numData++;
stmt.setDate(numData, CR.getDataA());
numData++;
}
}
return findRows(stmt, pageNumber, pageRows);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public String getDescrizioneEvento() {
return (this.descrizioneEvento == null) ? "" : this.descrizioneEvento.trim();
}
public String getImgWmSlomoFilename() {
return getDocBase() + getDocBase() + getPathImg();
}
public String getPathImg() {
return "img/gare/";
}
public Date getDataEventoFine() {
return this.dataEventoFine;
}
public void setDataEventoFine(Date dataEventoFine) {
this.dataEventoFine = dataEventoFine;
}
public final ResParm startDetectFaceFoto() {
if (!isThreadGaraFace()) {
new ThreadDetectFaceFoto(this);
return new ResParm(true, "Thread Index Face EVENTO avviato");
}
return new ResParm(false, "ATTENZIONE!! Thread foto face sulla gara gia' in esecuzione!!!");
}
public static boolean isThreadGaraFace() {
return threadGaraFace;
}
public final ResParm startCreaPuntiFoto(Evento l_evento, boolean l_indicizza, long l_id_users) {
if (!isThreadCreaPuntiFotoAttivo()) {
new ThreadCreaPuntiFoto(l_evento, l_indicizza, l_id_users);
return new ResParm(true, "Thread Creazione Punti foto avviato");
}
return new ResParm(false, "ATTENZIONE!! Thread in esecuzione!!!");
}
public static boolean isThreadCreaPuntiFotoAttivo() {
return threadCreaPuntiFoto;
}
public static boolean isThreadIndicizzaPuntiFotoAttivo() {
return threadIndicizzaPuntiFoto;
}
public String getPathEvento() {
return (this.pathEvento == null) ? "" : this.pathEvento.trim();
}
public void setPathEvento(String pathEvento) {
this.pathEvento = pathEvento;
}
public Vectumerator<PuntoFoto> getPuntiFoto(int pageNumber, int pageRows) {
return new PuntoFoto(getApFull()).findPuntiFotoByEventoTipoIdx(getId_evento(), -1L, pageNumber, pageRows);
}
public ResParm addPuntoFoto(PuntoFoto ab) {
PuntoFoto bean = new PuntoFoto(getApFull());
if (ab.getId_puntoFoto() == 0L) {
ab.setDBState(0);
} else {
bean.findByPrimaryKey(ab.getId_puntoFoto());
if (bean != null)
ab.setDBState(bean.getDBState());
}
ab.setId_evento(getId_evento());
return ab.save();
}
public ResParm delPuntoFoto(long l_id) {
PuntoFoto bean = new PuntoFoto(getApFull());
bean.findByPrimaryKey(l_id);
return bean.delete();
}
public String getFileNameExport() {
return (this.fileNameExport == null) ? "" : this.fileNameExport.trim();
}
public void setFileNameExport(String fileName) {
this.fileNameExport = fileName;
}
public ResParm exportFileIdx(String fileName) {
int numTot = 0;
int numRec = 0;
String sep = ";";
new File(fileName).delete();
FileWr outFile = new FileWr(fileName, false);
String temp2 = System.getProperty("line.separator");
if (temp2.equals("\n"));
ResParm rp = new ResParm(false, "Errore in export: " + fileName + "<br>");
try {
outFile.writeLine("filename;md5;pettorali;labels");
FotoCR CR = new FotoCR();
CR.setId_evento(getId_evento());
Vectumerator<Foto> vec = new Foto(getApFull()).findByCR(CR, 0, 0);
StringBuilder temp = new StringBuilder();
while (vec.hasMoreElements()) {
Foto currentFoto = (Foto)vec.nextElement();
if (!currentFoto.getPettorali().isEmpty() || !currentFoto.getLabels().isEmpty()) {
temp.append(currentFoto.getFileName());
temp.append(";");
temp.append(currentFoto.getMd5());
temp.append(";");
temp.append(currentFoto.getPettorali());
temp.append(";");
temp.append(currentFoto.getLabels());
outFile.writeLine(temp.toString());
temp = new StringBuilder();
numRec++;
}
numTot++;
if (numTot % 100 == 0) {
System.out.println("" + numTot + "/" + numTot + " (" + vec.getTotNumberOfRecords() + ")");
continue;
}
if (numTot % 10 == 0)
System.out.print(".");
}
outFile.closeFile();
rp.setStatus(true);
rp.setMsg("Generazione file export avvenuta con successo.<br> n. foto esportate: " + numRec);
} catch (Exception e) {
handleDebug(e);
rp.setException(e);
rp.setStatus(false);
}
return rp;
}
public String getImpCsvFileName() {
return getDocBase() + "csv/" + getDocBase() + ".csv";
}
public ResParm indexFotoByCsv(String l_fileName, String TAG_THREAD_MSG) {
StatusMsg.updateMsgByTag(getApFull(), TAG_THREAD_MSG, "...index foto by csv ...");
boolean debug = false;
ResParm rp = new ResParm();
int se1 = 10;
int se2 = 100;
int i = 0;
int nrighe = 0;
int fotoTrovate = 0;
int fotoNonTrovate = 0;
if (debug)
System.out.println("indexFotoByCsv: start: filename; " + l_fileName);
StringBuffer errMsg = new StringBuffer();
if (getId_evento() == 0L) {
rp.setMsg("Indicizzazione foto: Bean gara non caricato");
rp.setStatus(false);
handleDebug("Indicizzazione foto: Bean gara non caricato", 2);
return rp;
}
BufferedReader reader = null;
Foto foto = new Foto(getApFull());
try {
reader = new BufferedReader(new FileReader(l_fileName));
if (reader != null) {
String currentLine = reader.readLine();
String[] intestazione = currentLine.split(";");
int colPettorali = 1;
if (intestazione.length == 3)
colPettorali = 2;
while ((currentLine = reader.readLine()) != null) {
nrighe++;
if (debug)
System.out.println("indexFotoByCsv: currentline: " + currentLine);
String[] row = currentLine.split(";");
String nomeFoto = row[0];
String pettorali = row[colPettorali];
if (debug)
System.out.println("indexFotoByCsv: pettorali " + nomeFoto + " - " + pettorali);
foto.findByFilenameEvento(nomeFoto, getId_evento());
if (foto.getDBState() == 1) {
fotoTrovate++;
pettorali = pettorali.replace("\"", "");
if (debug)
System.out.println("indexFotoByCsv: pettorali con replace" + nomeFoto + " - " + pettorali);
Foto.syncAggiornaPettorale_2(foto, pettorali);
} else {
fotoNonTrovate++;
}
StatusMsg.updateMsgByTag(getApFull(), TAG_THREAD_MSG, "Index csv: n. riga:" + nrighe + " foto trovate:" + fotoTrovate + " NON trovate:" + fotoNonTrovate);
i++;
if (se1 <= 0 || i % se1 == 0);
if (se2 <= 0 || i % se2 == 0);
}
}
} catch (Exception e) {
rp.setStatus(false);
rp.appendMsg("-------------------\nECCEZIONE !!!\n");
rp.appendMsg(e.getMessage());
rp.appendMsg(" \n Numero righe importate: " + nrighe);
rp.appendMsg(" \nFoto Trovate: " + fotoTrovate + " foto Non trovate: " + fotoNonTrovate);
} finally {
if (reader != null)
try {
reader.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
if (rp.getStatus())
rp.setMsg(" Numero righe importate: " + nrighe + " \nFoto Trovate: " + fotoTrovate + " foto Non trovate: " + fotoNonTrovate);
StatusMsg.updateMsgByTag(getApFull(), TAG_THREAD_MSG, "Index csv: Numero righe importate: " + nrighe + " Foto Trovate: " + fotoTrovate + " foto Non trovate: " + fotoNonTrovate);
StatusMsg.deleteMsgByTag(getApFull(), TAG_THREAD_MSG);
return rp;
}
public boolean isImportFileExist() {
String theFile = getImpCsvFileName();
return isFileExist(theFile);
}
public final ResParm startIndicizzaPuntiFoto(Evento l_evento, long l_id_users) {
if (!isThreadIndicizzaPuntiFotoAttivo()) {
new ThreadIndicizzaPuntiFoto(l_evento, l_id_users);
return new ResParm(true, "Thread Indicizza Punti foto avviato");
}
return new ResParm(false, "ATTENZIONE!! Thread in esecuzione!!!");
}
public String getPathEventoFace() {
return getPathEvento() + "_FACES";
}
public ResParm calcolaQuantitaPettorali(FotoCR CR) {
ResParm rp = new ResParm();
try {
if (getId_evento() > 0L) {
CR.setFlgConPettorali(1L);
CR.setId_evento(getId_evento());
Foto foto = new Foto(getApFull());
Vectumerator<Foto> vec = foto.findByCR(CR, 0, 0);
while (vec.hasMoreElements()) {
Foto row = (Foto)vec.nextElement();
StringTokenizer st = new StringTokenizer(row.getPettorali(), ",");
while (st.hasMoreTokens()) {
String pet = st.nextToken();
if (!pet.isEmpty() &&
!getPettoraliTS().contains(pet))
getPettoraliTS().add(pet);
}
}
}
if (getPettoraliTS().size() == 0) {
rp.setMsg("Numero pettorali trovati: 0");
rp.setStatus(false);
} else {
String fileCsv = "pettorali_" + getNow().getTime() + ".csv";
String filename = getDocBase() + getDocBase() + getParm("PATH_TMP").getTesto();
new File(filename).delete();
FileWr outFile = new FileWr(filename, "UTF-8", false);
outFile.writeLine("Evento: " + getDescrizioneEvento());
outFile.writeLine("\nTOT PETTORALI: " + getPettoraliTS().size());
StringBuilder sb = new StringBuilder();
int i = 0;
for (String pett : getPettoraliTS()) {
i++;
sb.append(pett + ",");
if (i % 10 == 0)
sb.append("\n");
}
System.out.println("calcolaQuantitaPettorali " + i);
outFile.writeLine("\n" + sb.toString());
rp.setMsg("Numero pettorali trovati: " + getPettoraliTS().size());
rp.setStatus(true);
outFile.closeFile();
rp.setReturnObj(fileCsv);
}
} catch (Exception e) {
handleDebug(e);
rp.setException(e);
rp.setStatus(false);
}
return rp;
}
public TreeSet<String> getPettoraliTS() {
if (this.pettoraliTS == null)
this.pettoraliTS = new TreeSet<>();
return this.pettoraliTS;
}
public void setPettoraliTS(TreeSet<String> pettoraliTS) {
this.pettoraliTS = pettoraliTS;
}
public long getMargineFotoDx() {
return this.margineFotoDx;
}
public void setMargineFotoDx(long margineFotoDx) {
this.margineFotoDx = margineFotoDx;
}
public long getMargineFotoSx() {
return this.margineFotoSx;
}
public void setMargineFotoSx(long margineFotoSx) {
this.margineFotoSx = margineFotoSx;
}
public long getMargineFotoTop() {
return this.margineFotoTop;
}
public void setMargineFotoTop(long margineFotoTop) {
this.margineFotoTop = margineFotoTop;
}
public long getMargineFotoBottom() {
return this.margineFotoBottom;
}
public void setMargineFotoBottom(long margineFotoBottom) {
this.margineFotoBottom = margineFotoBottom;
setFaceRecognizer(null);
}
public long getDimMinFotoFaceEvento() {
return (this.dimMinFotoFaceEvento <= 0L) ? 25L : this.dimMinFotoFaceEvento;
}
public void setDimMinFotoFaceEvento(long dimMinFotoFace) {
this.dimMinFotoFaceEvento = dimMinFotoFace;
}
protected void initFields() {
super.initFields();
setFlgProcessingDB(getFlgProcessing());
setScoreThresoldSelfieSearch(0.2D);
setScoreThresoldSelfieSearch2(0.6D);
setId_faceDetectionMethodEvento(14L);
setDimMinFotoFaceEvento(25L);
setFrImageWidth(2560L);
setDetectFaceConfidentThresold(0.7D);
setScoreThresold(0.6D);
setNumFotoNoScore(2L);
setScoreSelfieTargetThresold(25L);
setScoreSelfieNTarget(20L);
}
public long getFrImageWidth() {
return (this.frImageWidth <= 0L) ? 2560L : this.frImageWidth;
}
public void setFrImageWidth(long frImageWidth) {
this.frImageWidth = frImageWidth;
}
public long getFlgDetectNumbers() {
return this.flgDetectNumbers;
}
public void setFlgDetectNumbers(long flgDetectNumbers) {
this.flgDetectNumbers = flgDetectNumbers;
}
public long getId_faceRecognizer() {
return this.id_faceRecognizer;
}
public void setId_faceRecognizer(long id_faceRecognizer) {
this.id_faceRecognizer = id_faceRecognizer;
}
public FaceRecognizer getFaceRecognizer() {
this.faceRecognizer = (FaceRecognizer)getSecondaryObject(this.faceRecognizer, FaceRecognizer.class, getId_faceRecognizer());
return this.faceRecognizer;
}
public void setFaceRecognizer(FaceRecognizer faceRecognizer) {
this.faceRecognizer = faceRecognizer;
}
public FaceDetectionMethod getFaceDetectionMethodEvento() {
this.faceDetectionMethodEvento = (FaceDetectionMethod)getSecondaryObject(this.faceDetectionMethodEvento, FaceDetectionMethod.class,
getId_faceDetectionMethodEvento());
return this.faceDetectionMethodEvento;
}
public long getId_faceDetectionMethodEvento() {
return (this.id_faceDetectionMethodEvento <= 0L) ? 14L : this.id_faceDetectionMethodEvento;
}
public void setFaceDetectionMethodEvento(FaceDetectionMethod faceDetectionMethod) {
this.faceDetectionMethodEvento = faceDetectionMethod;
}
public void setId_faceDetectionMethodEvento(long id_faceDetectionMethod) {
this.id_faceDetectionMethodEvento = id_faceDetectionMethod;
setFaceDetectionMethodEvento(null);
}
public double getDetectFaceConfidentThresold() {
return (this.detectFaceConfidentThresold <= 0.0D || this.detectFaceConfidentThresold > 0.99D) ? 0.7D :
this.detectFaceConfidentThresold;
}
public void setDetectFaceConfidentThresold(double detectFaceConfidentThresold) {
this.detectFaceConfidentThresold = detectFaceConfidentThresold;
}
public double getScoreThresold() {
return (this.scoreThresold <= 0.0D || this.scoreThresold > 0.99D) ? 0.6D : this.scoreThresold;
}
public void setScoreThresold(double scoreThresold) {
this.scoreThresold = scoreThresold;
}
public ResParm save() {
long flgProgDb = getFlgProcessingDB();
if (getPathEvento().isEmpty()) {
Calendar cal = Calendar.getInstance();
cal.setTime(getDataEvento());
if (getFlgTipoEvento() == 0L) {
setPathEvento("" + cal.get(1) + "/E_" + cal.get(1) + "/");
} else if (getFlgTipoEvento() == 1L) {
setPathEvento("" + cal.get(1) + "/" + cal.get(1) + "/");
}
}
ResParm rp = super.save();
if (rp.getStatus())
setFlgProcessingDB(getFlgProcessing());
return rp;
}
public long getNumFotoNoScore() {
return (this.numFotoNoScore <= 0L) ? 2L : this.numFotoNoScore;
}
public void setNumFotoNoScore(long numFotoNoScore) {
this.numFotoNoScore = numFotoNoScore;
}
public static boolean isthreadEventoScoring() {
return threadEventoScoring;
}
public final ResParm startEventoScoring(Evento l_evento, int fase) {
if (!isthreadEventoScoring()) {
new ThreadEventoScoring(l_evento, fase);
return new ResParm(true, "Thread Evento Scoring avviato");
}
return new ResParm(false, "ATTENZIONE!! Thread in esecuzione!!!");
}
public final ResParm stopScoring() {
if (!isthreadEventoScoring())
return new ResParm(false, "ATTENZIONE!! Thread NON in esecuzione!!!");
threadEventoScoringSTOP = true;
SmartFaceScoringQueue smartFaceScoringQueue = SmartFaceScoringQueue.getInstance(getApFull());
smartFaceScoringQueue.setStopScoring(true);
return new ResParm(true, "Stop Evento Scoring inviato!!!");
}
public final ResParm stopBuildModel() {
if (!threadBuildModel)
return new ResParm(false, "ATTENZIONE!! Thread NON in esecuzione!!!");
threadBuildModelSTOP = true;
return new ResParm(true, "Stop Build Model inviato!!!");
}
public final ResParm stopIndicizzaConModello() {
if (!threadIndicizzaConModello)
return new ResParm(false, "ATTENZIONE!! Thread NON in esecuzione!!!");
threadIndicizzaConModelloSTOP = true;
return new ResParm(true, "Stop Indicizza con modello inviato!!!");
}
@Deprecated
public long getCurrentFaceTarget2() {
return this.currentFaceTarget2;
}
@Deprecated
public void setCurrentFaceTarget2(long currentFaceTarget) {
this.currentFaceTarget2 = currentFaceTarget;
}
public long getCurrentPuntofoto2() {
return this.currentPuntofoto2;
}
public void setCurrentPuntofoto2(long currentPuntofoto) {
this.currentPuntofoto2 = currentPuntofoto;
}
@Deprecated
public long getCurrentTargetindex7() {
return this.currentTargetindex7;
}
@Deprecated
public void setCurrentTargetindex7(long currentTargetindex7) {
this.currentTargetindex7 = currentTargetindex7;
}
public final ResParm startBuildModel(Evento l_evento, int fase) {
if (!threadBuildModel) {
new ThreadBuildModel(l_evento, fase);
return new ResParm(true, "Thread Build Model avviato");
}
return new ResParm(false, "ATTENZIONE!! Thread in esecuzione!!!");
}
public final ResParm startBuildIndicizzaConModello(Evento l_evento) {
if (!threadIndicizzaConModello) {
new ThreadIndicizzaConModello(l_evento);
return new ResParm(true, "Thread Indicizza Con Modello avviato");
}
return new ResParm(false, "ATTENZIONE!! Thread in esecuzione!!!");
}
public long getCodeGara() {
return this.codeGara;
}
public void setCodeGara(long codGara) {
this.codeGara = codGara;
}
public void findByCodeGara(long l_codeGara) {
String s_Sql_Find = "select A.* from EVENTO AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc("A.codeGara=" + l_codeGara);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
findFirstRecord(stmt);
} catch (SQLException e) {
removeCPConnection();
handleDebug(e);
}
}
public double getScoreThresoldSelfieSearch() {
return (this.scoreThresoldSelfieSearch <= 0.0D || this.scoreThresoldSelfieSearch > 0.99D) ? 0.2D :
this.scoreThresoldSelfieSearch;
}
public void setScoreThresoldSelfieSearch(double scoreThresoldSelfieSearch) {
this.scoreThresoldSelfieSearch = scoreThresoldSelfieSearch;
}
public ResParm checkSaveScoreExecutor() {
SaveScoreProcessor ssProcessor = SaveScoreProcessor.getInstance(getApFull());
if (ssProcessor == null)
return new ResParm(true, "SaveScoreProcessor non attivo");
if (ssProcessor.isIdle()) {
ssProcessor.shutdown();
return new ResParm(true, "SaveScoreProcessor: shutdown lanciato");
}
return new ResParm(true, "SaveScoreProcessor: shutdown attivo. " + ssProcessor.getDescProcess());
}
public double getScoreThresoldSelfieSearch2() {
return (this.scoreThresoldSelfieSearch2 <= 0.0D) ? 0.6D : this.scoreThresoldSelfieSearch2;
}
public void setScoreThresoldSelfieSearch2(double scoreThresoldSelfieSearch2) {
this.scoreThresoldSelfieSearch2 = scoreThresoldSelfieSearch2;
}
public static ResParm inviaNotificaRemotaWww(ApplParmFull apFull, long l_id_gara) {
ResParm rp = new ResParm();
Properties p = new Properties();
p.setProperty("cmd", "notificaApp");
p.setProperty("id_gara", String.valueOf(l_id_gara));
rp.setMsg("Invio comando manda notifica al www..\n");
rp.append(startRemoteCmdWWW(apFull, p));
return rp;
}
public long getScoreSelfieNTarget() {
return (this.scoreSelfieNTarget <= 0L) ? 20L : this.scoreSelfieNTarget;
}
public void setScoreSelfieNTarget(long scoreSelfieNTarget) {
this.scoreSelfieNTarget = scoreSelfieNTarget;
}
public long getScoreSelfieTargetThresold() {
return (this.scoreSelfieTargetThresold <= 0L) ? 25L : this.scoreSelfieTargetThresold;
}
public void setScoreSelfieTargetThresold(long scoreSelfieTargetThresold) {
this.scoreSelfieTargetThresold = scoreSelfieTargetThresold;
}
public ResParm updateCurrentTargetindex7(long L_currentTargetindex7) {
if (getId_evento() == 0L)
return new ResParm(false, "Evento con id a 0");
ResParm rp = update("UPDATE EVENTO SET currentTargetindex7=" + L_currentTargetindex7 + " where id_evento=" + getId_evento());
if (rp.getStatus())
setCurrentTargetindex7(L_currentTargetindex7);
return rp;
}
public static long stimaConfrontiMergeAggressivo(long numeroQueryRimanenti, double mediaMd5ToRemove) {
long n = numeroQueryRimanenti;
double m = mediaMd5ToRemove;
int k = (int)Math.floor((double)n / (m + 1.0D));
double confronti = (double)k / 2.0D * ((double)(2L * n) - (double)(k + 1) * (m + 1.0D));
return Math.round(confronti);
}
public long getSelfieRangeExt() {
return this.selfieRangeExt;
}
public void setSelfieRangeExt(long selfieRangeExt) {
this.selfieRangeExt = selfieRangeExt;
}
public long getFlgProcessing() {
return this.flgProcessing;
}
public void setFlgProcessing(long flgProcessing) {
this.flgProcessing = flgProcessing;
}
public Timestamp getTsLastProcess() {
return this.tsLastProcess;
}
public void setTsLastProcess(Timestamp tsLastProcess) {
this.tsLastProcess = tsLastProcess;
}
public long getFlgProcessingDB() {
return this.flgProcessingDB;
}
public void setFlgProcessingDB(long flgProcessingDB) {
this.flgProcessingDB = flgProcessingDB;
}
protected void prepareSave(PreparedStatement ps) throws SQLException {
if (getFlgProcessingDB() == 0L && getFlgProcessing() == 1L)
setTsLastProcess(DBAdapter.getNowTs());
super.prepareSave(ps);
}
protected void fillFields(ResultSet rst) {
super.fillFields(rst);
setFlgProcessingDB(getFlgProcessing());
}
public ResParm startProcessing() {
ResParm rp = new ResParm();
if (getId_evento() > 0L) {
try {
EventoProcessingDispatcher d = new EventoProcessingDispatcher(this);
d.startProcessingLoop();
rp = update("UPDATE EVENTO SET flgProcessing=1 where id_evento=" + getId_evento());
if (rp.getStatus())
rp.setMsg("ATTENZIONE! Attivato EventoProcessingDispatcher!! " + rp.getMsg());
} catch (Exception e) {
rp.setMsg("ATTENZIONE! " + e.getMessage() + " " + rp.getMsg());
}
rp.append(update("UPDATE EVENTO SET flgProcessing=1 where id_evento=" + getId_evento()));
}
return rp;
}
public ResParm stopProcessing() {
ResParm rp = new ResParm();
if (getId_evento() > 0L) {
try {
EventoProcessingDispatcher.shutdown(this);
rp = update("UPDATE EVENTO SET flgProcessing=0 where id_evento=" + getId_evento());
if (rp.getStatus())
rp.setMsg("ATTENZIONE! SHUTDOWN GaraProcessingDispatcher!! " + rp.getMsg());
} catch (Exception e) {
rp.setMsg("ATTENZIONE! " + e.getMessage() + " " + rp.getMsg());
}
rp.append(update("UPDATE EVENTO SET flgProcessing=0 where id_evento=" + getId_evento()));
}
return rp;
}
public long getFlgTipoEvento() {
return this.flgTipoEvento;
}
public void setFlgTipoEvento(long flgTipoEvento) {
this.flgTipoEvento = flgTipoEvento;
}
}