public function testNumberParsing()
 {
     $this->assertEquals(10, WMUtility::interpretNumberWithMetricPrefix("10"));
     $this->assertEquals(1000, WMUtility::interpretNumberWithMetricPrefix("1K"));
     $this->assertEquals(1024, WMUtility::interpretNumberWithMetricPrefix("1K", 1024));
     $this->assertEquals(1000 * 1000, WMUtility::interpretNumberWithMetricPrefix("1M"));
     $this->assertEquals(1024 * 1024, WMUtility::interpretNumberWithMetricPrefix("1M", 1024));
     $this->assertEquals(1000 * 1000 * 1000, WMUtility::interpretNumberWithMetricPrefix("1G"));
     $this->assertEquals(1024 * 1024 * 1024, WMUtility::interpretNumberWithMetricPrefix("1G", 1024));
     $this->assertEquals(1000 * 1000 * 1000 * 1000, WMUtility::interpretNumberWithMetricPrefix("1T"));
     $this->assertEquals(1024 * 1024 * 1024 * 1024, WMUtility::interpretNumberWithMetricPrefix("1T", 1024));
     $this->assertEquals(1 / 1000, WMUtility::interpretNumberWithMetricPrefix("1m"));
     $this->assertEquals(1 / 1024, WMUtility::interpretNumberWithMetricPrefix("1m", 1024));
     $this->assertEquals(1 / 1000000, WMUtility::interpretNumberWithMetricPrefix("1u"));
     $this->assertEquals(1 / (1024 * 1024), WMUtility::interpretNumberWithMetricPrefix("1u", 1024));
 }
 function ReadData($targetString, &$map, &$mapItem)
 {
     $inbw = null;
     $outbw = null;
     $data_time = 0;
     if (preg_match($this->regexpsHandled[0], $targetString, $matches)) {
         $inbw = WMUtility::interpretNumberWithMetricPrefix($matches[1], $map->kilo);
         $outbw = WMUtility::interpretNumberWithMetricPrefix($matches[2], $map->kilo);
         $data_time = time();
     }
     if (preg_match($this->regexpsHandled[1], $targetString, $matches)) {
         $inbw = WMUtility::interpretNumberWithMetricPrefix($matches[1], $map->kilo);
         $outbw = $inbw;
         $data_time = time();
     }
     wm_debug("Static ReadData: Returning ({$inbw}, {$outbw}, {$data_time})\n");
     return array($inbw, $outbw, $data_time);
 }
 private function handleSCALE($fullcommand, $args, $matches)
 {
     // The default scale name is DEFAULT
     if ($matches[1] == '') {
         $matches[1] = 'DEFAULT';
     } else {
         $matches[1] = trim($matches[1]);
     }
     if (isset($this->mapObject->scales[$matches[1]])) {
         $newscale = $this->mapObject->scales[$matches[1]];
     } else {
         $this->mapObject->scales[$matches[1]] = new WeatherMapScale($matches[1], $this->mapObject);
         $newscale = $this->mapObject->scales[$matches[1]];
     }
     $key = $matches[2] . '_' . $matches[3];
     $tag = $matches[11];
     $colour1 = null;
     $colour2 = null;
     $bottom = WMUtility::interpretNumberWithMetricPrefix($matches[2], $this->mapObject->kilo);
     $top = WMUtility::interpretNumberWithMetricPrefix($matches[3], $this->mapObject->kilo);
     $this->mapObject->colours[$matches[1]][$key]['key'] = $key;
     $this->mapObject->colours[$matches[1]][$key]['tag'] = $tag;
     $this->mapObject->colours[$matches[1]][$key]['bottom'] = WMUtility::interpretNumberWithMetricPrefix($matches[2], $this->mapObject->kilo);
     $this->mapObject->colours[$matches[1]][$key]['top'] = WMUtility::interpretNumberWithMetricPrefix($matches[3], $this->mapObject->kilo);
     $this->mapObject->colours[$matches[1]][$key]['special'] = 0;
     if (isset($matches[10]) && $matches[10] == 'none') {
         $this->mapObject->colours[$matches[1]][$key]['c1'] = new WMColour('none');
         $colour1 = new WMColour("none");
     } else {
         $colour1 = new WMColour((int) $matches[4], (int) $matches[5], (int) $matches[6]);
         $colour2 = $colour1;
         $this->mapObject->colours[$matches[1]][$key]['c1'] = $colour1;
     }
     // this is the second colour, if there is one
     if (isset($matches[7]) && $matches[7] != '') {
         $colour2 = new WMColour((int) $matches[7], (int) $matches[8], (int) $matches[9]);
         $this->mapObject->colours[$matches[1]][$key]['c2'] = $colour2;
     }
     $newscale->AddSpan($bottom, $top, $colour1, $colour2, $tag);
     if (!isset($this->mapObject->numscales[$matches[1]])) {
         $this->mapObject->numscales[$matches[1]] = 1;
     } else {
         $this->mapObject->numscales[$matches[1]]++;
     }
     // we count if we've seen any default scale, otherwise, we have to add
     // one at the end.
     //        if ($matches[1] == 'DEFAULT') {
     //            $this->mapObject->scalesseen++;
     //        }
     return true;
 }
 public function updateMaxValues($kilo)
 {
     // while we're looping through, let's set the real bandwidths
     $this->maxValues[IN] = WMUtility::interpretNumberWithMetricPrefix($this->max_bandwidth_in_cfg, $kilo);
     $this->maxValues[OUT] = WMUtility::interpretNumberWithMetricPrefix($this->max_bandwidth_out_cfg, $kilo);
     $this->max_bandwidth_in = $this->maxValues[IN];
     $this->max_bandwidth_out = $this->maxValues[OUT];
     wm_debug(sprintf("   Setting bandwidth on %s (%s -> %d bps, %s -> %d bps, KILO = %d)\n", $this, $this->max_bandwidth_in_cfg, $this->max_bandwidth_in, $this->max_bandwidth_out_cfg, $this->max_bandwidth_out, $kilo));
 }