From 571e247fd8b91f61ce7db1e895334662b50c11e4 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Wed, 28 Aug 2024 06:19:06 +0200 Subject: [PATCH] =?UTF-8?q?measures=20list=20pourrait=20=C3=AAtre=20une=20?= =?UTF-8?q?liste=20simple=20tri=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/fsm.h | 25 ++++---- src/fsm/measure/list.c | 135 +++++++++++++++++---------------------- src/fsm/measure/manage.c | 62 ++++++++++-------- src/signal.c | 5 +- 4 files changed, 111 insertions(+), 116 deletions(-) diff --git a/include/fsm.h b/include/fsm.h index 493aa37..e8a699d 100644 --- a/include/fsm.h +++ b/include/fsm.h @@ -44,22 +44,15 @@ enum fsm_select_STORE_RESTORE_RESET { STORE, RESTORE, RESET }; enum fsm_measure_type {DATE_RULE_EXEC, RULE_EXEC_NB, OBJECT_NB, ELAPSED_TIME }; -typedef struct m_pile // 1er essai : measures (2024-08-26) -{ - int value; // to replace - int measure_type; - int *p_rule; // réserve un emplacement pour stocker une adresse mémoire. - // at_rule = &rule; < écrira l'adresse de rule dans cet emplacement. - struct m_pile *prev; -} m_pile; - #define n_rules 128 // arbitrary #define n_objects 32 // arbitrary too, #define n_situations 128 // and so on... +typedef struct measure_list {int value; struct measure_list *suiv;} measure_list ; + void fsm_init(); // def: fsm/dispatch; call: main; void fsm_preferences_init(); // def: fsm/prefer; call: fsm/dispatch; -void fsm_measures_list_init(); // def: fsm/measure/list.c; call: fsm/dispatch; +void fsm_measures_list_init(); // def: fsm/measure/manage.c; call: fsm/dispatch; void fsm_results_list_init(); // def: fsm/results; call: fsm/dispatch; void fsm_displayable_list_init(); // def: fsm/prefer; call: fsm/dispatch; @@ -91,7 +84,11 @@ void fsm_debug_msg (int choice, int value, char *string, int sub_automaton); // fsm/measure; // fsm/result; -int fsm_pile_push (m_pile **p, int val); // def: measure/list call measure/list -int fsm_pile_pop (m_pile **p); // def: measure/list call measure/list -void fsm_pile_view (m_pile *p); // def: measure/list call measure/list -int fsm_pile_length (m_pile *p); // def: measure/list call measure/list +// --------------------------------------------------------------- WIP +// def: measure/list call measure/list (following functions...) +void fsm_measures_sorted_list_insert (measure_list **sl, int value); +int fsm_measures_sorted_list_pop (measure_list **sl); +int fsm_measures_sorted_list_length (measure_list *sl); +void fsm_measures_sorted_list_clear (measure_list **sl); +void fsm_measures_sorted_list_view (measure_list *sl); +void fsm_measures_sorted_list_test(); // def: measure/manage; call measure/manage; diff --git a/src/fsm/measure/list.c b/src/fsm/measure/list.c index fe40123..956ef87 100644 --- a/src/fsm/measure/list.c +++ b/src/fsm/measure/list.c @@ -2,7 +2,7 @@ * * * Gem-graph client * * * -* State machine * +* State machine / Measures * * * * Copyright © 2024 Libre en Communs * * Copyright © 2024 Adrien Bourmault * @@ -31,49 +31,25 @@ #include #include #include "../../../include/fsm.h" -#include "../../../include/util.h" + /******************************************************************************/ +/* An editable list of measurements is defined and maintained here */ +/* - - - */ +/* Each possible measurement can be activated or silenced */ +/* - - - */ +/* The measures relate to */ +/* - the number of occurrences of a rule or group of rules, */ +/* - the number of objects or situations before/after the rule was applied, */ +/* - the time (date) of the event, */ +/* - the time elapsed between two events, */ +/* - the occurrence of events C between events A and B, */ /* */ -/* FFFFFFFFFFF SSSSS MM MM */ -/* FF SSS SS MMMM MMMM */ -/* FF SS MM MM MM MM */ -/* FFFFFFF SS MM MM MM MM */ -/* FF SS MM MM MM */ -/* FF SSS MM MM */ -/* FF SS SSS MM MM */ -/* FF SSSSSS MM MM */ -/* */ +/* When a list of measurements is established, it is possible to evaluate */ +/* if the results of a measurement are correlated with some other results. */ /******************************************************************************/ -/******************************************************************************/ -/* Each state of the finite state machine (fsm) must be */ -/* - saved at the end of a work session and */ -/* - reread (available) at the start of a new session. */ -/* */ -/* No state of the fsm should be defined in another module. */ -/* No fsm transition needs to be executed in another module. */ -/******************************************************************************/ - - -/******************************************************************************/ -/* M E A S U R E M E N T S */ -/******************************************************************************/ -// An editable list of measurements is defined and maintained here. -// Each possible measurement can be activated or silenced. - -// The measures relate to -// - the number of occurrences of a rule or group of rules, -// - the number of objects or situations before/after the rule was applied, -// - the time (date) of the event, -// - the time elapsed between two events, -// - the occurrence of events C between events A and B -// - (non limitative, maybe) < pattern recognition tools ? - -// When a list of measurements is established, it is possible to evaluate -// if the results of a measurement are correlated with some other results. - //------------------------------------------------------------------------------ // structure de données : chaque "item" comportera : @@ -97,58 +73,67 @@ // - pointeur vers une liste de mesures similaires // - pointeur vers des données, des représentations de données ? - -void fsm_measures_list_init () +void fsm_measures_sorted_list_insert (measure_list **ml, int value) { - m_pile *exemple = NULL; // doit être initialisée à NULL - printf ("fsm push > %d\n", fsm_pile_push (&exemple, 4)); - fsm_pile_view (exemple); - printf ("fsm pop > %d\n", fsm_pile_pop (&exemple)); - fsm_pile_view (exemple); - + measure_list *tmp = NULL; + measure_list *cml = *ml; + measure_list *elem = malloc (sizeof (measure_list)); + if (!elem) exit (EXIT_FAILURE); + elem->value = value; + while (cml && cml->value < value) + { + tmp = cml; + cml = cml->suiv; + } + elem->suiv = cml; + if (tmp) tmp->suiv = elem; + else *ml = elem; } -int fsm_pile_push (m_pile **p, int val) +int fsm_measures_sorted_list_pop (measure_list **ml) { - m_pile *element = malloc (sizeof(m_pile)); - if (!element) exit (EXIT_FAILURE); // Si l'allocation a échoué. - element->value = val; - element->prev = *p; - *p = element; // Le pointeur pointe sur le dernier élément. - return val; + int value; + measure_list *tmp; + if (! *ml) return -1; + tmp = (*ml)->suiv; + value = (*ml)->value; + printf("value = %d < removed from the measures list\n", (*ml)->value); + free (*ml); + *ml = tmp; + return value; } -int fsm_pile_pop (m_pile **p) +int fsm_measures_sorted_list_length (measure_list *ml) { - int Val; - m_pile *tmp; - if (!*p) return -1; // Retourne -1 si la pile est vide. - tmp = (*p)->prev; - Val = (*p)->value; - free (*p); - *p = tmp; // Le pointeur pointe sur le dernier élément. - return Val; // Retourne la value soutirée de la pile. -} - -int fsm_pile_length (m_pile *p) -{ - int n=0; - while (p) + int n = 0; + while (ml) { n++; - p = p->prev; + ml = ml->suiv; } return n; } -void fsm_pile_view (m_pile *p) +void fsm_measures_sorted_list_clear (measure_list **ml) { - printf ("fsm view pile (n = %d)\n", fsm_pile_length (p)); - while (p) + measure_list *tmp; + while (*ml) { - printf ("fsm > %d\n", p->value); - p = p->prev; + tmp = (*ml)->suiv; + free (*ml); + *ml = tmp; } - puts ("------"); +} + +void fsm_measures_sorted_list_view (measure_list *ml) +{ + printf ("-------- view measures list (n = %d)\n", + fsm_measures_sorted_list_length (ml)); + while(ml) + { + printf("%d\n", ml->value); + ml = ml->suiv; + } + puts ("--------------"); } diff --git a/src/fsm/measure/manage.c b/src/fsm/measure/manage.c index ee70788..78cf52d 100644 --- a/src/fsm/measure/manage.c +++ b/src/fsm/measure/manage.c @@ -2,7 +2,7 @@ * * * Gem-graph client * * * -* State machine * +* State machine / Measures * * * * Copyright © 2024 Libre en Communs * * Copyright © 2024 Adrien Bourmault * @@ -33,30 +33,6 @@ #include "../../../include/fsm.h" #include "../../../include/util.h" -/******************************************************************************/ -/* */ -/* FFFFFFFFFFF SSSSS MM MM */ -/* FF SSS SS MMMM MMMM */ -/* FF SS MM MM MM MM */ -/* FFFFFFF SS MM MM MM MM */ -/* FF SS MM MM MM */ -/* FF SSS MM MM */ -/* FF SS SSS MM MM */ -/* FF SSSSSS MM MM */ -/* */ -/******************************************************************************/ - - -/******************************************************************************/ -/* Each state of the finite state machine (fsm) must be */ -/* - saved at the end of a work session and */ -/* - reread (available) at the start of a new session. */ -/* */ -/* No state of the fsm should be defined in another module. */ -/* No fsm transition needs to be executed in another module. */ -/******************************************************************************/ - - /******************************************************************************/ /* M E A S U R E M E N T S */ /******************************************************************************/ @@ -100,4 +76,40 @@ void fsm_add_measure (char *measure_name) {fsm_debug_msg (2, 0, measure_name, 2);} +void fsm_measures_list_init() {fsm_measures_sorted_list_test();} + +void fsm_measures_sorted_list_test() +{ + measure_list *Mysl = NULL; + + puts("\ncréation d'une liste de 10 elements :"); + fsm_measures_sorted_list_insert (&Mysl,9); + fsm_measures_sorted_list_insert (&Mysl,-8); + fsm_measures_sorted_list_insert (&Mysl,3); + fsm_measures_sorted_list_insert (&Mysl,5); + fsm_measures_sorted_list_insert (&Mysl,-1); + fsm_measures_sorted_list_insert (&Mysl,4); + fsm_measures_sorted_list_insert (&Mysl,-6); + fsm_measures_sorted_list_insert (&Mysl,2); + fsm_measures_sorted_list_insert (&Mysl,0); + fsm_measures_sorted_list_insert (&Mysl,7); + fsm_measures_sorted_list_view (Mysl); + + puts("retrait des 3 premiers elements :"); + fsm_measures_sorted_list_pop (&Mysl); + fsm_measures_sorted_list_pop (&Mysl); + fsm_measures_sorted_list_pop (&Mysl); + fsm_measures_sorted_list_view (Mysl); + + puts("ajout des 3 elements (8, 1, 6) :"); + fsm_measures_sorted_list_insert (&Mysl,8); + fsm_measures_sorted_list_insert (&Mysl,1); + fsm_measures_sorted_list_insert (&Mysl,6); + fsm_measures_sorted_list_view (Mysl); + + fsm_measures_sorted_list_clear (&Mysl); + printf("clear()\n> nombre d'éléments restant = %d\n\n", + fsm_measures_sorted_list_length(Mysl)); +} + diff --git a/src/signal.c b/src/signal.c index 8343afd..f0bdcf6 100644 --- a/src/signal.c +++ b/src/signal.c @@ -365,8 +365,9 @@ void on_situations_box_do_reset (GtkWidget *btt_reset, GtkScrollbar *reset_scrol void on_clicked_topbar_right_measure (GtkWidget *btt, gpointer data) { - gtk_window_set_child (GTK_WINDOW (widget_get_main_window ()), - GTK_WIDGET (widget_get_measure_page())); + fsm_measures_sorted_list_test(); +// gtk_window_set_child (GTK_WINDOW (widget_get_main_window ()), +// GTK_WIDGET (widget_get_measure_page())); } void on_start_new_measure (GtkWidget *btt, gpointer data)