定义月初和今天日期之间的日期间隔 JMP16早上好,
从今天早上开始,我在 JMP 上的脚本遇到了问题,我需要您的帮助。
J'ai essayé de définir deux fonctions pour avoir la date de début de mois et la date d'aujourd'hui :
axe1:get_day_of_month- 此函数将日期作为输入并以数字形式返回该月的日期。
axe1:get_dates- 此函数检索当前月份的开始日期和今天的日期。
然后是一个函数来计算:
//nb_total_ict 和 nb_total_fct:允许您计算执行的测试总数
//nb_nok_ict 和 nb_nok_fct:允许您计算所有测试中 nok 的数量
为了计算月初到今天之间 ICT 和 FCT 的挪威克朗百分比。
附件是我的部分代码的副本。
我提前谢谢你。
真挚地,
亚斯
// Fonction pour obtenir le jour du mois
axe1:get_day_of_month = Function({date},
day_of_month = Num(Format(date, "dd"));
day_of_month
);
// Fonction pour récupérer les dates
axe1:get_dates = Function({},
today_date = Format(Today(), "yyyy-mm-dd");
day_of_month = axe1:get_day_of_month(Today());
start_of_month = Format(Today() - (day_of_month - 1), "yyyy-mm-dd");
{start_of_month, today_date}
);
// Fonction pour calculer les pourcentages de NOK
axe1:calculate_nok_percentages = Function({dt},
{start_of_month, today_date} = axe1:get_dates();
// Initialisation des variables
nb_total_ict = 0;
nb_total_fct = 0;
nb_nok_ict = 0;
nb_nok_fct = 0;
// Récupération des lignes correspondant à la période spécifiée
FileRows = dt << Get Rows Where(
Num(Char(:Date)) >= Num(start_of_month) & Num(Char(:Date)) <= Num(today_date) & Contains(:File Name, "GOLDEN") == 0
);
total_rows = N Items(FileRows);
For(j = 1, j <= total_rows, j++,
If(dt:ICT_FCT[FileRows[j]] == "ICT",
nb_total_ict += dt:Nb_de_lignes[FileRows[j]];
If(dt:Result[FileRows[j]] == "NOK",
nb_nok_ict += dt:Nb_de_lignes[FileRows[j]]
)
);
If(dt:ICT_FCT[FileRows[j]] == "FCT",
nb_total_fct += dt:Nb_de_lignes[FileRows[j]];
If(dt:Result[FileRows[j]] == "NOK",
nb_nok_fct += dt:Nb_de_lignes[FileRows[j]]
)
);
);
// Calcul des pourcentages NOK
percent_nok_ict = (nb_nok_ict / nb_total_ict) * 100;
percent_nok_fct = (nb_nok_fct / nb_total_fct) * 100;
// Affichage des résultats
Window("Analyse des données") << Append(
V List Box(
Outline Box("Résultat NOK",
Border Box(
Text Box("Pourcentage de NOK ICT du " || start_of_month || " au " || today_date || " : " || Char(Round(percent_nok_ict, 2)) || "%"),
Text Box("Pourcentage de NOK FCT du " || start_of_month || " au " || today_date || " : " || Char(Round(percent_nok_fct, 2)) || "%")
)
)
)
);
);
自动化和脚本视窗回复:定义月初和今天日期之间的日期间隔 JMP16您遇到了什么问题(社区中的翻译可能不正确,因为我无法轻松找到问题所在)?您很可能想要使用Date Difference()或Date Increment() 。使用“month”作为间隔名称并使用“start”作为对齐方式来获取月份的第一天。例如本月的第一天
Date Increment(Today(), "Month", 0, "start");
JMP 还具有 Month() 来获取日期的月份以及许多其他日期时间函数,您可能会发现这些函数对此类工作很有用

回复:定义月初和今天日期之间的日期间隔 JMP16我尝试定义两个函数来获取月份的开始日期和今天的日期,以便根据日期表 (dt) 计算 ICT 和 FCT 表中 NOK 结果的百分比。
我确实用过
axe1:get_day_of_month - This function takes a date as input and returns the day of the month as a number.axe1:get_dates - This function gets the start date of the current month and today's date.axe1:calculate_nok_percentages - This function calculates the percentage of NOK results for ICT and FCT based on a date table (dt). It filters the data for rows where the file name does not contain "GOLDEN" and then calculates the percentage of NOK for ICT and FCT for the specified date range.
但每次我都会收到此错误信息:
JMP警报
符号评估过于递归(>250 级),在第 1 行访问或评估 << start_of_month 时,月初
1号线
检测到堆栈溢出。已超出最大调用级别数。执行在第 1 行终止
回复:定义月初和今天日期之间的日期间隔 JMP16我猜问题出在你的 For 循环上。很可能它可以被优化,你甚至不需要使用循环。如果你已经了解行,你可以使用例如数据表下标来从表中获取你想要的值。你也很可能使用 Subset + Summary 来执行计算。
如果您可以提供一个小数据示例(或模拟日期)来演示,我可以提供更多建议。此外,如果您可以提供示例,请尝试提供一些有关正确结果的信息。
回复:定义月初和今天日期之间的日期间隔 JMP16两种可能性,第二种可能性较大。
axe1:get_day_of_month = Function({date},
{ day_of_month },// 1: use local variables
day_of_month = Num(Format(date, "dd"));
day_of_month
);
// Fonction pour récupérer les dates
axe1:get_dates = Function({},
today_date = Format(Today(), "yyyy-mm-dd");
day_of_month = axe1:get_day_of_month(Today());
start_of_month = Format(Today() - (day_of_month - 1), "yyyy-mm-dd");
// 2: use evallist
evallist( {start_of_month, today_date} )
);
1:day_of_month 可能是全局的,并且可能会在函数之间混淆
2:返回的列表包含变量的名称,而不是值,并且它们存储在...它们自己中。我认为那将是递归。
(代码看上去很漂亮!)
回复:定义月初和今天日期之间的日期间隔 JMP16我想要感谢您的建议和帮助。
我最终修改了我的 get_dates 函数,在其中获取了今天的日期和月初日期,并使用了不同的 For 循环,因为我在原始循环中发现了一些错误。不过,你的建议非常有帮助
这就是 get_dates 函数:
axe1:get_dates = Function({},
today_date = Format(Today(), "yyyy-mm-dd");
start_of_month = Format(Date Increment(Today(), "Month", 0, "Start"), "yyyy-mm-dd");
evallist({start_of_month, today_date});
);再次感谢一切!