<commit_before><?php

function count_transactions($orderid)
{
    $query = "
        SELECT COUNT(*) as count
        FROM transactions
        WHERE (transactions.a_orderid=$orderid
           OR  transactions.b_orderid=$orderid)
          AND  transactions.a_amount != -1
          AND  transactions.b_amount != -1;
    ";
    $result = do_query($query);
    $row = mysql_fetch_assoc($result);
    return $row['count'];
}
    
function display_transactions($uid, $orderid)
{
    $ordselq = '';
    if ($orderid == -1)
        $sort = "DESC";
    else {
        $sort = "ASC";
        $ordselq = " AND orderbook.orderid='$orderid' ";
    }
    $query = "
        SELECT
            orderbook.orderid AS orderid,
            IF(transactions.a_orderid=orderbook.orderid, 'A', 'B') AS who,
            transactions.a_amount AS a_amount,
            transactions.b_amount AS b_amount,
            transactions.a_commission AS a_commission,
            transactions.b_commission AS b_commission,
            orderbook.type AS type,
            orderbook.want_type AS want_type,
            DATE_FORMAT(transactions.timest, '%H:%i %d/%m/%y') AS timest
        FROM transactions
        JOIN orderbook
        ON
            transactions.a_orderid=orderbook.orderid
            OR transactions.b_orderid=orderbook.orderid
        WHERE orderbook.uid='$uid' $ordselq
        ORDER BY transactions.txid $sort;
    ";
    $result = do_query($query);
    $first = true;
    $a_total = 0;
    $b_total = 0;
    $commission_total = 0;
    $count = 0;
    while ($row = mysql_fetch_assoc($result)) {
        $count++;
        $who = $row['who'];
        $a_amount = $row['a_amount'];
        $b_amount = $row['b_amount'];
        $a_commission = $row['a_commission'];
        $b_commission = $row['b_commission'];
        if ($who == 'B') {
            list($a_amount, $b_amount) = array($b_amount, $a_amount);
            $b_commission = $a_commission;
        }
        # skip cancelled orders since we already show those
        if ((int)$b_amount == -1)
            continue;

        if ($first) {
            $first = false;
            ?> <div class='content_box'>
            <h3>Your trades <?php if ($orderid != -1) echo 'for this order'; ?></h3>
            <table class='display_data'>
                <tr>
                    <th>You gave</th>
                    <th>You got</th>
                    <th>Commission</th>
                    <th>Effective Price</th>
                    <th>Time</th>
                    <?php if ($orderid == -1) echo '<th></th>'; ?>
                </tr><?php
        }

        $a_total = gmp_add($a_total, $a_amount);
        $b_total = gmp_add($b_total, $b_amount);
        $commission_total = gmp_add($commission_total, $b_commission);

        $commission_percent = bcdiv(bcmul($b_commission, 100), $b_amount, 3);

        $b_amount = gmp_sub($b_amount, $b_commission);

        $a_amount = internal_to_numstr($a_amount);
        $b_amount = internal_to_numstr($b_amount);
        $b_commission = internal_to_numstr($b_commission);
        $type = $row['type'];
        $want_type = $row['want_type'];
        if ($type == 'BTC')
           $price = $b_amount / $a_amount;
        else
           $price = $a_amount / $b_amount;
        $price = sprintf("%.4f", $price);
        $this_orderid = $row['orderid'];
        $timest = $row['timest'];
        echo "    <tr>\n";
        echo "        <td>$a_amount $type</td><td>$b_amount $want_type</td><td>$b_commission $want_type (",
            sprintf("%.3f", $commission_percent), "%)</td><td>$price</td>\n";
        echo "        <td>$timest</td>\n";
        if ($orderid == -1)
            echo "        <td><a href='?page=view_order&orderid=$this_orderid'>View</a></td>\n";
        echo "    </tr>\n";
    }
    if (!$first) {
        if ($orderid != -1 && $count > 1) {
            $commission_percent = bcdiv(bcmul(gmp_strval($commission_total), 100), gmp_strval($b_total), 3);

            $b_total = gmp_sub($b_total, $commission_total);
            $a_total = internal_to_numstr($a_total);
            $b_total = internal_to_numstr($b_total);
            $commission_total = internal_to_numstr($commission_total);

            if ($type == 'BTC')
                $price = $b_total / $a_total;
            else
                $price = $a_total / $b_total;
            $price = sprintf("%.6f", $price);
            
            echo "    <tr>\n";
            echo "        <td>--------</td><td>--------</td><td>--------</td><td>--------</td>\n";
            echo "        <td></td>\n";
            echo "    </tr>\n";
            echo "    <tr>\n";
            echo "        <td>$a_total $type</td><td>$b_total $want_type</td><td>$commission_total $want_type (",
                sprintf("%.3f", $commission_percent), "%)</td><td>$price</td>\n";
            echo "        <td></td>\n";
            echo "    </tr>\n";
        }

        echo "</table></div>";
    }
}

?><commit_msg>Add a couple of lines of text under the trades table.<commit_after><?php

function count_transactions($orderid)
{
    $query = "
        SELECT COUNT(*) as count
        FROM transactions
        WHERE (transactions.a_orderid=$orderid
           OR  transactions.b_orderid=$orderid)
          AND  transactions.a_amount != -1
          AND  transactions.b_amount != -1;
    ";
    $result = do_query($query);
    $row = mysql_fetch_assoc($result);
    return $row['count'];
}
    
