Project: engagement_recognition License: BSD Dependencies:
Used by:
None |
engagement_recognition/src/recognition/statistics/timeline.cppGo to the documentation of this file.00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2010, Worcester Polytechnic Institute 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of Worcester Polytechnic Institute. nor the names 00018 * of its contributors may be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 */ 00034 // @author Brett Ponsler (bponsler (at) wpi (dot) edu) 00035 #include "timeline.h" 00036 #include "../recognizers/recognizer_factory.h" 00037 #include "../lib/engagement_params.h" 00038 00039 Timeline::Timeline() 00040 { 00041 ros::NodeHandle *handle_ = EngagementParams::getConfHandle(); 00042 00043 // Attempt to grab the parameters from the param server 00044 // NOTE: Make sure this parameter is stored in seconds 00045 handle_->param(engagement::WINDOW_SIZE_PARAM, this->window_size_, 00046 (double)5.0); 00047 00048 // Use the default values for the rest of the properties 00049 this->delay_time_ = Duration(); 00050 this->between_time_ = Duration(); 00051 this->num_failures_ = 0; 00052 this->interaction_start_time_ = 1; 00053 00054 // Update the windows 00055 this->all_events_.setWindowSize(this->window_size_); 00056 this->success_events_.setWindowSize(this->window_size_); 00057 } 00058 00059 void Timeline::setWindowSize(double window_size) 00060 { 00061 this->window_size_ = abs(window_size); 00062 00063 // Update the window with the new window size. 00064 this->updateWindow(); 00065 } 00066 00067 double Timeline::getWindowSize() 00068 { 00069 return this->window_size_; 00070 } 00071 00072 void Timeline::updateWindow() 00073 { 00074 this->all_events_.updateWindow(); 00075 this->success_events_.updateWindow(); 00076 } 00077 00078 void Timeline::addEvent(std::string type, bool success, unsigned long start, 00079 unsigned long delay, unsigned long duration, 00080 std::string data) 00081 { 00082 // If this is the first event then we need to set the start time 00083 if (this->interaction_start_time_ == 1) 00084 this->interaction_start_time_ = CURRENT_TIME; 00085 00086 // Create the new connection event 00087 ConnectionEvent ce = ConnectionEvent(type, success, start, delay, duration); 00088 00089 // If the event failed, keep track of it 00090 // NOTE: Backchannel events cannot fail. 00091 if (!success && type != RecognizerFactory::getBackchannelType()) 00092 this->num_failures_++; 00093 00094 // Add the connection event to the vector 00095 this->all_events_.addEvent(ce); 00096 00097 // Add the event to the successful events 00098 if (ce.getSuccess()) 00099 this->success_events_.addEvent(ce); 00100 00101 // Calculate the between time for this event and the previous event 00102 unsigned long between = this->all_events_.getTimeBetween(); 00103 00104 // Add the events to the delay time, duration time and the between time 00105 // NOTE: Backchannel events don't get added into the delay 00106 if (type != RecognizerFactory::getBackchannelType()) 00107 this->delay_time_.event(delay); 00108 00109 // Only add to the between time if the time exists 00110 if (between > 0) 00111 this->between_time_.event(between); 00112 00113 // Add the duration time 00114 this->duration_time_.event(duration); 00115 00116 // Update the window 00117 this->updateWindow(); 00118 } 00119 00120 unsigned long Timeline::getMeanDelay() 00121 { 00122 // Return the mean of the delay duration object 00123 return this->delay_time_.getMean(); 00124 } 00125 00126 unsigned long Timeline::getMaxDelay() 00127 { 00128 // Return the max of the delay duration object 00129 return this->delay_time_.getMax(); 00130 } 00131 00132 unsigned long Timeline::getRecentMeanDelay() 00133 { 00134 return this->all_events_.getRecentMeanDelay(); 00135 } 00136 00137 unsigned long Timeline::getRecentMaxDelay() 00138 { 00139 return this->all_events_.getRecentMaxDelay(); 00140 } 00141 00142 unsigned long Timeline::getMeanDuration() 00143 { 00144 // Return the mean of the duration object 00145 return this->duration_time_.getMean(); 00146 } 00147 00148 unsigned long Timeline::getMaxDuration() 00149 { 00150 // Return the max of the duration object 00151 return this->duration_time_.getMax(); 00152 } 00153 00154 unsigned long Timeline::getRecentMeanDuration() 00155 { 00156 return this->all_events_.getRecentMeanDuration(); 00157 } 00158 00159 unsigned long Timeline::getRecentMaxDuration() 00160 { 00161 return this->all_events_.getRecentMaxDuration(); 00162 } 00163 00164 unsigned long Timeline::getMeanTBCE() 00165 { 00166 // Return the mean of the between duration object 00167 return this->between_time_.getMean(); 00168 } 00169 00170 unsigned long Timeline::getMaxTBCE() 00171 { 00172 // Return the mean of the between duration object 00173 return this->between_time_.getMax(); 00174 } 00175 00176 unsigned long Timeline::getRecentMeanTBCE() 00177 { 00178 return this->success_events_.getRecentMeanTBCE(); 00179 } 00180 00181 unsigned long Timeline::getRecentMaxTBCE() 00182 { 00183 return this->success_events_.getRecentMaxTBCE(); 00184 } 00185 00186 int Timeline::getFailureRate() 00187 { 00188 // Make sure the interaction has been started 00189 if (this->interaction_start_time_ == 1) 00190 return 0; 00191 00192 // Calculate the total duration of the interaction 00193 unsigned long interaction_duration = CURRENT_TIME - this->interaction_start_time_; 00194 00195 // Calculate the number of failed events per interaction time 00196 double rate_ms = (interaction_duration != 0 ? 00197 ((double)this->num_failures_ / 00198 (double)abs(interaction_duration)) 00199 : 0); 00200 00201 // Return the number of failed connections per minute of time 00202 return (rate_ms * 60000); 00203 } 00204 00205 int Timeline::getRecentFailureRate() 00206 { 00207 // Make sure the interaction has been started 00208 if (this->interaction_start_time_ == 1) 00209 return 0; 00210 else 00211 return this->all_events_.getRecentFailureRate(); 00212 } |