cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
Yass
Level IV

Définir une intervalle de date entre début de mois jusqu'au la date d'aujourd'hui JMP16

Bonjour,

 

Je rencontre depuis ce matin un problème avec mon script sur JMP et j'ai besoin de votre aide svp.

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 - Cette fonction prend une date en entrée et renvoie le jour du mois sous forme de nombre.

axe1:get_dates - Cette fonction récupère la date de début du mois en cours et la date du jour.

Puis une fonction pour calculer :

//nb_total_ict et nb_total_fct : permettent de compter le nombre total de tests effectués
//nb_nok_ict et nb_nok_fct : permettent de compter le nombre de nok parmi tous les tests

Afin de calculer le pourcentage de NOK pour les ICT et les FCT entre le début de mois et la date d'aujourd'hui.
vous trouvez ci-joint une copie de la partie de mon code.

Je vous remercie par avance.

Cordialement,
Yass

 

 

// 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)) || "%")
                )
            )
        )
    );
);

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: Définir une intervalle de date entre début de mois jusqu'au la date d'aujourd'hui JMP16

I would guess the issue is with your For loop. Most likely it can be optimized and you won't even need to use a loop. If you already have the knowledge of the rows you can use for exampleData table subscripting to get the values you want from the table. You could also most likely use Subset + Summary to perform the calculations.

 

If you can provide a small example of your data (or mock up date) which can be used to demonstrate I can give more suggestions. Also if you can provide an example try to provide some information about the correct results.

-Jarmo

View solution in original post

Craige_Hales
Super User

Re: Définir une intervalle de date entre début de mois jusqu'au la date d'aujourd'hui JMP16

two possibilities, 2nd seems likely.

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 may be global and may be confused between the functions

2: the list you return has the names of the variables, not the values, and they get stored into...themselves. I think that will be the recursion.

(Nice looking code!)

Craige

View solution in original post

5 REPLIES 5
jthi
Super User

Re: Définir une intervalle de date entre début de mois jusqu'au la date d'aujourd'hui JMP16

What is the problem you are having (translation in the community might be incorrect as I couldn't really find the issue easily)? Most likely you want to use Date Difference() or Date Increment(). Use "month" as intervalname and "start" as alignment to get the first date of month. For example first date of this month

Date Increment(Today(), "Month", 0, "start");

JMP also has Month() to get the month of date and many more datetime functions which you might find useful for this type of work

jthi_0-1720190829149.png

 

-Jarmo
Yass
Level IV

Re: Définir une intervalle de date entre début de mois jusqu'au la date d'aujourd'hui JMP16

I tried to define two functions to get the start date of the month and today's date in order to calculate the percentage of NOK results in a table for ICT and FCT based on a date table (dt).

i did use 

  • 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.

but every time i get this error message :

JMP Alert

The symbol evaluation is too recursive (>250 levels), on line 1 during access or evaluation of << start_of_month, start_of_month

on line 1

A stack overflow has been detected. The maximum number of call levels has been exceeded. Execution terminated on line 1

 

jthi
Super User

Re: Définir une intervalle de date entre début de mois jusqu'au la date d'aujourd'hui JMP16

I would guess the issue is with your For loop. Most likely it can be optimized and you won't even need to use a loop. If you already have the knowledge of the rows you can use for exampleData table subscripting to get the values you want from the table. You could also most likely use Subset + Summary to perform the calculations.

 

If you can provide a small example of your data (or mock up date) which can be used to demonstrate I can give more suggestions. Also if you can provide an example try to provide some information about the correct results.

-Jarmo
Craige_Hales
Super User

Re: Définir une intervalle de date entre début de mois jusqu'au la date d'aujourd'hui JMP16

two possibilities, 2nd seems likely.

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 may be global and may be confused between the functions

2: the list you return has the names of the variables, not the values, and they get stored into...themselves. I think that will be the recursion.

(Nice looking code!)

Craige
Yass
Level IV

Re: Définir une intervalle de date entre début de mois jusqu'au la date d'aujourd'hui JMP16

I would like to thank you for your suggestions and help.

I ended up modifying my get_dates function where i did get Today's date and start of month date and using a different For loop because I found some errors in the original loop. However, your suggestions were very helpful
that is the get_dates function :

 

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});
);

Thanks again for everything !