001/*
002 * Copyright 2006 - 2013
003 *     Stefan Balev     <stefan.balev@graphstream-project.org>
004 *     Julien Baudry    <julien.baudry@graphstream-project.org>
005 *     Antoine Dutot    <antoine.dutot@graphstream-project.org>
006 *     Yoann Pigné      <yoann.pigne@graphstream-project.org>
007 *     Guilhelm Savin   <guilhelm.savin@graphstream-project.org>
008 * 
009 * This file is part of GraphStream <http://graphstream-project.org>.
010 * 
011 * GraphStream is a library whose purpose is to handle static or dynamic
012 * graph, create them from scratch, file or any source and display them.
013 * 
014 * This program is free software distributed under the terms of two licenses, the
015 * CeCILL-C license that fits European law, and the GNU Lesser General Public
016 * License. You can  use, modify and/ or redistribute the software under the terms
017 * of the CeCILL-C license as circulated by CEA, CNRS and INRIA at the following
018 * URL <http://www.cecill.info> or under the terms of the GNU LGPL as published by
019 * the Free Software Foundation, either version 3 of the License, or (at your
020 * option) any later version.
021 * 
022 * This program is distributed in the hope that it will be useful, but WITHOUT ANY
023 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
024 * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
025 * 
026 * You should have received a copy of the GNU Lesser General Public License
027 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
028 * 
029 * The fact that you are presently reading this means that you have had
030 * knowledge of the CeCILL-C and LGPL licenses and that you accept their terms.
031 */
032package org.graphstream.algorithm.measure;
033
034import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
035
036/**
037 * A measure to add 1D entries (y). x is auto-incremented by one at each new
038 * value.
039 */
040public class ChartSeries1DMeasure extends ChartSeriesMeasure {
041        /**
042         * Data containing values.
043         */
044        protected DescriptiveStatistics data;
045
046        /**
047         * Default constructor.
048         * 
049         * @param name
050         *            name of this measure
051         */
052        public ChartSeries1DMeasure(String name) {
053                super(name);
054
055                this.data = new DescriptiveStatistics();
056                this.data.setWindowSize(DEFAULT_WINDOW_SIZE);
057        }
058
059        /*
060         * (non-Javadoc)
061         * 
062         * @see org.graphstream.algorithm.measure.ChartMeasure#setWindowSize(int)
063         */
064        public void setWindowSize(int size) {
065                super.setWindowSize(size);
066                data.setWindowSize(size);
067        }
068
069        /**
070         * Add a new value to the series.
071         * 
072         * @param v
073         *            the new value
074         */
075        public void addValue(double v) {
076                data.addValue(v);
077                series.add(data.getN() - 1, v);
078        }
079
080        /**
081         * Get the count of values that have been added to this series.
082         * 
083         * @return count of values
084         */
085        public long getCount() {
086                return data.getN();
087        }
088
089        /**
090         * Get the mean of the series.
091         * 
092         * @return mean of the series
093         */
094        public double getMean() {
095                return data.getMean();
096        }
097
098        /**
099         * Get the max of the series.
100         * 
101         * @return max of the series
102         */
103        public double getMax() {
104                return data.getMax();
105        }
106
107        /**
108         * Get the min of the series.
109         * 
110         * @return min of the series
111         */
112        public double getMin() {
113                return data.getMin();
114        }
115
116        /**
117         * Get the variance of the series.
118         * 
119         * @return variance of the series
120         */
121        public double getVariance() {
122                return data.getVariance();
123        }
124}