stats.cc
Go to the documentation of this file.
00001 /*------------------------------------------------------------------------
00002  *---------------------           WMPSNIFFER          --------------------
00003  *------------------------------------------------------------------------
00004  *                                                         V7.0B  11/05/10
00005  *
00006  *
00007  *  File: stas.cc
00008  *  Authors: Danilo Tardioli
00009  *  ----------------------------------------------------------------------
00010  *  Copyright (C) 2000-2012, Universidad de Zaragoza, SPAIN
00011  *
00012  *  Contact Addresses: Danilo Tardioli                   dantard@unizar.es
00013  *
00014  *  RT-WMP is free software; you can  redistribute it and/or  modify it
00015  *  under the terms of the GNU General Public License  as published by the
00016  *  Free Software Foundation;  either  version 2, or (at  your option) any
00017  *  later version.
00018  *
00019  *  RT-WMP  is distributed  in the  hope  that  it will be   useful, but
00020  *  WITHOUT  ANY  WARRANTY;     without  even the   implied   warranty  of
00021  *  MERCHANTABILITY  or  FITNESS FOR A  PARTICULAR PURPOSE.    See the GNU
00022  *  General Public License for more details.
00023  *
00024  *  You should have received  a  copy of  the  GNU General Public  License
00025  *  distributed with RT-WMP;  see file COPYING.   If not,  write to the
00026  *  Free Software  Foundation,  59 Temple Place  -  Suite 330,  Boston, MA
00027  *  02111-1307, USA.
00028  *
00029  *  As a  special exception, if you  link this  unit  with other  files to
00030  *  produce an   executable,   this unit  does  not  by  itself cause  the
00031  *  resulting executable to be covered by the  GNU General Public License.
00032  *  This exception does  not however invalidate  any other reasons why the
00033  *  executable file might be covered by the GNU Public License.
00034  *
00035  *----------------------------------------------------------------------*/
00036 
00037 
00038 #include "stats.h"
00039 #include <string.h>
00040 #include <math.h>
00041 #include <stdlib.h>
00042 #include <stdio.h>
00043 
00044 void initStats(Stats * s, const char * name, const char* unit) {
00045         s->min = (int) pow(2.0, 32.0) - 1;
00046         s->max = 0;
00047         s->mean = 0;
00048         s->pos_max = 0;
00049         s->pos_min = 0;
00050         s->sum = 0;
00051         s->bookmark = 0;
00052         s->idx = 0;
00053         sprintf(s->name,"%s",name);
00054         sprintf(s->unit,"%s",unit);
00055         s->v.clear();
00056         s->v2.clear();
00057 }
00058 
00059 void initStats(Stats * s, const char * name, const char* unit, const char* child_name) {
00060         sprintf(s->child_name, "%s", child_name);
00061         initStats(s, name, unit);
00062 }
00063 
00064 /* Min/Max values */
00065 void updateStat(Stats * s, int val, int pos) {
00066         s->idx++;
00067         s->sum += val;
00068         if (val > s->max) {
00069                 s->max = val;
00070                 s->pos_max = pos;
00071         }
00072         if (val < s->min) {
00073                 s->min = val;
00074                 s->pos_min = pos;
00075         }
00076         s->v.push_back(val);
00077 }
00078 
00079 /* Value/Pose */
00080 void addElement(Stats * s, int value, int pos) {
00081         s->sum += value;
00082         s->v.push_back(value);
00083         s->v2.push_back(pos);
00084         s->idx++;
00085 }
00086 
00087 /* Value and num of elements */
00088 void updateValueStats(Stats * s, int value, int index) {
00089         while ((index + 1) > s->v.size()) {
00090                 s->v.push_back(0);
00091                 s->v2.push_back(0);
00092         }
00093         s->v.at(index) += value;
00094         s->v2.at(index)++;
00095         s->idx++;
00096 }
00097 
00098 /* Value and Value */
00099 void updateValueStats2(Stats * s, int value, int index) {
00100         while ((index + 1) > s->v.size()) {
00101                 s->v.push_back(0);
00102                 s->v2.push_back(0);
00103         }
00104         s->v.at(index)  += value;
00105         s->v2.at(index) += value;
00106         s->idx+=value;
00107 }


ros_rt_wmp_sniffer
Author(s): Danilo Tardioli, dantard@unizar.es
autogenerated on Mon Oct 6 2014 08:27:57