diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2013-08-23 15:34:50 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2013-08-23 15:34:50 +0000 |
commit | 8830d27022a4c303baab008ad5d4dfeef0c0ee8e (patch) | |
tree | 213aa70cf04e8131f198cdd8600806011851138a /src/testbed/testbed_api_sd.c | |
parent | c60f24fa1d3db9f446d8cc6cc5606e4fd387529a (diff) | |
download | gnunet-8830d27022a4c303baab008ad5d4dfeef0c0ee8e.tar.gz gnunet-8830d27022a4c303baab008ad5d4dfeef0c0ee8e.zip |
- negative deviation factor
Diffstat (limited to 'src/testbed/testbed_api_sd.c')
-rw-r--r-- | src/testbed/testbed_api_sd.c | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/testbed/testbed_api_sd.c b/src/testbed/testbed_api_sd.c index cbafff08f..62f358de9 100644 --- a/src/testbed/testbed_api_sd.c +++ b/src/testbed/testbed_api_sd.c | |||
@@ -173,33 +173,40 @@ GNUNET_TESTBED_SD_add_data_ (struct SDHandle *h, unsigned int amount) | |||
173 | 173 | ||
174 | 174 | ||
175 | /** | 175 | /** |
176 | * Returns the factor by which the given amount differs from the standard deviation | 176 | * Calculates the factor by which the given amount differs |
177 | * | 177 | * |
178 | * @param h the SDhandle | 178 | * @param h the SDhandle |
179 | * @param amount the value for which the deviation is returned | 179 | * @param amount the value for which the deviation is returned |
180 | 180 | * @param factor the factor by which the given amont differs | |
181 | * @return the deviation from the average; GNUNET_SYSERR if the deviation cannot | 181 | * @return GNUNET_SYSERR if the deviation cannot |
182 | * be calculated OR 0 if the given amount is less than or equal to the | 182 | * be calculated; GNUNET_OK if the deviation is returned through factor |
183 | * average; a maximum of 4 is returned for deviations equal to or | ||
184 | * larger than 4 | ||
185 | */ | 183 | */ |
186 | int | 184 | int |
187 | GNUNET_TESTBED_SD_deviation_factor_ (struct SDHandle *h, unsigned int amount) | 185 | GNUNET_TESTBED_SD_deviation_factor_ (struct SDHandle *h, unsigned int amount, |
186 | int *factor) | ||
188 | { | 187 | { |
189 | double diff; | 188 | double diff; |
190 | unsigned int n; | 189 | int f; |
190 | int n; | ||
191 | 191 | ||
192 | if (h->cnt < 2) | 192 | if (h->cnt < 2) |
193 | return GNUNET_SYSERR; | 193 | return GNUNET_SYSERR; |
194 | if (((float) amount) > h->avg) | 194 | if (((float) amount) > h->avg) |
195 | { | ||
195 | diff = ((float) amount) - h->avg; | 196 | diff = ((float) amount) - h->avg; |
197 | f = 1; | ||
198 | } | ||
196 | else | 199 | else |
197 | return 0; //diff = h->avg - ((float) amount); | 200 | { |
201 | diff = h->avg - ((float) amount); | ||
202 | f = -1; | ||
203 | } | ||
198 | diff *= diff; | 204 | diff *= diff; |
199 | for (n = 1; n < 4; n++) | 205 | for (n = 1; n < 4; n++) |
200 | if (diff < (((double) (n * n)) * h->vr)) | 206 | if (diff < (((double) (n * n)) * h->vr)) |
201 | break; | 207 | break; |
202 | return n; | 208 | *factor = f * n; |
209 | return GNUNET_OK; | ||
203 | } | 210 | } |
204 | 211 | ||
205 | /* end of testbed_api_sd.c */ | 212 | /* end of testbed_api_sd.c */ |