コード例 #1
0
ファイル: SummaryGraph.php プロジェクト: phpsource/openclerk
 /**
  * @return an array of 1..2 values of the values for the particular row,
  *      maybe formatted with {@link #graph_number_format()}.
  */
 function getTickerData($row)
 {
     if (isset($row['balance_closing'])) {
         return array(graph_number_format(demo_scale($row['balance_closing'])));
     } else {
         return array(graph_number_format(demo_scale($row['balance'])));
     }
 }
コード例 #2
0
ファイル: Ticker.php プロジェクト: phpsource/openclerk
 /**
  * @return an array of 1..2 values of the values for the particular row,
  *      maybe formatted with {@link #graph_number_format()}.
  */
 function getTickerData($row)
 {
     if ($this->onlyHasLastTrade()) {
         // last_trade is in ticker; last_trade_closing is in graph_data_ticker
         if (isset($row['last_trade'])) {
             return array(graph_number_format($row['last_trade']));
         } else {
             return array(graph_number_format($row['last_trade_closing']));
         }
     } else {
         return array(graph_number_format($row['bid']), graph_number_format($row['ask']));
     }
 }
コード例 #3
0
 public function getData($days)
 {
     $key_column = array('type' => 'string', 'title' => ct("Currency"));
     $columns = array();
     // get all balances
     $balances = get_all_summary_instances($this->getUser());
     $last_updated = find_latest_created_at($balances, "total");
     // and convert them using the most recent rates
     $rates = get_all_recent_rates();
     // create data
     // TODO refactor this into generic any-currency balances
     $data = array();
     if (isset($balances['totalbtc']) && $balances['totalbtc']['balance'] != 0) {
         $columns[] = array('type' => 'number', 'title' => get_currency_abbr('btc'));
         $data[] = graph_number_format(demo_scale($balances['totalbtc']['balance']));
     }
     foreach (get_all_currencies() as $cur) {
         // if the key is a currency, use the same currency colour across all graphs (#293)
         $color = array_search($cur, get_all_currencies());
         if ($cur == 'btc') {
             continue;
         }
         if (!is_fiat_currency($cur) && isset($balances['total' . $cur]) && $balances['total' . $cur]['balance'] != 0 && isset($rates['btc' . $cur])) {
             $columns[] = array('type' => 'number', 'title' => get_currency_abbr($cur), 'color' => $color);
             $data[] = graph_number_format(demo_scale($balances['total' . $cur]['balance'] * $rates['btc' . $cur]['bid']));
         }
         if (is_fiat_currency($cur) && isset($balances['total' . $cur]) && $balances['total' . $cur]['balance'] != 0 && isset($rates[$cur . 'btc']) && $rates[$cur . 'btc']['ask']) {
             $columns[] = array('type' => 'number', 'title' => get_currency_abbr($cur), 'color' => $color);
             $data[] = graph_number_format(demo_scale($balances['total' . $cur]['balance'] / $rates[$cur . 'btc']['ask']));
         }
     }
     // display a helpful message if there's no data
     if (!$data) {
         throw new NoDataGraphException_AddAccountsAddresses();
     }
     // sort data by balance
     arsort($data);
     $data = array(get_currency_abbr('btc') => $data);
     return array('key' => $key_column, 'columns' => $columns, 'data' => $data, 'last_updated' => $last_updated);
 }
