I took your suggestions into account and tried this method. However, I'm still facing an issue: my function returns a table with points in rows.
and I kept date = today_date;
because when I run the script with today_date
as a parameter directly, JMP doesn't respond. I don't understand why assigning date = today_date
handles the run more efficiently.
TOP5:get_dates_percent = Function({},
today_date = Today();
start_of_month = Date Increment(Today(), "Month", 0, "Start");
evallist({start_of_month, today_date});
);
TOP5:calculate_nok_percentages_over_time = Function({dt},
{start_of_month, today_date} = TOP5:get_dates_percent();
dt_results = New Table("NOK Percentages Over Time",
New Column("Date", Numeric),
New Column("Percent_NOK_ICT", Numeric),
New Column("Percent_NOK_FCT", Numeric)
);
// Set the format for the Date column
Column(dt_results, "Date") << Data Type(
Numeric,
Format("Format Pattern", "<YYYY>-<MM>-<DD>", 10),
Input Format("Format Pattern", "<YYYY>-<MM>-<DD>"),
Format("Date Abbrev", 20)
) << Set Field Width(10);
date = today_date;
While(date >= start_of_month,
{percent_nok_ict, percent_nok_fct} = TOP5:calculate_nok_percentages_for_date(dt, date);
dt_results << Add Rows(
{Format(date, "yyyy-mm-dd"), percent_nok_ict, percent_nok_fct}
);
date = Date Increment(date, "day", -1);
);
dt_results;
);
TOP5:calculate_nok_percentages_for_date = Function({dt, specific_date},
{start_of_month, today_date} = TOP5:get_dates_percent();
dt_top5 = dt << Summary(
Group(:Date, :Nom de fichier, :Ref Produit, :ProductName, :Baie, :ICT_FCT, :Result, :Reason Error, :CodeError),
Freq("Aucun(e)"),
Weight("Aucun(e)"),
invisible
);
nameFilesNok = Associative Array(Column(dt_top5, "Nom de fichier") << Get Values) << Get Keys;
total_nb_total_ict = 0;
total_nb_total_fct = 0;
total_nb_nok_ict = 0;
total_nb_nok_fct = 0;
For(k = 1, k <= N Items(nameFilesNok), k++,
FileRows = dt_top5 << get rows where(
:File Name == nameFilesNok[k] & :Date >= start_of_month & :Date <= specific_date & Contains(:File Name, "GOLDEN") == 0
);
nb_total_ict = 0;
nb_total_fct = 0;
nb_nok_ict = 0;
nb_nok_fct = 0;
total_rows = N Items(FileRows);
For(j = 1, j <= total_rows, j++,
If(dt_top5:ICT_FCT[FileRows[j]] == "ICT",
nb_total_ict = nb_total_ict + dt_top5:Nb. de lignes[FileRows[j]];
If(dt_top5:Result[FileRows[j]] == "NOK",
nb_nok_ict = nb_nok_ict + dt_top5:Nb. de lignes[FileRows[j]]
);
, dt_top5:ICT_FCT[FileRows[j]] == "FCT",
nb_total_fct = nb_total_fct + dt_top5:Nb. de lignes[FileRows[j]];
If(dt_top5:Result[FileRows[j]] == "NOK",
nb_nok_fct = nb_nok_fct + dt_top5:Nb. de lignes[FileRows[j]]
);
)
);
total_nb_total_ict += nb_total_ict;
total_nb_total_fct += nb_total_fct;
total_nb_nok_ict += nb_nok_ict;
total_nb_nok_fct += nb_nok_fct;
);
percent_nok_ict = (total_nb_nok_ict / total_nb_total_ict) * 100;
percent_nok_fct = (total_nb_nok_fct / total_nb_total_fct) * 100;
Eval List({percent_nok_ict, percent_nok_fct});
);
thank you in advance.