<commit_before><?php

require_once ABSPATH . '/ezcomponents/Base/src/ezc_bootstrap.php';

function format_exponential_axis_label($x) {
    $vals = explode('^', $x);
    return sprintf("%.0f", pow($vals[0], $vals[1]));
}

function get_transfers()
{
    $btc = array();
    $fiat = array();

    $query = "
        SELECT
            req_type, amount, curr_type, " . sql_format_date('timest') . " AS timest2
        FROM
            requests
        WHERE
            status != 'CANCEL'
        ORDER BY
            timest;
    ";

    $result = do_query($query);
    $btc_sum = 0;
    $fiat_sum = 0;
    while ($row = mysql_fetch_array($result)) {
        $req_type = $row['req_type'];
        $amount = $row['amount'];
        $curr_type = $row['curr_type'];
        $timest = $row['timest2'];

        if ($req_type == 'WITHDR')
            $amount = gmp_mul(-1, $amount);

        if ($curr_type == 'BTC') {
            $btc_sum = gmp_add($btc_sum, $amount);
            $btc[$timest] = internal_to_numstr($btc_sum);
        } else {
            $fiat_sum = gmp_add($fiat_sum, $amount);
            $fiat[$timest] = internal_to_numstr($fiat_sum);
        }
    }

    return array($btc, $fiat);
}

function show_funds_graph($x = 0, $y = 0)
{
    global $is_logged_in, $is_admin;

    if (!$is_admin) return;

    if (!$x)
        if (isset($_GET['x']))
            $x = get('x');
        else
            $x = 720;

    if (!$y)
        if (isset($_GET['y']))
            $y = get('y');
        else
            $y = 500;

    if (!isset($_GET['svg'])) {
        show_header('graph', $is_logged_in);

        echo "<div class='content_box'>\n";
        echo "<h3>Graphs</h3>\n";
        echo "<p>\n";
        echo "<iframe src='?page=graph&type=funds&x=$x&y=$y&svg' type='image/svg+xml' width='$x' height='$y' scrolling='no' frameborder='0' />\n";
        echo "</p>\n";
        echo "</div>\n";
        return;
    }

    $symbol = ezcGraph::NO_SYMBOL;
    // $symbol = ezcGraph::BULLET;

    $graph = new ezcGraphLineChart();
    $graph->options->fillLines = 128;
    // $graph->title = 'Funds on the Exchange';
    $graph->legend->position = ezcGraph::BOTTOM;

    $graph->xAxis = new ezcGraphChartElementDateAxis();
    $graph->xAxis->dateFormat = 'j M';
    $graph->xAxis->interval = 60*60*24*7;

    $graph->yAxis = new ezcGraphChartElementLogarithmicalAxis();
    $graph->yAxis->base = pow(10, 1/2);;
    $graph->yAxis->logarithmicalFormatString = '%1$f^%2$f';
    $graph->yAxis->labelCallback = "format_exponential_axis_label";

    $graph->title->font->maxFontSize = 20;
    $graph->options->font->maxFontSize = 12;

    list ($btc, $fiat) = get_transfers();

    $graph->data[CURRENCY_FULL_PLURAL] = new ezcGraphArrayDataSet($fiat);
    $graph->data[CURRENCY_FULL_PLURAL]->symbol = $symbol;

    $graph->data['Bitcoins'] = new ezcGraphArrayDataSet($btc);
    $graph->data['Bitcoins']->symbol = $symbol;

    $graph->palette = new ezcGraphPaletteEzGreen();

    $graph->renderToOutput($x, $y);
}

function graph_main()
{
    global $is_logged_in, $is_admin;

    if (isset($_GET['type'])) {
        switch(get('type')) {
        case 'funds':
            show_funds_graph();
            break;
        default:
            show_header('graph', $is_logged_in);
            return;
        }
        exit();                 // we don't want the footer
    } else {
        show_header('graph', $is_logged_in);

        echo "<div class='content_box'>\n";
        echo "<h3>Graphs</h3>\n";
        echo "<p>which?</p>\n";
        echo "<p><a href='?page=graph&type=funds&x=800&y=500'>funds</a>\n";
        show_funds_graph(350,250);
        echo "</p></div>\n";
    }
}

graph_main();

?><commit_msg>Close the iframe tag.<commit_after><?php

require_once ABSPATH . '/ezcomponents/Base/src/ezc_bootstrap.php';

