} if ($last_exchange != null) { echo "</ul>\n"; } ?> </ul> </div> <div class="column"> <?php foreach ($historical_graphs as $graph_key => $def) { $bits = explode("_", $graph_key); if ($bits[0] == "securities") { $security_type = $bits[1]; $exchanges = get_security_exchange_pairs(); $tables = get_security_exchange_tables(); if (!isset($exchanges[$security_type])) { throw new Exception("Unknown security type '" . htmlspecialchars($security_type) . "'"); } // get all "new" securities $q = db()->prepare("SELECT * FROM " . $tables[$security_type] . " WHERE created_at > DATE_SUB(NOW(), INTERVAL 7 DAY)"); $q->execute(); $new_securities = array(); while ($sec = $q->fetch()) { $new_securities[$sec['name']] = 1; } } // TODO should refactor this with layout/graphs.php if (isset($def['arg0'])) { $values = $def['arg0'](isset($def['param0']) ? $def['param0'] : false, isset($def['param1']) ? $def['param1'] : false);
/** * Get all of the defined public graph types. These are then included into graph_types() * as necessary. */ function graph_types_public($summaries = array()) { $data = array(); $data['category_exchanges'] = array('title' => t('Exchanges'), 'category' => true); // we can generate a list of daily graphs from all of the exchanges that we support // but we'll only want to display currency pairs that we're interested in $all_pairs = get_exchange_pairs() + get_disabled_exchange_pairs(); foreach ($all_pairs as $key => $pairs) { $data['subcategory_exchanges_' . $key] = array('title' => get_exchange_name($key), 'subcategory' => true); foreach ($pairs as $pair) { $pp = get_currency_abbr($pair[0]) . "/" . get_currency_abbr($pair[1]); $data[$key . "_" . $pair[0] . $pair[1] . "_daily"] = array('title' => t(":exchange historical :pair (graph)", array(':exchange' => get_exchange_name($key), ':pair' => $pp)), 'heading' => get_exchange_name($key) . " {$pp}", 'description' => t("A line graph displaying the historical bid/ask values for :pair on :exchange.", array(':exchange' => get_exchange_name($key), ':pair' => $pp)), 'pairs' => $pair, 'hide' => !(isset($summaries[$pair[0]]) && isset($summaries[$pair[1]])), 'public' => true, 'days' => true, 'technical' => true, 'delta' => true, 'historical' => 'get_exchange_historical', 'historical_arg0' => array('key' => $key, 'pair' => $pair), 'exchange' => $key); } foreach ($pairs as $pair) { $pp = get_currency_abbr($pair[0]) . "/" . get_currency_abbr($pair[1]); $data["pair_" . $key . "_" . $pair[0] . $pair[1]] = array('title' => t(":exchange :pair (table)", array(':exchange' => get_exchange_name($key), ':pair' => $pp)), 'heading' => get_exchange_name($key) . " {$pp}", 'description' => t("A simple table displaying the current bid/ask :pair price on :exchange.", array(':exchange' => get_exchange_name($key), ':pair' => $pp)), 'pairs' => $pair, 'hide' => !(isset($summaries[$pair[0]]) && isset($summaries[$pair[1]])), 'public' => true, 'days' => false, 'technical' => false, 'delta' => false, 'historical' => 'get_exchange_historical', 'historical_arg0' => array('key' => $key, 'pair' => $pair), 'exchange' => $key); } } // generate the possible average graphs independently, using ticker_recent $key = 'average'; // get the averages pairs once $q = db()->prepare("SELECT * FROM ticker_recent WHERE exchange=? ORDER BY currency1 ASC, currency2 ASC"); $q->execute(array($key)); $averages = $q->fetchAll(); $data['subcategory_exchanges_' . $key] = array('title' => get_exchange_name($key), 'subcategory' => true); foreach ($averages as $ticker) { if (!in_array($ticker['currency1'], get_all_currencies())) { continue; } if (!in_array($ticker['currency2'], get_all_currencies())) { continue; } $pp = get_currency_abbr($ticker['currency1']) . "/" . get_currency_abbr($ticker['currency2']); $data[$key . "_" . $ticker['currency1'] . $ticker['currency2'] . "_daily"] = array('title' => t(":exchange historical :pair (graph)", array(':exchange' => get_exchange_name($key), ':pair' => $pp)), 'heading' => get_exchange_name($key) . " {$pp}", 'description' => t("A line graph displaying the historical average market bid/ask values for :pair.", array(':pair' => $pp)), 'pairs' => $pair, 'hide' => !(isset($summaries[$ticker['currency1']]) && isset($summaries[$ticker['currency2']])), 'public' => true, 'days' => true, 'technical' => true, 'delta' => true, 'historical' => 'get_average_exchange_historical', 'historical_arg0' => array('key' => $key, 'currency1' => $ticker['currency1'], 'currency2' => $ticker['currency2']), 'exchange' => $key); } foreach ($averages as $ticker) { if (!in_array($ticker['currency1'], get_all_currencies())) { continue; } if (!in_array($ticker['currency2'], get_all_currencies())) { continue; } $pp = get_currency_abbr($ticker['currency1']) . "/" . get_currency_abbr($ticker['currency2']); $data[$key . "_" . $ticker['currency1'] . $ticker['currency2'] . "_markets"] = array('title' => t(":exchange historical :pair (market data)", array(':exchange' => get_exchange_name($key), ':pair' => $pp)), 'heading' => t(":exchange :pair exchange data", array(':exchange' => get_exchange_name($key), ':pair' => $pp)), 'description' => t("A table displaying the market data used to generate the average market price for :pair.", array(':pair' => $pp)), 'pairs' => $pair, 'hide' => !(isset($summaries[$ticker['currency1']]) && isset($summaries[$ticker['currency2']])), 'public' => true, 'days' => true, 'technical' => true, 'delta' => true, 'historical' => 'get_average_exchange_markets', 'historical_arg0' => array('key' => $key, 'currency1' => $ticker['currency1'], 'currency2' => $ticker['currency2']), 'exchange' => $key); } $data['category_securities'] = array('title' => t('Securities'), 'category' => true); $data['subcategory_securities'] = array('title' => t('Security values'), 'subcategory' => true); // get all securities foreach (get_security_exchange_pairs() as $key => $currencies) { foreach ($currencies as $c) { $data['securities_' . $key . '_' . $c] = array('title' => t(':exchange :currency security value (graph)', array(':exchange' => get_exchange_name($key), ':currency' => get_currency_abbr($c))), 'heading' => t(":exchange security", array(':exchange' => get_exchange_name($key))), 'description' => t('A line graph displaying the historical value of a particular :exchange security.', array(':exchange' => get_exchange_name($key))), 'hide' => !isset($summaries[$c]), 'days' => true, 'delta' => true, 'arg0' => 'get_security_instances_keys', 'arg0_title' => t('Security:'), 'param0' => $key, 'param1' => $c, 'technical' => true, 'historical' => 'get_security_instances_historical', 'historical_param0' => $key, 'historical_param1' => $c, 'title_callback' => 'get_security_instance_title'); } } $data['category_tools'] = array('title' => t('Tools'), 'category' => true); $data['subcategory_tools'] = array('title' => t('Tools'), 'subcategory' => true); $data['calculator'] = array('title' => t('Currency converter (calculator)'), 'heading' => t('Currency converter'), 'description' => t('A :calculator to convert any currency into any other currency, using the most recent exchange rates.', array(':calculator' => link_to(url_for('calculator'), t("simple calculator")))), 'technical' => false, 'no_refresh' => true); $data['external_historical'] = array('title' => t('External API status (graph)'), 'heading' => t('External API status'), 'description' => t('A line graph displaying the historical status of an external API, by displaying the percentage of failing samples.'), 'days' => true, 'arg0' => 'get_external_status_titles', 'arg0_title' => t('External API:'), 'technical' => false, 'historical' => 'get_external_status_historical'); $data['statistics_queue'] = array('title' => "Job queue delay (graph)", 'heading' => "Job queue delay (hours)", 'description' => 'The job queue delay for free and premium users, represented as a graph over time.', 'hide' => true, 'admin' => true); $data['admin_statistics'] = array('title' => "Site status (table)", 'heading' => "Site status", 'description' => 'Key performance metics of the site.', 'hide' => true, 'admin' => true); $data['statistics_system_load'] = array('title' => "System load (graph)", 'heading' => "System load (hours)", 'description' => 'The system load, represented as a graph over time.', 'hide' => true, 'admin' => true); $data['statistics_db_system_load'] = array('title' => "Database system load (graph)", 'heading' => "Database system load (hours)", 'description' => 'The database system load, represented as a graph over time.', 'hide' => true, 'admin' => true); $data['metrics_db_slow_queries_graph'] = array('title' => "Slowest DB queries (graph)", 'heading' => "Slowest DB queries (ms)", 'description' => 'The slowest database queries represented as a graph over time.', 'hide' => true, 'admin' => true); $data['metrics_curl_slow_urls_graph'] = array('title' => "Slowest CURL URLs (graph)", 'heading' => "Slowest CURL URLs (ms)", 'description' => 'The slowest CURL requests represented as a graph over time.', 'hide' => true, 'admin' => true); $data['metrics_slow_jobs_graph'] = array('title' => "Slowest jobs (graph)", 'heading' => "Slowest jobs (ms)", 'description' => 'The slowest jobs represented as a graph over time.', 'hide' => true, 'admin' => true); $data['metrics_slow_jobs_db_graph'] = array('title' => "Slowest jobs database time (graph)", 'heading' => "Slowest jobs database time (ms)", 'description' => 'The time spent in the database on the slowest jobs represented as a graph over time.', 'hide' => true, 'admin' => true); $data['metrics_slow_pages_graph'] = array('title' => "Slowest pages (graph)", 'heading' => "Slowest pages (ms)", 'description' => 'The slowest pages represented as a graph over time.', 'hide' => true, 'admin' => true); $data['metrics_slow_pages_db_graph'] = array('title' => "Slowest pages database time (graph)", 'heading' => "Slowest pages database time (ms)", 'description' => 'The time spent in the database on the slowest pages represented as a graph over time.', 'hide' => true, 'admin' => true); $data['metrics_slow_graphs_graph'] = array('title' => "Slowest graphs (graph)", 'heading' => "Slowest graphs (ms)", 'description' => 'The slowest graphs represented as a graph over time.', 'hide' => true, 'admin' => true); $data['metrics_slow_graphs_db_graph'] = array('title' => "Slowest graphs database time (graph)", 'heading' => "Slowest graphs database time (ms)", 'description' => 'The time spent in the database on the slowest graphs represented as a graph over time.', 'hide' => true, 'admin' => true); $data['metrics_slow_graphs_count_graph'] = array('title' => "Slowest graphs frequency (graph)", 'heading' => "Slowest graphs frequency", 'description' => 'The frequency that the slowest graphs are requested, represented as a graph over time.', 'hide' => true, 'admin' => true); $data['metrics_jobs_frequency_graph'] = array('title' => "Job frequency (graph)", 'heading' => "Job frequency (jobs/hour)", 'description' => 'The frequency of particular jobs per hour, represented as a graph over time.', 'hide' => true, 'admin' => true); return $data; }
if ($pages) { if (require_get("securities", false)) { // displaying securities page? $graphs = array(); $page_title = t("Your Securities"); $page_id = "securities"; $page_title_prefix = ""; $enable_editing_dialog = false; $id_counter = 0; // $graph[id] needs to be set for unique graph HTML IDs // premium check if (get_premium_value($user, 'your_securities')) { // assumes each securities_XXX table has a 'name' $tables = get_security_exchange_tables(); $account_data = account_data_grouped(); foreach (get_security_exchange_pairs() as $exchange => $currencies) { $table = $tables[$exchange]; $q = db()->prepare("SELECT securities.* " . (count($currencies) > 1 ? ", ss.currency" : "") . " FROM securities\n JOIN " . $table . " AS ss ON securities.security_id=ss.id\n WHERE exchange=? AND securities.user_id=? AND is_recent=1 ORDER BY exchange ASC, ss.name ASC"); $q->execute(array($exchange, user_id())); $securities = $q->fetchAll(); // also get all individual securities if (isset($account_data['Individual Securities']['individual_' . $exchange])) { $ind_account = $account_data['Individual Securities']['individual_' . $exchange]; $table_name = $ind_account['table']; $security_table_name = $ind_account['securities_table']; $q = db()->prepare("SELECT t.* " . (count($currencies) > 1 ? ", ss.currency" : "") . " FROM {$table_name} AS t\n JOIN {$security_table_name} AS ss ON t.security_id=ss.id\n WHERE t.user_id=? ORDER BY ss.name ASC"); $q->execute(array(user_id())); $securities2 = $q->fetchAll(); $securities = array_merge($securities, $securities2); } if ($securities) {