measures list pourrait être une liste simple triée

This commit is contained in:
Jean Sirmai 2024-08-28 06:19:06 +02:00
parent 9e0ef7d28f
commit 571e247fd8
Signed by: jean
GPG Key ID: FB3115C340E057E3
4 changed files with 111 additions and 116 deletions

View File

@ -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 }; 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_rules 128 // arbitrary
#define n_objects 32 // arbitrary too, #define n_objects 32 // arbitrary too,
#define n_situations 128 // and so on... #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_init(); // def: fsm/dispatch; call: main;
void fsm_preferences_init(); // def: fsm/prefer; call: fsm/dispatch; 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_results_list_init(); // def: fsm/results; call: fsm/dispatch;
void fsm_displayable_list_init(); // def: fsm/prefer; 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/measure;
// fsm/result; // fsm/result;
int fsm_pile_push (m_pile **p, int val); // def: measure/list call measure/list // --------------------------------------------------------------- WIP
int fsm_pile_pop (m_pile **p); // def: measure/list call measure/list // def: measure/list call measure/list (following functions...)
void fsm_pile_view (m_pile *p); // def: measure/list call measure/list void fsm_measures_sorted_list_insert (measure_list **sl, int value);
int fsm_pile_length (m_pile *p); // def: measure/list call measure/list 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;

View File

@ -2,7 +2,7 @@
* * * *
* Gem-graph client * * Gem-graph client *
* * * *
* State machine * * State machine / Measures *
* * * *
* Copyright © 2024 Libre en Communs <contact@a-lec.org> * * Copyright © 2024 Libre en Communs <contact@a-lec.org> *
* Copyright © 2024 Adrien Bourmault <neox@a-lec.org> * * Copyright © 2024 Adrien Bourmault <neox@a-lec.org> *
@ -31,49 +31,25 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "../../../include/fsm.h" #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 */ /* When a list of measurements is established, it is possible to evaluate */
/* FF SSS SS MMMM MMMM */ /* if the results of a measurement are correlated with some other results. */
/* 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 */
/******************************************************************************/
// 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 : // structure de données : chaque "item" comportera :
@ -97,58 +73,67 @@
// - pointeur vers une liste de mesures similaires // - pointeur vers une liste de mesures similaires
// - pointeur vers des données, des représentations de données ? // - pointeur vers des données, des représentations de données ?
void fsm_measures_sorted_list_insert (measure_list **ml, int value)
void fsm_measures_list_init ()
{ {
m_pile *exemple = NULL; // doit être initialisée à NULL measure_list *tmp = NULL;
printf ("fsm push > %d\n", fsm_pile_push (&exemple, 4)); measure_list *cml = *ml;
fsm_pile_view (exemple); measure_list *elem = malloc (sizeof (measure_list));
printf ("fsm pop > %d\n", fsm_pile_pop (&exemple)); if (!elem) exit (EXIT_FAILURE);
fsm_pile_view (exemple); 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)); int value;
if (!element) exit (EXIT_FAILURE); // Si l'allocation a échoué. measure_list *tmp;
element->value = val; if (! *ml) return -1;
element->prev = *p; tmp = (*ml)->suiv;
*p = element; // Le pointeur pointe sur le dernier élément. value = (*ml)->value;
return val; 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; int n = 0;
m_pile *tmp; while (ml)
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)
{ {
n++; n++;
p = p->prev; ml = ml->suiv;
} }
return n; 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)); measure_list *tmp;
while (p) while (*ml)
{ {
printf ("fsm > %d\n", p->value); tmp = (*ml)->suiv;
p = p->prev; 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 ("--------------");
} }

View File

@ -2,7 +2,7 @@
* * * *
* Gem-graph client * * Gem-graph client *
* * * *
* State machine * * State machine / Measures *
* * * *
* Copyright © 2024 Libre en Communs <contact@a-lec.org> * * Copyright © 2024 Libre en Communs <contact@a-lec.org> *
* Copyright © 2024 Adrien Bourmault <neox@a-lec.org> * * Copyright © 2024 Adrien Bourmault <neox@a-lec.org> *
@ -33,30 +33,6 @@
#include "../../../include/fsm.h" #include "../../../include/fsm.h"
#include "../../../include/util.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 */ /* 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_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));
}

View File

@ -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) void on_clicked_topbar_right_measure (GtkWidget *btt, gpointer data)
{ {
gtk_window_set_child (GTK_WINDOW (widget_get_main_window ()), fsm_measures_sorted_list_test();
GTK_WIDGET (widget_get_measure_page())); // 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) void on_start_new_measure (GtkWidget *btt, gpointer data)