function display_transactions($uid, $orderid)
{
    $ordselq = '';
    if ($orderid == -1)
        $sort = "DESC";
    else {
        $sort = "ASC";
        $ordselq = " AND orderbook.orderid='$orderid' ";
    }
    $query = "
        SELECT
            orderbook.orderid AS orderid,
            IF(transactions.a_orderid=orderbook.orderid, 'A', 'B') AS who,
            transactions.a_amount AS a_amount,
            transactions.b_amount AS b_amount,
            transactions.a_commission AS a_commission,
            transactions.b_commission AS b_commission,
            orderbook.type AS type,
            orderbook.want_type AS want_type,
            DATE_FORMAT(transactions.timest, '%H:%i %d/%m/%y') AS timest
        FROM transactions
        JOIN orderbook
        ON
            transactions.a_orderid=orderbook.orderid
            OR transactions.b_orderid=orderbook.orderid
        WHERE orderbook.uid='$uid' $ordselq
        ORDER BY transactions.txid $sort;
    ";
    $result = do_query($query);
    $first = true;
    $a_total = 0;
    $b_total = 0;
    $commission_total = 0;
    $count = 0;
    while ($row = mysql_fetch_assoc($result)) {
        $count++;
        $who = $row['who'];
        $a_amount = $row['a_amount'];
        $b_amount = $row['b_amount'];
        $a_commission = $row['a_commission'];
        $b_commission = $row['b_commission'];
        if ($who == 'B') {
            list($a_amount, $b_amount) = array($b_amount, $a_amount);
            $b_commission = $a_commission;
        }
        # skip cancelled orders since we already show those
        if ((int)$b_amount == -1)
            continue;

        if ($first) {
            $first = false;
            ?> <div class='content_box'>
            <h3>Your trades <?php if ($orderid != -1) echo 'for this order'; ?></h3>
            <table class='display_data'>
                <tr>
                    <th>You gave</th>
                    <th>You got</th>
                    <th>Commission</th>
                    <th>Effective Price</th>
                    <th>Time</th>
                    <?php if ($orderid == -1) echo '<th></th>'; ?>
                </tr><?php
        }

        $a_total = gmp_add($a_total, $a_amount);
        $b_total = gmp_add($b_total, $b_amount);
        $commission_total = gmp_add($commission_total, $b_commission);

        $commission_percent = bcdiv(bcmul($b_commission, 100), $b_amount, 3);

        $b_amount = gmp_sub($b_amount, $b_commission);

        $a_amount = internal_to_numstr($a_amount);
        $b_amount = internal_to_numstr($b_amount);
        $b_commission = internal_to_numstr($b_commission);
        $type = $row['type'];
        $want_type = $row['want_type'];
        if ($type == 'BTC')
           $price = $b_amount / $a_amount;
        else
           $price = $a_amount / $b_amount;
        $price = sprintf("%.4f", $price);
        $this_orderid = $row['orderid'];
        $timest = $row['timest'];
        echo "    <tr>\n";
        echo "        <td>$a_amount $type</td><td>$b_amount $want_type</td><td>$b_commission $want_type (",
            sprintf("%.3f", $commission_percent), "%)</td><td>$price</td>\n";
        echo "        <td>$timest</td>\n";
        if ($orderid == -1)
            echo "        <td><a href='?page=view_order&orderid=$this_orderid'>View</a></td>\n";
        echo "    </tr>\n";
    }
    if (!$first) {
        if ($orderid != -1 && $count > 1) {
            $commission_percent = bcdiv(bcmul(gmp_strval($commission_total), 100), gmp_strval($b_total), 3);

            $b_total = gmp_sub($b_total, $commission_total);
            $a_total = internal_to_numstr($a_total);
            $b_total = internal_to_numstr($b_total);
            $commission_total = internal_to_numstr($commission_total);

            if ($type == 'BTC')
                $price = $b_total / $a_total;
            else
                $price = $a_total / $b_total;
            $price = sprintf("%.6f", $price);
            
            echo "    <tr>\n";
            echo "        <td>--------</td><td>--------</td><td>--------</td><td>--------</td>\n";
            echo "        <td></td>\n";
            echo "    </tr>\n";
            echo "    <tr>\n";
            echo "        <td>$a_total $type</td><td>$b_total $want_type</td><td>$commission_total $want_type (",
                sprintf("%.3f", $commission_percent), "%)</td><td>$price</td>\n";
            echo "        <td></td>\n";
            echo "    </tr>\n";
        }

        echo "</table>\n";
        echo "<p>The 'you got' column is the amount you received after commission was taken off.</p>";
        echo "<p>The 'effective price' also includes the effect of commission, and so may be slightly worse than the price you requested.</p>";
        echo "</div>\n";
    }
}

?>
{'fraction_non_alphanumeric': 0.1622174590802806, 'fraction_numerical': 0.005261106780982073, 'mean_word_length': 1.8609253065774805, 'pattern_counts': {'":': 0, '<': 135, '<?xml version=': 0, '>': 137, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '5123746', 'n_tokens_mistral': 3383, 'n_tokens_neox': 3321, 'n_words': 634}