LCOV - code coverage report
Current view: top level - src/utils/gui/tracker - TrackerValueDesc.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 0.0 % 71 0
Test Date: 2024-11-22 15:46:21 Functions: 0.0 % 16 0

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
       4              : // This program and the accompanying materials are made available under the
       5              : // terms of the Eclipse Public License 2.0 which is available at
       6              : // https://www.eclipse.org/legal/epl-2.0/
       7              : // This Source Code may also be made available under the following Secondary
       8              : // Licenses when the conditions for such availability set forth in the Eclipse
       9              : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10              : // or later which is available at
      11              : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12              : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13              : /****************************************************************************/
      14              : /// @file    TrackerValueDesc.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Jakob Erdmann
      17              : /// @author  Michael Behrisch
      18              : /// @author  Laura Bieker
      19              : /// @date    Sept 2002
      20              : ///
      21              : // Storage for a tracked value
      22              : /****************************************************************************/
      23              : #include <config.h>
      24              : 
      25              : #include <string>
      26              : #include <vector>
      27              : #include <utils/common/RGBColor.h>
      28              : #include <utils/gui/globjects/GUIGlObject.h>
      29              : #include "TrackerValueDesc.h"
      30              : 
      31              : 
      32              : // ===========================================================================
      33              : // method definitions
      34              : // ===========================================================================
      35            0 : TrackerValueDesc::TrackerValueDesc(const std::string& name,
      36              :                                    const RGBColor& col,
      37              :                                    SUMOTime recordBegin,
      38            0 :                                    double aggregationSeconds)
      39            0 :     : myName(name), myActiveCol(col), myInactiveCol(col),
      40            0 :       myMin(0), myMax(0),
      41            0 :       myAggregationInterval(MAX2(1, (int)(TIME2STEPS(aggregationSeconds) / DELTA_T))),
      42            0 :       myInvalidValue(INVALID_DOUBLE),
      43            0 :       myValidNo(0),
      44            0 :       myRecordingBegin(recordBegin), myTmpLastAggValue(0) {}
      45              : 
      46              : 
      47            0 : TrackerValueDesc::~TrackerValueDesc() {
      48              :     // just to quit cleanly on a failure
      49            0 :     if (myLock.locked()) {
      50            0 :         myLock.unlock();
      51              :     }
      52            0 : }
      53              : 
      54              : 
      55              : void
      56            0 : TrackerValueDesc::addValue(double value) {
      57            0 :     if (myValues.size() == 0) {
      58            0 :         myMin = value;
      59            0 :         myMax = value;
      60              :     } else {
      61            0 :         myMin = value < myMin ? value : myMin;
      62            0 :         myMax = value > myMax ? value : myMax;
      63              :     }
      64            0 :     FXMutexLock locker(myLock);
      65            0 :     myValues.push_back(value);
      66            0 :     if (value != myInvalidValue) {
      67            0 :         myTmpLastAggValue += value;
      68            0 :         myValidNo++;
      69              :     }
      70            0 :     const double avg = myValidNo == 0 ? static_cast<double>(0) : myTmpLastAggValue / static_cast<double>(myValidNo);
      71            0 :     if (myAggregationInterval == 1 || myValues.size() % myAggregationInterval == 1) {
      72            0 :         myAggregatedValues.push_back(avg);
      73              :     } else {
      74            0 :         myAggregatedValues.back() = avg;
      75              :     }
      76            0 :     if (myValues.size() % myAggregationInterval == 0) {
      77            0 :         myTmpLastAggValue = 0;
      78            0 :         myValidNo = 0;
      79              :     }
      80            0 : }
      81              : 
      82              : 
      83              : double
      84            0 : TrackerValueDesc::getRange() const {
      85            0 :     return myMax - myMin;
      86              : }
      87              : 
      88              : 
      89              : double
      90            0 : TrackerValueDesc::getMin() const {
      91            0 :     return myMin;
      92              : }
      93              : 
      94              : 
      95              : double
      96            0 : TrackerValueDesc::getMax() const {
      97            0 :     return myMax;
      98              : }
      99              : 
     100              : 
     101              : double
     102            0 : TrackerValueDesc::getYCenter() const {
     103            0 :     return (myMin + myMax) / 2.0f;
     104              : }
     105              : 
     106              : 
     107              : const RGBColor&
     108            0 : TrackerValueDesc::getColor() const {
     109            0 :     return myActiveCol;
     110              : }
     111              : 
     112              : 
     113              : const std::vector<double>&
     114            0 : TrackerValueDesc::getValues() {
     115            0 :     myLock.lock();
     116            0 :     return myValues;
     117              : }
     118              : 
     119              : 
     120              : const std::vector<double>&
     121            0 : TrackerValueDesc::getAggregatedValues() {
     122            0 :     myLock.lock();
     123            0 :     return myAggregatedValues;
     124              : }
     125              : 
     126              : 
     127              : const std::string&
     128            0 : TrackerValueDesc::getName() const {
     129            0 :     return myName;
     130              : }
     131              : 
     132              : void
     133            0 : TrackerValueDesc::unlockValues() {
     134            0 :     myLock.unlock();
     135            0 : }
     136              : 
     137              : 
     138              : void
     139            0 : TrackerValueDesc::setAggregationSpan(SUMOTime as) {
     140            0 :     FXMutexLock locker(myLock);
     141            0 :     if (myAggregationInterval != as / DELTA_T) {
     142            0 :         myAggregationInterval = (int)(as / DELTA_T);
     143              :         // ok, the aggregation has changed,
     144              :         //  let's recompute the list of aggregated values
     145              :         myAggregatedValues.clear();
     146              :         std::vector<double>::const_iterator i = myValues.begin();
     147            0 :         while (i != myValues.end()) {
     148            0 :             myTmpLastAggValue = 0;
     149            0 :             myValidNo = 0;
     150            0 :             for (int j = 0; j < myAggregationInterval && i != myValues.end(); j++, ++i) {
     151            0 :                 if ((*i) != myInvalidValue) {
     152            0 :                     myTmpLastAggValue += (*i);
     153            0 :                     myValidNo++;
     154              :                 }
     155              :             }
     156            0 :             if (myValidNo == 0) {
     157            0 :                 myAggregatedValues.push_back(0);
     158              :             } else {
     159            0 :                 myAggregatedValues.push_back(myTmpLastAggValue / static_cast<double>(myValidNo));
     160              :             }
     161              :         }
     162              :     }
     163            0 : }
     164              : 
     165              : 
     166              : SUMOTime
     167            0 : TrackerValueDesc::getAggregationSpan() const {
     168            0 :     return myAggregationInterval * DELTA_T;
     169              : }
     170              : 
     171              : 
     172              : SUMOTime
     173            0 : TrackerValueDesc::getRecordingBegin() const {
     174            0 :     return myRecordingBegin;
     175              : }
     176              : 
     177              : 
     178              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1