コード例 #4
0
 public function getData($days)
 {
     $columns = array();
     $key_column = array('type' => 'date', 'title' => ct("Date"));
     // $columns = $this->getTickerColumns();
     // TODO extra_days_necessary
     $extra_days = 10;
     $sources = $this->getCompositionSources($days, $extra_days);
     $args = $this->getCompositionArgs();
     $data = array();
     $last_updated = false;
     $exchanges_found = array();
     $maximum_balances = array();
     // only used to check for non-zero accounts
     $data_temp = array();
     $hide_missing_data = !require_get("debug_show_missing_data", false);
     $latest = array();
     foreach ($sources as $source) {
         $q = db()->prepare($source['query']);
         $q->execute($args);
         while ($ticker = $q->fetch()) {
             $key = date('Y-m-d', strtotime($ticker[$source['key']]));
             if (!isset($data_temp[$key])) {
                 $data_temp[$key] = array();
             }
             if (!isset($data_temp[$key][$ticker['exchange']])) {
                 $data_temp[$key][$ticker['exchange']] = 0;
             }
             $data_temp[$key][$ticker['exchange']] += $ticker[$source['balance_key']];
             $last_updated = max($last_updated, strtotime($ticker['created_at']));
             $exchanges_found[$ticker['exchange']] = $ticker['exchange'];
             if (!isset($maximum_balances[$ticker['exchange']])) {
                 $maximum_balances[$ticker['exchange']] = 0;
             }
             $maximum_balances[$ticker['exchange']] = max($ticker[$source['balance_key']], $maximum_balances[$ticker['exchange']]);
             if (!isset($latest[$ticker['exchange']])) {
                 $latest[$ticker['exchange']] = 0;
             }
             $latest[$ticker['exchange']] = max($latest[$ticker['exchange']], strtotime($ticker[$source['key']]));
         }
     }
     // get rid of any exchange summaries that had zero data
     foreach ($maximum_balances as $key => $balance) {
         if ($balance == 0) {
             foreach ($data_temp as $dt_key => $values) {
                 unset($data_temp[$dt_key][$key]);
             }
             unset($exchanges_found[$key]);
         }
     }
     // sort by date so we can get previous dates if necessary for missing data
     ksort($data_temp);
     $data = array();
     // add headings after we know how many exchanges we've found
     $first_heading = array('title' => t("Date"));
     $headings = array($first_heading);
     $i = 0;
     // sort them so they're always in the same order
     ksort($exchanges_found);
     foreach ($exchanges_found as $key => $ignored) {
         $headings[$key] = array('title' => $this->getHeadingTitle($key, $args));
     }
     // $data[0] = $headings;
     // add '0' for exchanges that we've found at one point, but don't have a data point
     // but reset to '0' for exchanges that are no longer present (i.e. from graph_data_balances archives)
     // this fixes a bug where old securities data is still displayed as present in long historical graphs
     $previous_row = array();
     foreach ($data_temp as $date => $values) {
         $row = array();
         foreach ($exchanges_found as $key => $ignored) {
             if (!$hide_missing_data || strtotime($date) <= $latest[$key]) {
                 if (!isset($values[$key])) {
                     $row[$key] = graph_number_format(isset($previous_row[$key]) ? $previous_row[$key] : 0);
                 } else {
                     $row[$key] = graph_number_format(demo_scale($values[$key]));
                 }
             } else {
                 $row[$key] = graph_number_format(0);
             }
         }
         if (count($row) > 0) {
             // don't add empty rows
             $data[$date] = $row;
             $previous_row = $row;
         }
     }
     // sort each row by the biggest value in the most recent data
     // so e.g. BTC comes first, LTC comes second, regardless of order of summary_instances, balances etc
     $keys = array_keys($data);
     // we can only sort if we actually have data
     if (count($keys) == 0) {
         // bail early
         throw new NoDataGraphException_AddCurrencies();
     }
     $last_row = $data[$keys[count($keys) - 1]];
     arsort($last_row);
     $data_temp = array();
     foreach ($data as $row => $columns) {
         $temp = array();
         foreach ($last_row as $key => $ignored) {
             $temp[$key] = $columns[$key];
         }
         $data_temp[$row] = $temp;
     }
     $data = $data_temp;
     // convert columns and data into numeric indices
     $result_columns = array();
     $result_column_map = array();
     foreach ($columns as $key => $column) {
         $result_columns[] = array('type' => 'number', 'title' => $this->getHeadingTitle($key, $args));
         // if the key is a currency, use the same currency colour across all graphs
         if (in_array(strtolower($key), get_all_currencies())) {
             $result_columns[count($result_columns) - 1]['color'] = array_search(strtolower($key), get_all_currencies());
         }
         $result_column_map[$key] = count($result_columns) - 1;
     }
     $result_data = array();
     foreach ($data as $date => $row) {
         $new_row = array();
         foreach ($row as $key => $value) {
             $new_row[$result_column_map[$key]] = $value;
         }
         $result_data[$date] = $new_row;
     }
     // find the last row, and calculate its total for later
     $last_row = array();
     $last_row_total = 0;
     foreach ($result_data as $date => $row) {
         $last_row = $row;
     }
     foreach ($row as $value) {
         $last_row_total += $value;
     }
     // sort the last row, and then use this new order to resort all
     // of the columns and data
     arsort($last_row);
     $sorted_columns = array();
     $sorted_data = array();
     foreach ($last_row as $i => $ignored) {
         $sorted_columns[] = $result_columns[$i];
     }
     foreach ($result_data as $date => $rows) {
         $sorted_row = array();
         foreach ($last_row as $i => $ignored) {
             $sorted_row[] = $rows[$i];
         }
         $sorted_rows[$date] = $sorted_row;
     }
     return array('key' => $key_column, 'columns' => $sorted_columns, 'data' => $sorted_rows, 'last_updated' => $last_updated, 'last_row_total' => $last_row_total);
 }
コード例 #5
0
 /**
  * @return an array of 1..2 values of the values for the particular row,
  *      maybe formatted with {@link #graph_number_format()}.
  */
 function getTickerData($row)
 {
     return array(graph_number_format($row['free_delay_minutes'] / 60), graph_number_format($row['premium_delay_minutes'] / 60));
 }
コード例 #6
0
ファイル: GraphRenderer.php プロジェクト: phpsource/openclerk
 /**
  * Relabel all columns to have ' %' prefix,
  * and reformat all data to be proportional based on the sum of each row.
  * Uses the output of {@link #getData()}.
  * @see #getData()
  */
 public function convertGraphToProportional($original)
 {
     // relabel all columns to also have ' %' suffix
     foreach ($original['columns'] as $i => $column) {
         $original['columns'][$i]['title'] .= " %";
         $original['columns'][$i]['min'] = 0;
         $original['columns'][$i]['max'] = 100;
     }
     // reformat data to be proportional
     $data = array();
     foreach ($original['data'] as $date => $row) {
         $new_row = array();
         $total = 0;
         foreach ($row as $i => $value) {
             $total += $value;
         }
         foreach ($row as $i => $value) {
             if ($total == 0) {
                 $new_row[$i] = 0;
             } else {
                 $new_row[$i] = graph_number_format($value / $total * 100);
             }
         }
         $data[$date] = $new_row;
     }
     return array('key' => $original['key'], 'columns' => $original['columns'], 'data' => $data, 'last_updated' => $original['last_updated']);
 }
コード例 #7
0
 /**
  * @return an array of 1..2 values of the values for the particular row,
  *      maybe formatted with {@link #graph_number_format()}.
  */
 function getTickerData($row)
 {
     return array(graph_number_format($row[$this->prefix . 'system_load_1min']), graph_number_format($row[$this->prefix . 'system_load_5min']), graph_number_format($row[$this->prefix . 'system_load_15min']));
 }
コード例 #8
0
ファイル: AdminMetrics.php プロジェクト: phpsource/openclerk
 public function getData($days)
 {
     $columns = array();
     $key_column = array('type' => 'date', 'title' => ct("Date"));
     $report_type = $this->report_type;
     $report_table = $this->report_table;
     $report_ref_table = $this->report_ref_table;
     $report_reference = $this->report_reference;
     $key_prefix = $this->key_prefix;
     $key = $this->key;
     $actual_value_key = $this->actual_value_key;
     $q = db()->prepare("SELECT * FROM performance_reports WHERE report_type=? ORDER BY id DESC LIMIT 30");
     $q->execute(array($report_type));
     $reports = $q->fetchAll();
     if (!$reports) {
         return render_text($graph, "No report {$report_type} found.");
     }
     // construct an array of (date => )
     $data = array();
     $keys = array();
     $last_updated = false;
     foreach ($reports as $report) {
         // get all queries
         $q = db()->prepare("SELECT * FROM {$report_table} AS r " . ($report_ref_table ? "JOIN {$report_ref_table} AS q ON r.{$report_reference}=q.id " : "") . "WHERE report_id=?");
         $q->execute(array($report['id']));
         $date = date('Y-m-d H:i:s', strtotime($report['created_at']));
         $row = array();
         while ($query = $q->fetch()) {
             if (!isset($keys[$query[$key]])) {
                 $keys[$query[$key]] = count($keys);
                 $columns[] = array('type' => 'number', 'title' => $query[$key]);
             }
             if ($actual_value_key === null) {
                 if ($query[$key_prefix . '_count'] == 0) {
                     // prevent division by 0
                     $row[$keys[$query[$key]]] = graph_number_format(0);
                 } else {
                     $row[$keys[$query[$key]]] = graph_number_format($query[$key_prefix . '_time'] / $query[$key_prefix . '_count']);
                 }
             } else {
                 $row[$keys[$query[$key]]] = graph_number_format($query[$actual_value_key]);
             }
         }
         $data[$date] = $row;
         $last_updated = max($last_updated, strtotime($report['created_at']));
     }
     // fill in any missing rows, e.g. queries that may not have featured in certain reports
     foreach ($data as $date => $row) {
         foreach ($keys as $id) {
             if (!isset($row[$id])) {
                 $data[$date][$id] = 0;
             }
         }
     }
     return array('key' => $key_column, 'columns' => $columns, 'data' => $data, 'last_updated' => $last_updated);
 }
コード例 #9
0
ファイル: render.php プロジェクト: phpsource/openclerk
/**
 * @param $report_ref_table can be null
 * @param $report_reference can be null
 * @param $actual_value_key if null, use {$key_prefix}_time/{$key_prefix}_count; otherwise, use this key
 */
function render_metrics_graph($graph, $report_type, $report_table, $report_ref_table, $report_reference, $key_prefix, $key = null, $actual_value_key = null)
{
    if ($key == null) {
        $key = $key_prefix;
    }
    if (!is_admin()) {
        return render_text(t("This graph is for administrators only."));
    }
    $q = db()->prepare("SELECT * FROM performance_reports WHERE report_type=? ORDER BY id DESC LIMIT 30");
    $q->execute(array($report_type));
    $reports = $q->fetchAll();
    if (!$reports) {
        return render_text($graph, "No report {$report_type} found.");
    }
    // construct an array of (date => )
    $data = array();
    $data[0] = array(t("Date"));
    $keys = array();
    $graph['last_updated'] = 0;
    foreach ($reports as $report) {
        // get all queries
        $q = db()->prepare("SELECT * FROM {$report_table} AS r " . ($report_ref_table ? "JOIN {$report_ref_table} AS q ON r.{$report_reference}=q.id " : "") . "WHERE report_id=?");
        $q->execute(array($report['id']));
        $date = date('Y-m-d H:i:s', strtotime($report['created_at']));
        $row = array('new Date(' . date('Y, n-1, j, H, i, s', strtotime($report['created_at'])) . ')');
        while ($query = $q->fetch()) {
            if (!isset($keys[$query[$key]])) {
                $keys[$query[$key]] = count($keys) + 1;
                $data[0][] = array("title" => $query[$key]);
            }
            if ($actual_value_key === null) {
                $row[$keys[$query[$key]]] = graph_number_format($query[$key_prefix . '_time'] / $query[$key_prefix . '_count']);
            } else {
                $row[$keys[$query[$key]]] = graph_number_format($query[$actual_value_key]);
            }
        }
        $data[$date] = $row;
        $graph['last_updated'] = max($graph['last_updated'], strtotime($report['created_at']));
    }
    // fill in any missing rows, e.g. queries that may not have featured in certain reports
    foreach ($data as $date => $row) {
        if ($date === 0) {
            continue;
        }
        foreach ($keys as $id) {
            if (!isset($row[$id])) {
                $data[$date][$id] = 0;
            }
        }
    }
    if (count($data) > 1) {
        render_linegraph_date($graph, array_values($data));
    } else {
        render_text($graph, t("There is not yet any historical data for these statistics."));
    }
}
コード例 #10
0
 /**
  * @return an array of 1..2 values of the values for the particular row,
  *      maybe formatted with {@link #graph_number_format()}.
  */
 function getTickerData($row)
 {
     return array(graph_number_format(100 * (1 - $row['job_errors'] / $row['job_count'])));
 }