Files
matlab-python/ATD/report_CT.m

200 lines
8.6 KiB
Matlab
Executable File

function [FIG,FIG_ENG] = report_CT(c1trigger,c6trigger,alarms,nCT,rpt,Font_caption,...
Font_table,Font_section,datarif,CT,CT_ENG,FIG,FIG_ENG,activeEN,conn,FileName)
fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'report_CT function started';
fprintf(fileID,fmt,text);
import mlreportgen.dom.*
import mlreportgen.report.*
% Make sure DOM is compilable
makeDOMCompilable()
CT_Att = zeros(1,nCT);
att = cell(1,nCT);
for A = 1:nCT
array = char(alarms(A,2));
comando = ['select EventDate, EventTime, XShift, X from ELABDATACTRL where EventDate > ''' ...
datestr(datenum(datarif),'yyyy-mm-dd') ''' and CtrlToolName = ''' ...
array ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Dati = curs.Data;
CTS = Section();
app = Heading2(array);
app.Style = {OuterMargin('0in','0in','0.2in','0.2in'),FontSize(Font_section),HAlign('justify')}; % Sx-Dx-Alto-Basso
CTS.Title = app;
if activeEN == 1
CTS_ENG = Section();
appENG = Heading2(array);
appENG.Style = {OuterMargin('0in','0in','0.2in','0.2in'),FontSize(Font_section),HAlign('justify')}; % Sx-Dx-Alto-Basso
CTS_ENG.Title = appENG;
end
% Modifico il formato di data e ora
[rD,rC] = size(Dati);
if rC ~= 1
% Camera
if cell2mat(alarms(A,3)) == 4
ftpobj = ftp('160.78.30.106','asega','mums'); % connessione FTP
percorso = ['/ctrlToolsImages/' array];
cd(ftpobj, percorso); % vado alla cartella con le immagini della camera elaborata
cartella = dir(ftpobj); % elenco file nella cartella
infoPIC = struct2cell(cartella(end)); % estraggo info ultima foto
mget(ftpobj, infoPIC(1)); % scarico foto
close(ftpobj)
IMGCam = Image(char(infoPIC(1)));
IMGCam.Style = [IMGCam.Style {ScaleToFit}];
IMGCam_cap = Paragraph(['Fig. ' num2str(FIG) ' - Immagine acquisita dalla '...
'videocamera ASECam ' array ' presente in sito']);
FIG = FIG+1;
IMGCam_cap.Style = {HAlign('center'),FontSize(Font_caption),Italic(1),Color('midnightblue')};
timePIC = cell2mat(infoPIC(5));
% % check ora legale
% if isdst(datetime(infoPIC(4),'Timezone','Europe/Zurich')) == 1
% timePIC = cell2mat(infoPIC(5))-(1/24);
% end
testoC = Paragraph(['Di seguito viene riportata l''ultima immagine acquisita in data '...
datestr(timePIC,'dd/mm/yyyy') ' dalla videocamera ASECam ' array '.']);
testoC.HAlign = 'justify';
add(CTS,testoC);
add(CTS,IMGCam);
add(CTS,IMGCam_cap);
% -- ENG --
if activeEN == 1
IMGCam_ENG_cap = Paragraph(['Fig. ' num2str(FIG_ENG) ' - Image acquired by the '...
'ASECam video camera ' array ' installed on site']);
FIG_ENG = FIG_ENG+1;
IMGCam_ENG_cap.Style = {HAlign('center'),FontSize(Font_caption),Italic(1),Color('midnightblue')};
testoC_ENG = Paragraph(['The following figure displays the last image acquired by ASECam '...
array ' installe on site, referring to the following date:' datestr(cell2mat(infoPIC(5)),'dd/mm/yyyy HH:MM:SS') '.']);
testoC_ENG.HAlign = 'justify';
add(CTS_ENG,testoC_ENG);
add(CTS_ENG,IMGCam);
add(CTS_ENG,IMGCam_ENG_cap);
end
else
T = [cell2mat(Dati(:,1)) repmat(' ', [rD,1]) cell2mat(Dati(:,2))];
Date = datenum(T); % Data
Att_Loc = cell2mat(Dati(:,3)); % Attivazioni Locali
Att_Cum = cell2mat(Dati(:,4)); % Attivazioni Cumulate
Att_Loc_Tot = cumsum(Att_Loc);
testo = Paragraph(['Durante il periodo temporale di riferimento, '...
'sono state registrate ' num2str(Att_Loc_Tot(end)) ' attivazioni del dispositivo.' ]);
testo2 = Paragraph(['Il numero di attivazioni totali dalla data di inizio monitoraggio ' char(232) ' pari '...
'a ' num2str(Att_Cum(end)) '.' ]);
if Att_Loc_Tot(end) > 1
CT_Att(1,A) = A;
end
testo.HAlign = 'justify';
testo2.HAlign = 'justify';
att_temp = find(Att_Loc);
if isempty(att_temp) == 0
att{1,A} = splitlines(strjoin(cellstr(Date(att_temp)), '\n'));
end
add(CTS,testo);
add(CTS,testo2);
%--- ENG ---
if activeEN == 1
testo = Paragraph(['During the reference time period, '...
'the Control Tool recorded a total of ' num2str(Att_Loc_Tot(end)) ' activations.' ]);
testo2 = Paragraph(['The total number of activations since the beginning of the monitoring '...
'activity amounts to ' num2str(Att_Cum(end)) '.' ]);
if Att_Loc_Tot(end) > 1
CT_Att(1,A) = A;
end
testo.HAlign = 'justify';
testo2.HAlign = 'justify';
add(CTS_ENG,testo);
add(CTS_ENG,testo2);
att_temp = find(Att_Loc);
if isempty(att_temp) == 0
att{1,A} = splitlines(strjoin(cellstr(Date(att_temp)), '\n'));
end
end
end
% elseif
else
testo = Paragraph('Non sono presenti dati relativi al periodo temporale considerato.');
add(CTS,testo);
if activeEN == 1
testo = Paragraph('No data available for the reference time period.');
add(CTS,testo);
end
end
br = PageBreak();
add(CTS,br);
add(CT,CTS);
end
clear A
A = find(CT_Att); % Cerco eventuali attivazioni nei singoli dispositivi CT
if isempty(A) == 0
colonna1(1,1) = {'ID'};
colonna2(1,1) = {'Tipologia di dispositivo'};
colonna3(1,1) = {'Attivazioni [gg-mm-aaaa OO:MM:SS]'};
disp = c1trigger(A);
type = c6trigger(A);
[num,~] = size(disp);
for n = 1:num
colonna1(n+1,1) = {disp};
colonna2(n+1,1) = {type};
colonna3(n+1,1) = {att};
end
tab = FormalTable([colonna1,colonna2,colonna3]);
% formattazione tabella
tab.TableEntriesStyle = {HAlign('center'),VAlign('middle'),FontSize(Font_table),InnerMargin('0.5mm')};
tab.Style = {ResizeToFitContents(true),Width("100%"),RowSep('solid','black','1px'),...
ColSep('solid','black','1px'),Hyphenation(false),BackgroundColor('#E0F1FF')};
tab.Border = 'single';
tabCaption = Paragraph('Tab. 2 - Tipologia di control tools e relative attivazioni durante il periodo analizzato');
tabCaption.Style = {HAlign('center'),FontSize(Font_caption),Italic(1),Color('midnightblue')};
bodyFirstRow = tab.Body.Children(1);
bodyFirstRow.Style = [bodyFirstRow.Style {Bold()}];
add(CT,tabCaption);
add(CT,tab);
% --- ENG ---
if activeEN == 1
colonna1_ENG(1,1) = {'ID'};
colonna2_ENG(1,1) = {'Control Tool typology'};
colonna3_ENG(1,1) = {'Activation [dd-mm-yyyy HH:MM:SS]'};
disp = c1trigger(A);
type = c6trigger(A);
[num,~] = size(disp);
for n = 1:num
colonna1_ENG(n+1,1) = {disp};
colonna2_ENG(n+1,1) = {type};
colonna3_ENG(n+1,1) = {att};
end
tab_ENG = FormalTable([colonna1_ENG,colonna2_ENG,colonna3_ENG]);
% formattazione tabella
tab_ENG.TableEntriesStyle = {HAlign('center'),VAlign('middle'),FontSize(Font_table),InnerMargin('0.5mm')};
tab_ENG.Style = {ResizeToFitContents(true),Width("100%"),RowSep('solid','black','1px'),...
ColSep('solid','black','1px'),Hyphenation(false),BackgroundColor('#E0F1FF')};
tab_ENG.Border = 'single';
tabCaption_ENG = Paragraph('Tab. 2 - Control Tools typology and relative activations recorded during the reference time period');
tabCaption_ENG.Style = {HAlign('center'),FontSize(Font_caption),Italic(1),Color('midnightblue')};
bodyFirstRow = tab_ENG.Body.Children(1);
bodyFirstRow.Style = [bodyFirstRow.Style {Bold()}];
add(CT_ENG,tabCaption_ENG);
add(CT_ENG,tab_ENG);
end
end
add(rpt,CT);
template(rpt);
text = 'report_CT function executed correctly';
fprintf(fileID,fmt,text);
fclose(fileID);
end