diff --git a/analyze_from_csv.m b/analyze_from_csv.m new file mode 100644 index 0000000..8d00b3b --- /dev/null +++ b/analyze_from_csv.m @@ -0,0 +1,139 @@ +%% Cellule 1 : Chargement des données +filename = 'recording_20250806_155908.csv'; +opts = detectImportOptions(filename); +opts = setvaropts(opts, 'timestamp', 'Type', 'datetime'); +df = readtable(filename, opts); + +df_PatientSkid = df(strcmp(df.pu, 'PatientSkid'), :); + +%% Cellule 2 : Affichage multi-PU par grandeur +reference_lines = struct('Qperm', 1200, 'Pdilute', 2.5); +quantities = {'Qperm', 'Qdilute', 'Qdrain', 'Pro', 'Pdilute','MV07_sp'}; +n_quantities = numel(quantities); +pus_all = {'PU_1', 'PU_2', 'PU_3'}; + +figure('Name', 'Évolution des grandeurs par PU', 'Position', [100 100 1400 300*n_quantities]); +tiledlayout(n_quantities,1) + +for i = 1:n_quantities + quantity = quantities{i}; + nexttile + hold on + for j = 1:length(pus_all) + pu = pus_all{j}; + df_pu = df(strcmp(df.pu, pu), :); + if any(strcmp(df_pu.Properties.VariableNames, quantity)) + plot(df_pu.timestamp, df_pu.(quantity), 'DisplayName', pu,'LineWidth',1.5); + end + end + + % Lignes de référence + if isfield(reference_lines, quantity) + yline(reference_lines.(quantity), '--r'); + end + + if strcmp(quantity, 'Qdilute') && ismember('QSkid', df_PatientSkid.Properties.VariableNames) + plot(df_PatientSkid.timestamp, df_PatientSkid.QSkid, 'DisplayName', 'QSkid','LineWidth',1.5); + end + + ylabel(quantity) + grid on + legend('Location', 'northeast') + if i == n_quantities + xlabel('Timestamp') + end +end + +sgtitle('Évolution des grandeurs par PU') + +%% Analyse initiale pour PU_1 +df_pu_1 = df(strcmp(df.pu, 'PU_1'), :); +delta_t = seconds(diff(df_pu_1.timestamp)); + +figure('Name','Time between messages','Position',[100 100 1000 400]) +histogram(delta_t, 10, 'Normalization', 'probability') +title("Time between messages for PU\_1") +xlabel("Δt (seconds)") +ylabel("Probability") +grid on + +fprintf("Average time is %.3f seconds\n", mean(delta_t)); + +%% Affichage pour tous les PU +pus = unique(df.pu); +disp("PU disponibles :") +disp(pus) + +pus = {'PU_2'}; % Modifier ici si besoin +for i = 1:length(pus) + pu = pus{i}; + fprintf('\n--- Data for %s ---\n', pu) + plot_pu_data(df, df_PatientSkid, pu); +end + + +%% Fonction d'affichage PU (similaire à plot_pu_data) +function plot_pu_data(df, df_PatientSkid, pu_name) + df_pu = df(strcmp(df.pu, pu_name), :); + + % --------- Plot 1: Débits --------- + flow_cols = {'Qperm', 'Qdilute', 'Qdrain', 'Qrecirc'}; + available_flows = intersect(flow_cols, df_pu.Properties.VariableNames); + + if ~isempty(available_flows) + figure('Name', [pu_name ' - Débits']) + hold on + for i = 1:length(available_flows) + plot(df_pu.timestamp, df_pu.(available_flows{i}), 'DisplayName', available_flows{i},'LineWidth',1.5); + end + if ismember('QSkid', df_PatientSkid.Properties.VariableNames) + plot(df_PatientSkid.timestamp, df_PatientSkid.QSkid, 'DisplayName', 'QSkid','LineWidth',1.5); + end + title([pu_name ' - Flow Rates']) + xlabel("Timestamp") + ylabel("Flow (L/min)") + legend('Location','northeast') + grid on + end + + % --------- Plot 2: Pressions --------- + pressure_cols = {'Pro', 'Pdilute', 'Pretentate'}; + available_pressures = intersect(pressure_cols, df_pu.Properties.VariableNames); + + if ~isempty(available_pressures) + figure('Name', [pu_name ' - Pressions']) + hold on + for i = 1:length(available_pressures) + plot(df_pu.timestamp, df_pu.(available_pressures{i}), 'DisplayName', available_pressures{i},'LineWidth',1.5); + end + title([pu_name ' - Pressures']) + xlabel("Timestamp") + ylabel("Pressure (bar)") + legend('Location','northeast') + grid on + end + + % --------- Plot 3: Vannes motorisées --------- + figure('Name', [pu_name ' - Motor Valve Positions'], 'Position', [100 100 1500 800]) + tiledlayout(3,3) + idx = 1; + for mv = 2:8 + mv_real = sprintf('MV0%d', mv); + mv_sp = sprintf('MV0%d_sp', mv); + nexttile + if ismember(mv_real, df_pu.Properties.VariableNames) && ... + ismember(mv_sp, df_pu.Properties.VariableNames) + plot(df_pu.timestamp, df_pu.(mv_real), 'b', 'DisplayName', 'Actual','LineWidth',1.5) + hold on + plot(df_pu.timestamp, df_pu.(mv_sp), '--', 'Color', [1 0.5 0], 'DisplayName', 'Setpoint','LineWidth',1.5) + title(mv_real) + ylabel("Position (%)") + legend + grid on + else + axis off + end + idx = idx + 1; + end + sgtitle([pu_name ' - Motor Valve Positions vs Setpoints']) +end