Files
matlab-python/ATD/soglie.m

3472 lines
200 KiB
Matlab
Executable File

function [siteID,unitID,chainID,Chain_Scheme,num_nodi] = soglie(IDcentralina,...
yesTuL,yesRL,yesTLH,yesTLHRH,yesPCL,yesPCLHR,conn,FileName)
fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'soglie function started';
fprintf(fileID,fmt,text);
%% Raccolgo Informazioni
% Cerco tutte le centraline presenti in quel sito
comando = ['select site_id from units where name = ''' IDcentralina ''' ']; % il rapporto centralina sito è di 1 a 1
curs = exec(conn,comando);
curs = fetch(curs);
siteID = curs.Data;
% Scarico tutte le centraline presenti in sito
comando = ['select id, name from units where site_id = ''' num2str(cell2mat(siteID)) ''' order by name']; % il rapporto centralina sito è di 1 a 1
curs = exec(conn,comando);
curs = fetch(curs);
unitID = curs.Data;
col = size(unitID);
chainID = cell(1,4);
ini = 1;
for c = 1:col(1,1)
% dalle centraline presenti, risalgo alle catene disponibili
comando = ['select id, name from tools where unit_id = ''' num2str(cell2mat(unitID(c,1))) ''' order by name'];
curs = exec(conn,comando);
curs = fetch(curs);
chainID_down = curs.Data; % id tool, nome tool
[fin,~] = size(chainID_down);
fin = fin+ini-1;
chainID(ini:fin,3:4) = chainID_down;
for j = ini:fin
chainID(j,1:2) = unitID(c,1:2); % Id centralina, nome centralina, id tool, nome tool
end
ini = fin+1;
end
% Scarico gli schemi delle catene
[col,~] = size(chainID); % Numero di Array
Chain_Scheme = cell(1,3);
num_nodi = zeros(col,1);
ini = 1;
cont = 1;
for c = 1:col(1,1)
comando = ['select nodetype_id, depth, num from nodes where tool_id = ''' num2str(cell2mat(chainID(c,3))) ''' order by num'];
curs = exec(conn,comando);
curs = fetch(curs);
scheme_down = curs.Data; % id nodo, profondità, numero
[fin,~] = size(scheme_down);
num_nodi(cont) = fin;
Chain_Scheme(1:fin,ini:ini+2) = scheme_down;
ini = ini+3;
cont = cont+1;
end
if yesTuL == 1 || yesRL == 1 || yesTLH == 1 || yesTLHRH == 1 || ...
yesPCL == 1 || yesPCLHR == 1
% Per ogni tipologia di nodo, riconosco se è presente o meno nella catena
yesTL = zeros(col,1); % Tilt Link V
yesTLHR = zeros(col,1); % Tilt Link HR V
yesTLH = zeros(col,1); % Tilt Link H
yesTLHRH = zeros(col,1); % Tilt Link HR H
yesIPL = zeros(col,1); % In Place Link
yesIPLHR = zeros(col,1); % In Place Link HR
yesTuL = zeros(col,1); % Tunnel Link
yesRL = zeros(col,1); % Radial Link
yesPCL = zeros(col,1); % PreConv Link
yesPCLHR = zeros(col,1); % PreConv Link HR
yesPL = zeros(col,1); % Piezo Link
yesKL = zeros(col,1); % Klino Link
yesKLHR = zeros(col,1); % Klino Link HR
yesRaL = zeros(col,1); % Rain Link
yesLL = zeros(col,1); % Load Link
yesPrL = zeros(col,1); % Pressure Link
yesEL = zeros(col,1); % Extensometer Link
yes3DEL = zeros(col,1); % 3D Extensometer Link
yesWEL = zeros(col,1); % Wire Extensometer Link
yesMPBEL = zeros(col,1); % Multi Point BoreHole Extensometer Link
yesCrL = zeros(col,1); % Crack Link
yes3DCrL = zeros(col,1); % 3D Crack Link
% Numero di nodi per catena
rTL = zeros(col,1);
rTLHR = zeros(col,1);
rTLH = zeros(col,1);
rTLHRH = zeros(col,1);
rIPL = zeros(col,1);
rIPLHR = zeros(col,1);
rTuL = zeros(col,1);
rRL = zeros(col,1);
rPCL = zeros(col,1);
rPCLHR = zeros(col,1);
rKL = zeros(col,1);
rKLHR = zeros(col,1);
rRaL = zeros(col,1);
rPL = zeros(col,1);
rLL = zeros(col,1);
rPrL = zeros(col,1);
rEL = zeros(col,1);
r3DEL = zeros(col,1);
rWEL = zeros(col,1);
rMPBEL = zeros(col,1);
rCrL = zeros(col,1);
r3DCrL = zeros(col,1);
indice = 1;
for a = 1:col % Array
nTL = 1;
nTLHR = 1;
nTLH = 1;
nTLHRH = 1;
nIPL = 1;
nIPLHR = 1;
nTuL = 1;
nRL = 1;
nPCL = 1;
nPCLHR = 1;
nKL = 1;
nKLHR = 1;
nRaL = 1;
nPL = 1;
nLL = 1;
nPrL = 1;
nEL = 1;
n3DEL = 1;
nMPBEL = 1;
nCrL = 1;
n3DCrL = 1;
nWEL = 1;
for b = 1:num_nodi(a) % Numero di nodi dell'Array
if cell2mat(Chain_Scheme(b,indice)) == 1 % Tilt Link V
yesTL(a) = 1;
NodoTiltLink(nTL,a) = Chain_Scheme(b,indice+2); % Ogni colonna riporta i nodi di un array
nTL = nTL+1;
elseif cell2mat(Chain_Scheme(b,indice)) == 5 % Tilt Link HR V
yesTLHR(a) = 1;
NodoTiltLinkHR(nTLHR,a) = Chain_Scheme(b,indice+2); % Ogni colonna riporta i nodi di un array
nTLHR = nTLHR+1;
elseif cell2mat(Chain_Scheme(b,indice)) == 11 % Tilt Link H
yesTLH(a) = 1;
NodoTiltLinkH(nTLH,a) = Chain_Scheme(b,indice+2); % Ogni colonna riporta i nodi di un array
nTLH = nTLH+1;
elseif cell2mat(Chain_Scheme(b,indice)) == 12 % Tilt Link HR H
yesTLHRH(a) = 1;
NodoTiltLinkHRH(nTLHRH,a) = Chain_Scheme(b,indice+2); % Ogni colonna riporta i nodi di un array
nTLHRH = nTLHRH+1;
elseif cell2mat(Chain_Scheme(b,indice)) == 42 % In Place Link
yesIPL(a) = 1;
NodoInPlaceLink(nIPL,a) = Chain_Scheme(b,indice+2); % Ogni colonna riporta i nodi di un array
nIPL = nIPL+1;
elseif cell2mat(Chain_Scheme(b,indice)) == 43 % In Place Link HR
yesIPLHR(a) = 1;
NodoInPlaceLinkHR(nIPLHR,a) = Chain_Scheme(b,indice+2); % Ogni colonna riporta i nodi di un array
nIPLHR = nIPLHR+1;
elseif cell2mat(Chain_Scheme(b,indice)) == 17 % Tunnel Link
yesTuL(a) = 1;
NodoTunnelLink(nTuL,a) = Chain_Scheme(b,indice+2); % Ogni colonna riporta i nodi di un array
nTuL = nTuL+1;
elseif cell2mat(Chain_Scheme(b,indice)) == 18 % Radial Link
yesRL(a) = 1;
NodoRadialLink(nRL,a) = Chain_Scheme(b,indice+2); % Ogni colonna riporta i nodi di un array
nRL = nRL+1;
elseif cell2mat(Chain_Scheme(b,indice)) == 23 % PreConv Link
yesPCL(a) = 1;
NodoPreConvLink(nPCL,a) = Chain_Scheme(b,indice+2); % Ogni colonna riporta i nodi di un array
nPCL = nPCL+1;
elseif cell2mat(Chain_Scheme(b,indice)) == 24 % PreConv Link HR
yesPCLHR(a) = 1;
NodoPreConvLinkHR(nPCLHR,a) = Chain_Scheme(b,indice+2); % Ogni colonna riporta i nodi di un array
nPCLHR = nPCLHR+1;
elseif cell2mat(Chain_Scheme(b,indice)) == 2 % Piezo Link
yesPL(a) = 1;
NodoPiezoLink(nPL,a) = Chain_Scheme(b,indice+2); % Ogni colonna riporta i nodi di un array
nPL = nPL+1;
elseif cell2mat(Chain_Scheme(b,indice)) == 26 % Klino Link
yesKL(a) = 1;
NodoKlinoLink(nKL,a) = Chain_Scheme(b,indice+2); % Ogni colonna riporta i nodi di un array
nKL = nKL+1;
elseif cell2mat(Chain_Scheme(b,indice)) == 44 % Klino Link HR
yesKLHR(a) = 1;
NodoKlinoLinkHR(nKLHR,a) = Chain_Scheme(b,indice+2); % Ogni colonna riporta i nodi di un array
nKLHR = nKLHR+1;
elseif cell2mat(Chain_Scheme(b,indice)) == 27 % Rain Link
yesRaL(a) = 1;
NodoRainLink(nRaL,a) = Chain_Scheme(b,indice+2); % Ogni colonna riporta i nodi di un array
nRaL = nRaL+1;
elseif cell2mat(Chain_Scheme(b,indice)) == 15 % Load Link
yesLL(a) = 1;
NodoLoadLink(nLL,a) = Chain_Scheme(b,indice+2); % Ogni colonna riporta i nodi di un array
nLL = nLL+1;
elseif cell2mat(Chain_Scheme(b,indice)) == 21 % Pressure Link
yesPrL(a) = 1;
NodoPressureLink(nPrL,a) = Chain_Scheme(b,indice+2); % Ogni colonna riporta i nodi di un array
nPrL = nPrL+1;
elseif cell2mat(Chain_Scheme(b,indice)) == 16 % Extensometer Link
yesEL(a) = 1;
NodoExtensometerLink(nEL,a) = Chain_Scheme(b,indice+2); % Ogni colonna riporta i nodi di un array
nEL = nEL+1;
elseif cell2mat(Chain_Scheme(b,indice)) == 19 % 3D Extensometer Link
yes3DEL(a) = 1;
Nodo3DExtensometerLink(n3DEL,a) = Chain_Scheme(b,indice+2); % Ogni colonna riporta i nodi di un array
n3DEL = n3DEL+1;
elseif cell2mat(Chain_Scheme(b,indice)) == 22 % Wire Extensometer Link
yesWEL(a) = 1;
NodoWireExtensometerLink(nWEL,a) = Chain_Scheme(b,indice+2); % Ogni colonna riporta i nodi di un array
nWEL = nWEL+1;
elseif cell2mat(Chain_Scheme(b,indice)) == 25 % Multi Point Borehole Extensometer Link
yesMPBEL(a) = 1;
NodoMultiPointExtensometerLink(nMPBEL,a) = Chain_Scheme(b,indice+2); % Ogni colonna riporta i nodi di un array
nMPBEL = nMPBEL+1;
elseif cell2mat(Chain_Scheme(b,indice)) == 36 % Crack Link
yesCrL(a) = 1;
NodoCrackLink(nCrL,a) = Chain_Scheme(b,indice+2); % Ogni colonna riporta i nodi di un array
nCrL = nCrL+1;
elseif cell2mat(Chain_Scheme(b,indice)) == 37 % 3D Crack Link
yes3DCrL(a) = 1;
Nodo3DCrackLink(n3DCrL,a) = Chain_Scheme(b,indice+2); % Ogni colonna riporta i nodi di un array
n3DCrL = n3DCrL+1;
end
end
indice = indice+3;
rTL(a) = nTL-1;
rTLHR(a) = nTLHR-1;
rTLH(a) = nTLH-1;
rTLHRH(a) = nTLHRH-1;
rIPL(a) = nIPL-1;
rIPLHR(a) = nIPLHR-1;
rTuL(a) = nTuL-1;
rRL(a) = nRL-1;
rPCL(a) = nPCL-1;
rPCLHR(a) = nPCLHR-1;
rKL(a) = nKL-1;
rKLHR(a) = nKLHR-1;
rRaL(a) = nRaL-1;
rPL(a) = nPL-1;
rPrL(a) = nPrL-1;
rCrL(a) = nCrL-1;
r3DCrL(a) = n3DCrL-1;
rEL(a) = nEL-1;
r3DEL(a) = n3DEL-1;
rWEL(a) = nWEL-1;
rMPBEL(a) = nMPBEL-1;
end
try
% --- Analizzo i singoli nodi ---
%% Tilt Link V
if isempty(find(yesTL)) == 1 % Non ho Tilt Link V
text = 'Tilt Link V have not been analyzed during the execution of soglie function';
fprintf(fileID,fmt,text);
Num_Allarmi_TL = 0;
else
TL = cumsum(rTL);
Alert_TL = zeros(1,TL(end)); % Livello di Allerta
Date_Alert_TL = zeros(1,TL(end)); % Data di Allerta
Node_Alert_TL = zeros(1,TL(end)); % Numero di nodo in Allerta
ID_Alert_TL = cell(1,TL(end)); % ID centralina - ID catena in Allerta
index = 1;
prog = 1;
for n = 1:col % Ripeto per ogni Array
DatiElab = cell(1);
Date = zeros(1);
if yesTL(n) == 1
date_rif = now-15; % 15 giorni
for nn = 1:rTL(n) % Ripeto per ogni nodo
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' num2str(cell2mat(NodoTiltLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DateElab = curs.Data;
% Modifico il formato di data e ora in DATini.
[rD,cD] = size(DateElab);
if rD ~= 1 && cD ~= 1
T = [cell2mat(DateElab(:,1)) repmat(' ', [rD,1]) cell2mat(DateElab(:,2))];
if nn == 1
Date(1:rD,n) = datenum(T); % scrivo la matrice date usando il primo nodo
end
comando = ['select XShift, YShift from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' num2str(cell2mat(NodoTiltLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Control = curs.Data;
[rCD,~] = size(Control); % Dati del nodo N dell'Array X
[rDE,~] = size(DatiElab);
if rCD ~= rDE
if rCD > rDE
DatiElab(1:rCD,index:index+1) = Control;
RIF = rCD;
elseif rCD < rDE
DatiElab(1:rCD,index:index+1) = Control;
DatiElab(rCD+1:rDE,index:index+1) = Control(end,:);
RIF = rDE;
end
else
DatiElab(:,index:index+1) = Control; % Tutti i dati dei sensori dell'Array n
RIF = rDE;
end
% Guardo le soglie
[rCheck,cCheck] = size(DatiElab);
if rCheck > 1 && cCheck > 1
% Da Ieri
index1 = find(datenum(Date(:,n))>(now-1));
[rID,~] = size(index1);
if isempty(index1) == 0 && rID ~= 1 % non posso fare la diff
Incrementi_1gg = sqrt((diff(cell2mat(DatiElab(index1(1):end,index))))...
.^2+(diff(cell2mat(DatiElab(index1(1):end,index+1)))).^2);
Date_1gg(1:RIF-index1(1),n) = Date(index1(2):index1(end),n);
% 15 gg
Incrementi_15gg = sqrt((diff(cell2mat(DatiElab(:,index)))).^2+(diff(cell2mat(DatiElab(:,index+1)))).^2);
ST15 = std(Incrementi_15gg(1:index1(1),:)); % 1 Deviazione standard per i 15 giorni
MAX15 = max(Incrementi_15gg(1:index1(1),:));
% 7 gg
index7 = find(datenum(Date(:,n))>(now-7));
Incrementi_7gg = sqrt((diff(cell2mat(DatiElab(index7(1):index1(1),index)))).^2+(diff(cell2mat(DatiElab(index7(1):index1(1),index+1)))).^2);
ST7 = 3*std(Incrementi_7gg); % 3 Deviazioni standard per i 7 giorni
MAX7 = max(Incrementi_7gg);
% 3 gg
index3 = find(datenum(Date(:,n))>(now-3));
Incrementi_3gg = sqrt((diff(cell2mat(DatiElab(index3(1):index1(1),index)))).^2+(diff(cell2mat(DatiElab(index3(1):index1(1),index+1)))).^2);
ST3 = 5*std(Incrementi_3gg); % 5 Deviazioni standard per i 3 giorni
MAX3 = max(Incrementi_3gg);
[rI,cI] = size(Incrementi_1gg); % Dati per quel nodo
soglia3 = zeros(rI,cI);
soglia7 = zeros(rI,cI);
soglia15 = zeros(rI,cI);
for cc = 1:cI
for s = 1:rI
if Incrementi_1gg(s,cc) > ST15+MAX15
soglia15(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST7+MAX7
soglia7(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST3+MAX3
soglia3(s,cc) = 1;
end
if soglia3(s,cc) == 1 && soglia7(s,cc) == 1 && soglia15(s,cc) == 1
Alert_TL(s,prog) = 3; % Allerta del nodo di Livello 3
Date_Alert_TL(s,prog) = Date_1gg(s,n);
Node_Alert_TL(s,prog) = cell2mat(NodoTiltLink(nn,n));
ID_Alert_TL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 && soglia7(s,cc) == 1 || soglia3(s,cc) == 1 && soglia15(s,cc) == 1 || soglia15(s,cc) == 1 && soglia7(s,cc) == 1
Alert_TL(s,prog) = 2; % Allerta del nodo di Livello 2
Date_Alert_TL(s,prog) = Date_1gg(s,n);
Node_Alert_TL(s,prog) = cell2mat(NodoTiltLink(nn,n));
ID_Alert_TL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 || soglia7(s,cc) == 1 || soglia15(s,cc) == 1
Alert_TL(s,prog) = 1; % Allerta del nodo di Livello 1
Date_Alert_TL(s,prog) = Date_1gg(s,n);
Node_Alert_TL(s,prog) = cell2mat(NodoTiltLink(nn,n));
ID_Alert_TL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
end
end
end
end
end
end
index = index+2;
prog = prog+1;
end
text = ['Data of ' char(chainID(n,2)) '-' char(chainID(n,4)) ' Tilt Link V have been analyzed'];
fprintf(fileID,fmt,text);
index = 1;
end
end
[num_TL,~] = size(rTL);
ini = 1;
fin = cumsum(rTL);
Num_Allarmi_TL = zeros(1,num_TL);
for AL = 1:num_TL
if ini > fin(AL) % si va a quello dopo
else
Livello = max(max(Alert_TL(:,ini:fin(AL))));
if isempty(Livello) == 1
Livello = 0;
end
Num_Allarmi_TL(1,AL) = Livello;
ini = fin(AL)+1;
end
end
end
%% Tilt Link HR V
if isempty(find(yesTLHR)) == 1 % Non ho Tilt Link HR V
text = 'Tilt Link HR V have not been analyzed during the execution of soglie function';
fprintf(fileID,fmt,text);
Num_Allarmi_TLHR = 0;
else
clear Date_1gg
TLHR = cumsum(rTLHR);
Alert_TLHR = zeros(1,TLHR(end)); % Livello di Allerta
Date_Alert_TLHR = zeros(1,TLHR(end)); % Data di Allerta
Node_Alert_TLHR = zeros(1,TLHR(end)); % Numero di nodo in Allerta
ID_Alert_TLHR = cell(1,TLHR(end)); % ID centralina - ID catena in Allerta
index = 1;
prog = 1;
for n = 1:col % Ripeto per ogni Array
DatiElab = cell(1);
Date = zeros(1);
if yesTLHR(n) == 1
date_rif = now-15; % 15 giorni
for nn = 1:rTLHR(n) % Ripeto per ogni nodo
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' num2str(cell2mat(NodoTiltLinkHR(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DateElab = curs.Data;
% Modifico il formato di data e ora in DATini.
[rD,cD] = size(DateElab);
if rD ~= 1 && cD ~= 1
T = [cell2mat(DateElab(:,1)) repmat(' ', [rD,1]) cell2mat(DateElab(:,2))];
if nn == 1
Date(1:rD,n) = datenum(T); % scrivo lamatrice date usando il primo nodo
end
comando = ['select XShift, YShift from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' num2str(cell2mat(NodoTiltLinkHR(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Control = curs.Data;
[rCD,~] = size(Control);
[rDE,~] = size(DatiElab);
if rCD ~= rDE
if rCD > rDE
DatiElab(1:rCD,index:index+1) = Control;
RIF = rCD;
elseif rCD < rDE
DatiElab(1:rCD,index:index+1) = Control;
DatiElab(rCD+1:rDE,index:index+1) = Control(end,:);
RIF = rDE;
end
else
DatiElab(:,index:index+1) = Control; % Tutti i dati dei sensori dell'Array n
RIF = rDE;
end
% Guardo le soglie
[rCheck,cCheck] = size(DatiElab);
if rCheck > 1 && cCheck > 1
% Da Ieri
index1 = find(datenum(Date(:,n))>(now-1));
[rID,~] = size(index1);
if isempty(index1) == 0 && rID ~= 1 % non posso fare la diff
Incrementi_1gg = sqrt((diff(cell2mat(DatiElab(index1(1):end,index))))...
.^2+(diff(cell2mat(DatiElab(index1(1):end,index+1)))).^2);
Date_1gg(1:RIF-index1(1),n) = Date(index1(2):index1(end),n);
% 15 gg
Incrementi_15gg = sqrt((diff(cell2mat(DatiElab(:,index)))).^2+(diff(cell2mat(DatiElab(:,index+1)))).^2);
ST15 = std(Incrementi_15gg(1:index1(1),:)); % 1 Deviazione standard per i 15 giorni
MAX15 = max(Incrementi_15gg(1:index1(1),:));
% 7 gg
index7 = find(datenum(Date(:,n))>(now-7));
Incrementi_7gg = sqrt((diff(cell2mat(DatiElab(index7(1):index1(1),index)))).^2+(diff(cell2mat(DatiElab(index7(1):index1(1),index+1)))).^2);
ST7 = 3*std(Incrementi_7gg); % 3 Deviazioni standard per i 7 giorni
MAX7 = max(Incrementi_7gg);
% 3 gg
index3 = find(datenum(Date(:,n))>(now-3));
Incrementi_3gg = sqrt((diff(cell2mat(DatiElab(index3(1):index1(1),index)))).^2+(diff(cell2mat(DatiElab(index3(1):index1(1),index+1)))).^2);
ST3 = 5*std(Incrementi_3gg); % 5 Deviazioni standard per i 3 giorni
MAX3 = max(Incrementi_3gg);
[rI,cI] = size(Incrementi_1gg); % Dati per quel nodo
soglia3 = zeros(rI,cI);
soglia7 = zeros(rI,cI);
soglia15 = zeros(rI,cI);
for cc = 1:cI
for s = 1:rI
if Incrementi_1gg(s,cc) > ST15+MAX15
soglia15(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST7+MAX7
soglia7(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST3+MAX3
soglia3(s,cc) = 1;
end
if soglia3(s,cc) == 1 && soglia7(s,cc) == 1 && soglia15(s,cc) == 1
Alert_TLHR(s,prog) = 3; % Allerta del nodo di Livello 3
Date_Alert_TLHR(s,prog) = Date_1gg(s,n);
Node_Alert_TLHR(s,prog) = cell2mat(NodoTiltLinkHR(nn,n));
ID_Alert_TLHR(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 && soglia7(s,cc) == 1 || soglia3(s,cc) == 1 && soglia15(s,cc) == 1 || soglia15(s,cc) == 1 && soglia7(s,cc) == 1
Alert_TLHR(s,prog) = 2; % Allerta del nodo di Livello 2
Date_Alert_TLHR(s,prog) = Date_1gg(s,n);
Node_Alert_TLHR(s,prog) = cell2mat(NodoTiltLinkHR(nn,n));
ID_Alert_TLHR(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 || soglia7(s,cc) == 1 || soglia15(s,cc) == 1
Alert_TLHR(s,prog) = 1; % Allerta del nodo di Livello 1
Date_Alert_TLHR(s,prog) = Date_1gg(s,n);
Node_Alert_TLHR(s,prog) = cell2mat(NodoTiltLinkHR(nn,n));
ID_Alert_TLHR(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
end
end
end
end
end
end
index = index+2;
prog = prog+1;
end
text = ['Data of ' char(chainID(n,2)) '-' char(chainID(n,4)) ' Tilt Link HR V have been analyzed'];
fprintf(fileID,fmt,text);
index = 1;
end
end
[num_TLHR,~] = size(rTLHR);
ini = 1;
fin = cumsum(rTLHR);
Num_Allarmi_TLHR = zeros(1,num_TLHR);
for AL = 1:num_TLHR
if ini > fin(AL) % si va a quello dopo
else
Livello = max(max(Alert_TLHR(:,ini:fin(AL))));
if isempty(Livello) == 1
Livello = 0;
end
Num_Allarmi_TLHR(1,AL) = Livello;
ini = fin(AL)+1;
end
end
end
%% In Place Link
if isempty(find(yesIPL)) == 1 % Non ho In Place Link
text = 'In Place Link have not been analyzed during the execution of soglie function';
fprintf(fileID,fmt,text);
Num_Allarmi_IPL = 0;
else
IPL = cumsum(rIPL);
Alert_IPL = zeros(1,IPL(end)); % Livello di Allerta
Date_Alert_IPL = zeros(1,IPL(end)); % Data di Allerta
Node_Alert_IPL = zeros(1,IPL(end)); % Numero di nodo in Allerta
ID_Alert_IPL = cell(1,IPL(end)); % ID centralina - ID catena in Allerta
index = 1;
prog = 1;
for n = 1:col % Ripeto per ogni Array
DatiElab = cell(1);
Date = zeros(1);
if yesIPL(n) == 1
date_rif = now-15; % 15 giorni
for nn = 1:rIPL(n) % Ripeto per ogni nodo
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' ...
num2str(cell2mat(NodoInPlaceLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DateElab = curs.Data;
% Modifico il formato di data e ora in DATini.
[rD,cD] = size(DateElab);
if rD ~= 1 && cD ~= 1
T = [cell2mat(DateElab(:,1)) repmat(' ', [rD,1]) cell2mat(DateElab(:,2))];
if nn == 1
Date(1:rD,n) = datenum(T); % scrivo la matrice date usando il primo nodo
end
comando = ['select XShift, YShift from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' ...
num2str(cell2mat(NodoInPlaceLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Control = curs.Data;
[rCD,~] = size(Control); % Dati del nodo N dell'Array X
[rDE,~] = size(DatiElab);
if rCD ~= rDE
if rCD > rDE
DatiElab(1:rCD,index:index+1) = Control;
RIF = rCD;
elseif rCD < rDE
DatiElab(1:rCD,index:index+1) = Control;
DatiElab(rCD+1:rDE,index:index+1) = Control(end,:);
RIF = rDE;
end
else
DatiElab(:,index:index+1) = Control; % Tutti i dati dei sensori dell'Array n
RIF = rDE;
end
% Guardo le soglie
[rCheck,cCheck] = size(DatiElab);
if rCheck > 1 && cCheck > 1
% Da Ieri
index1 = find(datenum(Date(:,n))>(now-1));
[rID,~] = size(index1);
if isempty(index1) == 0 && rID ~= 1 % non posso fare la diff
Incrementi_1gg = sqrt((diff(cell2mat(DatiElab(index1(1):end,index))))...
.^2+(diff(cell2mat(DatiElab(index1(1):end,index+1)))).^2);
Date_1gg(1:RIF-index1(1),n) = Date(index1(2):index1(end),n);
% 15 gg
Incrementi_15gg = sqrt((diff(cell2mat(DatiElab(:,index)))).^2+(diff(cell2mat(DatiElab(:,index+1)))).^2);
ST15 = std(Incrementi_15gg(1:index1(1),:)); % 1 Deviazione standard per i 15 giorni
MAX15 = max(Incrementi_15gg(1:index1(1),:));
% 7 gg
index7 = find(datenum(Date(:,n))>(now-7));
Incrementi_7gg = sqrt((diff(cell2mat(DatiElab(index7(1):index1(1),index)))).^2+(diff(cell2mat(DatiElab(index7(1):index1(1),index+1)))).^2);
ST7 = 3*std(Incrementi_7gg); % 3 Deviazioni standard per i 7 giorni
MAX7 = max(Incrementi_7gg);
% 3 gg
index3 = find(datenum(Date(:,n))>(now-3));
Incrementi_3gg = sqrt((diff(cell2mat(DatiElab(index3(1):index1(1),index)))).^2+(diff(cell2mat(DatiElab(index3(1):index1(1),index+1)))).^2);
ST3 = 5*std(Incrementi_3gg); % 5 Deviazioni standard per i 3 giorni
MAX3 = max(Incrementi_3gg);
[rI,cI] = size(Incrementi_1gg); % Dati per quel nodo
soglia3 = zeros(rI,cI);
soglia7 = zeros(rI,cI);
soglia15 = zeros(rI,cI);
for cc = 1:cI
for s = 1:rI
if Incrementi_1gg(s,cc) > ST15+MAX15
soglia15(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST7+MAX7
soglia7(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST3+MAX3
soglia3(s,cc) = 1;
end
if soglia3(s,cc) == 1 && soglia7(s,cc) == 1 && soglia15(s,cc) == 1
Alert_IPL(s,prog) = 3; % Allerta del nodo di Livello 3
Date_Alert_IPL(s,prog) = Date_1gg(s,n);
Node_Alert_IPL(s,prog) = cell2mat(NodoInPlaceLink(nn,n));
ID_Alert_IPL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 && soglia7(s,cc) == 1 || soglia3(s,cc) == 1 && soglia15(s,cc) == 1 || soglia15(s,cc) == 1 && soglia7(s,cc) == 1
Alert_IPL(s,prog) = 2; % Allerta del nodo di Livello 2
Date_Alert_IPL(s,prog) = Date_1gg(s,n);
Node_Alert_IPL(s,prog) = cell2mat(NodoInPlaceLink(nn,n));
ID_Alert_IPL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 || soglia7(s,cc) == 1 || soglia15(s,cc) == 1
Alert_IPL(s,prog) = 1; % Allerta del nodo di Livello 1
Date_Alert_IPL(s,prog) = Date_1gg(s,n);
Node_Alert_IPL(s,prog) = cell2mat(NodoInPlaceLink(nn,n));
ID_Alert_IPL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
end
end
end
end
end
end
index = index+2;
prog = prog+1;
end
text = ['Data of ' char(chainID(n,2)) '-' char(chainID(n,4)) ' In Place Link have been analyzed'];
fprintf(fileID,fmt,text);
index = 1;
end
end
[num_IPL,~] = size(rIPL);
ini = 1;
fin = cumsum(rIPL);
Num_Allarmi_IPL = zeros(1,num_IPL);
for AL = 1:num_IPL
if ini > fin(AL) % si va a quello dopo
else
Livello = max(max(Alert_IPL(:,ini:fin(AL))));
if isempty(Livello) == 1
Livello = 0;
end
Num_Allarmi_IPL(1,AL) = Livello;
ini = fin(AL)+1;
end
end
end
%% In Place Link HR
if isempty(find(yesIPLHR)) == 1 % Non ho In Place Link HR
text = 'In Place Link HR have not been analyzed during the execution of soglie function';
fprintf(fileID,fmt,text);
Num_Allarmi_IPLHR = 0;
else
clear Date_1gg
IPLHR = cumsum(rIPLHR);
Alert_IPLHR = zeros(1,IPLHR(end)); % Livello di Allerta
Date_Alert_IPLHR = zeros(1,IPLHR(end)); % Data di Allerta
Node_Alert_IPLHR = zeros(1,IPLHR(end)); % Numero di nodo in Allerta
ID_Alert_IPLHR = cell(1,IPLHR(end)); % ID centralina - ID catena in Allerta
index = 1;
prog = 1;
for n = 1:col % Ripeto per ogni Array
DatiElab = cell(1);
Date = zeros(1);
if yesIPLHR(n) == 1
date_rif = now-15; % 15 giorni
for nn = 1:rIPLHR(n) % Ripeto per ogni nodo
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' ...
num2str(cell2mat(NodoInPlaceLinkHR(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DateElab = curs.Data;
% Modifico il formato di data e ora in DATini.
[rD,cD] = size(DateElab);
if rD ~= 1 && cD ~= 1
T = [cell2mat(DateElab(:,1)) repmat(' ', [rD,1]) cell2mat(DateElab(:,2))];
if nn == 1
Date(1:rD,n) = datenum(T); % scrivo lamatrice date usando il primo nodo
end
comando = ['select XShift, YShift from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' ...
num2str(cell2mat(NodoInPlaceLinkHR(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Control = curs.Data;
[rCD,~] = size(Control);
[rDE,~] = size(DatiElab);
if rCD ~= rDE
if rCD > rDE
DatiElab(1:rCD,index:index+1) = Control;
RIF = rCD;
elseif rCD < rDE
DatiElab(1:rCD,index:index+1) = Control;
DatiElab(rCD+1:rDE,index:index+1) = Control(end,:);
RIF = rDE;
end
else
DatiElab(:,index:index+1) = Control; % Tutti i dati dei sensori dell'Array n
RIF = rDE;
end
% Guardo le soglie
[rCheck,cCheck] = size(DatiElab);
if rCheck > 1 && cCheck > 1
% Da Ieri
index1 = find(datenum(Date(:,n))>(now-1));
[rID,~] = size(index1);
if isempty(index1) == 0 && rID ~= 1 % non posso fare la diff
Incrementi_1gg = sqrt((diff(cell2mat(DatiElab(index1(1):end,index))))...
.^2+(diff(cell2mat(DatiElab(index1(1):end,index+1)))).^2);
Date_1gg(1:RIF-index1(1),n) = Date(index1(2):index1(end),n);
% 15 gg
Incrementi_15gg = sqrt((diff(cell2mat(DatiElab(:,index)))).^2+(diff(cell2mat(DatiElab(:,index+1)))).^2);
ST15 = std(Incrementi_15gg(1:index1(1),:)); % 1 Deviazione standard per i 15 giorni
MAX15 = max(Incrementi_15gg(1:index1(1),:));
% 7 gg
index7 = find(datenum(Date(:,n))>(now-7));
Incrementi_7gg = sqrt((diff(cell2mat(DatiElab(index7(1):index1(1),index)))).^2+(diff(cell2mat(DatiElab(index7(1):index1(1),index+1)))).^2);
ST7 = 3*std(Incrementi_7gg); % 3 Deviazioni standard per i 7 giorni
MAX7 = max(Incrementi_7gg);
% 3 gg
index3 = find(datenum(Date(:,n))>(now-3));
Incrementi_3gg = sqrt((diff(cell2mat(DatiElab(index3(1):index1(1),index)))).^2+(diff(cell2mat(DatiElab(index3(1):index1(1),index+1)))).^2);
ST3 = 5*std(Incrementi_3gg); % 5 Deviazioni standard per i 3 giorni
MAX3 = max(Incrementi_3gg);
[rI,cI] = size(Incrementi_1gg); % Dati per quel nodo
soglia3 = zeros(rI,cI);
soglia7 = zeros(rI,cI);
soglia15 = zeros(rI,cI);
for cc = 1:cI
for s = 1:rI
if Incrementi_1gg(s,cc) > ST15+MAX15
soglia15(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST7+MAX7
soglia7(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST3+MAX3
soglia3(s,cc) = 1;
end
if soglia3(s,cc) == 1 && soglia7(s,cc) == 1 && soglia15(s,cc) == 1
Alert_IPLHR(s,prog) = 3; % Allerta del nodo di Livello 3
Date_Alert_IPLHR(s,prog) = Date_1gg(s,n);
Node_Alert_IPLHR(s,prog) = cell2mat(NodoInPlaceLinkHR(nn,n));
ID_Alert_IPLHR(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 && soglia7(s,cc) == 1 || soglia3(s,cc) == 1 && soglia15(s,cc) == 1 || soglia15(s,cc) == 1 && soglia7(s,cc) == 1
Alert_IPLHR(s,prog) = 2; % Allerta del nodo di Livello 2
Date_Alert_IPLHR(s,prog) = Date_1gg(s,n);
Node_Alert_IPLHR(s,prog) = cell2mat(NodoInPlaceLinkHR(nn,n));
ID_Alert_IPLHR(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 || soglia7(s,cc) == 1 || soglia15(s,cc) == 1
Alert_IPLHR(s,prog) = 1; % Allerta del nodo di Livello 1
Date_Alert_IPLHR(s,prog) = Date_1gg(s,n);
Node_Alert_IPLHR(s,prog) = cell2mat(NodoInPlaceLinkHR(nn,n));
ID_Alert_IPLHR(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
end
end
end
end
end
end
index = index+2;
prog = prog+1;
end
text = ['Data of ' char(chainID(n,2)) '-' char(chainID(n,4)) ' In Place Link HR have been analyzed'];
fprintf(fileID,fmt,text);
index = 1;
end
end
[num_IPLHR,~] = size(rIPLHR);
ini = 1;
fin = cumsum(rIPLHR);
Num_Allarmi_IPLHR = zeros(1,num_IPLHR);
for AL = 1:num_IPLHR
if ini > fin(AL) % si va a quello dopo
else
Livello = max(max(Alert_IPLHR(:,ini:fin(AL))));
if isempty(Livello) == 1
Livello = 0;
end
Num_Allarmi_IPLHR(1,AL) = Livello;
ini = fin(AL)+1;
end
end
end
%% Tilt Link H
if isempty(find(yesTLH)) == 1 % Non ho Tilt Link H
text = 'Tilt Link H have not been analyzed during the execution of soglie function';
fprintf(fileID,fmt,text);
Num_Allarmi_TLH = 0;
else
clear Date_1gg
TLH = cumsum(rTLH);
Alert_TLH = zeros(1,TLH(end)); % Livello di Allerta
Date_Alert_TLH = zeros(1,TLH(end)); % Data di Allerta
Node_Alert_TLH = zeros(1,TLH(end)); % Numero di nodo in Allerta
ID_Alert_TLH = cell(1,TLH(end)); % ID centralina - ID catena in Allerta
index = 1;
prog = 1;
for n = 1:col % Ripeto per ogni Array
DatiElab = cell(1);
Date = zeros(1);
if yesTLH(n) == 1
date_rif = now-15; % 15 giorni
for nn = 1:rTLH(n) % Ripeto per ogni nodo
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' num2str(cell2mat(NodoTiltLinkH(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DateElab = curs.Data;
% Modifico il formato di data e ora in DATini.
[rD,cD] = size(DateElab);
if rD ~= 1 && cD ~= 1
T = [cell2mat(DateElab(:,1)) repmat(' ', [rD,1]) cell2mat(DateElab(:,2))];
if nn == 1
Date(1:rD,n) = datenum(T); % scrivo lamatrice date usando il primo nodo
end
comando = ['select ZShift from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' num2str(cell2mat(NodoTiltLinkH(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Control = curs.Data;
[rCD,~] = size(Control);
[rDE,~] = size(DatiElab);
if rCD ~= rDE
if rCD > rDE
DatiElab(1:rCD,index) = Control;
RIF = rCD;
elseif rCD < rDE
DatiElab(1:rCD,index) = Control;
DatiElab(rCD+1:rDE,index) = Control(end,:);
RIF = rDE;
end
else
DatiElab(:,index) = Control; % Tutti i dati dei sensori dell'Array n
RIF = rDE;
end
% Guardo le soglie
[rCheck,cCheck] = size(DatiElab);
if rCheck > 1 && cCheck > 1
% Da Ieri
index1 = find(datenum(Date(:,n))>(now-1));
[rID,~] = size(index1);
if isempty(index1) == 0 && rID ~= 1 % non posso fare la diff
Incrementi_1gg = abs(diff(cell2mat(DatiElab(index1(1):end,index))));
Date_1gg(1:RIF-index1(1),n) = Date(index1(2):index1(end),n);
% 15 gg
Incrementi_15gg = abs(diff(cell2mat(DatiElab(:,index))));
ST15 = std(Incrementi_15gg(1:index1(1),:)); % 1 Deviazione standard per i 15 giorni
MAX15 = max(Incrementi_15gg(1:index1(1),:));
% 7 gg
index7 = find(datenum(Date(:,n))>(now-7));
Incrementi_7gg = abs(diff(cell2mat(DatiElab(index7(1):index1(1),index))));
ST7 = 3*std(Incrementi_7gg); % 3 Deviazioni standard per i 7 giorni
MAX7 = max(Incrementi_7gg);
% 3 gg
index3 = find(datenum(Date(:,n))>(now-3));
Incrementi_3gg = abs(diff(cell2mat(DatiElab(index3(1):index1(1),index))));
ST3 = 5*std(Incrementi_3gg); % 5 Deviazioni standard per i 3 giorni
MAX3 = max(Incrementi_3gg);
[rI,cI] = size(Incrementi_1gg); % Dati per quel nodo
soglia3 = zeros(rI,cI);
soglia7 = zeros(rI,cI);
soglia15 = zeros(rI,cI);
for cc = 1:cI
for s = 1:rI
if Incrementi_1gg(s,cc) > ST15+MAX15
soglia15(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST7+MAX7
soglia7(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST3+MAX3
soglia3(s,cc) = 1;
end
if soglia3(s,cc) == 1 && soglia7(s,cc) == 1 && soglia15(s,cc) == 1
Alert_TLH(s,prog) = 3; % Allerta del nodo di Livello 3
Date_Alert_TLH(s,prog) = Date_1gg(s,n);
Node_Alert_TLH(s,prog) = cell2mat(NodoTiltLinkH(nn,n));
ID_Alert_TLH(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 && soglia7(s,cc) == 1 || soglia3(s,cc) == 1 && soglia15(s,cc) == 1 || soglia15(s,cc) == 1 && soglia7(s,cc) == 1
Alert_TLH(s,prog) = 2; % Allerta del nodo di Livello 2
Date_Alert_TLH(s,prog) = Date_1gg(s,n);
Node_Alert_TLH(s,prog) = cell2mat(NodoTiltLinkH(nn,n));
ID_Alert_TLH(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 || soglia7(s,cc) == 1 || soglia15(s,cc) == 1
Alert_TLH(s,prog) = 1; % Allerta del nodo di Livello 1
Date_Alert_TLH(s,prog) = Date_1gg(s,n);
Node_Alert_TLH(s,prog) = cell2mat(NodoTiltLinkH(nn,n));
ID_Alert_TLH(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
end
end
end
end
end
end
index = index+1;
prog = prog+1;
end
text = ['Data of ' char(chainID(n,2)) '-' char(chainID(n,4)) ' Tilt Link H have been analyzed'];
fprintf(fileID,fmt,text);
index = 1;
end
end
[num_TLH,~] = size(rTLH);
ini = 1;
fin = cumsum(rTLH);
Num_Allarmi_TLH = zeros(1,num_TLH);
for AL = 1:num_TLH
if ini > fin(AL) % si va a quello dopo
else
Livello = max(max(Alert_TLH(:,ini:fin(AL))));
if isempty(Livello) == 1
Livello = 0;
end
Num_Allarmi_TLH(1,AL) = Livello;
ini = fin(AL)+1;
end
end
end
%% Tilt Link HR H
if isempty(find(yesTLHRH)) == 1 % Non ho Tilt Link HR H
text = 'Tilt Link HR H have not been analyzed during the execution of soglie function';
fprintf(fileID,fmt,text);
Num_Allarmi_TLHRH = 0;
else
clear Date_1gg
TLHRH = cumsum(rTLHRH);
Alert_TLHRH = zeros(1,TLHRH(end)); % Livello di Allerta
Date_Alert_TLHRH = zeros(1,TLHRH(end)); % Data di Allerta
Node_Alert_TLHRH = zeros(1,TLHRH(end)); % Numero di nodo in Allerta
ID_Alert_TLHRH = cell(1,TLHRH(end)); % ID centralina - ID catena in Allerta
index = 1;
prog = 1;
for n = 1:col % Ripeto per ogni Array
DatiElab = cell(1);
Date = zeros(1);
if yesTLHRH(n) == 1
date_rif = now-15; % 15 giorni
for nn = 1:rTLHRH(n) % Ripeto per ogni nodo
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' num2str(cell2mat(NodoTiltLinkHRH(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DateElab = curs.Data;
% Modifico il formato di data e ora in DATini.
[rD,cD] = size(DateElab);
if rD ~= 1 && cD ~= 1
T = [cell2mat(DateElab(:,1)) repmat(' ', [rD,1]) cell2mat(DateElab(:,2))];
if nn == 1
Date(1:rD,n) = datenum(T); % scrivo lamatrice date usando il primo nodo
end
comando = ['select ZShift from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' num2str(cell2mat(NodoTiltLinkHRH(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Control = curs.Data;
[rCD,~] = size(Control);
[rDE,~] = size(DatiElab);
if rCD ~= rDE
if rCD > rDE
DatiElab(1:rCD,index) = Control;
RIF = rCD;
elseif rCD < rDE
DatiElab(1:rCD,index) = Control;
DatiElab(rCD+1:rDE,index) = Control(end,:);
RIF = rDE;
end
else
DatiElab(:,index) = Control; % Tutti i dati dei sensori dell'Array n
RIF = rDE;
end
% Guardo le soglie
[rCheck,cCheck] = size(DatiElab);
if rCheck > 1 && cCheck > 1
% Da Ieri
index1 = find(datenum(Date(:,n))>(now-1));
[rID,~] = size(index1);
if isempty(index1) == 0 && rID ~= 1 % non posso fare la diff
Incrementi_1gg = abs(diff(cell2mat(DatiElab(index1(1):end,index))));
Date_1gg(1:RIF-index1(1),n) = Date(index1(2):index1(end),n);
% 15 gg
Incrementi_15gg = abs(diff(cell2mat(DatiElab(:,index))));
ST15 = std(Incrementi_15gg(1:index1(1),:)); % 1 Deviazione standard per i 15 giorni
MAX15 = max(Incrementi_15gg(1:index1(1),:));
% 7 gg
index7 = find(datenum(Date(:,n))>(now-7));
Incrementi_7gg = abs(diff(cell2mat(DatiElab(index7(1):index1(1),index))));
ST7 = 3*std(Incrementi_7gg); % 3 Deviazioni standard per i 7 giorni
MAX7 = max(Incrementi_7gg);
% 3 gg
index3 = find(datenum(Date(:,n))>(now-3));
Incrementi_3gg = abs(diff(cell2mat(DatiElab(index3(1):index1(1),index))));
ST3 = 5*std(Incrementi_3gg); % 5 Deviazioni standard per i 3 giorni
MAX3 = max(Incrementi_3gg);
[rI,cI] = size(Incrementi_1gg); % Dati per quel nodo
soglia3 = zeros(rI,cI);
soglia7 = zeros(rI,cI);
soglia15 = zeros(rI,cI);
for cc = 1:cI
for s = 1:rI
if Incrementi_1gg(s,cc) > ST15+MAX15
soglia15(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST7+MAX7
soglia7(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST3+MAX3
soglia3(s,cc) = 1;
end
if soglia3(s,cc) == 1 && soglia7(s,cc) == 1 && soglia15(s,cc) == 1
Alert_TLHRH(s,prog) = 3; % Allerta del nodo di Livello 3
Date_Alert_TLHRH(s,prog) = Date_1gg(s,n);
Node_Alert_TLHRH(s,prog) = cell2mat(NodoTiltLinkHRH(nn,n));
ID_Alert_TLHRH(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 && soglia7(s,cc) == 1 || soglia3(s,cc) == 1 && soglia15(s,cc) == 1 || soglia15(s,cc) == 1 && soglia7(s,cc) == 1
Alert_TLHRH(s,prog) = 2; % Allerta del nodo di Livello 2
Date_Alert_TLHRH(s,prog) = Date_1gg(s,n);
Node_Alert_TLHRH(s,prog) = cell2mat(NodoTiltLinkHRH(nn,n));
ID_Alert_TLHRH(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 || soglia7(s,cc) == 1 || soglia15(s,cc) == 1
Alert_TLHRH(s,prog) = 1; % Allerta del nodo di Livello 1
Date_Alert_TLHRH(s,prog) = Date_1gg(s,n);
Node_Alert_TLHRH(s,prog) = cell2mat(NodoTiltLinkHRH(nn,n));
ID_Alert_TLHRH(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
end
end
end
end
end
end
index = index+1;
prog = prog+1;
end
text = ['Data of ' char(chainID(n,2)) '-' char(chainID(n,4)) ' Tilt Link HR H have been analyzed'];
fprintf(fileID,fmt,text);
index = 1;
end
end
[num_TLHRH,~] = size(rTLHRH);
ini = 1;
fin = cumsum(rTLHRH);
Num_Allarmi_TLHRH = zeros(1,num_TLHRH);
for AL = 1:num_TLHRH
if ini > fin(AL) % si va a quello dopo
else
Livello = max(max(Alert_TLHRH(:,ini:fin(AL))));
if isempty(Livello) == 1
Livello = 0;
end
Num_Allarmi_TLHRH(1,AL) = Livello;
ini = fin(AL)+1;
end
end
end
%% Tunnel Link
if isempty(find(yesTuL)) == 1 % Non ho Tunnel Link
text = 'Tunnel Link have not been analyzed during the execution of soglie function';
fprintf(fileID,fmt,text);
Num_Allarmi_TuL = 0;
else
TuL = cumsum(rTuL);
Alert_TuL = zeros(1,TuL(end)); % Livello di Allerta
Date_Alert_TuL = zeros(1,TuL(end)); % Data di Allerta
Node_Alert_TuL = zeros(1,TuL(end)); % Numero di nodo in Allerta
ID_Alert_TuL = cell(1,TuL(end)); % ID centralina - ID catena in Allerta
index = 1;
prog = 1;
for n = 1:col % Ripeto per ogni Array
DatiElab = cell(1);
Date = zeros(1);
if yesTuL(n) == 1
date_rif = now-15; % 15 giorni
for nn = 1:rTuL(n) % Ripeto per ogni nodo
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' ...
num2str(cell2mat(NodoTunnelLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DateElab = curs.Data;
% Modifico il formato di data e ora in DATini.
[rD,cD] = size(DateElab);
if rD ~= 1 && cD ~= 1
T = [cell2mat(DateElab(:,1)) repmat(' ', [rD,1]) cell2mat(DateElab(:,2))];
if nn == 1
Date(1:rD,n) = datenum(T); % scrivo la matrice date usando il primo nodo
end
comando = ['select XShift, ZShift from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' ...
num2str(cell2mat(NodoTunnelLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Control = curs.Data;
[rCD,~] = size(Control); % Dati del nodo N dell'Array X
[rDE,~] = size(DatiElab);
if rCD ~= rDE
if rCD > rDE
DatiElab(1:rCD,index:index+1) = Control;
RIF = rCD;
elseif rCD < rDE
DatiElab(1:rCD,index:index+1) = Control;
DatiElab(rCD+1:rDE,index:index+1) = Control(end,:);
RIF = rDE;
end
else
DatiElab(:,index:index+1) = Control; % Tutti i dati dei sensori dell'Array n
RIF = rDE;
end
% Guardo le soglie
[rCheck,cCheck] = size(DatiElab);
if rCheck > 1 && cCheck > 1
% Da Ieri
index1 = find(datenum(Date(:,n))>(now-1));
[rID,~] = size(index1);
if isempty(index1) == 0 && rID ~= 1 % non posso fare la diff
Incrementi_1gg = sqrt((diff(cell2mat(DatiElab(index1(1):end,index))))...
.^2+(diff(cell2mat(DatiElab(index1(1):end,index+1)))).^2);
Date_1gg(1:RIF-index1(1),n) = Date(index1(2):index1(end),n);
% 15 gg
Incrementi_15gg = sqrt((diff(cell2mat(DatiElab(:,index)))).^2+(diff(cell2mat(DatiElab(:,index+1)))).^2);
ST15 = std(Incrementi_15gg(1:index1(1),:)); % 1 Deviazione standard per i 15 giorni
MAX15 = max(Incrementi_15gg(1:index1(1),:));
% 7 gg
index7 = find(datenum(Date(:,n))>(now-7));
Incrementi_7gg = sqrt((diff(cell2mat(DatiElab(index7(1):index1(1),index)))).^2+(diff(cell2mat(DatiElab(index7(1):index1(1),index+1)))).^2);
ST7 = 3*std(Incrementi_7gg); % 3 Deviazioni standard per i 7 giorni
MAX7 = max(Incrementi_7gg);
% 3 gg
index3 = find(datenum(Date(:,n))>(now-3));
Incrementi_3gg = sqrt((diff(cell2mat(DatiElab(index3(1):index1(1),index)))).^2+(diff(cell2mat(DatiElab(index3(1):index1(1),index+1)))).^2);
ST3 = 5*std(Incrementi_3gg); % 5 Deviazioni standard per i 3 giorni
MAX3 = max(Incrementi_3gg);
[rI,cI] = size(Incrementi_1gg); % Dati per quel nodo
soglia3 = zeros(rI,cI);
soglia7 = zeros(rI,cI);
soglia15 = zeros(rI,cI);
for cc = 1:cI
for s = 1:rI
if Incrementi_1gg(s,cc) > ST15+MAX15
soglia15(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST7+MAX7
soglia7(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST3+MAX3
soglia3(s,cc) = 1;
end
if soglia3(s,cc) == 1 && soglia7(s,cc) == 1 && soglia15(s,cc) == 1
Alert_TuL(s,prog) = 3; % Allerta del nodo di Livello 3
Date_Alert_TuL(s,prog) = Date_1gg(s,n);
Node_Alert_TuL(s,prog) = cell2mat(NodoTunnelLink(nn,n));
ID_Alert_TuL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 && soglia7(s,cc) == 1 || soglia3(s,cc) == 1 && soglia15(s,cc) == 1 || soglia15(s,cc) == 1 && soglia7(s,cc) == 1
Alert_TuL(s,prog) = 2; % Allerta del nodo di Livello 2
Date_Alert_TuL(s,prog) = Date_1gg(s,n);
Node_Alert_TuL(s,prog) = cell2mat(NodoTunnelLink(nn,n));
ID_Alert_TuL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 || soglia7(s,cc) == 1 || soglia15(s,cc) == 1
Alert_TuL(s,prog) = 1; % Allerta del nodo di Livello 1
Date_Alert_TuL(s,prog) = Date_1gg(s,n);
Node_Alert_TuL(s,prog) = cell2mat(NodoTunnelLink(nn,n));
ID_Alert_TuL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
end
end
end
end
end
end
index = index+2;
prog = prog+1;
end
text = ['Data of ' char(chainID(n,2)) '-' char(chainID(n,4)) ' Tunnel Link have been analyzed'];
fprintf(fileID,fmt,text);
index = 1;
end
end
[num_TuL,~] = size(rTuL);
ini = 1;
fin = cumsum(rTuL);
Num_Allarmi_TuL = zeros(1,num_TuL);
for AL = 1:num_TuL
if ini > fin(AL) % si va a quello dopo
else
Livello = max(max(Alert_TuL(:,ini:fin(AL))));
if isempty(Livello) == 1
Livello = 0;
end
Num_Allarmi_TuL(1,AL) = Livello;
ini = fin(AL)+1;
end
end
end
%% Radial Link
if isempty(find(yesRL)) == 1 % Non ho Radial Link
text = 'Radial Link have not been analyzed during the execution of soglie function';
fprintf(fileID,fmt,text);
Num_Allarmi_RL = 0;
else
RL = cumsum(rRL);
Alert_RL = zeros(1,RL(end)); % Livello di Allerta
Date_Alert_RL = zeros(1,RL(end)); % Data di Allerta
Node_Alert_RL = zeros(1,RL(end)); % Numero di nodo in Allerta
ID_Alert_RL = cell(1,RL(end)); % ID centralina - ID catena in Allerta
index = 1;
prog = 1;
for n = 1:col % Ripeto per ogni Array
DatiElab = cell(1);
Date = zeros(1);
if yesRL(n) == 1
date_rif = now-15; % 15 giorni
for nn = 1:rRL(n) % Ripeto per ogni nodo
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' ...
num2str(cell2mat(NodoRadialLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DateElab = curs.Data;
% Modifico il formato di data e ora in DATini.
[rD,cD] = size(DateElab);
if rD ~= 1 && cD ~= 1
T = [cell2mat(DateElab(:,1)) repmat(' ', [rD,1]) cell2mat(DateElab(:,2))];
if nn == 1
Date(1:rD,n) = datenum(T); % scrivo la matrice date usando il primo nodo
end
comando = ['select XShift, YShift, ZShift from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' ...
num2str(cell2mat(NodoRadialLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Control = curs.Data;
[rCD,~] = size(Control); % Dati del nodo N dell'Array X
[rDE,~] = size(DatiElab);
if rCD ~= rDE
if rCD > rDE
DatiElab(1:rCD,index:index+2) = Control;
RIF = rCD;
elseif rCD < rDE
DatiElab(1:rCD,index:index+2) = Control;
DatiElab(rCD+1:rDE,index:index+2) = Control(end,:);
RIF = rDE;
end
else
DatiElab(:,index:index+2) = Control; % Tutti i dati dei sensori dell'Array n
RIF = rDE;
end
% Guardo le soglie
[rCheck,cCheck] = size(DatiElab);
if rCheck > 1 && cCheck > 1
% Da Ieri
index1 = find(datenum(Date(:,n))>(now-1));
[rID,~] = size(index1);
if isempty(index1) == 0 && rID ~= 1 % non posso fare la diff
Incrementi_1gg = sqrt((diff(cell2mat(DatiElab(index1(1):end,index))))...
.^2+(diff(cell2mat(DatiElab(index1(1):end,index+1)))).^2+...
+(diff(cell2mat(DatiElab(index1(1):end,index+2)))).^2);
Date_1gg(1:RIF-index1(1),n) = Date(index1(2):index1(end),n);
% 15 gg
Incrementi_15gg = sqrt((diff(cell2mat(DatiElab(:,index)))).^2+...
(diff(cell2mat(DatiElab(:,index+1)))).^2 ...
+(diff(cell2mat(DatiElab(:,index+2)))).^2);
ST15 = std(Incrementi_15gg(1:index1(1),:)); % 1 Deviazione standard per i 15 giorni
MAX15 = max(Incrementi_15gg(1:index1(1),:));
% 7 gg
index7 = find(datenum(Date(:,n))>(now-7));
Incrementi_7gg = sqrt((diff(cell2mat(DatiElab(index7(1):index1(1),index)))).^2+...
(diff(cell2mat(DatiElab(index7(1):index1(1),index+1)))).^2+...
(diff(cell2mat(DatiElab(index7(1):index1(1),index+2)))).^2);
ST7 = 3*std(Incrementi_7gg); % 3 Deviazioni standard per i 7 giorni
MAX7 = max(Incrementi_7gg);
% 3 gg
index3 = find(datenum(Date(:,n))>(now-3));
Incrementi_3gg = sqrt((diff(cell2mat(DatiElab(index3(1):index1(1),index)))).^2+...
(diff(cell2mat(DatiElab(index3(1):index1(1),index+1)))).^2+...
(diff(cell2mat(DatiElab(index3(1):index1(1),index+2)))).^2);
ST3 = 5*std(Incrementi_3gg); % 5 Deviazioni standard per i 3 giorni
MAX3 = max(Incrementi_3gg);
[rI,cI] = size(Incrementi_1gg); % Dati per quel nodo
soglia3 = zeros(rI,cI);
soglia7 = zeros(rI,cI);
soglia15 = zeros(rI,cI);
for cc = 1:cI
for s = 1:rI
if Incrementi_1gg(s,cc) > ST15+MAX15
soglia15(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST7+MAX7
soglia7(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST3+MAX3
soglia3(s,cc) = 1;
end
if soglia3(s,cc) == 1 && soglia7(s,cc) == 1 && soglia15(s,cc) == 1
Alert_RL(s,prog) = 3; % Allerta del nodo di Livello 3
Date_Alert_RL(s,prog) = Date_1gg(s,n);
Node_Alert_RL(s,prog) = cell2mat(NodoTiltLink(nn,n));
ID_Alert_RL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 && soglia7(s,cc) == 1 || soglia3(s,cc) == 1 && soglia15(s,cc) == 1 || soglia15(s,cc) == 1 && soglia7(s,cc) == 1
Alert_RL(s,prog) = 2; % Allerta del nodo di Livello 2
Date_Alert_RL(s,prog) = Date_1gg(s,n);
Node_Alert_RL(s,prog) = cell2mat(NodoTiltLink(nn,n));
ID_Alert_RL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 || soglia7(s,cc) == 1 || soglia15(s,cc) == 1
Alert_RL(s,prog) = 1; % Allerta del nodo di Livello 1
Date_Alert_RL(s,prog) = Date_1gg(s,n);
Node_Alert_RL(s,prog) = cell2mat(NodoTiltLink(nn,n));
ID_Alert_RL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
end
end
end
end
end
end
index = index+3;
prog = prog+1;
end
text = ['Data of ' char(chainID(n,2)) '-' char(chainID(n,4)) ' Radial Link have been analyzed'];
fprintf(fileID,fmt,text);
index = 1;
end
end
[num_RL,~] = size(rRL);
ini = 1;
fin = cumsum(rRL);
Num_Allarmi_RL = zeros(1,num_RL);
for AL = 1:num_RL
if ini > fin(AL) % si va a quello dopo
else
Livello = max(max(Alert_RL(:,ini:fin(AL))));
if isempty(Livello) == 1
Livello = 0;
end
Num_Allarmi_RL(1,AL) = Livello;
ini = fin(AL)+1;
end
end
end
%% PreConv Link
if isempty(find(yesPCL)) == 1 % Non ho PreConv Link
text = 'PreConv Link have not been analyzed during the execution of soglie function';
fprintf(fileID,fmt,text);
Num_Allarmi_PCL = 0;
else
clear Date_1gg
PCL = cumsum(rPCL);
Alert_PCL = zeros(1,PCL(end)); % Livello di Allerta
Date_Alert_PCL = zeros(1,PCL(end)); % Data di Allerta
Node_Alert_PCL = zeros(1,PCL(end)); % Numero di nodo in Allerta
ID_Alert_PCL = cell(1,PCL(end)); % ID centralina - ID catena in Allerta
index = 1;
prog = 1;
for n = 1:col % Ripeto per ogni Array
DatiElab = cell(1);
Date = zeros(1);
if yesPCL(n) == 1
date_rif = now-15; % 15 giorni
for nn = 1:rPCL(n) % Ripeto per ogni nodo
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' ...
num2str(cell2mat(NodoPreConvLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DateElab = curs.Data;
% Modifico il formato di data e ora in DATini.
[rD,cD] = size(DateElab);
if rD ~= 1 && cD ~= 1
T = [cell2mat(DateElab(:,1)) repmat(' ', [rD,1]) cell2mat(DateElab(:,2))];
if nn == 1
Date(1:rD,n) = datenum(T); % scrivo lamatrice date usando il primo nodo
end
comando = ['select ZShift from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' ...
num2str(cell2mat(NodoPreConvLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Control = curs.Data;
[rCD,~] = size(Control);
[rDE,~] = size(DatiElab);
if rCD ~= rDE
if rCD > rDE
DatiElab(1:rCD,index) = Control;
RIF = rCD;
elseif rCD < rDE
DatiElab(1:rCD,index) = Control;
DatiElab(rCD+1:rDE,index) = Control(end,:);
RIF = rDE;
end
else
DatiElab(:,index) = Control; % Tutti i dati dei sensori dell'Array n
RIF = rDE;
end
% Guardo le soglie
[rCheck,cCheck] = size(DatiElab);
if rCheck > 1 && cCheck > 1
% Da Ieri
index1 = find(datenum(Date(:,n))>(now-1));
[rID,~] = size(index1);
if isempty(index1) == 0 && rID ~= 1 % non posso fare la diff
Incrementi_1gg = abs(diff(cell2mat(DatiElab(index1(1):end,index))));
Date_1gg(1:RIF-index1(1),n) = Date(index1(2):index1(end),n);
% 15 gg
Incrementi_15gg = abs(diff(cell2mat(DatiElab(:,index))));
ST15 = std(Incrementi_15gg(1:index1(1),:)); % 1 Deviazione standard per i 15 giorni
MAX15 = max(Incrementi_15gg(1:index1(1),:));
% 7 gg
index7 = find(datenum(Date(:,n))>(now-7));
Incrementi_7gg = abs(diff(cell2mat(DatiElab(index7(1):index1(1),index))));
ST7 = 3*std(Incrementi_7gg); % 3 Deviazioni standard per i 7 giorni
MAX7 = max(Incrementi_7gg);
% 3 gg
index3 = find(datenum(Date(:,n))>(now-3));
Incrementi_3gg = abs(diff(cell2mat(DatiElab(index3(1):index1(1),index))));
ST3 = 5*std(Incrementi_3gg); % 5 Deviazioni standard per i 3 giorni
MAX3 = max(Incrementi_3gg);
[rI,cI] = size(Incrementi_1gg); % Dati per quel nodo
soglia3 = zeros(rI,cI);
soglia7 = zeros(rI,cI);
soglia15 = zeros(rI,cI);
for cc = 1:cI
for s = 1:rI
if Incrementi_1gg(s,cc) > ST15+MAX15
soglia15(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST7+MAX7
soglia7(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST3+MAX3
soglia3(s,cc) = 1;
end
if soglia3(s,cc) == 1 && soglia7(s,cc) == 1 && soglia15(s,cc) == 1
Alert_PCL(s,prog) = 3; % Allerta del nodo di Livello 3
Date_Alert_PCL(s,prog) = Date_1gg(s,n);
Node_Alert_PCL(s,prog) = cell2mat(NodoPreConvLink(nn,n));
ID_Alert_PCL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 && soglia7(s,cc) == 1 || soglia3(s,cc) == 1 && soglia15(s,cc) == 1 || soglia15(s,cc) == 1 && soglia7(s,cc) == 1
Alert_PCL(s,prog) = 2; % Allerta del nodo di Livello 2
Date_Alert_PCL(s,prog) = Date_1gg(s,n);
Node_Alert_PCL(s,prog) = cell2mat(NodoPreConvLink(nn,n));
ID_Alert_PCL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 || soglia7(s,cc) == 1 || soglia15(s,cc) == 1
Alert_PCL(s,prog) = 1; % Allerta del nodo di Livello 1
Date_Alert_PCL(s,prog) = Date_1gg(s,n);
Node_Alert_PCL(s,prog) = cell2mat(NodoPreConvLink(nn,n));
ID_Alert_PCL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
end
end
end
end
end
end
index = index+1;
prog = prog+1;
end
text = ['Data of ' char(chainID(n,2)) '-' char(chainID(n,4)) ' PreConv Link have been analyzed'];
fprintf(fileID,fmt,text);
index = 1;
end
end
[num_PCL,~] = size(rPCL);
ini = 1;
fin = cumsum(rPCL);
Num_Allarmi_PCL = zeros(1,num_PCL);
for AL = 1:num_PCL
if ini > fin(AL) % si va a quello dopo
else
Livello = max(max(Alert_PCL(:,ini:fin(AL))));
if isempty(Livello) == 1
Livello = 0;
end
Num_Allarmi_PCL(1,AL) = Livello;
ini = fin(AL)+1;
end
end
end
%% PreConv Link HR
if isempty(find(yesPCLHR)) == 1 % Non ho PreConv Link HR
text = 'PreConv Link HR have not been analyzed during the execution of soglie function';
fprintf(fileID,fmt,text);
Num_Allarmi_PCLHR = 0;
else
clear Date_1gg
PCLHR = cumsum(rPCLHR);
Alert_PCLHR = zeros(1,PCLHR(end)); % Livello di Allerta
Date_Alert_PCLHR = zeros(1,PCLHR(end)); % Data di Allerta
Node_Alert_PCLHR = zeros(1,PCLHR(end)); % Numero di nodo in Allerta
ID_Alert_PCLHR = cell(1,PCLHR(end)); % ID centralina - ID catena in Allerta
index = 1;
prog = 1;
for n = 1:col % Ripeto per ogni Array
DatiElab = cell(1);
Date = zeros(1);
if yesPCLHR(n) == 1
date_rif = now-15; % 15 giorni
for nn = 1:rPCLHR(n) % Ripeto per ogni nodo
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' ...
num2str(cell2mat(NodoPreConvLinkHR(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DateElab = curs.Data;
% Modifico il formato di data e ora in DATini.
[rD,cD] = size(DateElab);
if rD ~= 1 && cD ~= 1
T = [cell2mat(DateElab(:,1)) repmat(' ', [rD,1]) cell2mat(DateElab(:,2))];
if nn == 1
Date(1:rD,n) = datenum(T); % scrivo lamatrice date usando il primo nodo
end
comando = ['select ZShift from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' ...
num2str(cell2mat(NodoPreConvLinkHR(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Control = curs.Data;
[rCD,~] = size(Control);
[rDE,~] = size(DatiElab);
if rCD ~= rDE
if rCD > rDE
DatiElab(1:rCD,index) = Control;
RIF = rCD;
elseif rCD < rDE
DatiElab(1:rCD,index) = Control;
DatiElab(rCD+1:rDE,index) = Control(end,:);
RIF = rDE;
end
else
DatiElab(:,index) = Control; % Tutti i dati dei sensori dell'Array n
RIF = rDE;
end
% Guardo le soglie
[rCheck,cCheck] = size(DatiElab);
if rCheck > 1 && cCheck > 1
% Da Ieri
index1 = find(datenum(Date(:,n))>(now-1));
[rID,~] = size(index1);
if isempty(index1) == 0 && rID ~= 1 % non posso fare la diff
Incrementi_1gg = abs(diff(cell2mat(DatiElab(index1(1):end,index))));
Date_1gg(1:RIF-index1(1),n) = Date(index1(2):index1(end),n);
% 15 gg
Incrementi_15gg = abs(diff(cell2mat(DatiElab(:,index))));
ST15 = std(Incrementi_15gg(1:index1(1),:)); % 1 Deviazione standard per i 15 giorni
MAX15 = max(Incrementi_15gg(1:index1(1),:));
% 7 gg
index7 = find(datenum(Date(:,n))>(now-7));
Incrementi_7gg = abs(diff(cell2mat(DatiElab(index7(1):index1(1),index))));
ST7 = 3*std(Incrementi_7gg); % 3 Deviazioni standard per i 7 giorni
MAX7 = max(Incrementi_7gg);
% 3 gg
index3 = find(datenum(Date(:,n))>(now-3));
Incrementi_3gg = abs(diff(cell2mat(DatiElab(index3(1):index1(1),index))));
ST3 = 5*std(Incrementi_3gg); % 5 Deviazioni standard per i 3 giorni
MAX3 = max(Incrementi_3gg);
[rI,cI] = size(Incrementi_1gg); % Dati per quel nodo
soglia3 = zeros(rI,cI);
soglia7 = zeros(rI,cI);
soglia15 = zeros(rI,cI);
for cc = 1:cI
for s = 1:rI
if Incrementi_1gg(s,cc) > ST15+MAX15
soglia15(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST7+MAX7
soglia7(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST3+MAX3
soglia3(s,cc) = 1;
end
if soglia3(s,cc) == 1 && soglia7(s,cc) == 1 && soglia15(s,cc) == 1
Alert_PCLHR(s,prog) = 3; % Allerta del nodo di Livello 3
Date_Alert_PCLHR(s,prog) = Date_1gg(s,n);
Node_Alert_PCLHR(s,prog) = cell2mat(NodoTiltLinkH(nn,n));
ID_Alert_PCLHR(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 && soglia7(s,cc) == 1 || soglia3(s,cc) == 1 && soglia15(s,cc) == 1 || soglia15(s,cc) == 1 && soglia7(s,cc) == 1
Alert_PCLHR(s,prog) = 2; % Allerta del nodo di Livello 2
Date_Alert_PCLHR(s,prog) = Date_1gg(s,n);
Node_Alert_PCLHR(s,prog) = cell2mat(NodoTiltLinkH(nn,n));
ID_Alert_PCLHR(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 || soglia7(s,cc) == 1 || soglia15(s,cc) == 1
Alert_PCLHR(s,prog) = 1; % Allerta del nodo di Livello 1
Date_Alert_PCLHR(s,prog) = Date_1gg(s,n);
Node_Alert_PCLHR(s,prog) = cell2mat(NodoTiltLinkH(nn,n));
ID_Alert_PCLHR(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
end
end
end
end
end
end
index = index+1;
prog = prog+1;
end
text = ['Data of ' char(chainID(n,2)) '-' char(chainID(n,4)) ' PreConv Link HR have been analyzed'];
fprintf(fileID,fmt,text);
index = 1;
end
end
[num_PCLHR,~] = size(rPCLHR);
ini = 1;
fin = cumsum(rPCLHR);
Num_Allarmi_PCLHR = zeros(1,num_PCLHR);
for AL = 1:num_PCLHR
if ini > fin(AL) % si va a quello dopo
else
Livello = max(max(Alert_PCLHR(:,ini:fin(AL))));
if isempty(Livello) == 1
Livello = 0;
end
Num_Allarmi_PCLHR(1,AL) = Livello;
ini = fin(AL)+1;
end
end
end
%% Piezo Link
if isempty(find(yesPL)) == 1 % Non ho Piezo Link
text = 'Piezo Link have not been analyzed during the execution of soglie function';
fprintf(fileID,fmt,text);
Num_Allarmi_PL = 0;
else
clear Date_1gg
PL = cumsum(rPL);
Alert_PL = zeros(1,PL(end)); % Livello di Allerta
Date_Alert_PL = zeros(1,PL(end)); % Data di Allerta
Node_Alert_PL = zeros(1,PL(end)); % Numero di nodo in Allerta
ID_Alert_PL = cell(1,PL(end)); % ID centralina - ID catena in Allerta
index = 1;
prog = 1;
for n = 1:col % Ripeto per ogni Array
DatiElab = cell(1);
Date = zeros(1);
if yesPL(n) == 1
date_rif = now-15; % 15 giorni
for nn = 1:rPL(n) % Ripeto per ogni nodo
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' num2str(cell2mat(NodoPiezoLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DateElab = curs.Data;
% Modifico il formato di data e ora in DATini.
[rD,cD] = size(DateElab);
if rD ~= 1 && cD ~= 1
T = [cell2mat(DateElab(:,1)) repmat(' ', [rD,1]) cell2mat(DateElab(:,2))];
if nn == 1
Date(1:rD,n) = datenum(T); % scrivo la matrice date usando il primo nodo
end
comando = ['select water_level from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' num2str(cell2mat(NodoPiezoLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Control = curs.Data;
[rCD,~] = size(Control);
[rDE,~] = size(DatiElab);
if rCD ~= rDE
if rCD > rDE
DatiElab(1:rCD,index) = Control;
RIF = rCD;
elseif rCD < rDE
DatiElab(1:rCD,index) = Control;
DatiElab(rCD+1:rDE,index) = Control(end,:);
RIF = rDE;
end
else
DatiElab(:,index) = Control; % Tutti i dati dei sensori dell'Array n
RIF = rDE;
end
% Guardo le soglie
[rCheck,cCheck] = size(DatiElab);
if rCheck > 1 && cCheck > 1
% Da Ieri
index1 = find(datenum(Date(:,n))>(now-1));
[rID,~] = size(index1);
if isempty(index1) == 0 && rID ~= 1 % non posso fare la diff
Incrementi_1gg = abs(diff(cell2mat(DatiElab(index1(1):end,index))));
Date_1gg(1:RIF-index1(1),n) = Date(index1(2):index1(end),n);
% 15 gg
Incrementi_15gg = abs(diff(cell2mat(DatiElab(:,index))));
ST15 = std(Incrementi_15gg(1:index1(1),:)); % 1 Deviazione standard per i 15 giorni
MAX15 = max(Incrementi_15gg(1:index1(1),:));
% 7 gg
index7 = find(datenum(Date(:,n))>(now-7));
Incrementi_7gg = abs(diff(cell2mat(DatiElab(index7(1):index1(1),index))));
ST7 = 3*std(Incrementi_7gg); % 3 Deviazioni standard per i 7 giorni
MAX7 = max(Incrementi_7gg);
% 3 gg
index3 = find(datenum(Date(:,n))>(now-3));
Incrementi_3gg = abs(diff(cell2mat(DatiElab(index3(1):index1(1),index))));
ST3 = 5*std(Incrementi_3gg); % 5 Deviazioni standard per i 3 giorni
MAX3 = max(Incrementi_3gg);
[rI,cI] = size(Incrementi_1gg); % Dati per quel nodo
soglia3 = zeros(rI,cI);
soglia7 = zeros(rI,cI);
soglia15 = zeros(rI,cI);
for cc = 1:cI
for s = 1:rI
if Incrementi_1gg(s,cc) > ST15+MAX15
soglia15(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST7+MAX7
soglia7(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST3+MAX3
soglia3(s,cc) = 1;
end
if soglia3(s,cc) == 1 && soglia7(s,cc) == 1 && soglia15(s,cc) == 1
Alert_PL(s,prog) = 3; % Allerta del nodo di Livello 3
Date_Alert_PL(s,prog) = Date_1gg(s,n);
Node_Alert_PL(s,prog) = cell2mat(NodoPiezoLink(nn,n));
ID_Alert_PL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 && soglia7(s,cc) == 1 || soglia3(s,cc) == 1 && soglia15(s,cc) == 1 || soglia15(s,cc) == 1 && soglia7(s,cc) == 1
Alert_PL(s,prog) = 2; % Allerta del nodo di Livello 2
Date_Alert_PL(s,prog) = Date_1gg(s,n);
Node_Alert_PL(s,prog) = cell2mat(NodoPiezoLink(nn,n));
ID_Alert_PL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 || soglia7(s,cc) == 1 || soglia15(s,cc) == 1
Alert_PL(s,prog) = 1; % Allerta del nodo di Livello 1
Date_Alert_PL(s,prog) = Date_1gg(s,n);
Node_Alert_PL(s,prog) = cell2mat(NodoPiezoLink(nn,n));
ID_Alert_PL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
end
end
end
end
end
end
index = index+1;
prog = prog+1;
end
text = ['Data of ' char(chainID(n,2)) '-' char(chainID(n,4)) ' Piezo Link have been analyzed'];
fprintf(fileID,fmt,text);
index = 1;
end
end
[num_PL,~] = size(rPL);
ini = 1;
fin = cumsum(rPL);
Num_Allarmi_PL = zeros(1,num_PL);
for AL = 1:num_PL
if ini > fin(AL) % si va a quello dopo
else
Livello = max(max(Alert_PL(:,ini:fin(AL))));
if isempty(Livello) == 1
Livello = 0;
end
Num_Allarmi_PL(1,AL) = Livello;
ini = fin(AL)+1;
end
end
end
%% Klino Link
if isempty(find(yesKL)) == 1 % Non ho Klino Link
text = 'Klino Link have not been analyzed during the execution of soglie function';
fprintf(fileID,fmt,text);
Num_Allarmi_KL = 0;
else
clear Date_1gg
K = cumsum(rKL);
Alert_KL = zeros(1,K(end)); % Livello di Allerta
Date_Alert_KL = zeros(1,K(end)); % Data di Allerta
Node_Alert_KL = zeros(1,K(end)); % Numero di nodo in Allerta
ID_Alert_KL = cell(1,K(end)); % ID centralina - ID catena in Allerta
index = 1;
prog = 1;
for n = 1:col % Ripeto per ogni Array
DatiElab = cell(1);
Date = zeros(1);
if yesKL(n) == 1
date_rif = now-15; % 15 giorni
for nn = 1:rKL(n) % Ripeto per ogni nodo
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' num2str(cell2mat(NodoKlinoLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DateElab = curs.Data;
% Modifico il formato di data e ora in DATini.
[rD,cD] = size(DateElab);
if rD ~= 1 && cD ~= 1
T = [cell2mat(DateElab(:,1)) repmat(' ', [rD,1]) cell2mat(DateElab(:,2))];
if nn == 1
Date(1:rD,n) = datenum(T); % scrivo lamatrice date usando il primo nodo
end
comando = ['select XShift, YShift from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' num2str(cell2mat(NodoKlinoLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Control = curs.Data;
[rCD,~] = size(Control);
[rDE,~] = size(DatiElab);
if rCD ~= rDE
if rCD > rDE
DatiElab(1:rCD,index:index+1) = Control;
RIF = rCD;
elseif rCD < rDE
DatiElab(1:rCD,index:index+1) = Control;
DatiElab(rCD+1:rDE,index:index+1) = Control(end,:);
RIF = rDE;
end
else
DatiElab(:,index:index+1) = Control; % Tutti i dati dei sensori dell'Array n
RIF = rDE;
end
% Guardo le soglie
[rCheck,cCheck] = size(DatiElab);
if rCheck > 1 && cCheck > 1
% Da Ieri
index1 = find(datenum(Date(:,n))>(now-1));
[rID,~] = size(index1);
if isempty(index1) == 0 && rID ~= 1 % non posso fare la diff
Incrementi_1gg = abs(diff(cell2mat(DatiElab(index1(1):end,index:index+1))));
Date_1gg(1:RIF-index1(1),n) = Date(index1(2):index1(end),n);
% 15 gg
Incrementi_15gg = abs(diff(cell2mat(DatiElab(:,index:index+1))));
ST15 = std(Incrementi_15gg(1:index1(1),:)); % 1 Deviazione standard per i 15 giorni
MAX15 = max(Incrementi_15gg(1:index1(1),:));
% 7 gg
index7 = find(datenum(Date(:,n))>(now-7));
Incrementi_7gg = abs(diff(cell2mat(DatiElab(index7(1):index1(1),index:index+1))));
ST7 = 3*std(Incrementi_7gg); % 3 Deviazioni standard per i 7 giorni
MAX7 = max(Incrementi_7gg);
% 3 gg
index3 = find(datenum(Date(:,n))>(now-3));
Incrementi_3gg = abs(diff(cell2mat(DatiElab(index3(1):index1(1),index:index+1))));
ST3 = 5*std(Incrementi_3gg); % 5 Deviazioni standard per i 3 giorni
MAX3 = max(Incrementi_3gg);
[rI,cI] = size(Incrementi_1gg); % Dati per quel nodo
soglia3 = zeros(rI,cI);
soglia7 = zeros(rI,cI);
soglia15 = zeros(rI,cI);
for cc = 1:cI
for s = 1:rI
if Incrementi_1gg(s,cc) > ST15+MAX15
soglia15(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST7+MAX7
soglia7(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST3+MAX3
soglia3(s,cc) = 1;
end
if soglia3(s,cc) == 1 && soglia7(s,cc) == 1 && soglia15(s,cc) == 1
Alert_KL(s,prog) = 3; % Allerta del nodo di Livello 3
Date_Alert_KL(s,prog) = Date_1gg(s,n);
Node_Alert_KL(s,prog) = cell2mat(NodoKlinoLink(nn,n));
ID_Alert_KL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 && soglia7(s,cc) == 1 || soglia3(s,cc) == 1 && soglia15(s,cc) == 1 || soglia15(s,cc) == 1 && soglia7(s,cc) == 1
Alert_KL(s,prog) = 2; % Allerta del nodo di Livello 2
Date_Alert_KL(s,prog) = Date_1gg(s,n);
Node_Alert_KL(s,prog) = cell2mat(NodoKlinoLink(nn,n));
ID_Alert_KL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 || soglia7(s,cc) == 1 || soglia15(s,cc) == 1
Alert_KL(s,prog) = 1; % Allerta del nodo di Livello 1
Date_Alert_KL(s,prog) = Date_1gg(s,n);
Node_Alert_KL(s,prog) = cell2mat(NodoKlinoLink(nn,n));
ID_Alert_KL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
end
end
end
end
end
end
index = index+2;
prog = prog+1;
end
text = ['Data of ' char(chainID(n,2)) '-' char(chainID(n,4)) ' Klino Link have been analyzed'];
fprintf(fileID,fmt,text);
index = 1;
end
end
[num_KL,~] = size(rKL);
ini = 1;
fin = cumsum(rKL);
Num_Allarmi_KL = zeros(1,num_KL);
for AL = 1:num_KL
if ini > fin(AL) % si va a quello dopo
else
Livello = max(max(Alert_KL(:,ini:fin(AL))));
if isempty(Livello) == 1
Livello = 0;
end
Num_Allarmi_KL(1,AL) = Livello;
ini = fin(AL)+1;
end
end
end
%% Klino Link HR
if isempty(find(yesKLHR)) == 1 % Non ho Klino Link HR
text = 'Klino Link HR have not been analyzed during the execution of soglie function';
fprintf(fileID,fmt,text);
Num_Allarmi_KLHR = 0;
else
clear Date_1gg
KHR = cumsum(rKLHR);
Alert_KLHR = zeros(1,KHR(end)); % Livello di Allerta
Date_Alert_KLHR = zeros(1,KHR(end)); % Data di Allerta
Node_Alert_KLHR = zeros(1,KHR(end)); % Numero di nodo in Allerta
ID_Alert_KLHR = cell(1,KHR(end)); % ID centralina - ID catena in Allerta
index = 1;
prog = 1;
for n = 1:col % Ripeto per ogni Array
DatiElab = cell(1);
Date = zeros(1);
if yesKLHR(n) == 1
date_rif = now-15; % 15 giorni
for nn = 1:rKLHR(n) % Ripeto per ogni nodo
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' num2str(cell2mat(NodoKlinoLinkHR(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DateElab = curs.Data;
% Modifico il formato di data e ora in DATini.
[rD,cD] = size(DateElab);
if rD ~= 1 && cD ~= 1
T = [cell2mat(DateElab(:,1)) repmat(' ', [rD,1]) cell2mat(DateElab(:,2))];
if nn == 1
Date(1:rD,n) = datenum(T); % scrivo lamatrice date usando il primo nodo
end
comando = ['select XShift, YShift from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' num2str(cell2mat(NodoKlinoLinkHR(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Control = curs.Data;
[rCD,~] = size(Control);
[rDE,~] = size(DatiElab);
if rCD ~= rDE
if rCD > rDE
DatiElab(1:rCD,index:index+1) = Control;
RIF = rCD;
elseif rCD < rDE
DatiElab(1:rCD,index:index+1) = Control;
DatiElab(rCD+1:rDE,index:index+1) = Control(end,:);
RIF = rDE;
end
else
DatiElab(:,index:index+1) = Control; % Tutti i dati dei sensori dell'Array n
RIF = rDE;
end
% Guardo le soglie
[rCheck,cCheck] = size(DatiElab);
if rCheck > 1 && cCheck > 1
% Da Ieri
index1 = find(datenum(Date(:,n))>(now-1));
[rID,~] = size(index1);
if isempty(index1) == 0 && rID ~= 1 % non posso fare la diff
Incrementi_1gg = abs(diff(cell2mat(DatiElab(index1(1):end,index:index+1))));
Date_1gg(1:RIF-index1(1),n) = Date(index1(2):index1(end),n);
% 15 gg
Incrementi_15gg = abs(diff(cell2mat(DatiElab(:,index:index+1))));
ST15 = std(Incrementi_15gg(1:index1(1),:)); % 1 Deviazione standard per i 15 giorni
MAX15 = max(Incrementi_15gg(1:index1(1),:));
% 7 gg
index7 = find(datenum(Date(:,n))>(now-7));
Incrementi_7gg = abs(diff(cell2mat(DatiElab(index7(1):index1(1),index:index+1))));
ST7 = 3*std(Incrementi_7gg); % 3 Deviazioni standard per i 7 giorni
MAX7 = max(Incrementi_7gg);
% 3 gg
index3 = find(datenum(Date(:,n))>(now-3));
Incrementi_3gg = abs(diff(cell2mat(DatiElab(index3(1):index1(1),index:index+1))));
ST3 = 5*std(Incrementi_3gg); % 5 Deviazioni standard per i 3 giorni
MAX3 = max(Incrementi_3gg);
[rI,cI] = size(Incrementi_1gg); % Dati per quel nodo
soglia3 = zeros(rI,cI);
soglia7 = zeros(rI,cI);
soglia15 = zeros(rI,cI);
for cc = 1:cI
for s = 1:rI
if Incrementi_1gg(s,cc) > ST15+MAX15
soglia15(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST7+MAX7
soglia7(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST3+MAX3
soglia3(s,cc) = 1;
end
if soglia3(s,cc) == 1 && soglia7(s,cc) == 1 && soglia15(s,cc) == 1
Alert_KLHR(s,prog) = 3; % Allerta del nodo di Livello 3
Date_Alert_KLHR(s,prog) = Date_1gg(s,n);
Node_Alert_KLHR(s,prog) = cell2mat(NodoKlinoLinkHR(nn,n));
ID_Alert_KLHR(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 && soglia7(s,cc) == 1 || soglia3(s,cc) == 1 && soglia15(s,cc) == 1 || soglia15(s,cc) == 1 && soglia7(s,cc) == 1
Alert_KLHR(s,prog) = 2; % Allerta del nodo di Livello 2
Date_Alert_KLHR(s,prog) = Date_1gg(s,n);
Node_Alert_KLHR(s,prog) = cell2mat(NodoKlinoLinkHR(nn,n));
ID_Alert_KLHR(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 || soglia7(s,cc) == 1 || soglia15(s,cc) == 1
Alert_KLHR(s,prog) = 1; % Allerta del nodo di Livello 1
Date_Alert_KLHR(s,prog) = Date_1gg(s,n);
Node_Alert_KLHR(s,prog) = cell2mat(NodoKlinoLinkHR(nn,n));
ID_Alert_KLHR(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
end
end
end
end
end
end
index = index+2;
prog = prog+1;
end
text = ['Data of ' char(chainID(n,2)) '-' char(chainID(n,4)) ' Klino Link HR have been analyzed'];
fprintf(fileID,fmt,text);
index = 1;
end
end
[num_KLHR,~] = size(rKLHR);
ini = 1;
fin = cumsum(rKLHR);
Num_Allarmi_KLHR = zeros(1,num_KLHR);
for AL = 1:num_KLHR
if ini > fin(AL) % si va a quello dopo
else
Livello = max(max(Alert_KLHR(:,ini:fin(AL))));
if isempty(Livello) == 1
Livello = 0;
end
Num_Allarmi_KLHR(1,AL) = Livello;
ini = fin(AL)+1;
end
end
end
%% Load Link
if isempty(find(yesLL)) == 1 % Non ho Load Link
text = 'Load Link have not been analyzed during the execution of soglie function';
fprintf(fileID,fmt,text);
Num_Allarmi_LL = 0;
else
clear Date_1gg
LL = cumsum(rLL);
Alert_LL = zeros(1,LL(end)); % Livello di Allerta
Date_Alert_LL = zeros(1,LL(end)); % Data di Allerta
Node_Alert_LL = zeros(1,LL(end)); % Numero di nodo in Allerta
ID_Alert_LL = cell(1,LL(end)); % ID centralina - ID catena in Allerta
index = 1;
prog = 1;
for n = 1:col % Ripeto per ogni Array
DatiElab = cell(1);
Date = zeros(1);
if yesLL(n) == 1
status = system(['/usr/local/matlab_func/run_ATD_lnx.sh /usr/local/MATLAB/MATLAB_Runtime/v93 ' char(chainID(n,2)) ' ' char(chainID(n,4)) '']);
if status == 1
break % se crasha il SW salto l'analisi
end
date_rif = now-15; % 15 giorni
for nn = 1:rLL(n) % Ripeto per ogni nodo
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' num2str(cell2mat(NodoLoadLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DateElab = curs.Data;
% Modifico il formato di data e ora in DATini.
[rD,cD] = size(DateElab);
if rD ~= 1 && cD ~= 1
T = [cell2mat(DateElab(:,1)) repmat(' ', [rD,1]) cell2mat(DateElab(:,2))];
if nn == 1
Date(1:rD,n) = datenum(T); % scrivo lamatrice date usando il primo nodo
end
comando = ['select load_value from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' num2str(cell2mat(NodoLoadLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Control = curs.Data;
[rCD,~] = size(Control);
[rDE,~] = size(DatiElab);
if rCD ~= rDE
if rCD > rDE
DatiElab(1:rCD,index) = Control;
RIF = rCD;
elseif rCD < rDE
DatiElab(1:rCD,index) = Control;
DatiElab(rCD+1:rDE,index) = Control(end,:);
RIF = rDE;
end
else
DatiElab(:,index) = Control; % Tutti i dati dei sensori dell'Array n
RIF = rDE;
end
% Guardo le soglie
[rCheck,cCheck] = size(DatiElab);
if rCheck > 1 && cCheck > 1
% Da Ieri
index1 = find(datenum(Date(:,n))>(now-1));
[rID,~] = size(index1);
if isempty(index1) == 0 && rID ~= 1 % non posso fare la diff
Incrementi_1gg = abs(diff(cell2mat(DatiElab(index1(1):end,index))));
Date_1gg(1:RIF-index1(1),n) = Date(index1(2):index1(end),n);
% 15 gg
Incrementi_15gg = abs(diff(cell2mat(DatiElab(:,index))));
ST15 = std(Incrementi_15gg(1:index1(1),:)); % 1 Deviazione standard per i 15 giorni
MAX15 = max(Incrementi_15gg(1:index1(1),:));
% 7 gg
index7 = find(datenum(Date(:,n))>(now-7));
Incrementi_7gg = abs(diff(cell2mat(DatiElab(index7(1):index1(1),index))));
ST7 = 3*std(Incrementi_7gg); % 3 Deviazioni standard per i 7 giorni
MAX7 = max(Incrementi_7gg);
% 3 gg
index3 = find(datenum(Date(:,n))>(now-3));
Incrementi_3gg = abs(diff(cell2mat(DatiElab(index3(1):index1(1),index))));
ST3 = 5*std(Incrementi_3gg); % 5 Deviazioni standard per i 3 giorni
MAX3 = max(Incrementi_3gg);
[rI,cI] = size(Incrementi_1gg); % Dati per quel nodo
soglia3 = zeros(rI,cI);
soglia7 = zeros(rI,cI);
soglia15 = zeros(rI,cI);
for cc = 1:cI
for s = 1:rI
if Incrementi_1gg(s,cc) > ST15+MAX15
soglia15(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST7+MAX7
soglia7(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST3+MAX3
soglia3(s,cc) = 1;
end
if soglia3(s,cc) == 1 && soglia7(s,cc) == 1 && soglia15(s,cc) == 1
Alert_LL(s,prog) = 3; % Allerta del nodo di Livello 3
Date_Alert_LL(s,prog) = Date_1gg(s,n);
Node_Alert_LL(s,prog) = cell2mat(NodoLoadLink(nn,n));
ID_Alert_LL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 && soglia7(s,cc) == 1 || soglia3(s,cc) == 1 && soglia15(s,cc) == 1 || soglia15(s,cc) == 1 && soglia7(s,cc) == 1
Alert_LL(s,prog) = 2; % Allerta del nodo di Livello 2
Date_Alert_LL(s,prog) = Date_1gg(s,n);
Node_Alert_LL(s,prog) = cell2mat(NodoLoadLink(nn,n));
ID_Alert_LL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 || soglia7(s,cc) == 1 || soglia15(s,cc) == 1
Alert_LL(s,prog) = 1; % Allerta del nodo di Livello 1
Date_Alert_LL(s,prog) = Date_1gg(s,n);
Node_Alert_LL(s,prog) = cell2mat(NodoLoadLink(nn,n));
ID_Alert_LL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
end
end
end
end
end
end
index = index+1;
prog = prog+1;
end
text = ['Data of ' char(chainID(n,2)) '-' char(chainID(n,4)) ' Load Link have been analyzed'];
fprintf(fileID,fmt,text);
index = 1;
end
end
[num_LL,~] = size(rLL);
ini = 1;
fin = cumsum(rLL);
Num_Allarmi_LL = zeros(1,num_LL);
for AL = 1:num_LL
if ini > fin(AL) % si va a quello dopo
else
Livello = max(max(Alert_LL(:,ini:fin(AL))));
if isempty(Livello) == 1
Livello = 0;
end
Num_Allarmi_LL(1,AL) = Livello;
ini = fin(AL)+1;
end
end
end
%% Pressure Link
if isempty(find(yesPrL)) == 1 % Non ho Pressure Link
text = 'Pressure Link have not been analyzed during the execution of soglie function';
fprintf(fileID,fmt,text);
Num_Allarmi_PrL = 0;
else
clear Date_1gg
PrL = cumsum(rPrL);
Alert_PrL = zeros(1,PrL(end)); % Livello di Allerta
Date_Alert_PrL = zeros(1,PrL(end)); % Data di Allerta
Node_Alert_PrL = zeros(1,PrL(end)); % Numero di nodo in Allerta
ID_Alert_PrL = cell(1,PrL(end)); % ID centralina - ID catena in Allerta
index = 1;
prog = 1;
for n = 1:col % Ripeto per ogni Array
DatiElab = cell(1);
Date = zeros(1);
if yesPrL(n) == 1
status = system(['/usr/local/matlab_func/run_ATD_lnx.sh /usr/local/MATLAB/MATLAB_Runtime/v93 ' char(chainID(n,2)) ' ' char(chainID(n,4)) '']);
if status == 1
break % se crasha il SW salto l'analisi
end
date_rif = now-15; % 15 giorni
for nn = 1:rPrL(n) % Ripeto per ogni nodo
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' num2str(cell2mat(NodoPressureLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DateElab = curs.Data;
% Modifico il formato di data e ora in DATini.
[rD,cD] = size(DateElab);
if rD ~= 1 && cD ~= 1
T = [cell2mat(DateElab(:,1)) repmat(' ', [rD,1]) cell2mat(DateElab(:,2))];
if nn == 1
Date(1:rD,n) = datenum(T); % scrivo lamatrice date usando il primo nodo
end
comando = ['select pressure from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' num2str(cell2mat(NodoPressureLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Control = curs.Data;
[rCD,~] = size(Control);
[rDE,~] = size(DatiElab);
if rCD ~= rDE
if rCD > rDE
DatiElab(1:rCD,index) = Control;
RIF = rCD;
elseif rCD < rDE
DatiElab(1:rCD,index) = Control;
DatiElab(rCD+1:rDE,index) = Control(end,:);
RIF = rDE;
end
else
DatiElab(:,index) = Control; % Tutti i dati dei sensori dell'Array n
RIF = rDE;
end
% Guardo le soglie
[rCheck,cCheck] = size(DatiElab);
if rCheck > 1 && cCheck > 1
% Da Ieri
index1 = find(datenum(Date(:,n))>(now-1));
[rID,~] = size(index1);
if isempty(index1) == 0 && rID ~= 1 % non posso fare la diff
Incrementi_1gg = abs(diff(cell2mat(DatiElab(index1(1):end,index))));
Date_1gg(1:RIF-index1(1),n) = Date(index1(2):index1(end),n);
% 15 gg
Incrementi_15gg = abs(diff(cell2mat(DatiElab(:,index))));
ST15 = std(Incrementi_15gg(1:index1(1),:)); % 1 Deviazione standard per i 15 giorni
MAX15 = max(Incrementi_15gg(1:index1(1),:));
% 7 gg
index7 = find(datenum(Date(:,n))>(now-7));
Incrementi_7gg = abs(diff(cell2mat(DatiElab(index7(1):index1(1),index))));
ST7 = 3*std(Incrementi_7gg); % 3 Deviazioni standard per i 7 giorni
MAX7 = max(Incrementi_7gg);
% 3 gg
index3 = find(datenum(Date(:,n))>(now-3));
Incrementi_3gg = abs(diff(cell2mat(DatiElab(index3(1):index1(1),index))));
ST3 = 5*std(Incrementi_3gg); % 5 Deviazioni standard per i 3 giorni
MAX3 = max(Incrementi_3gg);
[rI,cI] = size(Incrementi_1gg); % Dati per quel nodo
soglia3 = zeros(rI,cI);
soglia7 = zeros(rI,cI);
soglia15 = zeros(rI,cI);
for cc = 1:cI
for s = 1:rI
if Incrementi_1gg(s,cc) > ST15+MAX15
soglia15(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST7+MAX7
soglia7(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST3+MAX3
soglia3(s,cc) = 1;
end
if soglia3(s,cc) == 1 && soglia7(s,cc) == 1 && soglia15(s,cc) == 1
Alert_PrL(s,prog) = 3; % Allerta del nodo di Livello 3
Date_Alert_PrL(s,prog) = Date_1gg(s,n);
Node_Alert_PrL(s,prog) = cell2mat(NodoPressureLink(nn,n));
ID_Alert_PrL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 && soglia7(s,cc) == 1 || soglia3(s,cc) == 1 && soglia15(s,cc) == 1 || soglia15(s,cc) == 1 && soglia7(s,cc) == 1
Alert_PrL(s,prog) = 2; % Allerta del nodo di Livello 2
Date_Alert_PrL(s,prog) = Date_1gg(s,n);
Node_Alert_PrL(s,prog) = cell2mat(NodoPressureLink(nn,n));
ID_Alert_PrL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 || soglia7(s,cc) == 1 || soglia15(s,cc) == 1
Alert_PrL(s,prog) = 1; % Allerta del nodo di Livello 1
Date_Alert_PrL(s,prog) = Date_1gg(s,n);
Node_Alert_PrL(s,prog) = cell2mat(NodoPressureLink(nn,n));
ID_Alert_PrL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
end
end
end
end
end
end
index = index+1;
prog = prog+1;
end
text = ['Data of ' char(chainID(n,2)) '-' char(chainID(n,4)) ' Pressure Link have been analyzed'];
fprintf(fileID,fmt,text);
index = 1;
end
end
[num_PrL,~] = size(rPrL);
ini = 1;
fin = cumsum(rPrL);
Num_Allarmi_PrL = zeros(1,num_PrL);
for AL = 1:num_PrL
if ini > fin(AL) % si va a quello dopo
else
Livello = max(max(Alert_PrL(:,ini:fin(AL))));
if isempty(Livello) == 1
Livello = 0;
end
Num_Allarmi_PrL(1,AL) = Livello;
ini = fin(AL)+1;
end
end
end
%% Crack Link
if isempty(find(yesCrL)) == 1 % Non ho Crack Link
text = 'Crack Link have not been analyzed during the execution of soglie function';
fprintf(fileID,fmt,text);
Num_Allarmi_CrL = 0;
else
clear Date_1gg
C = cumsum(rCrL);
Alert_CrL = zeros(1,C(end)); % Livello di Allerta
Date_Alert_CrL = zeros(1,C(end)); % Data di Allerta
Node_Alert_CrL = zeros(1,C(end)); % Numero di nodo in Allerta
ID_Alert_CrL = cell(1,C(end)); % ID centralina - ID catena in Allerta
index = 1;
prog = 1;
for n = 1:col % Ripeto per ogni Array
DatiElab = cell(1);
Date = zeros(1);
if yesCrL(n) == 1
status = system(['/usr/local/matlab_func/run_ATD_lnx.sh /usr/local/MATLAB/MATLAB_Runtime/v93 ' char(chainID(n,2)) ' ' char(chainID(n,4)) '']);
if status == 1
break % se crasha il SW salto l'analisi
end
date_rif = now-15; % 15 giorni
for nn = 1:rCrL(n) % Ripeto per ogni nodo
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' num2str(cell2mat(NodoCrackLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DateElab = curs.Data;
% Modifico il formato di data e ora in DATini.
[rD,cD] = size(DateElab);
if rD ~= 1 && cD ~= 1
T = [cell2mat(DateElab(:,1)) repmat(' ', [rD,1]) cell2mat(DateElab(:,2))];
if nn == 1
Date(1:rD,n) = datenum(T); % scrivo lamatrice date usando il primo nodo
end
comando = ['select XShift from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' num2str(cell2mat(NodoCrackLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Control = curs.Data;
[rCD,~] = size(Control);
[rDE,~] = size(DatiElab);
if rCD ~= rDE
if rCD > rDE
DatiElab(1:rCD,index) = Control;
RIF = rCD;
elseif rCD < rDE
DatiElab(1:rCD,index) = Control;
DatiElab(rCD+1:rDE,index) = Control(end,:);
RIF = rDE;
end
else
DatiElab(:,index) = Control; % Tutti i dati dei sensori dell'Array n
RIF = rDE;
end
% Guardo le soglie
[rCheck,cCheck] = size(DatiElab);
if rCheck > 1 && cCheck > 1
% Da Ieri
index1 = find(datenum(Date(:,n))>(now-1));
[rID,~] = size(index1);
if isempty(index1) == 0 && rID ~= 1 % non posso fare la diff
Incrementi_1gg = abs(diff(cell2mat(DatiElab(index1(1):end,index))));
Date_1gg(1:RIF-index1(1),n) = Date(index1(2):index1(end),n);
% 15 gg
Incrementi_15gg = abs(diff(cell2mat(DatiElab(:,index))));
ST15 = std(Incrementi_15gg(1:index1(1),:)); % 1 Deviazione standard per i 15 giorni
MAX15 = max(Incrementi_15gg(1:index1(1),:));
% 7 gg
index7 = find(datenum(Date(:,n))>(now-7));
Incrementi_7gg = abs(diff(cell2mat(DatiElab(index7(1):index1(1),index))));
ST7 = 3*std(Incrementi_7gg); % 3 Deviazioni standard per i 7 giorni
MAX7 = max(Incrementi_7gg);
% 3 gg
index3 = find(datenum(Date(:,n))>(now-3));
Incrementi_3gg = abs(diff(cell2mat(DatiElab(index3(1):index1(1),index))));
ST3 = 5*std(Incrementi_3gg); % 5 Deviazioni standard per i 3 giorni
MAX3 = max(Incrementi_3gg);
[rI,cI] = size(Incrementi_1gg); % Dati per quel nodo
soglia3 = zeros(rI,cI);
soglia7 = zeros(rI,cI);
soglia15 = zeros(rI,cI);
for cc = 1:cI
for s = 1:rI
if Incrementi_1gg(s,cc) > ST15+MAX15
soglia15(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST7+MAX7
soglia7(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST3+MAX3
soglia3(s,cc) = 1;
end
if soglia3(s,cc) == 1 && soglia7(s,cc) == 1 && soglia15(s,cc) == 1
Alert_CrL(s,prog) = 3; % Allerta del nodo di Livello 3
Date_Alert_CrL(s,prog) = Date_1gg(s,n);
Node_Alert_CrL(s,prog) = cell2mat(NodoCrackLink(nn,n));
ID_Alert_CrL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 && soglia7(s,cc) == 1 || soglia3(s,cc) == 1 && soglia15(s,cc) == 1 || soglia15(s,cc) == 1 && soglia7(s,cc) == 1
Alert_CrL(s,prog) = 2; % Allerta del nodo di Livello 2
Date_Alert_CrL(s,prog) = Date_1gg(s,n);
Node_Alert_CrL(s,prog) = cell2mat(NodoCrackLink(nn,n));
ID_Alert_CrL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 || soglia7(s,cc) == 1 || soglia15(s,cc) == 1
Alert_CrL(s,prog) = 1; % Allerta del nodo di Livello 1
Date_Alert_CrL(s,prog) = Date_1gg(s,n);
Node_Alert_CrL(s,prog) = cell2mat(NodoCrackLink(nn,n));
ID_Alert_CrL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
end
end
end
end
end
end
index = index+1;
prog = prog+1;
end
text = ['Data of ' char(chainID(n,2)) '-' char(chainID(n,4)) ' Crack Link have been analyzed'];
fprintf(fileID,fmt,text);
index = 1;
end
end
[num_CrL,~] = size(rCrL);
ini = 1;
fin = cumsum(rCrL);
Num_Allarmi_CrL = zeros(1,num_CrL);
for AL = 1:num_CrL
if ini > fin(AL) % si va a quello dopo
else
Livello = max(max(Alert_CrL(:,ini:fin(AL))));
if isempty(Livello) == 1
Livello = 0;
end
Num_Allarmi_CrL(1,AL) = Livello;
ini = fin(AL)+1;
end
end
end
%% 3D Crack Link
if isempty(find(yes3DCrL)) == 1 % Non ho 3D Crack Link
text = '3D Crack Link have not been analyzed during the execution of soglie function';
fprintf(fileID,fmt,text);
Num_Allarmi_3DCrL = 0;
else
clear Date_1gg
CrL3D = cumsum(r3DCrL);
Alert_3DCrL = zeros(1,CrL3D(end)); % Livello di Allerta
Date_Alert_3DCrL = zeros(1,CrL3D(end)); % Data di Allerta
Node_Alert_3DCrL = zeros(1,CrL3D(end)); % Numero di nodo in Allerta
ID_Alert_3DCrL = cell(1,CrL3D(end)); % ID centralina - ID catena in Allerta
index = 1;
prog = 1;
for n = 1:col % Ripeto per ogni Array
DatiElab = cell(1);
Date = zeros(1);
if yes3DCrL(n) == 1
status = system(['/usr/local/matlab_func/run_ATD_lnx.sh /usr/local/MATLAB/MATLAB_Runtime/v93 ' char(chainID(n,2)) ' ' char(chainID(n,4)) '']);
if status == 1
break % se crasha il SW salto l'analisi
end
date_rif = now-15; % 15 giorni
for nn = 1:r3DCrL(n) % Ripeto per ogni nodo
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' num2str(cell2mat(Nodo3DCrackLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DateElab = curs.Data;
% Modifico il formato di data e ora in DATini.
[rD,cD] = size(DateElab);
if rD ~= 1 && cD ~= 1
T = [cell2mat(DateElab(:,1)) repmat(' ', [rD,1]) cell2mat(DateElab(:,2))];
if nn == 1
Date(1:rD,n) = datenum(T); % scrivo lamatrice date usando il primo nodo
end
comando = ['select XShift, YShift, ZShift from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' num2str(cell2mat(Nodo3DCrackLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Control = curs.Data;
[rCD,~] = size(Control);
[rDE,~] = size(DatiElab);
if rCD ~= rDE
if rCD > rDE
DatiElab(1:rCD,index:index+2) = Control;
RIF = rCD;
elseif rCD < rDE
DatiElab(1:rCD,index:index+2) = Control;
DatiElab(rCD+1:rDE,index:index+2) = Control(end,:);
RIF = rDE;
end
else
DatiElab(:,index:index+2) = Control; % Tutti i dati dei sensori dell'Array n
RIF = rDE;
end
% Guardo le soglie
[rCheck,cCheck] = size(DatiElab);
if rCheck > 1 && cCheck > 1
% Da Ieri
index1 = find(datenum(Date(:,n))>(now-1));
[rID,~] = size(index1);
if isempty(index1) == 0 && rID ~= 1 % non posso fare la diff
Incrementi_1gg = abs(diff(cell2mat(DatiElab(index1(1):end,index:index+2))));
Date_1gg(1:RIF-index1(1),n) = Date(index1(2):index1(end),n);
% 15 gg
Incrementi_15gg = abs(diff(cell2mat(DatiElab(:,index:index+2))));
ST15 = std(Incrementi_15gg(1:index1(1),:)); % 1 Deviazione standard per i 15 giorni
MAX15 = max(Incrementi_15gg(1:index1(1),:));
% 7 gg
index7 = find(datenum(Date(:,n))>(now-7));
Incrementi_7gg = abs(diff(cell2mat(DatiElab(index7(1):index1(1),index:index+2))));
ST7 = 3*std(Incrementi_7gg); % 3 Deviazioni standard per i 7 giorni
MAX7 = max(Incrementi_7gg);
% 3 gg
index3 = find(datenum(Date(:,n))>(now-3));
Incrementi_3gg = abs(diff(cell2mat(DatiElab(index3(1):index1(1),index:index+2))));
ST3 = 5*std(Incrementi_3gg); % 5 Deviazioni standard per i 3 giorni
MAX3 = max(Incrementi_3gg);
[rI,cI] = size(Incrementi_1gg); % Dati per quel nodo
soglia3 = zeros(rI,cI);
soglia7 = zeros(rI,cI);
soglia15 = zeros(rI,cI);
for cc = 1:cI
for s = 1:rI
if Incrementi_1gg(s,cc) > ST15+MAX15
soglia15(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST7+MAX7
soglia7(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST3+MAX3
soglia3(s,cc) = 1;
end
if soglia3(s,cc) == 1 && soglia7(s,cc) == 1 && soglia15(s,cc) == 1
Alert_3DCrL(s,prog) = 3; % Allerta del nodo di Livello 3
Date_Alert_3DCrL(s,prog) = Date_1gg(s,n);
Node_Alert_3DCrL(s,prog) = cell2mat(Nodo3DCrackLink(nn,n));
ID_Alert_3DCrL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 && soglia7(s,cc) == 1 || soglia3(s,cc) == 1 && soglia15(s,cc) == 1 || soglia15(s,cc) == 1 && soglia7(s,cc) == 1
Alert_3DCrL(s,prog) = 2; % Allerta del nodo di Livello 2
Date_Alert_3DCrL(s,prog) = Date_1gg(s,n);
Node_Alert_3DCrL(s,prog) = cell2mat(Nodo3DCrackLink(nn,n));
ID_Alert_3DCrL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 || soglia7(s,cc) == 1 || soglia15(s,cc) == 1
Alert_3DCrL(s,prog) = 1; % Allerta del nodo di Livello 1
Date_Alert_3DCrL(s,prog) = Date_1gg(s,n);
Node_Alert_3DCrL(s,prog) = cell2mat(Nodo3DCrackLink(nn,n));
ID_Alert_3DCrL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
end
end
end
end
end
end
index = index+3;
prog = prog+1;
end
text = ['Data of ' char(chainID(n,2)) '-' char(chainID(n,4)) ' 3D Crack Link have been analyzed'];
fprintf(fileID,fmt,text);
index = 1;
end
end
[num_3DCrL,~] = size(r3DCrL);
ini = 1;
fin = cumsum(r3DCrL);
Num_Allarmi_3DCrL = zeros(1,num_3DCrL);
for AL = 1:num_3DCrL
if ini > fin(AL) % si va a quello dopo
else
Livello = max(max(Alert_3DCrL(:,ini:fin(AL))));
if isempty(Livello) == 1
Livello = 0;
end
Num_Allarmi_3DCrL(1,AL) = Livello;
ini = fin(AL)+1;
end
end
end
%% Rain Link
if isempty(find(yesRaL)) == 1 % Non ho Rain Link
text = 'Rain Link have not been analyzed during the execution of soglie function';
fprintf(fileID,fmt,text);
Num_Allarmi_RaL = 0;
else
clear Date_1gg
RaL = cumsum(rRaL);
Alert_RaL = zeros(1,RaL(end)); % Livello di Allerta
Date_Alert_RaL = zeros(1,RaL(end)); % Data di Allerta
Node_Alert_RaL = zeros(1,RaL(end)); % Numero di nodo in Allerta
ID_Alert_RaL = cell(1,RaL(end)); % ID centralina - ID catena in Allerta
index = 1;
prog = 1;
for n = 1:col % Ripeto per ogni Array
DatiElab = cell(1);
Date = zeros(1);
if yesRaL(n) == 1
date_rif = now-15; % 15 giorni
for nn = 1:rRaL(n) % Ripeto per ogni nodo
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' ...
num2str(cell2mat(NodoRainLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DateElab = curs.Data;
% Modifico il formato di data e ora in DATini.
[rD,cD] = size(DateElab);
if rD ~= 1 && cD ~= 1
T = [cell2mat(DateElab(:,1)) repmat(' ', [rD,1]) cell2mat(DateElab(:,2))];
if nn == 1
Date(1:rD,n) = datenum(T); % scrivo lamatrice date usando il primo nodo
end
comando = ['select Z from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = '''...
num2str(cell2mat(NodoRainLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Control = curs.Data;
[rCD,~] = size(Control);
[rDE,~] = size(DatiElab);
if rCD ~= rDE
if rCD > rDE
DatiElab(1:rCD,index) = Control;
RIF = rCD;
elseif rCD < rDE
DatiElab(1:rCD,index) = Control;
DatiElab(rCD+1:rDE,index) = Control(end,:);
RIF = rDE;
end
else
DatiElab(:,index) = Control; % Tutti i dati dei sensori dell'Array n
RIF = rDE;
end
% Guardo le soglie
[rCheck,cCheck] = size(DatiElab);
if rCheck > 1 && cCheck > 1
% Da Ieri
index1 = find(datenum(Date(:,n))>(now-1));
[rID,~] = size(index1);
if isempty(index1) == 0 && rID ~= 1 % non posso fare la diff
Incrementi_1gg = abs(diff(cell2mat(DatiElab(index1(1):end,index))));
Date_1gg(1:RIF-index1(1),n) = Date(index1(2):index1(end),n);
% 15 gg
Incrementi_15gg = abs(diff(cell2mat(DatiElab(:,index))));
ST15 = std(Incrementi_15gg(1:index1(1),:)); % 1 Deviazione standard per i 15 giorni
MAX15 = max(Incrementi_15gg(1:index1(1),:));
% 7 gg
index7 = find(datenum(Date(:,n))>(now-7));
Incrementi_7gg = abs(diff(cell2mat(DatiElab(index7(1):index1(1),index))));
ST7 = 3*std(Incrementi_7gg); % 3 Deviazioni standard per i 7 giorni
MAX7 = max(Incrementi_7gg);
% 3 gg
index3 = find(datenum(Date(:,n))>(now-3));
Incrementi_3gg = abs(diff(cell2mat(DatiElab(index3(1):index1(1),index))));
ST3 = 5*std(Incrementi_3gg); % 5 Deviazioni standard per i 3 giorni
MAX3 = max(Incrementi_3gg);
[rI,cI] = size(Incrementi_1gg); % Dati per quel nodo
soglia3 = zeros(rI,cI);
soglia7 = zeros(rI,cI);
soglia15 = zeros(rI,cI);
for cc = 1:cI
for s = 1:rI
if Incrementi_1gg(s,cc) > ST15+MAX15
soglia15(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST7+MAX7
soglia7(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST3+MAX3
soglia3(s,cc) = 1;
end
if soglia3(s,cc) == 1 && soglia7(s,cc) == 1 && soglia15(s,cc) == 1
Alert_RaL(s,prog) = 3; % Allerta del nodo di Livello 3
Date_Alert_RaL(s,prog) = Date_1gg(s,n);
Node_Alert_RLa(s,prog) = cell2mat(NodoRainLink(nn,n));
ID_Alert_RaL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 && soglia7(s,cc) == 1 || soglia3(s,cc) == 1 && soglia15(s,cc) == 1 || soglia15(s,cc) == 1 && soglia7(s,cc) == 1
Alert_RaL(s,prog) = 2; % Allerta del nodo di Livello 2
Date_Alert_RaL(s,prog) = Date_1gg(s,n);
Node_Alert_RaL(s,prog) = cell2mat(NodoRainLink(nn,n));
ID_Alert_RaL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 || soglia7(s,cc) == 1 || soglia15(s,cc) == 1
Alert_RaL(s,prog) = 1; % Allerta del nodo di Livello 1
Date_Alert_RaL(s,prog) = Date_1gg(s,n);
Node_Alert_RaL(s,prog) = cell2mat(NodoRainLink(nn,n));
ID_Alert_RaL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
end
end
end
end
end
end
index = index+1;
prog = prog+1;
end
text = ['Data of ' char(chainID(n,2)) '-' char(chainID(n,4)) ' Rain Link have been analyzed'];
fprintf(fileID,fmt,text);
index = 1;
end
end
[num_RaL,~] = size(rRaL);
ini = 1;
fin = cumsum(rRaL);
Num_Allarmi_RaL = zeros(1,num_RaL);
for AL = 1:num_RaL
if ini > fin(AL) % si va a quello dopo
else
Livello = max(max(Alert_RaL(:,ini:fin(AL))));
if isempty(Livello) == 1
Livello = 0;
end
Num_Allarmi_RaL(1,AL) = Livello;
ini = fin(AL)+1;
end
end
end
%% Extensometer Link
if isempty(find(yesEL)) == 1 % Non ho Extensometer Link
text = 'Extensometer Link have not been analyzed during the execution of soglie function';
fprintf(fileID,fmt,text);
Num_Allarmi_EL = 0;
else
clear Date_1gg
EL = cumsum(rEL);
Alert_EL = zeros(1,EL(end)); % Livello di Allerta
Date_Alert_EL = zeros(1,EL(end)); % Data di Allerta
Node_Alert_EL = zeros(1,EL(end)); % Numero di nodo in Allerta
ID_Alert_EL = cell(1,EL(end)); % ID centralina - ID catena in Allerta
index = 1;
prog = 1;
for n = 1:col % Ripeto per ogni Array
DatiElab = cell(1);
Date = zeros(1);
if yesEL(n) == 1
status = system(['/usr/local/matlab_func/run_ATD_lnx.sh /usr/local/MATLAB/MATLAB_Runtime/v93 ' char(chainID(n,2)) ' ' char(chainID(n,4)) '']);
if status == 1
break % se crasha il SW salto l'analisi
end
date_rif = now-15; % 15 giorni
for nn = 1:rEL(n) % Ripeto per ogni nodo
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' num2str(cell2mat(NodoExtensometerLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DateElab = curs.Data;
% Modifico il formato di data e ora in DATini.
[rD,cD] = size(DateElab);
if rD ~= 1 && cD ~= 1
T = [cell2mat(DateElab(:,1)) repmat(' ', [rD,1]) cell2mat(DateElab(:,2))];
if nn == 1
Date(1:rD,n) = datenum(T); % scrivo la matrice date usando il primo nodo
end
comando = ['select XShift from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' num2str(cell2mat(NodoExtensometerLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Control = curs.Data;
[rCD,~] = size(Control);
[rDE,~] = size(DatiElab);
if rCD ~= rDE
if rCD > rDE
DatiElab(1:rCD,index) = Control;
RIF = rCD;
elseif rCD < rDE
DatiElab(1:rCD,index) = Control;
DatiElab(rCD+1:rDE,index) = Control(end,:);
RIF = rDE;
end
else
DatiElab(:,index) = Control; % Tutti i dati dei sensori dell'Array n
RIF = rDE;
end
% Guardo le soglie
[rCheck,cCheck] = size(DatiElab);
if rCheck > 1 && cCheck > 1
% Da Ieri
index1 = find(datenum(Date(:,n))>(now-1));
[rID,~] = size(index1);
if isempty(index1) == 0 && rID ~= 1 % non posso fare la diff
Incrementi_1gg = abs(diff(cell2mat(DatiElab(index1(1):end,index))));
Date_1gg(1:RIF-index1(1),n) = Date(index1(2):index1(end),n);
% 15 gg
Incrementi_15gg = abs(diff(cell2mat(DatiElab(:,index))));
ST15 = std(Incrementi_15gg(1:index1(1),:)); % 1 Deviazione standard per i 15 giorni
MAX15 = max(Incrementi_15gg(1:index1(1),:));
% 7 gg
index7 = find(datenum(Date(:,n))>(now-7));
Incrementi_7gg = abs(diff(cell2mat(DatiElab(index7(1):index1(1),index))));
ST7 = 3*std(Incrementi_7gg); % 3 Deviazioni standard per i 7 giorni
MAX7 = max(Incrementi_7gg);
% 3 gg
index3 = find(datenum(Date(:,n))>(now-3));
Incrementi_3gg = abs(diff(cell2mat(DatiElab(index3(1):index1(1),index))));
ST3 = 5*std(Incrementi_3gg); % 5 Deviazioni standard per i 3 giorni
MAX3 = max(Incrementi_3gg);
[rI,cI] = size(Incrementi_1gg); % Dati per quel nodo
soglia3 = zeros(rI,cI);
soglia7 = zeros(rI,cI);
soglia15 = zeros(rI,cI);
for cc = 1:cI
for s = 1:rI
if Incrementi_1gg(s,cc) > ST15+MAX15
soglia15(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST7+MAX7
soglia7(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST3+MAX3
soglia3(s,cc) = 1;
end
if soglia3(s,cc) == 1 && soglia7(s,cc) == 1 && soglia15(s,cc) == 1
Alert_EL(s,prog) = 3; % Allerta del nodo di Livello 3
Date_Alert_EL(s,prog) = Date_1gg(s,n);
Node_Alert_EL(s,prog) = cell2mat(NodoExtensometerLink(nn,n));
ID_Alert_EL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 && soglia7(s,cc) == 1 || soglia3(s,cc) == 1 && soglia15(s,cc) == 1 || soglia15(s,cc) == 1 && soglia7(s,cc) == 1
Alert_EL(s,prog) = 2; % Allerta del nodo di Livello 2
Date_Alert_EL(s,prog) = Date_1gg(s,n);
Node_Alert_EL(s,prog) = cell2mat(NodoExtensometerLink(nn,n));
ID_Alert_EL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 || soglia7(s,cc) == 1 || soglia15(s,cc) == 1
Alert_EL(s,prog) = 1; % Allerta del nodo di Livello 1
Date_Alert_EL(s,prog) = Date_1gg(s,n);
Node_Alert_EL(s,prog) = cell2mat(NodoExtensometerLink(nn,n));
ID_Alert_EL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
end
end
end
end
end
end
index = index+1;
prog = prog+1;
end
text = ['Data of ' char(chainID(n,2)) '-' char(chainID(n,4)) ' Extensometer Link have been analyzed'];
fprintf(fileID,fmt,text);
index = 1;
end
end
[num_EL,~] = size(rEL);
ini = 1;
fin = cumsum(rEL);
Num_Allarmi_EL = zeros(1,num_EL);
for AL = 1:num_EL
if ini > fin(AL) % si va a quello dopo
else
Livello = max(max(Alert_EL(:,ini:fin(AL))));
if isempty(Livello) == 1
Livello = 0;
end
Num_Allarmi_EL(1,AL) = Livello;
ini = fin(AL)+1;
end
end
end
%% 3D Extensometer Link
if isempty(find(yes3DEL)) == 1 % Non ho 3D Extensometer Link
text = '3D Extensometer Link have not been analyzed during the execution of soglie function';
fprintf(fileID,fmt,text);
Num_Allarmi_3DEL = 0;
else
clear Date_1gg
EL3D = cumsum(r3DEL);
Alert_3DEL = zeros(1,EL3D(end)); % Livello di Allerta
Date_Alert_3DEL = zeros(1,EL3D(end)); % Data di Allerta
Node_Alert_3DEL = zeros(1,EL3D(end)); % Numero di nodo in Allerta
ID_Alert_3DEL = cell(1,EL3D(end)); % ID centralina - ID catena in Allerta
index = 1;
prog = 1;
for n = 1:col % Ripeto per ogni Array
DatiElab = cell(1);
Date = zeros(1);
if yes3DEL(n) == 1
status = system(['/usr/local/matlab_func/run_ATD_lnx.sh /usr/local/MATLAB/MATLAB_Runtime/v93 ' char(chainID(n,2)) ' ' char(chainID(n,4)) '']);
if status == 1
break % se crasha il SW salto l'analisi
end
date_rif = now-15; % 15 giorni
for nn = 1:r3DEL(n) % Ripeto per ogni nodo
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' num2str(cell2mat(Nodo3DExtensometerLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DateElab = curs.Data;
% Modifico il formato di data e ora in DATini.
[rD,cD] = size(DateElab);
if rD ~= 1 && cD ~= 1
T = [cell2mat(DateElab(:,1)) repmat(' ', [rD,1]) cell2mat(DateElab(:,2))];
if nn == 1
Date(1:rD,n) = datenum(T); % scrivo lamatrice date usando il primo nodo
end
comando = ['select XShift, YShift, ZShift from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' num2str(cell2mat(Nodo3DExtensometerLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Control = curs.Data;
[rCD,~] = size(Control);
[rDE,~] = size(DatiElab);
if rCD ~= rDE
if rCD > rDE
DatiElab(1:rCD,index:index+2) = Control;
RIF = rCD;
elseif rCD < rDE
DatiElab(1:rCD,index:index+2) = Control;
DatiElab(rCD+1:rDE,index:index+2) = Control(end,:);
RIF = rDE;
end
else
DatiElab(:,index) = Control; % Tutti i dati dei sensori dell'Array n
RIF = rDE;
end
% Guardo le soglie
[rCheck,cCheck] = size(DatiElab);
if rCheck > 1 && cCheck > 1
% Da Ieri
index1 = find(datenum(Date(:,n))>(now-1));
[rID,~] = size(index1);
if isempty(index1) == 0 && rID ~= 1 % non posso fare la diff
Incrementi_1gg = abs(diff(cell2mat(DatiElab(index1(1):end,index:index+2))));
Date_1gg(1:RIF-index1(1),n) = Date(index1(2):index1(end),n);
% 15 gg
Incrementi_15gg = abs(diff(cell2mat(DatiElab(:,index:index+2))));
ST15 = std(Incrementi_15gg(1:index1(1),:)); % 1 Deviazione standard per i 15 giorni
MAX15 = max(Incrementi_15gg(1:index1(1),:));
% 7 gg
index7 = find(datenum(Date(:,n))>(now-7));
Incrementi_7gg = abs(diff(cell2mat(DatiElab(index7(1):index1(1),index:index+2))));
ST7 = 3*std(Incrementi_7gg); % 3 Deviazioni standard per i 7 giorni
MAX7 = max(Incrementi_7gg);
% 3 gg
index3 = find(datenum(Date(:,n))>(now-3));
Incrementi_3gg = abs(diff(cell2mat(DatiElab(index3(1):index1(1),index:index+2))));
ST3 = 5*std(Incrementi_3gg); % 5 Deviazioni standard per i 3 giorni
MAX3 = max(Incrementi_3gg);
[rI,cI] = size(Incrementi_1gg); % Dati per quel nodo
soglia3 = zeros(rI,cI);
soglia7 = zeros(rI,cI);
soglia15 = zeros(rI,cI);
for cc = 1:cI
for s = 1:rI
if Incrementi_1gg(s,cc) > ST15+MAX15
soglia15(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST7+MAX7
soglia7(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST3+MAX3
soglia3(s,cc) = 1;
end
if soglia3(s,cc) == 1 && soglia7(s,cc) == 1 && soglia15(s,cc) == 1
Alert_3DEL(s,prog) = 3; % Allerta del nodo di Livello 3
Date_Alert_3DEL(s,prog) = Date_1gg(s,n);
Node_Alert_3DEL(s,prog) = cell2mat(Nodo3DExtensometerLink(nn,n));
ID_Alert_3DEL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 && soglia7(s,cc) == 1 || soglia3(s,cc) == 1 && soglia15(s,cc) == 1 || soglia15(s,cc) == 1 && soglia7(s,cc) == 1
Alert_3DEL(s,prog) = 2; % Allerta del nodo di Livello 2
Date_Alert_3DEL(s,prog) = Date_1gg(s,n);
Node_Alert_3DEL(s,prog) = cell2mat(Nodo3DExtensometerLink(nn,n));
ID_Alert_3DEL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 || soglia7(s,cc) == 1 || soglia15(s,cc) == 1
Alert_3DEL(s,prog) = 1; % Allerta del nodo di Livello 1
Date_Alert_3DEL(s,prog) = Date_1gg(s,n);
Node_Alert_3DEL(s,prog) = cell2mat(Nodo3DExtensometerLink(nn,n));
ID_Alert_3DEL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
end
end
end
end
end
end
index = index+3;
prog = prog+1;
end
text = ['Data of ' char(chainID(n,2)) '-' char(chainID(n,4)) ' 3D Extensometer Link have been analyzed'];
fprintf(fileID,fmt,text);
index = 1;
end
end
[num_3DEL,~] = size(r3DEL);
ini = 1;
fin = cumsum(r3DEL);
Num_Allarmi_3DEL = zeros(1,num_3DEL);
for AL = 1:num_3DEL
if ini > fin(AL) % si va a quello dopo
else
Livello = max(max(Alert_3DEL(:,ini:fin(AL))));
if isempty(Livello) == 1
Livello = 0;
end
Num_Allarmi_3DEL(1,AL) = Livello;
ini = fin(AL)+1;
end
end
end
%% Wire Extensometer Link
if isempty(find(yesWEL)) == 1 % Non ho Wire Extensometer Link
text = 'Wire Extensometer Link have not been analyzed during the execution of soglie function';
fprintf(fileID,fmt,text);
Num_Allarmi_WEL = 0;
else
clear Date_1gg
WEL = cumsum(rWEL);
Alert_WEL = zeros(1,WEL(end)); % Livello di Allerta
Date_Alert_WEL = zeros(1,WEL(end)); % Data di Allerta
Node_Alert_WEL = zeros(1,WEL(end)); % Numero di nodo in Allerta
ID_Alert_WEL = cell(1,WEL(end)); % ID centralina - ID catena in Allerta
index = 1;
prog = 1;
for n = 1:col % Ripeto per ogni Array
DatiElab = cell(1);
Date = zeros(1);
if yesWEL(n) == 1
status = system(['/usr/local/matlab_func/run_ATD_lnx.sh /usr/local/MATLAB/MATLAB_Runtime/v93 ' char(chainID(n,2)) ' ' char(chainID(n,4)) '']);
if status == 1
break % se crasha il SW salto l'analisi
end
date_rif = now-15; % 15 giorni
for nn = 1:rWEL(n) % Ripeto per ogni nodo
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' num2str(cell2mat(NodoWireExtensometerLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DateElab = curs.Data;
% Modifico il formato di data e ora in DATini.
[rD,cD] = size(DateElab);
if rD ~= 1 && cD ~= 1
T = [cell2mat(DateElab(:,1)) repmat(' ', [rD,1]) cell2mat(DateElab(:,2))];
if nn == 1
Date(1:rD,n) = datenum(T); % scrivo lamatrice date usando il primo nodo
end
comando = ['select XShift from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' num2str(cell2mat(NodoWireExtensometerLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Control = curs.Data;
[rCD,~] = size(Control);
[rDE,~] = size(DatiElab);
if rCD ~= rDE
if rCD > rDE
DatiElab(1:rCD,index) = Control;
RIF = rCD;
elseif rCD < rDE
DatiElab(1:rCD,index) = Control;
DatiElab(rCD+1:rDE,index) = Control(end,:);
RIF = rDE;
end
else
DatiElab(:,index) = Control; % Tutti i dati dei sensori dell'Array n
RIF = rDE;
end
% Guardo le soglie
[rCheck,cCheck] = size(DatiElab);
if rCheck > 1 && cCheck > 1
% Da Ieri
index1 = find(datenum(Date(:,n))>(now-1));
[rID,~] = size(index1);
if isempty(index1) == 0 && rID ~= 1 % non posso fare la diff
Incrementi_1gg = abs(diff(cell2mat(DatiElab(index1(1):end,index))));
Date_1gg(1:RIF-index1(1),n) = Date(index1(2):index1(end),n);
% 15 gg
Incrementi_15gg = abs(diff(cell2mat(DatiElab(:,index))));
ST15 = std(Incrementi_15gg(1:index1(1),:)); % 1 Deviazione standard per i 15 giorni
MAX15 = max(Incrementi_15gg(1:index1(1),:));
% 7 gg
index7 = find(datenum(Date(:,n))>(now-7));
Incrementi_7gg = abs(diff(cell2mat(DatiElab(index7(1):index1(1),index))));
ST7 = 3*std(Incrementi_7gg); % 3 Deviazioni standard per i 7 giorni
MAX7 = max(Incrementi_7gg);
% 3 gg
index3 = find(datenum(Date(:,n))>(now-3));
Incrementi_3gg = abs(diff(cell2mat(DatiElab(index3(1):index1(1),index))));
ST3 = 5*std(Incrementi_3gg); % 5 Deviazioni standard per i 3 giorni
MAX3 = max(Incrementi_3gg);
[rI,cI] = size(Incrementi_1gg); % Dati per quel nodo
soglia3 = zeros(rI,cI);
soglia7 = zeros(rI,cI);
soglia15 = zeros(rI,cI);
for cc = 1:cI
for s = 1:rI
if Incrementi_1gg(s,cc) > ST15+MAX15
soglia15(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST7+MAX7
soglia7(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST3+MAX3
soglia3(s,cc) = 1;
end
if soglia3(s,cc) == 1 && soglia7(s,cc) == 1 && soglia15(s,cc) == 1
Alert_WEL(s,prog) = 3; % Allerta del nodo di Livello 3
Date_Alert_WEL(s,prog) = Date_1gg(s,n);
Node_Alert_WEL(s,prog) = cell2mat(NodoWireExtensometerLink(nn,n));
ID_Alert_WEL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 && soglia7(s,cc) == 1 || soglia3(s,cc) == 1 && soglia15(s,cc) == 1 || soglia15(s,cc) == 1 && soglia7(s,cc) == 1
Alert_WEL(s,prog) = 2; % Allerta del nodo di Livello 2
Date_Alert_WEL(s,prog) = Date_1gg(s,n);
Node_Alert_WEL(s,prog) = cell2mat(NodoWireExtensometerLink(nn,n));
ID_Alert_WEL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 || soglia7(s,cc) == 1 || soglia15(s,cc) == 1
Alert_WEL(s,prog) = 1; % Allerta del nodo di Livello 1
Date_Alert_WEL(s,prog) = Date_1gg(s,n);
Node_Alert_WEL(s,prog) = cell2mat(NodoWireExtensometerLink(nn,n));
ID_Alert_WEL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
end
end
end
end
end
end
index = index+1;
prog = prog+1;
end
text = ['Data of ' char(chainID(n,2)) '-' char(chainID(n,4)) ' Wire Extensometer Link have been analyzed'];
fprintf(fileID,fmt,text);
index = 1;
end
end
[num_WEL,~] = size(rWEL);
ini = 1;
fin = cumsum(rWEL);
Num_Allarmi_WEL = zeros(1,num_WEL);
for AL = 1:num_WEL
if ini > fin(AL) % si va a quello dopo
else
Livello = max(max(Alert_WEL(:,ini:fin(AL))));
if isempty(Livello) == 1
Livello = 0;
end
Num_Allarmi_WEL(1,AL) = Livello;
ini = fin(AL)+1;
end
end
end
%% Multi Point Borehole Extensometer Link
if isempty(find(yesMPBEL)) == 1 % Non ho In Place Link
text = 'Multi Point Borehole Extensometer Link have not been analyzed during the execution of soglie function';
fprintf(fileID,fmt,text);
Num_Allarmi_MPBEL = 0;
else
clear Date_1gg
MPBEL = cumsum(rMPBEL);
Alert_MPBEL = zeros(1,MPBEL(end)); % Livello di Allerta
Date_Alert_MPBEL = zeros(1,MPBEL(end)); % Data di Allerta
Node_Alert_MPBEL = zeros(1,MPBEL(end)); % Numero di nodo in Allerta
ID_Alert_MPBEL = cell(1,MPBEL(end)); % ID centralina - ID catena in Allerta
index = 1;
prog = 1;
for n = 1:col % Ripeto per ogni Array
DatiElab = cell(1);
Date = zeros(1);
if yesMPBEL(n) == 1
status = system(['/usr/local/matlab_func/run_ATD_lnx.sh /usr/local/MATLAB/MATLAB_Runtime/v93 ' char(chainID(n,2)) ' ' char(chainID(n,4)) '']);
if status == 1
break % se crasha il SW salto l'analisi
end
date_rif = now-15; % 15 giorni
for nn = 1:rMPBEL(n) % Ripeto per ogni nodo
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' num2str(cell2mat(NodoMultiPointExtensometerLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DateElab = curs.Data;
% Modifico il formato di data e ora in DATini.
[rD,cD] = size(DateElab);
if rD ~= 1 && cD ~= 1
T = [cell2mat(DateElab(:,1)) repmat(' ', [rD,1]) cell2mat(DateElab(:,2))];
if nn == 1
Date(1:rD,n) = datenum(T); % scrivo lamatrice date usando il primo nodo
end
comando = ['select XShift, YShift, ZShift, X, Y, Z from ElabDataView where EventDate >= ''' ...
datestr(date_rif,'yyyy-mm-dd') ''' and ToolNameID = ''' char(chainID(n,4))...
''' and UnitName = ''' char(chainID(n,2)) ''' and NodeNum = ''' num2str(cell2mat(NodoMultiPointExtensometerLink(nn,n))) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Control = curs.Data;
[rCD,~] = size(Control);
[rDE,~] = size(DatiElab);
if rCD ~= rDE
if rCD > rDE
DatiElab(1:rCD,index:index+5) = Control;
RIF = rCD;
elseif rCD < rDE
DatiElab(1:rCD,index:index+5) = Control;
DatiElab(rCD+1:rDE,index) = Control(end,1);
DatiElab(rCD+1:rDE,index+1) = Control(end,2);
DatiElab(rCD+1:rDE,index+2) = Control(end,3);
DatiElab(rCD+1:rDE,index+3) = Control(end,4);
DatiElab(rCD+1:rDE,index+4) = Control(end,5);
DatiElab(rCD+1:rDE,index+5) = Control(end,6);
RIF = rDE;
end
else
DatiElab(:,index:index+5) = Control; % Tutti i dati dei sensori dell'Array n
RIF = rCD;
end
% Guardo le soglie
[rCheck,cCheck] = size(DatiElab);
if rCheck > 1 && cCheck > 1
% Da Ieri
index1 = find(datenum(Date(:,n))>(now-1));
[rID,~] = size(index1);
if isempty(index1) == 0 && rID ~= 1 % non posso fare la diff
Incrementi_1gg = abs(diff(cell2mat(DatiElab(index1(1):end,index:index+5))));
Date_1gg(1:RIF-index1(1),n) = Date(index1(2):index1(end),n);
% 15 gg
Incrementi_15gg = abs(diff(cell2mat(DatiElab(:,index:index+5))));
ST15 = std(Incrementi_15gg(1:index1(1),:)); % 1 Deviazione standard per i 15 giorni
MAX15 = max(Incrementi_15gg(1:index1(1),:));
% 7 gg
index7 = find(datenum(Date(:,n))>(now-7));
Incrementi_7gg = abs(diff(cell2mat(DatiElab(index7(1):index1(1),index:index+5))));
ST7 = 3*std(Incrementi_7gg); % 3 Deviazioni standard per i 7 giorni
MAX7 = max(Incrementi_7gg);
% 3 gg
index3 = find(datenum(Date(:,n))>(now-3));
Incrementi_3gg = abs(diff(cell2mat(DatiElab(index3(1):index1(1),index:index+5))));
ST3 = 5*std(Incrementi_3gg); % 5 Deviazioni standard per i 3 giorni
MAX3 = max(Incrementi_3gg);
[rI,cI] = size(Incrementi_1gg); % Dati per quel nodo
soglia3 = zeros(rI,cI);
soglia7 = zeros(rI,cI);
soglia15 = zeros(rI,cI);
for cc = 1:cI
for s = 1:rI
if Incrementi_1gg(s,cc) > ST15+MAX15
soglia15(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST7+MAX7
soglia7(s,cc) = 1;
end
if Incrementi_1gg(s,cc) > ST3+MAX3
soglia3(s,cc) = 1;
end
if soglia3(s,cc) == 1 && soglia7(s,cc) == 1 && soglia15(s,cc) == 1
Alert_MPBEL(s,prog) = 3; % Allerta del nodo di Livello 3
Date_Alert_MPBEL(s,prog) = Date_1gg(s,n);
Node_Alert_MPBEL(s,prog) = cell2mat(NodoMultiPointExtensometerLink(nn,n));
ID_Alert_MPBEL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 && soglia7(s,cc) == 1 || soglia3(s,cc) == 1 && soglia15(s,cc) == 1 || soglia15(s,cc) == 1 && soglia7(s,cc) == 1
Alert_MPBEL(s,prog) = 2; % Allerta del nodo di Livello 2
Date_Alert_MPBEL(s,prog) = Date_1gg(s,n);
Node_Alert_MPBEL(s,prog) = cell2mat(NodoMultiPointExtensometerLink(nn,n));
ID_Alert_MPBEL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
elseif soglia3(s,cc) == 1 || soglia7(s,cc) == 1 || soglia15(s,cc) == 1
Alert_MPBEL(s,prog) = 1; % Allerta del nodo di Livello 1
Date_Alert_MPBEL(s,prog) = Date_1gg(s,n);
Node_Alert_MPBEL(s,prog) = cell2mat(NodoMultiPointExtensometerLink(nn,n));
ID_Alert_MPBEL(1,prog) = cellstr([char(chainID(n,2)) '-' char(chainID(n,4))]);
end
end
end
end
end
end
index = index+6;
prog = prog+1;
end
fprintf(fileID,fmt,text);
text = ['Data of ' char(chainID(n,2)) '-' char(chainID(n,4)) ' MultiPoint Extensometer Link have been analyzed'];
index = 1;
end
end
[num_MPBEL,~] = size(rMPBEL);
ini = 1;
fin = cumsum(rMPBEL);
Num_Allarmi_MPBEL = zeros(1,num_MPBEL);
for AL = 1:num_MPBEL
if ini > fin(AL) % si va a quello dopo
else
Livello = max(max(Alert_MPBEL(:,ini:fin(AL))));
if isempty(Livello) == 1
Livello = 0;
end
Num_Allarmi_MPBEL(1,AL) = Livello;
ini = fin(AL)+1;
end
end
end
%% Valuto il numero di Array e Sensori che ho in sito
% In questa parte del codice ogni sensore posto in una posizione conta "1".
% Ad esempio due Vertical Array con 20 sensori Tilt Link V per ognuno conta
% 2 Sensori, mentre 3 clinometri in una stessa catena contano 3
Num_Sensori = cumsum(yesTL + yesTLHR + yesTLH + yesTLHRH + yesIPL + yesIPLHR + ...
yesTuL + yesRL + yesPCL + yesPCLHR + rKL + rKLHR + rCrL + r3DCrL +...
rEL + r3DEL + + rLL + rPrL + rMPBEL + yesPL + rRaL + rWEL);
Num_Sensori = Num_Sensori(end);
Num_Allarmi = cumsum(Num_Allarmi_TL) + cumsum(Num_Allarmi_TLHR) + cumsum(Num_Allarmi_TLH) +...
cumsum(Num_Allarmi_TLHRH) + cumsum(Num_Allarmi_IPL) + cumsum(Num_Allarmi_IPLHR) +...
cumsum(Num_Allarmi_TuL) + cumsum(Num_Allarmi_RL) + cumsum(Num_Allarmi_PCL) +...
cumsum(Num_Allarmi_PCLHR) + cumsum(Num_Allarmi_KL) + cumsum(Num_Allarmi_KLHR) +...
cumsum(Num_Allarmi_CrL) + cumsum(Num_Allarmi_3DCrL) + cumsum(Num_Allarmi_PL) +...
cumsum(Num_Allarmi_RaL) + cumsum(Num_Allarmi_MPBEL) + cumsum(Num_Allarmi_WEL) + ...
cumsum(Num_Allarmi_3DEL) + cumsum(Num_Allarmi_EL) + cumsum(Num_Allarmi_PrL) +...
cumsum(Num_Allarmi_LL);
Num_Allarmi = Num_Allarmi(end);
Codice_Allerta = Num_Allarmi*100/(Num_Sensori*3);
if isnan(Codice_Allerta) == 1
Codice_Allerta = 0;
end
alert = 0;
alarm = 0;
Code = 0;
if Codice_Allerta <= 25
Codex = 'White';
Code = 1;
elseif Codice_Allerta > 25 && Codice_Allerta <= 50
Codex = 'Green';
Code = 2;
elseif Codice_Allerta > 50 && Codice_Allerta <= 75
Codex = 'Yellow';
Codice = 'Giallo';
alert = 1;
Code = 3;
elseif Codice_Allerta > 75 && Codice_Allerta <= 90
Codex = 'Orange';
Codice = 'Arancione';
alert = 1;
Code = 4;
elseif Codice_Allerta > 90
Codex = 'Red';
Codice = 'Rosso';
if Num_Sensori < 5
alarm = 0;
alert = 1;
Code = 4.5;
else
alarm = 1;
Code = 5;
end
end
comando = ['select name from sites where id = ''' num2str(cell2mat(siteID)) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
sito = char(curs.Data);
FileNameFIFA = ['' sito '.txt'];
Date = importdata(FileNameFIFA);
if now > Date(1,1) +1 || Code > Date(2,1)
if alert == 1 || alarm == 1
% Email
setpref('Internet','E_mail','aseparma@gmail.com');
setpref('Internet','SMTP_Server','smtp.gmail.com');
setpref('Internet','SMTP_Username','aseparma@gmail.com');
setpref('Internet','SMTP_Password','Mums@2016');
props=java.lang.System.getProperties;
pp=props.setProperty('mail.smtp.auth','true'); %#ok
pp=props.setProperty('mail.smtp.socketFactory.class','javax.net.ssl.SSLSocketFactory'); %#ok
pp=props.setProperty('mail.smtp.socketFactory.port','465'); %#ok
% A chi mando la mail
recipients_ITA{1,1} = 'alessandro.valletta@aseltd.eu';
recipients_ITA{2,1} = 'andrea.carri@aseltd.eu';
% Messaggio
if alert == 1
text = 'Alert procedure activated';
fprintf(fileID,fmt,text);
subject_ITA = ['ASE Alert: ALLERTA di codice ''' Codice ''' registrata nel sito di ''' sito ''' '];
message_ITA = cellstr(['Gentile utente, si segnala un''allerta di codice ''' Codice...
''' nel sito di ''' sito ''' con indice pari a ''' num2str(Codice_Allerta)...
''' /100 .']);
elseif alarm == 1
text = 'Alarm procedure activated';
fprintf(fileID,fmt,text);
subject_ITA = ['ASE Alert: ALLARME di codice ''' Codice ''' registrato nel sito di ''' sito ''' '];
message_ITA = cellstr(['Gentile utente, si segnala un''allarme di codice ''' Codice...
''' nel sito di ''' sito ''' con indice pari a ''' num2str(Codice_Allerta)...
''' /100 .']);
% Criterio = 'FIFA';
% SMS(IDcentralina,DTcatena,Sito,siteID,conn,Criterio,alert,alarm,FileName);
fileID = fopen(FileName,'a');
fmt = '%s \r';
end
message = cellstr('Il team di ASE S.r.l.');
message_ITA = [message_ITA; message];
% Mando la mail
sendmail(recipients_ITA, subject_ITA, message_ITA)
end
end
outdat = fopen(FileNameFIFA,'wt+');
fileID_site = fopen(FileNameFIFA,'a');
fmt_site = '%.10f \r';
text = now;
fprintf(fileID_site,fmt_site,text);
text = Code;
fprintf(fileID_site,fmt_site,text);
fclose(fileID_site);
text = 'soglie function worked correctly.';
fprintf(fileID,fmt,text);
fclose(fileID);
catch
text = 'soglie function CRASHED.';
fprintf(fileID,fmt,text);
fclose(fileID);
end
else
text = 'soglie function executed with no calculations.';
fprintf(fileID,fmt,text);
fclose(fileID);
end
end