function [sogliaRSN,trigRSN,sogliaHR,trigHR,sogliaLL,trigLL,tipomail_MOD,... codice_mail,codice_SMS,MATsoglie,DT_BPM] = Triggercheck... (IDcentralina,DTcatena,conn,ARRAYdateTrL,TrigMod,i,j,date,FileName) %% Individuo i moduli associati al Trigger %scrivo nel logfile text = 'Funzione Triggercheck per il controllo delle soglie di trend inizializzata'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); DT_BPM=TrigMod(:,j); %indice j --> numero trigger %% Scarico i dati del Trigger Link data_rif = ARRAYdateTrL(i,1)-7; %7--> n° giorni su cui calcolare il trend if data_rif > datenum(date) data = datestr(data_rif,'yyyy-mm-dd'); else data = date; end NodeNum = num2str(j); comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ... data ''' and ToolNameID = ''' DTcatena ''' and UnitName = ''' IDcentralina ... ''' and NodeNum = ''' NodeNum ''' ']; curs = exec(conn,comando); curs = fetch(curs); Dati = curs.Data; % Modifico il formato di data e ora in DATini. [rD,~] = size(Dati); T = [cell2mat(Dati(:,1)) repmat(' ', [rD,1]) cell2mat(Dati(:,2))]; DateTrigger = datenum(T); dataindex = find(DateTrigger(:,1) == ARRAYdateTrL(i,1)); DataRifTRIGGER = DateTrigger(dataindex-1); % ultima data PRIMA dell'attivazione del trigger % Scarico i dati di attivazione del Trigger comando = ['select Xshift from ElabDataView where EventDate >= ''' ... data ''' and ToolNameID = ''' DTcatena ''' and UnitName = ''' IDcentralina ... ''' and NodeNum = ''' NodeNum ''' ']; curs = exec(conn,comando); curs = fetch(curs); DatiTrigger = cell2mat(curs.Data); %% scarico dati per calcolo trend e confronto soglie %inizializzo variabili [rBPM,~]=size(DT_BPM); sogliaRSN = zeros(rBPM,1); %soglie disattivate sogliaHR = zeros(rBPM,1); sogliaLL = zeros(rBPM,1); tipomail_MOD = zeros(rBPM,1); %tipo di mail da inviare tipomail_RSN = zeros(rBPM,1); %stato singoli sensori tipomail_HR = zeros(rBPM,1); tipomail_LL = zeros(rBPM,1); codice_SMS = 0; %livello di allerta SMS trigRSN(1:rBPM,1) = 99999; %valore "neutro" di incremento trigHR(1:rBPM,1) = 99999; trigLL(1:rBPM,1) = 99999; for n=1:rBPM if isempty(DT_BPM{n}) == 0 % ho un modulo BPM da elaborare DTmodulo = char(DT_BPM(n)); AlfaX_RSN = []; % matrici di dati (azzerate per evitare problemi di dimensioni tra array) AlfaX_HR = []; DatiCella = []; %scrivo nel logfile text = ['Inizio confronto soglia di trend per modulo ' DTmodulo '']; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); %% A partire dal nome della catena, risalgo all'identificativo con cui è % definita nel Database (mi serve successivamente) comando = ['select id from units where name = ''' IDcentralina ''' ']; unitID = num2str(cell2mat(fetch(conn,comando))); comando = ['select id from tools where name = ''' DTmodulo ''' and unit_id = ''' unitID ''' ']; idTool = num2str(cell2mat(fetch(conn,comando))); % leggo e converto in stringa %% Determino sensori per ciascun modulo RSN comando = ['select nodetype_id, num from nodes where tool_id = ''' idTool ''' order by num']; modulo = fetch(conn,comando); usoRSN = find(cell2mat(modulo(:,1)) == 38); % controllo presenza di RSN Link usoRSNHR = find(cell2mat(modulo(:,1)) == 39); % controllo presenza di RSNHR Link usoLOAD = find(cell2mat(modulo(:,1)) == 15); % controllo presenza di Load Link % RSN Link if isempty(usoRSN)== 0 data_rif = ARRAYdateTrL(i,1)-7; %7--> n° giorni su cui calcolare il trend if data_rif > datenum(date) data = datestr(data_rif,'yyyy-mm-dd'); else data = date; end NodeNum = num2str(cell2mat(modulo(usoRSN,2))); comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ... data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ... ''' and NodeNum = ''' NodeNum ''' ']; curs = exec(conn,comando); curs = fetch(curs); Dati = curs.Data; % Modifico il formato di data e ora in DATini. [rD,~] = size(Dati); T = [cell2mat(Dati(:,1)) repmat(' ', [rD,1]) cell2mat(Dati(:,2))]; DateRSN = datenum(T); indexRSN = find(DateRSN(:,1)<=DateTrigger(dataindex)); LastDataRSN = DateRSN(indexRSN(end)); % Scarico i dati X comando = ['select AlfaX from ElabDataView where EventDate >= ''' ... data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ... ''' and NodeNum = ''' NodeNum ''' ']; curs = exec(conn,comando); curs = fetch(curs); AlfaX_RSN(:,1) = cell2mat(curs.Data); % Scarico i dati calcerr comando = ['select calcerr from ElabDataView where EventDate >= ''' ... data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ... ''' and NodeNum = ''' NodeNum ''' ']; curs = exec(conn,comando); curs = fetch(curs); AlfaX_RSN(:,2) = cell2mat(curs.Data); %scrivo nel logfile text = 'Dati elaborati scaricati per RSN Link'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); end % RSNHR Link if isempty(usoRSNHR)== 0 data_rif = ARRAYdateTrL(i,1)-7; %7--> n° giorni su cui calcolare il trend if data_rif > datenum(date) data = datestr(data_rif,'yyyy-mm-dd'); else data = date; end NodeNum = num2str(cell2mat(modulo(usoRSNHR,2))); comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ... data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ... ''' and NodeNum = ''' NodeNum ''' ']; curs = exec(conn,comando); curs = fetch(curs); Dati = curs.Data; % Modifico il formato di data e ora in DATini. [rD,~] = size(Dati); T = [cell2mat(Dati(:,1)) repmat(' ', [rD,1]) cell2mat(Dati(:,2))]; DateHR = datenum(T); indexHR = find(DateHR(:,1)<=DateTrigger(dataindex)); LastDataHR = DateHR(indexHR(end)); % Scarico i dati X comando = ['select AlfaX from ElabDataView where EventDate >= ''' ... data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ... ''' and NodeNum = ''' NodeNum ''' ']; curs = exec(conn,comando); curs = fetch(curs); AlfaX_HR(:,1) = cell2mat(curs.Data); % Scarico i dati calcerr comando = ['select calcerr from ElabDataView where EventDate >= ''' ... data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ... ''' and NodeNum = ''' NodeNum ''' ']; curs = exec(conn,comando); curs = fetch(curs); AlfaX_HR(:,2) = cell2mat(curs.Data); %scrivo nel logfile text = 'Dati elaborati scaricati per RSNHR Link'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); end % Load Link if isempty(usoLOAD)== 0 data_rif = ARRAYdateTrL(i,1)-7; %7--> n° giorni su cui calcolare il trend if data_rif > datenum(date) data = datestr(data_rif,'yyyy-mm-dd'); else data = date; end NodeNum = num2str(cell2mat(modulo(usoLOAD,2))); comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ... data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ... ''' and NodeNum = ''' NodeNum ''' ']; curs = exec(conn,comando); curs = fetch(curs); Dati = curs.Data; % Modifico il formato di data e ora in DATini. [rD,~] = size(Dati); T = [cell2mat(Dati(:,1)) repmat(' ', [rD,1]) cell2mat(Dati(:,2))]; DateLL = datenum(T); indexLL = find(DateLL(:,1)<=DateTrigger(dataindex)); LastDataLOAD = DateLL(indexLL(end)); % Scarico i dati di carico comando = ['select load_value from ElabDataView where EventDate >= ''' ... data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ... ''' and NodeNum = ''' NodeNum ''' ']; curs = exec(conn,comando); curs = fetch(curs); DatiCella(:,1) = cell2mat(curs.Data); % Scarico i dati calcerr comando = ['select calcerr from ElabDataView where EventDate >= ''' ... data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ... ''' and NodeNum = ''' NodeNum ''' ']; curs = exec(conn,comando); curs = fetch(curs); DatiCella(:,2) = cell2mat(curs.Data); %scrivo nel logfile text = 'Dati elaborati scaricati per Load Link'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); end %% Rimuovo le letture dei moduli eseguite all'attivazione di un Trigger, % non necessarie per il calcolo del trend rT = dataindex; %contatore dati MatRSN = AlfaX_RSN; MatRSNHR = AlfaX_HR; MatLOAD = DatiCella; %creo nuovi indici da aggiornare per "seguire" la dimensione della %matrice su cui calcolare il trend indextrendRSN = indexRSN(end); indextrendHR = indexHR(end); indextrendLL = indexLL(end); del = 0; for k=1:rT if DatiTrigger(k,1)>=1 del = del + 1 ; if isempty(usoRSN)== 0 indextrendRSN = indextrendRSN - 1; precedRSN = find(DateRSN(:,1) <= DateTrigger(k,1)); MatRSN(precedRSN(end),:) = []; DateRSN(precedRSN(end),:) = []; end if isempty(usoRSNHR)== 0 indextrendHR = indextrendHR - 1; precedRSNHR = find(DateHR(:,1) <= DateTrigger(k,1)); MatRSNHR(precedRSNHR(end),:)=[]; DateHR(precedRSNHR(end),:) = []; end if isempty(usoLOAD)== 0 indextrendLL = indextrendLL - 1; precedLL = find(DateLL(:,1) <= DateTrigger(k,1)); MatLOAD(precedLL(end),:)=[]; DateLL(precedLL(end),:)=[]; end end end %scrivo nel logfile text = ['Creazione matrice di trend: Rimosse ' num2str(del) ' letture relative al modulo ' DTmodulo '']; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); %% Calcolo il trend di ciascun sensore presente nel modulo if isempty(usoRSN)== 0 nRSN = indextrendRSN; toterrRSN = sum(MatRSN(1:indextrendRSN,2)); if toterrRSN/nRSN > 0.5 % dati insufficienti a calcolare un trend significativo trendRSN=99999; else trendRSN = mean(diff(MatRSN(1:indextrendRSN,1))); end end if isempty(usoRSNHR)== 0 nRSNHR = indextrendHR; toterrRSNHR = sum(MatRSNHR(1:indextrendHR,2)); if toterrRSNHR/nRSNHR > 0.5 % dati insufficienti a calcolare un trend significativo trendHR=99999; else trendHR = mean(diff(MatRSNHR(1:indextrendHR,1))); end end if isempty(usoLOAD)== 0 nLL = indextrendLL; toterrLL = sum(MatLOAD(1:indextrendLL,2)); if toterrLL/nLL > 0.5 % dati insufficienti a calcolare un trend significativo trendLL=99999; else trendLL = mean(diff(MatLOAD(1:indextrendLL,1))); end end %scrivo nel logfile text = ['Trend calcolati per il modulo ' DTmodulo '']; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); %% Controllo che il modulo BPM sia già stato elaborato, altrimenti forzo % la funzione RSN per quel modulo in modo da avere l'ultimo dato elaborato % RSN Link %scrivo nel logfile text = 'Inizio controllo soglie di trend per RSN'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); nuovidati = 0; incRSN=1; if isempty(usoRSN)== 0 if LastDataRSN >= DataRifTRIGGER if AlfaX_RSN(indexRSN(end),2)==0 %lettura valida, calcolo incremento valRSN = AlfaX_RSN(indexRSN(end),1); trigRSN(n,1) = valRSN - AlfaX_RSN(indexRSN(end-1),1); %incremento allo scatto del trigger %scrivo nel logfile text = 'Confronto con soglia di trend RSN - nessun ricalcolo eseguito, incremento calcolato'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); elseif AlfaX_RSN(indexRSN(end),2)==1 && AlfaX_RSN(indexRSN(end-1),2)==0 %la lettura precedente NON è in errore, allarme sogliaRSN(n,1)=1; incRSN=0; tipomail_RSN(n,1)=0.33; %scrivo nel logfile text = 'Confronto con soglia di trend RSN - nessun ricalcolo eseguito, incremento NON calcolato/allarme per lettura precedente NON errore'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); elseif AlfaX_RSN(indexRSN(end),2)==1 && AlfaX_RSN(indexRSN(end-1),2)==1 %letture in errore, trigger disattivato sogliaRSN(n,1)=0; incRSN=0; %scrivo nel logfile text = 'Confronto con soglia di trend RSN - nessun ricalcolo eseguito, incremento NON calcolato/modulo in errore'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); end else rilancio = ['/usr/local/matlab_func/run_RSN_lnx.sh /usr/local/MATLAB/MATLAB_Runtime/v93 '... IDcentralina ' ' DTmodulo '']; status = system(rilancio); %forzo RSN nuovidati = 1; %ultimi dati elaborati disponibili per tutti i sensori successivi %scrivo nel logfile text = 'Confronto con soglia di trend RSN - il software e'''' stato rilanciato!'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); data_rif = ARRAYdateTrL(i-1,1); if data_rif > datenum(date) data = datestr(data_rif,'yyyy-mm-dd'); else data = date; end NodeNum = num2str(cell2mat(modulo(usoRSN,2))); comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ... data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ... ''' and NodeNum = ''' NodeNum ''' ']; curs = exec(conn,comando); curs = fetch(curs); Dati = curs.Data; % Modifico il formato di data e ora in DATini. [rD,~] = size(Dati); T = [cell2mat(Dati(:,1)) repmat(' ', [rD,1]) cell2mat(Dati(:,2))]; Date = datenum(T); indexRSN = indexRSN +1; % la data del Trigger è quella aggiunta dalla rielaborazione % Scarico i dati X comando = ['select AlfaX from ElabDataView where EventDate >= ''' ... data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ... ''' and NodeNum = ''' NodeNum ''' ']; curs = exec(conn,comando); curs = fetch(curs); valRSN = cell2mat(curs.Data); %valore post attivazione Trigger valRSN = valRSN(indexRSN(end)); % Scarico i dati calcerr comando = ['select calcerr from ElabDataView where EventDate >= ''' ... data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ... ''' and NodeNum = ''' NodeNum ''' ']; curs = exec(conn,comando); curs = fetch(curs); erroreRSN = cell2mat(curs.Data); %lettura valida-0 o in errore-1 erroreRSN = erroreRSN(indexRSN(end)); if erroreRSN ==0 %lettura valida, calcolo incremento trigRSN(n,1) = valRSN - AlfaX_RSN(indexRSN(end),1); %incremento allo scatto del trigger %scrivo nel logfile text = 'Confronto con soglia di trend RSN - ricalcolo eseguito, incremento calcolato'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); elseif erroreRSN==1 && AlfaX_RSN(indexRSN(end),2)==0 %la lettura precedente NON è in errore, allarme sogliaRSN(n,1)=1; incRSN=0; tipomail_RSN(n,1)=0.33; %scrivo nel logfile text = 'Confronto con soglia di trend RSN - ricalcolo eseguito, incremento NON calcolato/allarme per lettura precedente NON errore'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); elseif erroreRSN==1 && AlfaX_RSN(indexRSN(end),2)==1 %letture in errore, trigger disattivato sogliaRSN(n,1)=0; incRSN=0; %scrivo nel logfile text = 'Confronto con soglia di trend RSN - ricalcolo eseguito, incremento NON calcolato/modulo in errore'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); end end if incRSN==1 && trendRSN ~= 99999 %devo calcolare un incremento if abs(trigRSN(n,1))/abs(trendRSN) >= 1.3 %SOGLIA DI TREND SUPERATA! sogliaRSN(n,1) = 1; tipomail_RSN(n,1)=1; %scrivo nel logfile text = 'Soglia di trend per RSN Link superata!'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); else sogliaRSN(n,1) = 0; %scrivo nel logfile text = 'Soglia di trend per RSN Link non superata!'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); end end else trigRSN(n,1)=99999; %manca il sensore RSN oppure dati insufficienti per calcolare trend %scrivo nel logfile text = 'RSN assente o dati insufficienti: impossibile calcolare la soglia di trend per RSN'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); end % RSNHR Link %scrivo nel logfile text = 'Inizio controllo soglie di trend per RSNHR'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); incHR=1; if isempty(usoRSNHR)== 0 if LastDataHR >= DataRifTRIGGER if AlfaX_HR(indexHR(end),2)==0 %lettura valida, calcolo incremento valHR = AlfaX_HR(indexHR(end),1); trigHR(n,1) = valHR - AlfaX_HR(indexHR(end-1),1); %incremento allo scatto del trigger %scrivo nel logfile text = 'Confronto con soglia di trend RSNHR - nessun ricalcolo eseguito, incremento calcolato'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); elseif AlfaX_HR(indexHR(end),2)==1 && AlfaX_HR(indexHR(end-1),2)==0 %la lettura precedente NON è in errore, allarme sogliaHR(n,1)=1; incHR=0; tipomail_HR(n,1)=0.33; %scrivo nel logfile text = 'Confronto con soglia di trend RSNHR - nessun ricalcolo eseguito, incremento NON calcolato/allarme per lettura precedente NON errore'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); elseif AlfaX_HR(indexHR(end),2)==1 && AlfaX_HR(indexHR(end-1),2)==1 %letture in errore, trigger disattivato sogliaHR(n,1)=0; incHR=0; %scrivo nel logfile text = 'Confronto con soglia di trend RSNHR - nessun ricalcolo eseguito, incremento NON calcolato/modulo in errore'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); end else if nuovidati == 0 %nessun sensore ha già forzato RSN rilancio = ['/usr/local/matlab_func/run_RSN_lnx.sh /usr/local/MATLAB/MATLAB_Runtime/v93 '... IDcentralina ' ' DTmodulo '']; status = system(rilancio); %forzo RSN nuovidati = 1; %scrivo nel logfile text = 'Confronto con soglia di trend RSN HR - il software e'''' stato rilanciato'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); end data_rif = ARRAYdateTrL(i-1,1); if data_rif > datenum(date) data = datestr(data_rif,'yyyy-mm-dd'); else data = date; end NodeNum = num2str(cell2mat(modulo(usoRSNHR,2))); comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ... data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ... ''' and NodeNum = ''' NodeNum ''' ']; curs = exec(conn,comando); curs = fetch(curs); Dati = curs.Data; % Modifico il formato di data e ora in DATini. [rD,~] = size(Dati); T = [cell2mat(Dati(:,1)) repmat(' ', [rD,1]) cell2mat(Dati(:,2))]; Date = datenum(T); indexHR = indexHR + 1; % la data del Trigger è quella aggiunta dalla rielaborazione % Scarico i dati X comando = ['select AlfaX from ElabDataView where EventDate >= ''' ... data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ... ''' and NodeNum = ''' NodeNum ''' ']; curs = exec(conn,comando); curs = fetch(curs); valHR = cell2mat(curs.Data); %valore post attivazione Trigger valHR = valHR(indexHR(end)); % Scarico i dati calcerr comando = ['select calcerr from ElabDataView where EventDate >= ''' ... data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ... ''' and NodeNum = ''' NodeNum ''' ']; curs = exec(conn,comando); curs = fetch(curs); erroreHR = cell2mat(curs.Data); erroreHR = erroreHR(indexHR(end)); if erroreHR ==0 %lettura valida, calcolo incremento trigHR(n,1) = valHR - AlfaX_HR(indexHR(end),1); %incremento allo scatto del trigger %scrivo nel logfile text = 'Confronto con soglia di trend RSNHR - ricalcolo eseguito, incremento calcolato'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); elseif erroreHR==1 && AlfaX_HR(indexHR(end),2)==0 %la lettura precedente NON è in errore, allarme sogliaHR(n,1)=1; incHR=0; tipomail_HR(n,1)=0.33; %scrivo nel logfile text = 'Confronto con soglia di trend RSNHR - ricalcolo eseguito, incremento NON calcolato/allarme per lettura precedente NON errore'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); elseif erroreHR==1 && AlfaX_HR(indexHR(end),2)==1 %letture in errore, trigger disattivato sogliaRSN(n,1)=0; incHR=0; %scrivo nel logfile text = 'Confronto con soglia di trend RSNHR - ricalcolo eseguito, incremento NON calcolato/trigger in errore'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); end end if incHR==1 && trendHR ~= 99999 if abs(trigHR(n,1))/abs(trendHR) >= 1.3 %SOGLIA DI TREND SUPERATA! sogliaHR(n,1) = 1; tipomail_HR(n,1)=1; %scrivo nel logfile text = 'Soglia di trend per RSNHR Link superata!'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); else sogliaHR(n,1) = 0; %scrivo nel logfile text = 'Soglia di trend per RSNHR Link non superata!'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); end end else trigHR(n,1)=99999; %manca il sensore RSN HR oppure dati insufficienti per calcolare trend %scrivo nel logfile text = 'RSNHR assente, letture in errore o dati insufficienti: impossibile calcolare la soglia di trend per RSNHR'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); end % Load Link %scrivo nel logfile text = 'Inizio controllo soglie di trend per LL'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); incLL=1; if isempty(usoLOAD)== 0 if LastDataLOAD >= DataRifTRIGGER if DatiCella(indexLL(end),2)==0 %lettura valida, calcolo incremento valLL = DatiCella(indexLL(end),1); trigLL(n,1) = valLL - DatiCella(indexLL(end-1),1); %incremento allo scatto del trigger %scrivo nel logfile text = 'Confronto con soglia di trend LL - nessun ricalcolo eseguito, incremento calcolato'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); elseif DatiCella(indexLL(end),2)==1 && DatiCella(indexLL(end-1),2)==0 %la lettura precedente NON è in errore, allarme sogliaLL(n,1)=1; incLL=0; tipomail_LL(n,1)=0.33; %scrivo nel logfile text = 'Confronto con soglia di trend LL - nessun ricalcolo eseguito, incremento NON calcolato/allarme per lettura precedente NON errore'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); elseif DatiCella(indexLL(end),2)==1 && DatiCella(indexLL(end-1),2)==1 %la misura precedente è in errore, trigger disattivato sogliaLL(n,1)=0; incLL=0; %scrivo nel logfile text = 'Confronto con soglia di trend LL - nessun ricalcolo eseguito, incremento NON calcolato/trigger in errore'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); end else if nuovidati == 0 %nessun sensore ha già forzato RSN rilancio = ['/usr/local/matlab_func/run_RSN_lnx.sh /usr/local/MATLAB/MATLAB_Runtime/v93 '... IDcentralina ' ' DTmodulo '']; status = system(rilancio); %forzo RSN nuovidati = 1; %scrivo nel logfile text = 'Confronto con soglia di trend LL - il software e'''' stato rilanciato'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); end data_rif = ARRAYdateTrL(i-1,1); if data_rif > datenum(date) data = datestr(data_rif,'yyyy-mm-dd'); else data = date; end NodeNum = num2str(cell2mat(modulo(usoLOAD,2))); comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ... data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ... ''' and NodeNum = ''' NodeNum ''' ']; curs = exec(conn,comando); curs = fetch(curs); Dati = curs.Data; % Modifico il formato di data e ora in DATini. [rD,~] = size(Dati); T = [cell2mat(Dati(:,1)) repmat(' ', [rD,1]) cell2mat(Dati(:,2))]; Date = datenum(T); indexLL = indexLL + 1; % la lettura del Trigger è quella aggiunta dalla rielaborazione comando = ['select load_value from ElabDataView where EventDate >= ''' ... data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ... ''' and NodeNum = ''' NodeNum ''' ']; curs = exec(conn,comando); curs = fetch(curs); valLL = cell2mat(curs.Data); %valore post attivazione Trigger valLL = valLL(indexLL(end)); % Scarico i dati calcerr comando = ['select calcerr from ElabDataView where EventDate >= ''' ... data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ... ''' and NodeNum = ''' NodeNum ''' ']; curs = exec(conn,comando); curs = fetch(curs); erroreLL = cell2mat(curs.Data); erroreLL = erroreLL(indexLL(end)); if erroreLL==0 %lettura valida, calcolo incremento trigLL(n,1) = valLL - DatiCella(indexLL(end),1); %incremento allo scatto del trigger %scrivo nel logfile text = 'Confronto con soglia di trend LL - ricalcolo eseguito, incremento calcolato'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); elseif erroreLL==1 && DatiCella(indexLL(end),2)==0 %la lettura precedente NON è in errore, allarme sogliaLL(n,1)=1; incLL=0; tipomail_LL(n,1)=0.33; %scrivo nel logfile text = 'Confronto con soglia di trend LL - ricalcolo eseguito, incremento NON calcolato/allarme per lettura precedente NON errore'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); elseif erroreLL==1 && DatiCella(indexLL(end),2)==1 %la misura precedente è in errore, trigger disattivato sogliaLL(n,1)=0; incLL=0; %scrivo nel logfile text = 'Confronto con soglia di trend LL - ricalcolo eseguito, incremento NON calcolato/trigger in errore'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); end end if incLL==1 && trendLL ~= 99999 if abs(trigLL(n,1))/abs(trendLL) >= 1.3 %SOGLIA DI TREND SUPERATA! sogliaLL(n,1) = 1; tipomail_LL(n,1)=1; %scrivo nel logfile text = 'Soglia di trend per Load Link superata!'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); else sogliaLL(n,1) = 0; %scrivo nel logfile text = 'Soglia di trend per Load Link non superata!'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); end end else trigLL(n,1)=99999; %manca il sensore LL oppure dati insufficienti per calcolare trend %scrivo nel logfile text = 'LL assente, letture in errore o dati insufficienti: impossibile calcolare la soglia di trend per LL'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); end soglie_modulo = [tipomail_RSN(n,1) tipomail_HR(n,1) tipomail_LL(n,1)]; MATsoglie = []; if sum(soglie_modulo) == 0 || sum(soglie_modulo) == 1 tipomail_MOD(n,1) = 0; elseif sum(soglie_modulo) > 0 && sum(soglie_modulo) < 2 tipomail_MOD(n,1) = 0.5; elseif sum(soglie_modulo) >= 2 tipomail_MOD(n,1) = 1; end %scrivo nel logfile text = ['Codice di invio mail definito per modulo ' DTmodulo '']; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID); end end codice_mail = max(tipomail_MOD); %LIVELLO DI ALLERTAMENTO PER L'INVIO MAIL %scrivo nel logfile text = 'Funzione Triggercheck per il controllo delle soglie di trend eseguita correttamente'; fileID = fopen(FileName,'a'); fmt = '%s \r'; fprintf(fileID,fmt,text); fclose(fileID);