Files
matlab-python/RSN/tipologiaNodi.m

256 lines
8.7 KiB
Matlab
Executable File

% Funzione che ricostruisce la tipologia di nodi presenti
% NodoRSNLink ad esempio contiene numero del nodo e profondità per tutti i
% nodi di questo tipo
% idTool rappresenta l'identificativo con cui sono definite le
% installazioni su DB, serve più avanti nell'elaborazione
% idNode scrive gli identificativi dei nodi del DB. E' un output di
% controllo
function [idTool,NodoRSNLink,NodoSS,NodoRSNLinkHR,NodoRSNLinkHR3D,NodoLoadLink,...
NodoTriggerLink,NodoGflowLink,NodoGshockLink,NodoDebrisLink] = tipologiaNodi(...
DTcatena,unitID,conn,FileName)
%% Informazioni e credenziali relative al DataBase da leggere
fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'tipologiaNodi function started';
fprintf(fileID,fmt,text);
%% A partire dal nome della catena, risalgo all'identificativo con cui è
% definita nel Database (mi serve successivamente)
comando = ['select id from tools where name = ''' DTcatena ''' and unit_id = ''' num2str(unitID) ''' '];
idTool = num2str(cell2mat(fetch(conn,comando))); % leggo e converto in stringa
%% RSN Link
% carico le informazioni relative al numero e alla profondità per RSN LINK
comando = ['select num, depth, measurment from nodes where tool_id = ''' idTool ''' and nodetype_id = 38 order by num'];
Leggo = fetch(conn,comando);
[rL,cL] = size(Leggo);
if rL <= 1 && cL <= 1
textRSN = 'There are no RSN Link; ';
NodoRSNLink = [];
nodoRSN = 0; % mi serve nei RSN Link HR3D (SVILUPPO FUTURO?)
else
nodoRSN = 1; % mi serve nei RSN Link HR3D (SVILUPPO FUTURO?)
depth = cell2mat(Leggo(:,2));
depth = num2cell(depth);
nome = cell(rL,1);
for i=1:rL
nome(i,1) = cellstr('RSN Link');
end
NodoRSNLink = [nome Leggo(:,1) depth Leggo(:,3)];
textRSN = ['There are ',num2str(rL),' RSN Link nodes; '];
end
fprintf(fileID,fmt,textRSN);
%% Shock Sensor
% carico le informazioni relative al numero e alla profondità per SHOCK SENSOR
comando = ['select num, depth, measurment from nodes where tool_id = ''' idTool ''' and nodetype_id = 54 order by num'];
Leggo = fetch(conn,comando);
[rL,cL] = size(Leggo);
if rL <= 1 && cL <= 1
textSS = 'There are no Shock Sensor; ';
NodoSS = [];
else
depth = cell2mat(Leggo(:,2));
depth = num2cell(depth);
nome = cell(rL,1);
for i=1:rL
nome(i,1) = cellstr('Shock Sensor');
end
NodoSS = [nome Leggo(:,1) depth Leggo(:,3)];
textSS = ['There are ',num2str(rL),' Shock Sensor nodes; '];
end
fprintf(fileID,fmt,textSS);
%% RSN Link HR
% carico le informazioni relative al numero e alla profondità per
% RSN LINK HR
comando = ['select num, depth, measurment from nodes where tool_id = ''' idTool ''' and nodetype_id = 39 order by num'];
Leggo = fetch(conn,comando);
[rL,cL] = size(Leggo);
if rL <= 1 && cL <= 1
textRSNHR = 'There are not RSN HR Link; ';
NodoRSNLinkHR = [];
nodoRSNHR = 0; % mi serve nei RSN Link HR3D (SVILUPPO FUTURO?)
else
nodoRSNHR = 1; % mi serve nei RSN Link HR3D (SVILUPPO FUTURO?)
depth = cell2mat(Leggo(:,2));
depth = num2cell(depth);
nome = cell(rL,1);
for i=1:rL
nome(i,1) = cellstr('RSN Link HR');
end
NodoRSNLinkHR = [nome Leggo(:,1) depth Leggo(:,3)];
textRSNHR = ['There are ',num2str(rL),' RSN Link HR nodes; '];
end
fprintf(fileID,fmt,textRSNHR);
% confrontando le profondità di RSN Link e RSN Link HR riconosco i RSN LINK HR 3D
if nodoRSN == 1 && nodoRSNHR == 1
[rRSN,~] = size(NodoRSNLink);
[rRSNHR,~] = size(NodoRSNLinkHR);
NodoRSNLinkHR3Dwork = cell(rRSN,4); % creo matrice di zeri
p=1;
Control = 0;
for i=1:rRSN
for j=1:rRSNHR
if cell2mat(NodoRSNLink(i,3)) == cell2mat(NodoRSNLinkHR(j,3))
prof = NodoRSNLink(i,3);
nome = cellstr('RSN Link HR 3D');
% il numero nodo del RSN Link lo faccio diventare il numero nodo del RSN Link HR3D
num = NodoRSNLink(i,2);
num2 = NodoRSNLinkHR(j,2);
Leggo = [nome,num,num2,prof];
NodoRSNLinkHR3Dwork(p,:) = Leggo;
p = p+1;
Control = 1;
break
end
end
end
% elimino gli zeri in più
q = 1;
rL = 0;
[s,~] = size(NodoRSNLinkHR3Dwork);
a = 1;
while a == 1
if q > s
a = 0;
else
if strcmp(cell2mat(NodoRSNLinkHR3Dwork(q,1)),'RSN Link HR 3D')
rL = 1+rL; % ultima riga con dati che non siano celle vuote
end
end
q = q+1;
end
if Control == 1
NodoRSNLinkHR3D = NodoRSNLinkHR3Dwork(1:rL,:);
elseif Control == 0
NodoRSNLinkHR3D = [];
end
textRSNHR3D = ['There are ',num2str(rL),' RSN Link HR 3D nodes; '];
else
textRSNHR3D = 'There are no RSN Link HR 3D; ';
NodoRSNLinkHR3D = [];
end
fprintf(fileID,fmt,textRSNHR3D);
%% Load Link
% carico le informazioni relative al numero e alla profondità per LOAD LINK
comando = ['select num, depth, measurment from nodes where tool_id = ''' idTool ''' and nodetype_id = 15 order by num'];
curs = exec(conn,comando);
curs = fetch(curs);
Leggo = curs.Data;
[rL,cL] = size(Leggo);
if rL == 1 && cL == 1
textLL = 'There are not Load Link; ';
NodoLoadLink = [];
else
depth = cell2mat(Leggo(:,2));
depth = num2cell(depth);
nome = cell(rL,1);
for i=1:rL
nome(i,1) = cellstr('Load Link');
end
NodoLoadLink = [nome Leggo(:,1) depth Leggo(:,3)];
% inverto la matrice Nodi (il primo nodo è il più profondo)
textLL = ['There are ',num2str(rL),' Load Link nodes; '];
end
fprintf(fileID,fmt,textLL);
%% Trigger Link
% carico le informazioni relative al numero e alla profondità per TRIGGER LINK
comando = ['select num, depth, measurment from nodes where tool_id = ''' idTool ''' and nodetype_id = 40 order by num'];
curs = exec(conn,comando);
curs = fetch(curs);
Leggo = curs.Data;
[rL,cL] = size(Leggo);
if rL == 1 && cL == 1
textTrL = 'There are not Trigger Link; ';
NodoTriggerLink = [];
else
depth = cell2mat(Leggo(:,2));
depth = num2cell(depth);
nome = cell(rL,1);
for i=1:rL
nome(i,1) = cellstr('Trigger Link');
end
NodoTriggerLink = [nome Leggo(:,1) depth Leggo(:,3)];
% inverto la matrice Nodi (il primo nodo è il più profondo)
textTrL = ['There are ',num2str(rL),' Trigger Link nodes; '];
end
fprintf(fileID,fmt,textTrL);
%% G-Flow Link
comando = ['select num, depth, measurment from nodes where tool_id = ''' idTool ''' and nodetype_id = 48 order by num'];
curs = exec(conn,comando);
curs = fetch(curs);
Leggo = curs.Data;
[rL,cL] = size(Leggo);
if rL == 1 && cL == 1
textGFL = 'There are not G-Flow Link; ';
NodoGflowLink = [];
else
depth = cell2mat(Leggo(:,2));
depth = num2cell(depth);
nome = cell(rL,1);
for i=1:rL
nome(i,1) = cellstr('G-Flow Link');
end
NodoGflowLink = [nome Leggo(:,1) depth Leggo(:,3)];
% inverto la matrice Nodi (il primo nodo è il più profondo)
textGFL = ['There are ',num2str(rL),' G-Flow Link nodes; '];
end
fprintf(fileID,fmt,textGFL);
%% G-Shock Link
comando = ['select num, depth, measurment from nodes where tool_id = ''' idTool ''' and nodetype_id = 50 order by num'];
curs = exec(conn,comando);
curs = fetch(curs);
Leggo = curs.Data;
[rL,cL] = size(Leggo);
if rL == 1 && cL == 1
textGS = 'There are not G-Shock Link; ';
NodoGshockLink = [];
else
depth = cell2mat(Leggo(:,2));
depth = num2cell(depth);
nome = cell(rL,1);
for i=1:rL
nome(i,1) = cellstr('G-Shock Link');
end
NodoGshockLink = [nome Leggo(:,1) depth Leggo(:,3)];
% inverto la matrice Nodi (il primo nodo è il più profondo)
textGS = ['There are ',num2str(rL),' G-Shock Link nodes; '];
end
fprintf(fileID,fmt,textGS);
%% Debris Link
comando = ['select num, depth, measurment from nodes where tool_id = ''' idTool ''' and nodetype_id = 49 order by num'];
curs = exec(conn,comando);
curs = fetch(curs);
Leggo = curs.Data;
[rL,cL] = size(Leggo);
if rL == 1 && cL == 1
textDL = 'There are not Debris Link; ';
NodoDebrisLink = [];
else
depth = cell2mat(Leggo(:,2));
depth = num2cell(depth);
nome = cell(rL,1);
for i=1:rL
nome(i,1) = cellstr('Debris Link');
end
NodoDebrisLink = [nome Leggo(:,1) depth Leggo(:,3)];
% inverto la matrice Nodi (il primo nodo è il più profondo)
textDL = ['There are ',num2str(rL),' Debris Link nodes; '];
end
fprintf(fileID,fmt,textDL);
text = 'Nodes defined correctly and tipologiaNodi function closed';
fprintf(fileID,fmt,text);
fclose(fileID);
end