Commit 510fbeb3 authored by Kevin Coulomb's avatar Kevin Coulomb
Browse files

Debut d'ajout pour les statistiques

parent 2a7e6269
......@@ -64,6 +64,7 @@ HEADERS += message/Message.hpp \
trace/EventType.hpp \
trace/resource.hpp \
trace/State.hpp \
trace/Statistic.hpp \
trace/StateChange.hpp \
trace/StateType.hpp \
trace/Link.hpp \
......
......@@ -188,7 +188,11 @@ const map<VariableType *, Variable *> *Container::get_variables() const {
int Container::get_variable_number() const {
return _n_variables;
}
int Container::get_event_number() const {
return _n_events;
}
void Container::destroy(const Date &time) {
if (!_current_states.empty()) {
add_current_state(time);
......@@ -201,6 +205,62 @@ void Container::finish(const Date &time) {
if (_destruction_time.get_value() == 0.0)
destroy(time);
_event_tree = new BinaryTree<Event>(_events, _n_events);
_state_tree = new BinaryTree<StateChange>(_states,_n_states);//MODIF
_state_tree = new BinaryTree<StateChange>(_states,_n_states);
}
/*************************************/
void fill_stat(Container * cont, Statistic * stat, Interval I){
bool is_first_added = false;
// If the container is a proc -> no child container
if( cont->get_children()->empty() ){
Node<StateChange> * node = cont->get_states()->get_root();
browse_stat_state(node,stat,I,is_first_added);
browse_stat_link(cont,stat,I);
}
// stat->set_nb_event(cont->get_event_number());
}
void browse_stat_state(Node<StateChange> * node, Statistic * stats, Interval I, bool& is_displayed){
if( ! node ||
! node->get_element())
return;
// If the node is in the interval
if(node->get_element()->get_time() < I._right &&
node->get_element()->get_time() > I._left){
if(node->get_left_child())
// browse_stat_state(node->get_left_child(),stats,I,is_displayed);
if(node->get_right_child())
// browse_stat_state(node->get_right_child(),stats,I,is_displayed);
if(!is_displayed){// To add the first state
// stats->add_state(node->get_element()->get_left_state()->get_value(),node->get_element()->get_left_state()->get_duration());
is_displayed = true;
}
//Add the right state of the state change
// stats->add_state(node->get_element()->get_right_state()->get_value(),node->get_element()->get_right_state()->get_duration());
}
// Else if after the interval
else if(node->get_element()->get_time() > I._right ){
if(node->get_left_child()){
// browse_stat_state(node->get_left_child(),stats,I,is_displayed);
}
}
else{
// Else node is before the interval
if(node->get_right_child()){
// browse_stat_state(node->get_right_child(),stats,I,is_displayed);
}
}
}
void browse_stat_link(Container * cont, Statistic * S, Interval I){
//TODO
}
......@@ -26,6 +26,7 @@ class Container;
#include "VariableType.hpp"
#include "Variable.hpp"
#include "Statistic.hpp"
/*!
* \class Container
......@@ -244,6 +245,12 @@ public:
* \brief Get the number of variables
*/
int get_variable_number() const;
/*!
* \fn get_event_number()
* \brief Return the number of events
*/
int get_event_number() const;
/*!
* \fn destroy(const Date &time)
......@@ -260,4 +267,20 @@ public:
void finish(const Date &time);
};
/*!
* \fn browse_stat_state(Node<StateChange> * node, Statistic * stat, Interval I, bool & is_made)
* \brief Recursive function that browses the tree
* \param node : The node that is currently added
* \param stat : The Statistic class that is filled
* \param I : The interval we want the data in
* \param bool : A boolean used to remember if the first element has been displayed or not
*/
void browse_stat_state(Node<StateChange> * node, Statistic * stats, Interval I, bool& is_displayed);
/*!
* \fn fill_stat(Container * cont, Statistic * stat, Interval I)
* \brief Fill the stat element with the corresponding data to be displayed
*/
void fill_stat(Container * cont, Statistic * stat, Interval I);
void browse_stat_link(Container * cont, Statistic * S, Interval I);
#endif
......@@ -667,6 +667,9 @@ public:
return NULL;
}
};
#endif
#include "Statistic.hpp"
Statistic::Statistic(){
_event = 0;
_number_link = 0;
}
Statistic::~Statistic(){
// Delete states
for (map<VariableType *, stats *>::iterator it = _states.begin();
it != _states.end();
it++) {
delete (*it).second;
}
}
void Statistic::add_state( EntityValue const* ent, double length){
map<EntityValue *, stats*>::iterator i = _states.find(ent);
// If it does not exit, add a new entry
if (i == _states.end()) {
_states[entity] = ent;
_states[sta] = new stats(sta);
}
// Else update the state found
else {
(*i).second->_total_length += length;
(*i).second->_cardinal ++;
}
}
void Statistic::add_link(Container * cont){
map<Container*, int>::iterator i = _link.find(cont);
// If it does not exist, add a new entry
if( i == _link.end() ){
_link[target]=cont;
_link[number]=1;
}
// Else update the link to the container found
else{
(*i).second ++;
number_link ++;
}
}
void Statistic::set_nb_event(int n){
_event = n;
}
#ifndef STATISTIC_HPP
#define STATISTIC_HPP
#include "EntityValue.hpp"
#include "Container.hpp"
/*!
* \file Statistique.hpp
*/
typedef struct stats{
int _total_length;
int _cardinal;
}stats;
class Statistic{
private :
map<EntityValue*, stats*> _states;
map<Container*, int > _link;
int _number_link;
int _event;
public :
/*!
* \fn Statistique()
* \brief default constructor
*/
Statistic();
/*!
* \fn ~Statistique()
* \brief Destructor
*/
~Statistic();
/*!
* \fn add_state(EntityValue * val, double length)
* \brief Add a new entry to the state map
*/
void add_state(EntityValue const * val, double length);
/*!
* \fn add_link(Container * target)
* \brief Add a new entry to the link map
*/
void add_link(Container * target);
/*!
* \fn set_nb_event(int number);
* \brief set the number of event
*/
void set_nb_event(int number);
};
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment