public function __construct($key) { parent::__construct(); $data = GraphRenderer_AdminMetrics::getMetrics(); if (!isset($data[$key])) { throw new GraphException("Could not find any key '{$key}' in available metrics"); } $data = $data[$key]; $this->report_type = $data['report_type']; $this->report_table = $data['report_table']; $this->report_ref_table = isset($data['report_ref_table']) ? $data['report_ref_table'] : null; $this->report_reference = isset($data['report_reference']) ? $data['report_reference'] : null; $this->key_prefix = isset($data['key_prefix']) ? $data['key_prefix'] : null; $this->key = isset($data['key']) ? $data['key'] : $this->key_prefix; $this->actual_value_key = isset($data['actual_value_key']) ? $data['actual_value_key'] : null; $this->title = $data['title']; if ($this->key === null && $this->key_prefix === null) { throw new GraphException("Cannot render AdminMetrics with a null key and key_prefix"); } }
/** * Helper function that converts a {@code graph_type} to a GraphRenderer * object, which we can then use to get raw graph data and format it as necessary. */ function construct_graph_renderer($graph_type, $arg0, $arg0_resolved) { $bits = explode("_", $graph_type); $all_exchanges = get_all_exchanges(); if (count($bits) == 3) { $cur1 = false; $cur2 = false; if (strlen($bits[1]) == 6) { $cur1 = substr($bits[1], 0, 3); $cur2 = substr($bits[1], 3); $cur1 = in_array($cur1, get_all_currencies()) ? $cur1 : false; $cur2 = in_array($cur2, get_all_currencies()) ? $cur2 : false; } if (strlen($bits[2]) == 6 && !$cur1 && !$cur2) { $cur1 = substr($bits[2], 0, 3); $cur2 = substr($bits[2], 3); $cur1 = in_array($cur1, get_all_currencies()) ? $cur1 : false; $cur2 = in_array($cur2, get_all_currencies()) ? $cur2 : false; } if ($bits[2] == "daily" && $cur1 && $cur2 && isset($all_exchanges[$bits[0]])) { return new GraphRenderer_Ticker($bits[0], $cur1, $cur2); } if ($bits[2] == "markets" && $cur1 && $cur2 && $bits[0] == "average") { return new GraphRenderer_AverageMarketData($cur1, $cur2); } if ($bits[0] == "composition" && in_array($bits[1], get_all_currencies())) { switch ($bits[2]) { case "pie": return new GraphRenderer_CompositionPie($bits[1]); case "table": return new GraphRenderer_CompositionTable($bits[1]); case "daily": return new GraphRenderer_CompositionGraph($bits[1]); case "stacked": return new GraphRenderer_CompositionStacked($bits[1]); case "proportional": return new GraphRenderer_CompositionProportional($bits[1]); } } if ($bits[0] == "total" && in_array($bits[1], get_all_currencies()) && $bits[2] == "daily") { return new GraphRenderer_SummaryGraph('total' . $bits[1], $bits[1]); } if ($bits[0] == "hashrate" && in_array($bits[1], get_all_currencies()) && $bits[2] == "daily") { return new GraphRenderer_SummaryGraphHashrate('totalmh_' . $bits[1], $bits[1]); } if ($bits[0] == "securities" && in_array($bits[2], get_all_currencies())) { $renderer = new GraphRenderer_BalancesGraphSecurities('securities_' . $bits[1], $arg0, $bits[2], $arg0_resolved); return $renderer; } if ($bits[0] == "pair" && isset($all_exchanges[$bits[1]]) && $cur1 && $cur2) { return new GraphRenderer_ExchangePair($bits[1], $cur1, $cur2); } } // issue #273: fix bitmarket_pl exchange if (count($bits) == 4) { $cur1 = false; $cur2 = false; if (strlen($bits[2]) == 6) { $cur1 = substr($bits[2], 0, 3); $cur2 = substr($bits[2], 3); $cur1 = in_array($cur1, get_all_currencies()) ? $cur1 : false; $cur2 = in_array($cur2, get_all_currencies()) ? $cur2 : false; } if ($bits[3] == "daily" && $cur1 && $cur2 && isset($all_exchanges[$bits[0] . "_" . $bits[1]])) { return new GraphRenderer_Ticker($bits[0] . "_" . $bits[1], $cur1, $cur2); } } if (count($bits) >= 2) { if (substr($bits[0], 0, strlen("all2")) == "all2" || substr($bits[0], 0, strlen("crypto2")) == "crypto2") { $cur = substr($bits[0], -3); if (in_array($cur, get_all_currencies())) { if (count($bits) == 3 && $bits[2] == "daily" && isset($all_exchanges[$bits[1]])) { // e.g. all2nzd_bitnz_daily return new GraphRenderer_SummaryGraphConvertedExchange($bits[0] . "_" . $bits[1], $cur); } if (count($bits) == 4 && $bits[3] == "daily" && isset($all_exchanges[$bits[1] . "_" . $bits[2]])) { // e.g. all2pln_bitmarket_pl_daily (#273) return new GraphRenderer_SummaryGraphConvertedExchange($bits[0] . "_" . $bits[1] . "_" . $bits[2], $cur); } if (count($bits) == 2 && $bits[1] == "daily") { // e.g. crypto2ltc_daily return new GraphRenderer_SummaryGraphConvertedCrypto($bits[0], $cur); } } } } if (count($bits) >= 2 && $bits[0] == "metrics") { $possible = GraphRenderer_AdminMetrics::getMetrics(); $bits_two = explode("_", $graph_type, 2); if (isset($possible[$bits_two[1]])) { return new GraphRenderer_AdminMetrics($bits_two[1]); } } switch ($graph_type) { case "btc_equivalent": return new GraphRenderer_EquivalentPieBTC(); case "balances_table": return new GraphRenderer_BalancesTable(); case "total_converted_table": return new GraphRenderer_TotalConvertedTable(); case "crypto_converted_table": return new GraphRenderer_CryptoConvertedTable(); case "balances_offset_table": return new GraphRenderer_BalancesOffsetsTable(); case "ticker_matrix": return new GraphRenderer_TickerMatrix(); case "btc_equivalent_graph": return new GraphRenderer_BtcEquivalentGraph(); case "btc_equivalent_stacked": return new GraphRenderer_BtcEquivalentStacked(); case "btc_equivalent_proportional": return new GraphRenderer_BtcEquivalentProportional(); case "external_historical": return new GraphRenderer_ExternalHistorical($arg0_resolved); case "admin_statistics": return new GraphRenderer_AdminStatistics(); case "statistics_queue": return new GraphRenderer_StatisticsQueue(); case "statistics_system_load": return new GraphRenderer_StatisticsSystemLoad(""); case "statistics_db_system_load": return new GraphRenderer_StatisticsSystemLoad("db_"); default: throw new NoGraphRendererException("Unknown graph to render '{$graph_type}'"); } }