Files
matlab-python/ATD/report_table.m

600 lines
21 KiB
Matlab
Executable File

function [status,firstdata_num,datasample,colonna1,colonna2,colonna2bis,colonna3,...
colonna4,colonna5,colonna6,colonna6_short,colonna7,yesKLHR3D,c1trigger,c6trigger,cA] = ...
report_table(info_sito,controlsito,tipoarray,tipoalarms,alarms,chainID,Chain_Scheme,...
yesTL,yesTLHR,yesTLH,yesTLHRH,yesPL,yesBL,yesLL,yesRL,yesKL,yesKLHR,yesThL,...
yesPT100,yesIPL,yesIPLHR,yesTuL,yesRaL,yesPCL,yesPCLHR,yesPrL,yesEL,yes3DEL,...
yesWEL,yesMPBEL,yesCrL,yes3DCrL,yesBML,yesHL,yesLuxL,yesCO2,yesRSN,yesRSNHR,yesTrL,...
yesPE,yesWL,yes2DCrL,yesGF,yesGS,rTL,rTLHR,rTLH,rTLHRH,rKL,rKLHR,rIPL,rIPLHR,nCT,...
num_nodi,time,conn,FileName)
fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'report_table function started';
fprintf(fileID,fmt,text);
[rS,~] = size(info_sito);
[~,cCT] = size(controlsito);
rCT = nCT;
status = zeros(rS,1); % Stato dei Tool presenti in sito
% Riga 1 - ID
for j = 1:rS
coppia = {char(info_sito(j,1)) ' ' char(info_sito(j,2))};
info = cellstr(strjoin(coppia));
colonna1(1,j+1) = info;
end
colonna1(1,1) = {'ID'};
[rA,cA] = size(alarms);
if cA > 1
for j = 1:rA
IDallarme = {char(alarms(j,2))};
colonna1(1,rS+1+j) = IDallarme;
end
c1trigger = colonna1{1,rS+2:end};
else
c1trigger = [];
end
colonna1 = colonna1';
% Riga 2 - prima lettura valida disponibile
date_start = '2010-01-01'; % data "artificiale" per trovare la prima lettura
Data(1,1) = cellstr(date_start);
Data(1,2) = cellstr(time);
colonna2(1,1) = {'Prima lettura disponibile [gg-mm-aaaa]'};
for t = 1:rS
datalogger = num2str(cell2mat((chainID(t,1))));
array = char(info_sito(t,2));
comando = ['select statustool_id from tools where unit_ID like ''' ...
datalogger ''' and name like ''' array ''' '];
status(t,1) = cell2mat(fetch(conn,comando));
if status(t,1) == 1 % Inactive
colonna2{t+1,1} = 'Strumento non ancora installato o inattivo';
firstdata_num{t+1,1} = 0;
elseif status(t,1) == 3 % Monitoring Completed
colonna2{t+1,1} = 'Monitoraggio completato';
firstdata_num{t+1,1} = 0;
elseif status(t,1) == 2 || status(t,1) == 4 % Active o Manual Upload
comando = ['select prod_date from tools where unit_ID like ''' ...
datalogger ''' and name like ''' array ''' '];
data_ini = fetch(conn,comando);
Datab = datestr(data_ini(1,1),'yyyy-mm-dd HH:MM:SS');
[rI,cI] = size(Datab);
if rI && cI == 1
data1b = 0;
else
data1b = datenum(Datab);
end
Date = [cell2mat(Data(1,1)) repmat(' ', [1,1]) cell2mat(Data(1,2))];
data1a = datenum(Date);
if data1b > data1a
data1 = data1b;
else
data1 = data1a;
end
if data1 == data1a
colonna2{t+1,1} = 'Strumento non ancora installato';
firstdata_num{t+1,1} = 0;
else
colonna2{t+1,1} = datestr(data1,'dd-mm-yyyy');
firstdata_num{t+1,1} = data1; % mi serve per definire catena più recente in Centralina
end
else
firstdata_num{t+1,1} = 0;
end
end
if cCT > 1
for t = 1:rCT
array = char(alarms(t,2));
comando = ['select EventDate, EventTime from ELABDATACTRL where EventDate > ''' ...
date_start ''' and CtrlToolName = ''' ...
array ''' and NodeNum = 1 '];
curs = exec(conn,comando);
curs = fetch(curs);
D_num_ini = curs.Data;
Data_num_ini = [cell2mat(D_num_ini(1,1)) repmat(' ', [1,1]) cell2mat(D_num_ini(1,2))];
[rI,cI] = size(D_num_ini);
if rI && cI == 1
Data_num_ini = 0;
end
Date = [cell2mat(Data(1,1)) repmat(' ', [1,1]) cell2mat(Data(1,2))];
data1a = datenum(Date);
data1b = datenum(Data_num_ini(1,:));
if data1b > data1a
data1 = data1b;
else
data1 = data1a;
end
if data1 == data1a
colonna2{t+rS+1,1} = 'Dispositivo non ancora installato';
firstdata_num{t+1,1} = 0;
else
colonna2{t+rS+1,1} = datestr(data1,'dd-mm-yyyy');
firstdata_num{t+1,1} = data1; % mi serve per definire catena più recente in Centralina
end
end
end
% Riga 2 Bis - Lettura di riferimento
date_start = '2010-01-01'; % data "artificiale" per trovare la prima lettura
Data(1,1) = cellstr(date_start);
Data(1,2) = cellstr(time);
colonna2bis(1,1) = {'Lettura di riferimento [gg-mm-aaaa]'};
for t = 1:rS
if status(t,1) == 1 % Inactive
colonna2bis{t+1,1} = '-';
elseif status(t,1) == 3 % Monitoring Completed
colonna2bis{t+1,1} = '-';
elseif status(t,1) == 2 || status(t,1) == 4 % Active o Manual Upload
datalogger = num2str(cell2mat((chainID(t,1))));
array = char(info_sito(t,2));
comando = ['select graph_prod_date from tools where unit_ID like ''' datalogger ''' and name like ''' array ''' '];
data_ini = fetch(conn,comando);
stringa = cell2mat(data_ini);
[~,cS] = size(stringa);
esci = 0;
if cS == 4
esci = 1;
else
date = stringa(1,1:10);
time = stringa(1,11:21);
clear Datab
Datab(1,1) = cellstr(date);
Datab(1,2) = cellstr(time);
Datab = [cell2mat(Datab(1,1)) repmat(' ', [1,1]) cell2mat(Datab(1,2))];
data1b = datenum(Datab);
end
if esci == 0
Date = [cell2mat(Data(1,1)) repmat(' ', [1,1]) cell2mat(Data(1,2))];
data1a = datenum(Date);
if data1b > data1a
data1 = data1b;
else
data1 = data1a;
end
if data1 == data1a
colonna2bis{t+1,1} = 'Strumento non ancora installato';
else
colonna2bis{t+1,1} = datestr(data1,'dd-mm-yyyy');
firstdata_num{t+1,1} = data1; % mi serve per definire catena più recente in Centralina
end
else
colonna2bis{t+1,1} = colonna2{t+1,1};
end
end
end
if nCT > 0
for c = 1:nCT
colonna2bis{rS+1+c:rS+c+1,1} = colonna2{rS+1+c:rS+c+1,1};
end
end
% Riga 3 - Ultima lettura disponibile
colonna3(1,1) = {'Ultima lettura disponibile [gg-mm-aaaa]'};
for i = 1:rS
datalogger = char(info_sito(i,1));
array = char(info_sito(i,2));
dataU = datestr(today,'yyyy-mm-dd');
OK = 0;
if status(i,1) == 1 % Inactive
colonna3{i+1,1} = '-';
datasample{i+1,1} = 9999;
OK = 1;
end
while OK == 0
% trovo la data dell'ultima lettura disponibile
if strcmp(tipoarray(i),'MUSA') == 1
comando = ['select EventDate, EventTime from ElabDataMusaView where EventDate >= ''' dataU ''' and UnitName = ''' datalogger...
''' and ToolNameID = ''' array ''' and NodeNum = 1 '];
else
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' dataU ''' and UnitName = ''' datalogger...
''' and ToolNameID = ''' array ''' and NodeNum = 1 '];
end
curs = exec(conn,comando);
curs = fetch(curs);
Letture = curs.Data;
[~,cu] = size(Letture);
if cu == 1 % nessun dato trovato
dataU = datestr((datenum(dataU) - 1),'yyyy-mm-dd'); % provo con la data precedente
else
dataUL = datestr(dataU,'dd-mm-yyyy');
datasample{i+1,1} = datenum(dataU); % date numeriche per scegliere, a partità di centralina, la catena con i dati più recenti
colonna3{i+1,1} = dataUL;
OK = 1;
end
end
end
if cCT > 1
for t = 1:rCT
array = char(alarms(t,2));
comando = ['select EventDate, EventTime from ELABDATACTRL where EventDate > ''' ...
date_start ''' and CtrlToolName = ''' ...
array ''' and NodeNum = 1 '];
curs = exec(conn,comando);
curs = fetch(curs);
D_num_ini = curs.Data;
Data_num_ini = [cell2mat(D_num_ini(end,1)) repmat(' ', [1,1]) cell2mat(D_num_ini(end,2))];
[rI,cI] = size(D_num_ini);
if rI && cI == 1
Data_num_ini = 0;
end
Date = [cell2mat(Data(1,1)) repmat(' ', [1,1]) cell2mat(Data(1,2))];
data1a = datenum(Date);
data1b = datenum(Data_num_ini(1,:));
if data1b > data1a
data1 = data1b;
else
data1 = data1a;
end
if data1 == data1a
colonna3{t+rS+1,1} = 'Dispositivo non ancora installato';
else
colonna3{t+rS+1,1} = datestr(data1,'dd-mm-yyyy');
end
end
end
% Riga 4 - tipologia catena
colonna4(1,1) = {'Tipologia di Array'};
colonna4 = [colonna4, tipoarray'];
if cCT > 1
colonna4 = [colonna4, tipoalarms'];
end
colonna4 = colonna4';
% Riga 5 - Lunghezza catena
colonna5(1,1) = {'Lunghezza [m]'};
c = 0;
for k = 1:rS
L(k+1,1) = max(cell2mat(Chain_Scheme(:,2+c)));
conv2 = num2str(L(k+1,1));
[~,cc2] = size(conv2);
corretto = 0;
for cc = 1:cc2
if strcmp(conv2(cc),'.') % Cerco la virgola
corretto = 1; % Significa che ho trovato la virgola
if cc == cc2-1 % Un solo decimale
conv2 =[conv2 '0'];
break
end
end
end
if corretto == 0
conv2 = [conv2 '.00'];
end
colonna5(k+1,1) = {conv2};
if strcmp(colonna5(k+1,1),'0') || strcmp(colonna5(k+1,1),'0.00')
colonna5(k+1,1) = cellstr('-');
end
c = c+3;
end
if cCT > 1
colonna5(rS+2:rS+rCT+1,1) = cellstr('-');
end
% Riga 6 - tipologia sensori
colonna6(1,1) = {'Tipologia di sensori o dispositivi'};
colonna6_short(1,1) = {'Tipologia di sensori o dispositivi'};
for nn = 1:rS
s = 1; % conta sensori di tipo diverso
if yesTL(nn) == 1 % Tilt Link V
if yesTLHR(nn) == 1 % se ho Tilt Link HR elimino Tilt Link dalla lista
if rTL(nn) == rTLHR(nn)
riga6temp(s,1) = {'Tilt Link HR 3D V'};
riga6short(s,1) = {'Tilt Link HR 3D V'};
else
riga6temp(s,1) = {'Tilt Link V'};
riga6short(s,1) = {'Tilt Link V'};
end
else
riga6temp(s,1) = {'Tilt Link V'};
riga6short(s,1) = {'Tilt Link V'};
end
s = s+1;
end
if yesTLHR(nn) == 1 % Tilt Link HR V
if yesTL(nn) ~= 1 % Tilt Link V
riga6temp(s,1) = {'Tilt Link HR V'};
riga6short(s,1) = {'Tilt Link HR V'};
s = s+1;
end
end
if yesTLH(nn) == 1 % Tilt Link H
if yesTLHRH(nn) == 1 % se ho Tilt Link HR H elimino Tilt Link H dalla lista
if rTLH(nn) == rTLHRH(nn)
riga6temp(s,1) = {'Tilt Link HR 3D H'};
riga6short(s,1) = {'Tilt Link HR 3D H'};
else
riga6temp(s,1) = {'Tilt Link H'};
riga6short(s,1) = {'Tilt Link H'};
end
else
riga6temp(s,1) = {'Tilt Link H'};
riga6short(s,1) = {'Tilt Link H'};
end
s = s+1;
end
if yesTLHRH(nn) == 1 % Tilt Link HR H
if yesTLH(nn) ~= 1 % Tilt Link H
riga6temp(s,1) = {'Tilt Link HR H'};
riga6short(s,1) = {'Tilt Link HR H'};
s = s+1;
end
end
if yesPL(nn) == 1 % Piezo Link
riga6temp(s,1) = {'Piezo Link'};
riga6short(s,1) = {'Piezo Link'};
s = s+1;
end
if yesBL(nn) == 1 || yesBML(nn) == 1 % Baro Link (normale o MUSA)
riga6temp(s,1) = {'Baro Link'};
riga6short(s,1) = {'Baro Link'};
s = s+1;
end
if yesLL(nn) == 1 % Load Link
riga6temp(s,1) = {'Load Link'};
riga6short(s,1) = {'Load Link'};
s = s+1;
end
if yesRL(nn) == 1 % Rain Link
riga6temp(s,1) = {'Rain Link'};
riga6short(s,1) = {'Rain Link'};
s = s+1;
end
if yesKL(nn) == 1 % Klino Link
if yesKLHR(nn) == 1 % se ho Klino Link HR elimino Klino Link dalla lista
if rKL(nn) == rKLHR(nn)
yesKLHR3D(nn,1) = 1;
riga6temp(s,1) = {'Klino Link HR 3D'};
riga6short(s,1) = {'Klino Link HR 3D'};
else
yesKLHR3D(nn,1) = 0;
riga6temp(s,1) = {'Klino Link'};
riga6short(s,1) = {'Klino Link'};
end
else
yesKLHR3D(nn,1) = 0;
riga6temp(s,1) = {'Klino Link'};
riga6short(s,1) = {'Klino Link'};
end
s = s+1;
else
yesKLHR3D(nn,1) = 0;
end
if yesKLHR(nn) == 1 % Klino Link HR
if yesKL(nn) ~= 1 % Klino Link
riga6temp(s,1) = {'Klino Link HR'};
riga6short(s,1) = {'Klino Link HR'};
s = s+1;
end
end
if yesThL(nn) == 1 % Therm Link
riga6temp(s,1) = {'Therm Link'};
riga6short(s,1) = {'Therm Link'};
s = s+1;
end
if yesPT100(nn) == 1 % PT100 Link
riga6temp(s,1) = {'PT100 Link'};
riga6short(s,1) = {'PT100 Link'};
s = s+1;
end
if yesIPL(nn) == 1 % In Place Link
if yesIPLHR(nn) == 1 % se ho In Place Link HR elimino In Place Link dalla lista
if rIPL(nn) == rIPLHR(nn)
riga6temp(s,1) = {'In Place Link HR 3D'};
riga6short(s,1) = {'IP Link HR 3D'};
else
riga6temp(s,1) = {'In Place Link'};
riga6short(s,1) = {'In Place Link'};
end
else
riga6temp(s,1) = {'In Place Link'};
riga6short(s,1) = {'In Place Link'};
end
s = s+1;
end
if yesIPLHR(nn) == 1 % In Place Link HR
if yesIPL(nn) ~= 1 % In Place Link
riga6temp(s,1) = {'In Place Link HR'};
riga6short(s,1) = {'IP Link HR'};
s = s+1;
end
end
if yesTuL(nn) == 1 % Tunnel Link
riga6temp(s,1) = {'Tunnel Link'};
riga6short(s,1) = {'Tunnel Link'};
s = s+1;
end
if yesRaL(nn) == 1 % Radial Link
riga6temp(s,1) = {'Radial Link'};
riga6short(s,1) = {'Radial Link'};
s = s+1;
end
if yesPCL(nn) == 1 % PreConv Link
if yesPCLHR(nn) == 1 % se ho PreConv Link HR elimino PreConv Link dalla lista
if rPCL(nn) == rPCLHR(nn)
riga6temp(s,1) = {'PreConv Link HR 3D'};
riga6short(s,1) = {'PC Link HR 3D'};
else
riga6temp(s,1) = {'PreConv Link'};
riga6short(s,1) = {'PreConv Link'};
end
else
riga6temp(s,1) = {'PreConv Link'};
riga6short(s,1) = {'PreConv Link'};
end
s = s+1;
end
if yesPCLHR(nn) == 1 % PreConv Link HR
if yesPCL(nn) ~= 1 % PreConv Link
riga6temp(s,1) = {'PreConv Link HR'};
riga6short(s,1) = {'PC Link HR'};
s = s+1;
end
end
if yesPrL(nn) == 1 % Pressure Link
riga6temp(s,1) = {'Pressure Link'};
riga6short(s,1) = {'Press. Link'};
s = s+1;
end
if yesEL(nn) == 1% Extensometer Link
riga6temp(s,1) = {'Extensometer Link'};
riga6short(s,1) = {'Extens. Link'};
s = s+1;
end
if yes3DEL(nn) == 1 % 3D Extensometer Link
riga6temp(s,1) = {'3D Extensometer Link'};
riga6short(s,1) = {'3D Ext. Link'};
s = s+1;
end
if yesWEL(nn) == 1 % Wire Extensometer Link
riga6temp(s,1) = {'Wire Extensometer Link'};
riga6short(s,1) = {'Wire Ex. Link'};
s = s+1;
end
if yesMPBEL(nn) == 1 % Multi Point Borehole Extensometer Link
riga6temp(s,1) = {'Multi Point Borehole Extensometer Link'};
riga6short(s,1) = {'MPBX Link'};
s = s+1;
end
if yesCrL(nn) == 1 % Crack Link
riga6temp(s,1) = {'Crack Link'};
riga6short(s,1) = {'Crack Link'};
s = s+1;
end
if yes2DCrL(nn) == 1 % 2D Crack Link
riga6temp(s,1) = {'2D Crack Link'};
riga6short(s,1) = {'2D Crack Link'};
s = s+1;
end
if yes3DCrL(nn) == 1 % 3D Crack Link
riga6temp(s,1) = {'3D Crack Link'};
riga6short(s,1) = {'3D Cr. Link'};
s = s+1;
end
if yesHL(nn) == 1 % Humidity Link
riga6temp(s,1) = {'Humidity Link'};
riga6short(s,1) = {'Humidity Link'};
s = s+1;
end
if yesLuxL(nn) == 1 % Lux Link
riga6temp(s,1) = {'Lux Link'};
riga6short(s,1) = {'Lux Link'};
s = s+1;
end
if yesCO2(nn) == 1 % CO2 Link
riga6temp(s,1) = {'CO2 Link'};
riga6short(s,1) = {'CO2 Link'};
s = s+1;
end
if yesRSN(nn) == 1 % RSN Link
if yesRSNHR(nn) == 1 % se ho RSN Link HR elimino RSN Link dalla lista
if rPRSN(nn) == rRSNHR(nn)
riga6temp(s,1) = {'RSN Link HR 3D'};
riga6short(s,1) = {'RSN Link HR 3D'};
else
riga6temp(s,1) = {'RSN Link'};
riga6short(s,1) = {'RSN Link'};
end
else
riga6temp(s,1) = {'RSN Link'};
riga6short(s,1) = {'RSN Link'};
end
s = s+1;
end
if yesRSNHR(nn) == 1 % RSN Link HR
if yesRSN(nn) ~= 1 % RSN Link
riga6temp(s,1) = {'RSN Link HR'};
riga6short(s,1) = {'RSN Link HR'};
s = s+1;
end
end
if yesTrL(nn) == 1 % Trigger Link
riga6temp(s,1) = {'Trigger Link'};
riga6short(s,1) = {'Trigger Link'};
s = s+1;
end
if yesPE(nn) == 1 % Pendulum
riga6temp(s,1) = {'Pendulum'};
riga6short(s,1) = {'Pendulum'};
s = s+1;
end
if yesWL(nn) == 1 % Weir Link
riga6temp(s,1) = {'Weir Link'};
riga6short(s,1) = {'Weir Link'};
s = s+1;
end
if yesGF(nn) == 1 % G-Flow Link
riga6temp(s,1) = {'G-Flow Link'};
riga6short(s,1) = {'G-Flow Link'};
s = s+1;
end
if yesGS(nn) == 1 % G-Shock Link
riga6temp(s,1) = {'G-Shock Link'};
riga6short(s,1) = {'G-Shock Link'};
s = s+1;
end
if s == 2
colonna6(1,nn+1) = riga6temp(:,1);
colonna6_short(1,nn+1) = riga6short(:,1);
clear riga6temp
clear riga6short
else
colonna6{1,nn+1} = splitlines(strjoin(cellstr(riga6temp(:,1)), '\n'));
colonna6_short{1,nn+1} = splitlines(strjoin(cellstr(riga6short(:,1)), '\n'));
clear riga6temp;
clear riga6short
end
end
if cCT > 1
ct = 1; % conta dispositivi di tipo diverso
for mm = 1:nCT
if strcmp(char(tipoalarms(mm)),'Variable Message System')
CTtemp(ct,1) = {'Pannello a messaggio variabile'};
CTtemp_short(ct,1) = {'PMV'};
ct = ct +1;
elseif strcmp(char(tipoalarms(mm)),'Traffic Lights')
CTtemp(ct,1) = {'Impianto semaforico'};
CTtemp_short(ct,1) = {'Semafori'};
ct = ct +1;
elseif strcmp(char(tipoalarms(mm)),'Alarms')
CTtemp(ct,1) = {'Allarme acustico e/o visivo'};
CTtemp_short(ct,1) = {'Sistema di Allarme'};
ct = ct +1;
elseif strcmp(char(tipoalarms(mm)),'Camera')
CTtemp(ct,1) = {'Camera'};
CTtemp_short(ct,1) = {'Camera'};
ct = ct +1;
end
colonna6{1,rS+1+mm} = strjoin(cellstr(CTtemp(mm,1)), ', ');
colonna6_short{1,rS+1+mm} = strjoin(cellstr(CTtemp_short(mm,1)), ', ');
end
c6trigger = colonna6{1,rS+2:end};
else
c6trigger = [];
clear CTtemp
end
colonna6 = colonna6';
colonna6_short = colonna6_short';
% Riga 7 - numero sensori
colonna7(1,1)={'Numero di sensori o dispositivi'};
for s = 1:rS
if strcmp(cellstr(colonna4(s+1,1)),'Vertical Array') || strcmp(cellstr(colonna4(s+1,1)),'In Place Array')...
|| strcmp(cellstr(colonna4(s+1,1)),'Therm Array') || strcmp(cellstr(colonna4(s+1,1)),'Piezo Array')...
|| strcmp(cellstr(colonna4(s+1,1)),'Cir Array') || strcmp(cellstr(colonna4(s+1,1)),'Rad Array')...
|| strcmp(cellstr(colonna4(s+1,1)),'PreConv Array') || strcmp(cellstr(colonna4(s+1,1)),'Horizontal Array')...
|| strcmp(cellstr(colonna4(s+1,1)),'Vertical Array Structure')
colonna7(s+1,1) = cellstr(num2str(num_nodi(s,1)-1));
else
colonna7(s+1,1) = cellstr(num2str(num_nodi(s,1)));
end
end
if cCT > 1
colonna7(rS+2:rS+1+rCT) = cellstr('1');
end
text = 'report_table function executed correctly';
fprintf(fileID,fmt,text);
fclose(fileID);
end