定義月初和今天日期之間的日期間隔 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() 。使用「月」作為間隔名稱,使用「開始」作為對齊方式來取得該月的第一個日期。例如本月的第一天
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 級),在 << start_of_month 的存取或評估期間位於第 1 行,月初
1號線
檢測到堆疊溢位。已超出最大呼叫等級數。執行在第 1 行終止
回覆:定義月初和今天日期之間的日期間隔 JMP16我猜問題出在你的 For 迴圈。它很可能可以被優化,您甚至不需要使用循環。如果您已經了解行,則可以使用資料表下標等方法從表中取得所需的值。您也很可能使用子集 + 摘要來執行計算。
如果您可以提供一個可用於演示的資料(或模擬日期)的小範例,我可以提供更多建議。另外,如果您可以提供範例,請嘗試提供有關正確結果的一些資訊。
回覆:定義月初和今天日期之間的日期間隔 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});
);再次感謝所做的一切!