474 lines
21 KiB
Matlab
Executable File
474 lines
21 KiB
Matlab
Executable File
function [ATTIVA,FIG,FIG_ENG] = report_ThL(rThL,m,NodoThermLink,tipoCU,toolrif,...
|
|
unitrif,datarif,Font_caption,Font_tools,siteID,DT,DT_ENG,FIG,FIG_ENG,...
|
|
activeEN,br,status,ATTIVA,conn,FileName)
|
|
|
|
fileID = fopen(FileName,'a');
|
|
fmt = '%s \r';
|
|
text = 'report_ThL function started';
|
|
fprintf(fileID,fmt,text);
|
|
|
|
import mlreportgen.dom.*
|
|
import mlreportgen.report.*
|
|
|
|
% Make sure DOM is compilable
|
|
makeDOMCompilable()
|
|
|
|
NODATAThL(m,1) = 0;
|
|
check = 0;
|
|
while check == 0
|
|
if status(m,1) == 1
|
|
if ATTIVA == 1
|
|
ATTIVA = 0;
|
|
testo = Paragraph('Catena non ancora installata o inattiva.');
|
|
add(DT,testo);
|
|
if activeEN == 1
|
|
testo = Paragraph('Array not installed or inactive.');
|
|
add(DT_ENG,testo);
|
|
end
|
|
end
|
|
check = 1;
|
|
elseif status(m,1) == 3
|
|
if ATTIVA == 1
|
|
ATTIVA = 0;
|
|
testo = Paragraph(['Monitoraggio completato. Invitiamo a visitare la '...
|
|
'piattaforma web per la visione dei dati storici.']);
|
|
add(DT,testo);
|
|
if activeEN == 1
|
|
testo = Paragraph(['Monitoring completed. Please log into the web-based platform '...
|
|
'to access the complete dataset.']);
|
|
add(DT_ENG,testo);
|
|
end
|
|
end
|
|
check = 1;
|
|
else
|
|
titolo = 1;
|
|
ThE = Section();
|
|
if activeEN == 1
|
|
ThE_EN = Section();
|
|
end
|
|
for n = 1:rThL(m,1)
|
|
NodeNum = num2str(NodoThermLink(n,m));
|
|
if tipoCU == 9 % Nesa Evo
|
|
comando = ['select EventTimestamp, JSON_VALUE(dataJSON,"$.tempAvg") from elabdatanesaview where EventTimestamp >= ''' ...
|
|
datarif ''' and ToolNameID = ''' char(toolrif) ''' and UnitName = ''' char(unitrif) ...
|
|
''' and NodeNum = ''' NodeNum ''' '];
|
|
curs = exec(conn,comando);
|
|
curs = fetch(curs);
|
|
Dati = curs.Data;
|
|
else
|
|
comando = ['select T_node, NodeDepth, EventDate, EventTime from ElabDataView where EventDate >= ''' ...
|
|
datarif ''' and ToolNameID = ''' char(toolrif) ''' and UnitName = ''' char(unitrif) ...
|
|
''' and NodeNum = ''' NodeNum ''' '];
|
|
curs = exec(conn,comando);
|
|
curs = fetch(curs);
|
|
Dati = curs.Data;
|
|
end
|
|
|
|
% Modifico il formato di data e ora
|
|
[rD,rC] = size(Dati);
|
|
if rC == 2 % Nesa Evo
|
|
Date = datenum(Dati(:,1));
|
|
datiTemp = (char(Dati(:,2)));
|
|
% sostituisco valori fuori scala
|
|
for c=1:rD
|
|
if c == 1 && strcmp(datiTemp(c),'*') == 1 % forwardfill 1° dato
|
|
d = 2;
|
|
while d<=rD
|
|
if strcmp(datiTemp(d),'*') == 0
|
|
datiTemp(c,:) = datiTemp(d,:);
|
|
break
|
|
else
|
|
d=d+1;
|
|
end
|
|
end
|
|
else % backfill altri dati
|
|
if strcmp(datiTemp(c),'*') == 1
|
|
datiTemp(c,:) = datiTemp(c-1,:);
|
|
end
|
|
end
|
|
end
|
|
TempHR = str2num(datiTemp); % temperatura
|
|
if isempty(TempHR) == 1
|
|
NODATAThL = 1;
|
|
check = 1;
|
|
else
|
|
MaxTempHR = max(TempHR);
|
|
MinTempHR = min(TempHR);
|
|
end
|
|
elseif rC > 2
|
|
T = [cell2mat(Dati(:,3)) repmat(' ', [rD,1]) cell2mat(Dati(:,4))];
|
|
Date = datenum(T); % Data
|
|
if n == 1 % Il primo lo scrivo e creo la variabile di controllo
|
|
else
|
|
[rS,~] = size(TempHR);
|
|
if rD ~= rS
|
|
NODATAThL(m,1) = 2;
|
|
check = 0;
|
|
break
|
|
else
|
|
check = 1;
|
|
end
|
|
end
|
|
TempHR(:,n) = cell2mat(Dati(:,1)); % temperatura
|
|
MaxTempHR(1,n) = max(TempHR(:,n));
|
|
MinTempHR(1,n) = min(TempHR(:,n));
|
|
Prof(:,n) = -(cell2mat(Dati(1,2))); % Profondità
|
|
else
|
|
NODATAThL = 1;
|
|
check = 1;
|
|
end
|
|
end
|
|
if NODATAThL == 0
|
|
if rC > 2
|
|
%% Therm Link standard
|
|
testo = Paragraph(['I grafici seguenti mostrano i valori di temperatura lungo la verticale '...
|
|
'ed il loro andamento nel tempo, misurati dal termometro ad alta risoluzione '...
|
|
'durante il periodo temporale di riferimento. ']);
|
|
testo.HAlign = 'justify';
|
|
|
|
if activeEN == 1
|
|
testo_ENG = Paragraph(['The following graphs show the temperature values recorded at different depths '...
|
|
'and their evolution over time, recorded by the high-resolution thermometer '...
|
|
'during the reference time period. ']);
|
|
testo_ENG.HAlign = 'justify';
|
|
end
|
|
|
|
% grafico temperatura - profondità
|
|
figure(1)
|
|
plot(TempHR(end,:),Prof,'-o');
|
|
hold on
|
|
plot(MaxTempHR(1,:),Prof,'-o');
|
|
Tmin_nodi = plot(MinTempHR(1,:),Prof,'-o');
|
|
legend('Ultima temperatura','Temperatura massima','Temperatura minima','Location','southeast');
|
|
|
|
title('Temperatura');
|
|
xlabel(['Temperatura [' char(176) 'C]']);
|
|
ylabel(['Profondit' char(224) ' [m]']);
|
|
h = gca;
|
|
h.XAxis.MinorTick = 'on';
|
|
grid on
|
|
grid minor
|
|
|
|
TempName = char(strcat('Report',siteID,'-', char(toolrif),'Therm.png'));
|
|
saveas(Tmin_nodi,TempName);
|
|
ChartTh = Image(TempName);
|
|
ChartTh.Style = {Height('9.5cm'),HAlign('center')};
|
|
ChartTh_cap = Paragraph(['Fig. ' num2str(FIG) ' - Ultimo dato, '...
|
|
'temperatura massima e minima misurate '...
|
|
'durante il periodo temporale di riferimento']);
|
|
FIG = FIG+1;
|
|
ChartTh_cap.Style = {HAlign('center'),FontSize(Font_caption),Italic(1),Color('midnightblue')};
|
|
if titolo == 1
|
|
sezTherm = Heading3('Therm Link');
|
|
sezTherm.Style = {OuterMargin('0in','0in','0.15in','0in'),FontSize(Font_tools),Bold(1),Italic(1)};
|
|
ThE.Title = sezTherm;
|
|
add(DT,sezTherm);
|
|
if activeEN == 1
|
|
else
|
|
titolo = 0;
|
|
end
|
|
end
|
|
add(DT,testo);
|
|
add(DT,ChartTh);
|
|
add(DT,ChartTh_cap);
|
|
|
|
% Grafico Temperatura vs Tempo
|
|
cont = 1;
|
|
num = 2;
|
|
tab = 1;
|
|
while cont <= rThL(m,1)
|
|
figure(num)
|
|
if rThL(m,1)-cont > 5
|
|
str = cell(5,1);
|
|
else
|
|
str = cell(rThL(m,1)-cont+1,1);
|
|
end
|
|
hold on
|
|
grid on
|
|
grid minor
|
|
xlabel('Data [gg/mm/aaaa]');
|
|
ylabel(['Temperatura [' char(176) 'C]']);
|
|
Mx = [];
|
|
Mn = [];
|
|
for a = 1:5
|
|
if cont > rThL(m,1)
|
|
break
|
|
end
|
|
Tt = plot(Date,TempHR(:,cont));
|
|
Mx = [Mx; ceil(max(TempHR(:,cont)))];
|
|
Mn = [Mn; ceil(min(TempHR(:,cont)))];
|
|
xlim([Date(1)-1 Date(end)+1]);
|
|
h = gca;
|
|
h.XAxis.MinorTick = 'on';
|
|
datetick('x','dd/mm/yyyy','keepticks','keeplimits');
|
|
xtickangle(20);
|
|
str(a,1) = cellstr(['' num2str(Prof(cont)) ' m da P.C.']);
|
|
cont = cont+1;
|
|
end
|
|
ylim([min(Mn)-1 max(Mx)+1]);
|
|
lgd = legend(str,'Location','north');
|
|
num = num+1;
|
|
TempName = char(strcat('Report',siteID,'-', char(toolrif),'Therm ',num2str(num),'.png'));
|
|
saveas(Tt,TempName);
|
|
if tab == 2
|
|
TempName1 = char(strcat('Report',siteID,'-', char(toolrif),'Therm ',num2str(num-1),'.png'));
|
|
Chart1 = Image(TempName1);
|
|
Chart1.Style = {Height('6.8cm'),HAlign('center')};
|
|
Chart2 = Image(TempName);
|
|
Chart2.Style = {Height('6.8cm'),HAlign('center')};
|
|
lot = Table({Chart1, Chart2});
|
|
lot.Style = {ResizeToFitContents(false), Width('100%')};
|
|
add(DT,lot);
|
|
tab = 1;
|
|
elseif rThL <= 5 % Una sola immagine
|
|
Chart1 = Image(TempName);
|
|
Chart1.Style = {Height('7.5cm'),HAlign('center')};
|
|
add(DT,Chart1);
|
|
elseif cont > rThL
|
|
Chart2 = Image(TempName);
|
|
Chart2.Style = {Height('6.8cm'),HAlign('center')};
|
|
add(DT,Chart2);
|
|
else
|
|
tab = tab+1;
|
|
end
|
|
close(figure(num));
|
|
end
|
|
|
|
ChartTh2_cap = Paragraph(['Fig. ' num2str(FIG) ' - Andamento nel tempo della temperatura registrata '...
|
|
'dai singoli sensori']);
|
|
add(DT,ChartTh2_cap);
|
|
FIG = FIG+1;
|
|
ChartTh2_cap.Style = {HAlign('center'),FontSize(Font_caption),Italic(1),Color('midnightblue')};
|
|
|
|
add(DT,br);
|
|
close(figure(1));
|
|
close(figure(2));
|
|
|
|
if activeEN == 1
|
|
% grafico temperatura - profondità
|
|
figure(1)
|
|
plot(TempHR(end,:),Prof,'-o');
|
|
hold on
|
|
plot(MaxTempHR(1,:),Prof,'-o');
|
|
Tmin_nodi = plot(MinTempHR(1,:),Prof,'-o');
|
|
legend('Last value','T max','T min','Location','southeast');
|
|
|
|
title('Temperature');
|
|
xlabel(['Temperature [' char(176) 'C]']);
|
|
ylabel('Depth [m]');
|
|
h = gca;
|
|
h.XAxis.MinorTick = 'on';
|
|
grid on
|
|
grid minor
|
|
|
|
TempName = char(strcat('Report',siteID,'-', char(toolrif),'Therm_ENG.png'));
|
|
saveas(Tmin_nodi,TempName);
|
|
ChartTh = Image(TempName);
|
|
ChartTh.Style = {Height('9.5cm'),HAlign('center')};
|
|
ChartTh_cap = Paragraph(['Fig. ' num2str(FIG_ENG) ' - Last value, '...
|
|
'maximum and minimum temperature recorded '...
|
|
'during the reference time period']);
|
|
FIG_ENG = FIG_ENG+1;
|
|
ChartTh_cap.Style = {HAlign('center'),FontSize(Font_caption),Italic(1),Color('midnightblue')};
|
|
if titolo == 1
|
|
sezTherm = Heading3('Therm Link');
|
|
sezTherm.Style = {OuterMargin('0in','0in','0.15in','0in'),FontSize(Font_tools),Bold(1),Italic(1)};
|
|
ThE.Title = sezTherm;
|
|
add(DT_ENG,sezTherm);
|
|
titolo = 0;
|
|
end
|
|
add(DT_ENG,testo_ENG);
|
|
add(DT_ENG,ChartTh);
|
|
add(DT_ENG,ChartTh_cap);
|
|
|
|
% Grafico Temperatura vs Tempo
|
|
cont = 1;
|
|
num = 2;
|
|
tab = 1;
|
|
while cont <= rThL(m,1)
|
|
figure(num)
|
|
if rThL(m,1)-cont > 5
|
|
str = cell(5,1);
|
|
else
|
|
str = cell(rThL(m,1)-cont+1,1);
|
|
end
|
|
hold on
|
|
grid on
|
|
grid minor
|
|
xlabel('Date [dd/mm/yyyy]');
|
|
ylabel(['Temperature [' char(176) 'C]']);
|
|
Mx = [];
|
|
Mn = [];
|
|
for a = 1:5
|
|
if cont > rThL(m,1)
|
|
break
|
|
end
|
|
Tt = plot(Date,TempHR(:,cont));
|
|
Mx = [Mx; ceil(max(TempHR(:,cont)))];
|
|
Mn = [Mn; ceil(min(TempHR(:,cont)))];
|
|
xlim([Date(1)-1 Date(end)+1]);
|
|
h = gca;
|
|
h.XAxis.MinorTick = 'on';
|
|
datetick('x','dd/mm/yyyy','keepticks','keeplimits');
|
|
xtickangle(20);
|
|
str(a,1) = cellstr(['' num2str(Prof(cont)) ' m b.g.l.']);
|
|
cont = cont+1;
|
|
end
|
|
ylim([min(Mn)-1 max(Mx)+1]);
|
|
lgd = legend(str,'Location','north');
|
|
num = num+1;
|
|
TempName = char(strcat('Report',siteID,'-', char(toolrif),'Therm ',num2str(num),'.png'));
|
|
saveas(Tt,TempName);
|
|
if tab == 2
|
|
TempName1 = char(strcat('Report',siteID,'-', char(toolrif),'Therm ',num2str(num-1),'.png'));
|
|
Chart1 = Image(TempName1);
|
|
Chart1.Style = {Height('6.8cm'),HAlign('center')};
|
|
Chart2 = Image(TempName);
|
|
Chart2.Style = {Height('6.8cm'),HAlign('center')};
|
|
lot = Table({Chart1, Chart2});
|
|
lot.Style = {ResizeToFitContents(false), Width('100%')};
|
|
add(DT,lot);
|
|
tab = 1;
|
|
elseif rThL <= 5 % Una sola immagine
|
|
Chart1 = Image(TempName);
|
|
Chart1.Style = {Height('7.5cm'),HAlign('center')};
|
|
add(DT,Chart1);
|
|
elseif cont > rThL
|
|
Chart2 = Image(TempName);
|
|
Chart2.Style = {Height('6.8cm'),HAlign('center')};
|
|
add(DT,Chart2);
|
|
else
|
|
tab = tab+1;
|
|
end
|
|
close(figure(num));
|
|
end
|
|
|
|
ChartTh2_cap = Paragraph(['Fig. ' num2str(FIG_ENG) ' - Temporal evolution of the temperature recorded '...
|
|
'by the sensors']);
|
|
add(DT_ENG,ChartTh2_cap);
|
|
FIG_ENG = FIG_ENG+1;
|
|
ChartTh2_cap.Style = {HAlign('center'),FontSize(Font_caption),Italic(1),Color('midnightblue')};
|
|
|
|
add(DT_ENG,br);
|
|
close(figure(1));
|
|
close(figure(2));
|
|
end
|
|
else
|
|
%% Nesa Evo
|
|
testo = Paragraph(['Il grafico seguente mostra l''andamento deivalori di temperatura '...
|
|
'nel tempo, misurati dal termometro della stazione meteo '...
|
|
'durante il periodo temporale di riferimento. ']);
|
|
testo.HAlign = 'justify';
|
|
|
|
if activeEN == 1
|
|
testo_ENG = Paragraph(['The following graph shows the temperature values '...
|
|
'variation over time, recorded by the high-resolution thermometer '...
|
|
'during the reference time period. ']);
|
|
testo_ENG.HAlign = 'justify';
|
|
end
|
|
|
|
% Grafico Temperatura vs Tempo
|
|
figure(5);
|
|
Mx = [];
|
|
Mn = [];
|
|
Tt = plot(Date,TempHR);
|
|
title('Temperatura');
|
|
xlabel('Data [gg/mm/aaaa]');
|
|
ylabel(['Temperatura [' char(176) 'C]']);
|
|
Mx = [Mx; ceil(max(TempHR))];
|
|
Mn = [Mn; ceil(min(TempHR))];
|
|
xlim([Date(1)-1 Date(end)+1]);
|
|
h = gca;
|
|
h.XAxis.MinorTick = 'on';
|
|
datetick('x','dd/mm/yyyy','keepticks','keeplimits');
|
|
xtickangle(20);
|
|
ylim([min(Mn)-1 max(Mx)+1]);
|
|
grid on
|
|
grid minor
|
|
|
|
hold off
|
|
|
|
TempName = char(strcat('Report',siteID,'-', char(toolrif),'Therm ',num2str(num),'.png'));
|
|
saveas(Tt,TempName);
|
|
Chart1 = Image(TempName);
|
|
Chart1.Style = {Height('7.5cm'),HAlign('center')};
|
|
ChartTh_cap = Paragraph(['Fig. ' num2str(FIG) ' - Andamento nel tempo della temperatura registrata '...
|
|
'dai singoli sensori']);
|
|
FIG = FIG+1;
|
|
ChartTh_cap.Style = {HAlign('center'),FontSize(Font_caption),Italic(1),Color('midnightblue')};
|
|
|
|
add(DT,testo_ENG);
|
|
add(DT,Chart1);
|
|
add(DT,ChartTh_cap);
|
|
add(DT,br);
|
|
close(figure(5));
|
|
|
|
if activeEN == 1
|
|
% Grafico Temperatura vs Tempo
|
|
figure(5);
|
|
Mx = [];
|
|
Mn = [];
|
|
Tt = plot(Date,TempHR);
|
|
title('Temperature');
|
|
xlabel('Date [dd/mm/yyyy]');
|
|
ylabel(['Temperature [' char(176) 'C]']);
|
|
Mx = [Mx; ceil(max(TempHR))];
|
|
Mn = [Mn; ceil(min(TempHR))];
|
|
xlim([Date(1)-1 Date(end)+1]);
|
|
h = gca;
|
|
h.XAxis.MinorTick = 'on';
|
|
datetick('x','dd/mm/yyyy','keepticks','keeplimits');
|
|
xtickangle(20);
|
|
ylim([min(Mn)-1 max(Mx)+1]);
|
|
grid on
|
|
grid minor
|
|
|
|
hold off
|
|
|
|
TempName = char(strcat('Report',siteID,'-', char(toolrif),'Therm ',num2str(num),'_ENG.png'));
|
|
saveas(Tt,TempName);
|
|
Chart1 = Image(TempName);
|
|
Chart1.Style = {Height('7.5cm'),HAlign('center')};
|
|
ChartTh_cap = Paragraph(['Fig. ' num2str(FIG) ' - Temporal evolution of the temperature recorded '...
|
|
'by the sensors']);
|
|
FIG_ENG = FIG_ENG+1;
|
|
ChartTh_cap.Style = {HAlign('center'),FontSize(Font_caption),Italic(1),Color('midnightblue')};
|
|
|
|
add(DT,testo);
|
|
add(DT,Chart1);
|
|
add(DT,ChartTh_cap);
|
|
add(DT,br);
|
|
close(figure(5));
|
|
end
|
|
end
|
|
|
|
clear TempHR;
|
|
clear MaxTempHR;
|
|
clear MinTempHR;
|
|
clear Prof;
|
|
|
|
elseif NODATAThL(m,1) == 1
|
|
if ATTIVA == 1
|
|
testo = Paragraph('Non sono presenti dati relativi al periodo temporale considerato.');
|
|
ATTIVA = 0;
|
|
add(DT,testo);
|
|
if activeEN == 1
|
|
testo = Paragraph('No data available for the reference time period.');
|
|
add(DT_ENG,testo);
|
|
if m == 1
|
|
add(DT_ENG,br);
|
|
end
|
|
end
|
|
check = 1;
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
close all
|
|
|
|
text = 'report_ThL function executed correctly';
|
|
fprintf(fileID,fmt,text);
|
|
fclose(fileID);
|
|
|
|
end |