function format_exponential_axis_label($x) {
    $vals = explode('^', $x);
    return sprintf("%.0f", pow($vals[0], $vals[1]));
}

function get_transfers()
{
    $btc = array();
    $fiat = array();

    $query = "
        SELECT
            req_type, amount, curr_type, " . sql_format_date('timest') . " AS timest2
        FROM
            requests
        WHERE
            status != 'CANCEL'
        ORDER BY
            timest;
    ";

    $result = do_query($query);
    $btc_sum = 0;
    $fiat_sum = 0;
    while ($row = mysql_fetch_array($result)) {
        $req_type = $row['req_type'];
        $amount = $row['amount'];
        $curr_type = $row['curr_type'];
        $timest = $row['timest2'];

        if ($req_type == 'WITHDR')
            $amount = gmp_mul(-1, $amount);

        if ($curr_type == 'BTC') {
            $btc_sum = gmp_add($btc_sum, $amount);
            $btc[$timest] = internal_to_numstr($btc_sum);
        } else {
            $fiat_sum = gmp_add($fiat_sum, $amount);
            $fiat[$timest] = internal_to_numstr($fiat_sum);
        }
    }

    return array($btc, $fiat);
}

function show_funds_graph($x = 0, $y = 0)
{
    global $is_logged_in, $is_admin;

    if (!$is_admin) return;

    if (!$x)
        if (isset($_GET['x']))
            $x = get('x');
        else
            $x = 720;

    if (!$y)
        if (isset($_GET['y']))
            $y = get('y');
        else
            $y = 500;

    if (!isset($_GET['svg'])) {
        show_header('graph', $is_logged_in);

        echo "<div class='content_box'>\n";
        echo "<h3>Funds on the Exchange</h3>\n";
        echo "<p>\n";
        echo "<iframe src='?page=graph&type=funds&x=$x&y=$y&svg' type='image/svg+xml' width='$x' height='$y' scrolling='no' frameborder='0'></iframe>\n";
        echo "</p>\n";
        echo "</div>\n";
        return;
    }

    $symbol = ezcGraph::NO_SYMBOL;
    // $symbol = ezcGraph::BULLET;

    $graph = new ezcGraphLineChart();
    $graph->options->fillLines = 128;
    // $graph->title = 'Funds on the Exchange';
    $graph->legend->position = ezcGraph::BOTTOM;

    $graph->xAxis = new ezcGraphChartElementDateAxis();
    $graph->xAxis->dateFormat = 'j M';
    $graph->xAxis->interval = 60*60*24*7;

    $graph->yAxis = new ezcGraphChartElementLogarithmicalAxis();
    $graph->yAxis->base = pow(10, 1/2);;
    $graph->yAxis->logarithmicalFormatString = '%1$f^%2$f';
    $graph->yAxis->labelCallback = "format_exponential_axis_label";

    $graph->title->font->maxFontSize = 20;
    $graph->options->font->maxFontSize = 12;

    list ($btc, $fiat) = get_transfers();

    $graph->data[CURRENCY_FULL_PLURAL] = new ezcGraphArrayDataSet($fiat);
    $graph->data[CURRENCY_FULL_PLURAL]->symbol = $symbol;

    $graph->data['Bitcoins'] = new ezcGraphArrayDataSet($btc);
    $graph->data['Bitcoins']->symbol = $symbol;

    $graph->palette = new ezcGraphPaletteEzGreen();

    $graph->renderToOutput($x, $y);
    exit();                     // we don't want the footer
}

function graph_main()
{
    global $is_logged_in, $is_admin;

    if (isset($_GET['type']))
        switch(get('type')) {
        case 'funds':
            show_funds_graph();
            break;
        default:
            show_header('graph', $is_logged_in);
            throw new Error("Bad Argument", "Unknown graph type");
        }
    else {
        show_header('graph', $is_logged_in);

        echo "<div class='content_box'>\n";
        echo "<h3>Graphs</h3>\n";
        echo "<p>which?</p>\n";
        echo "<ul><li><a href='?page=graph&type=funds'>funds</a></li></ul>\n";
        echo "</p></div>\n";
    }
}

graph_main();

?>
{'fraction_non_alphanumeric': 0.18506101649456885, 'fraction_numerical': 0.012605605471369184, 'mean_word_length': 2.427389705882353, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 105, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5669289', 'n_tokens_mistral': 2766, 'n_tokens_neox': 2637, 'n_words': 460}