function GetLegendInterval(array &$spec, array &$cfg) { $spec['delta_size'] = $this->ComputeDeltaSize($cfg); $iv = new INTERVAL(); $iv->SetupInterval($spec['xmin'], $spec['xmax']); $iv->SetupWindow(INTERVAL::WINDOW_NEIGHBOURHOOD, $spec['x'], dsMathPreciseSubstract($spec['xmax'], $spec['xmin']) * $spec['delta_size'] / $this->width); $iv->EnableFlexibility(); return $iv; }
function FillCache($res, $start, $end, $optimize_empty, $subcall = false, $verbose = false) { if ($res === false) { throw new ADEIException(translate("Invalid CACHE resolution")); } $resolution = $this->resolution->GetWindowSize($res); $table = $this->GetTableName($resolution); # echo "FillCache: $resolution (start: $start)\n"; if (!$this->items) { $this->items = $this->reader->GetGroupSize($this->group); } if ($subcall) { $curdata = new DATA($this->items); } if ($resolution) { $sections = ($end - $start) / $resolution; if ($this->trace_timings && $sections) { if (is_array($this->trace_timings)) { if ((!$this->trace_timings['limit_interval'] || $end - $start >= $this->trace_timings['limit_interval']) && (!$this->trace_timings['overall_only'] || !$subcall)) { $tt_started = microtime(true); $tt_limit_time = $this->trace_timings['limit_processing_time']; $tt_limit_percentage = $this->trace_timings['limit_percentage']; $tt_exception = $this->trace_timings['raise_exception']; } } else { $tt_started = microtime(true); } } if ($subcall || $resolution != $this->current_cache_resolution) { try { $qres = $this->GetReady($table, $start, $end); if ($qres) { $qres->rewind(); $cache_time = $qres->key(); if (is_numeric($cache_time)) { $cache_ptr = $qres->current(); } } } catch (ADEIException $ae) { unset($qres); $cache_time = false; } } else { $cache_time = false; } if ($verbose) { $procdate = date("d.m.Y", $start); } for ($i = 0, $substart = $start; $i < $sections; $i++, $substart += $resolution) { if (is_numeric($cache_time) && $cache_time == $substart) { if ($subcall) { $curdata->PushRow($cache_ptr, $resolution); $qres->next(); $cache_time = $qres->key(); if (is_numeric($cache_time)) { $cache_ptr = $qres->current(); } } else { $qres->next(); $cache_time = $qres->key(); } $tt_started = false; // but ignoring if reusing only parts of subresolutions } else { if (!$optimize_empty) { if ($this->fill_raw_first) { $ivl = new INTERVAL(); $ivl->SetupInterval($substart, $substart + $resolution); $ivl->SetupWindow(); if (!$this->HavePoints($ivl)) { if (!$empty_data) { $empty_data = new DATA($this->items); } $query = $this->CreateQuery($table, $substart, $empty_data); $this->Insert($resolution, $query); continue; } } else { if (!$this->reader->HaveData($this->group, $substart, $substart + $resolution)) { //echo "$substart (+$resolution)\n"; if (!$empty_data) { $empty_data = new DATA($this->items); } $query = $this->CreateQuery($table, $substart, $empty_data); $this->Insert($resolution, $query); continue; } } } $d = $this->FillCache($this->resolution->Smaller($res), $substart, $substart + $resolution, false, true); if ($subcall) { $curdata->Push($d, $resolution); } $query = $this->CreateQuery($table, $substart, $d); $this->Insert($resolution, $query); // if ($resolutin > 600) echo $resolution . "\n"; // print_r($query); // echo "$resolution inserted\n"; } if ($verbose) { $newdate = date("d.m.Y", $start); if ($procdate != $newdate) { echo " " . $procdate; $procdate = $newdate; } } } if ($subcall) { $curdata->Finalize(); } if ($tt_started) { $tt_started = microtime(true) - $tt_started; $tt_percents = 100 * $tt_started / ($sections * $resolution); $report = true; if ($tt_limit_time && $tt_started < $tt_limit_time) { $report = false; } if ($tt_limit_percentage && $tt_percents < $tt_limit_percentage) { $report = false; } if ($report) { $tt_src = "/" . $this->default_db_server . "/" . $this->default_db_name . "/" . $this->default_db_group . "/" . $resolution; if ($curdata->n) { $msg = translate("%s: %d seconds (%d records) is processed in %dms (%f%%)", $tt_src, $sections * $resolution, $curdata->n, 1000 * $tt_started, $tt_percents); if ($tt_exception && $tt_percents >= $tt_exception) { throw new ADEIException($msg); } else { log_message($msg); } } else { $msg = translate("%s: %d seconds is processed in %dms (%f%%)", $tt_src, $sections * $resolution, 1000 * $tt_started, $tt_percents); if ($tt_exception && $tt_percents >= $tt_exception) { throw new ADEIException($msg); } else { log_message($msg); } } } } } else { if ($subcall && $this->fill_raw_first) { $ivl = new INTERVAL(); $ivl->SetupInterval($start, $end); $ivl->SetupWindow(); $data = $this->GetAllPoints($this->all_mask, $ivl); $pretime = $start; foreach ($data as $time => $value) { $curdata->PushValue($value, $time - $pretime); $pretime = $time; } $curdata->Finalize($end - $pretime); } else { // printf ("Filling: %u %u\n", $start, $end); if ($this->trace_timings) { if (is_array($this->trace_timings)) { if ((!$this->trace_timings['limit_interval'] || $end - $start >= $this->trace_timings['limit_interval']) && (!$this->trace_timings['overall_only'] || !$subcall)) { $tt_started = microtime(true); $tt_limit_time = $this->trace_timings['limit_processing_time']; $tt_limit_percentage = $this->trace_timings['limit_percentage']; $tt_exception = $this->trace_timings['raise_exception']; } } else { $tt_started = microtime(true); } } $data = $this->reader->GetFilteredData($this->group, $start, $end, $this->data_filter); // echo "Starting!\n"; $pretime = $start; if ($subcall) { foreach ($data as $time => $value) { if (sizeof($value) != $this->items) { if (!sizeof($value)) { continue; } throw new ADEIException(translate("Number of items in the group have changed from %u to %u (CACHE::Fill)", $this->items, sizeof($value))); } $curdata->PushValue($value, $time - $pretime); if ($time >= $this->current_raw_end) { $query = $this->CreateQuery($table, $time, $value); $this->Insert($resolution, $query); } $pretime = $time; } $curdata->Finalize($end - $pretime); } else { foreach ($data as $time => $value) { if (sizeof($value) != $this->items) { if (!sizeof($value)) { continue; } throw new ADEIException(translate("Number of items in the group have changed from %u to %u (CACHE::Fill)", $this->items, sizeof($value))); } // Check for raw_end is not neccessary, for !subcall the 'Update' is did it for us $query = $this->CreateQuery($table, $time, $value); $this->Insert($resolution, $query); $pretime = $time; } } if ($tt_started) { $tt_started = microtime(true) - $tt_started; $tt_percents = 100 * $tt_started / ($end - $start); $report = true; if ($tt_limit_time && $tt_started < $tt_limit_time) { $report = false; } if ($tt_limit_percentage && $tt_percents < $tt_limit_percentage) { $report = false; } if ($report) { $tt_src = "/" . $this->default_db_server . "/" . $this->default_db_name . "/" . $this->default_db_group . "/0"; if ($curdata->n) { $msg = translate("%s: %d seconds (%d records) is processed in %dms (%f%%)", $tt_src, $end - $start, $curdata->n, 1000 * $tt_started, $tt_percents); if ($tt_exception && $tt_percents >= $tt_exception) { throw new ADEIException($msg); } else { log_message($msg); } } else { $msg = translate("%s: %d seconds is processed in %dms (%f%%)", $tt_src, $end - $start, 1000 * $tt_started, $tt_percents); if ($tt_exception && $tt_percents >= $tt_exception) { throw new ADEIException($msg); } else { log_message($msg); } } } } // echo "Done"; } } return $curdata; }