@ 2024-06-30T21:03:31Z <?php
// gráfico normal e invertido com vários gráficos
function test_mysql_connection() {
$servername = "sql10.freemysqlhosting.net";
$username = "sql10716406";
$password = "14hhtpmHk7";
$dbname = "sql10716406";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
function timestamp_to_formatted_datetime($timestamp_ms, $date_format = 'Y-m-d H:i:s') {
$timestamp_s = $timestamp_ms / 1000;
return date($date_format, $timestamp_s);
}
// Check connection
if ($conn->connect_error) {
return "Connection failed: " . $conn->connect_error;
} else {
// SQL query to retrieve data
$sql = "SELECT * FROM cripto";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// Prepare an array to hold data for JavaScript
$data_for_js = [];
while ($row = $result->fetch_assoc()) {
$klinebar = json_decode($row['klinebar'], true);
$temp = [];
// Process the klines data
foreach ($klinebar as $kline) {
$timestamp_ms = $kline[0];
$open_price = floatval($kline[1]);
$high_price = floatval($kline[2]);
$low_price = floatval($kline[3]);
$close_price = floatval($kline[4]);
// Convert timestamp
$dt_object = timestamp_to_formatted_datetime($timestamp_ms);
$temp[] = [
'timestamp' => $dt_object,
'open' => $open_price,
'high' => $high_price,
'low' => $low_price,
'close' => $close_price,
];
}
$data_for_js[] = $temp;
}
// Close connection
$conn->close();
// Now, output the JavaScript for Plotly
ob_start(); // Start buffering output
?>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<table>
<?php
foreach ($data_for_js as $index => $data) {
echo "<tr>
<td><div id='chartDiv_$index'></div></td>
<td><div id='invertedChartDiv_$index'></div></td>
<td><div id='renkoChartDiv_$index'></div></td>
</tr>";
?>
<script>
document.addEventListener('DOMContentLoaded', function() {
var data = <?php echo json_encode($data); ?>;
var trace = {
x: data.map(function(entry) { return entry.timestamp; }),
open: data.map(function(entry) { return entry.open; }),
high: data.map(function(entry) { return entry.high; }),
low: data.map(function(entry) { return entry.low; }),
close: data.map(function(entry) { return entry.close; }),
// Customize colors
increasing: {line: {color: 'black'}},
decreasing: {line: {color: 'red'}},
type: 'candlestick',
};
var layout = {
dragmode: 'zoom',
showlegend: false,
xaxis: {
rangeslider: {
visible: false
}
},
yaxis: {
autorange: true,
zeroline: false
}
};
Plotly.newPlot('chartDiv_<?php echo $index; ?>', [trace], layout);
// Create the inverted chart data
var invertedData = data.map(function(entry) {
return {
timestamp: entry.timestamp,
open: entry.close, // swap open and close
high: entry.low, // swap high and low
low: entry.high, // swap high and low
close: entry.open // swap open and close
};
});
var invertedTrace = {
x: invertedData.map(function(entry) { return entry.timestamp; }),
open: invertedData.map(function(entry) { return entry.open; }),
high: invertedData.map(function(entry) { return entry.high; }),
low: invertedData.map(function(entry) { return entry.low; }),
close: invertedData.map(function(entry) { return entry.close; }),
// Customize colors
increasing: {line: {color: 'black'}},
decreasing: {line: {color: 'red'}},
type: 'candlestick',
};
Plotly.newPlot('invertedChartDiv_<?php echo $index; ?>', [invertedTrace], layout);
//renko abaixo
// Create the Renko chart
var renkoData = [{
dataPoints: data.map(function(entry) {
return {x: new Date(entry.timestamp), y: [entry.open, entry.high, entry.low, entry.close]};
})
}];
var renkoChart = new CanvasJS.Chart("renkoChartDiv_<?php echo $index; ?>", {
title: {
text: "Renko Chart",
fontFamily: "times new roman"
},
zoomEnabled: true,
exportEnabled: true,
axisY: {
includeZero: false,
title: "Prices",
prefix: "$ "
},
axisX: {
tickLength: 0,
labelFormatter: function(e) {
return "";
}
}
});
renkoChart.options.data = renderRenko(50, renkoData);
renkoChart.render();
function renderRenko(brickSize, data) {
var newDataPoints = [];
var oldValue = data[0].dataPoints[0].y[3];
var difference = 0;
var newValue, dataPoint, xValue;
for (var i = 1; i < data[0].dataPoints.length; i++) {
dataPoint = data[0].dataPoints[i].y[3];
xValue = CanvasJS.formatDate(data[0].dataPoints[i].x, "MMM-YYYY");
difference = dataPoint - oldValue;
if (difference > 0 && difference > brickSize) {
for (var j = 0; j < Math.floor(difference / brickSize); j++) {
newValue = oldValue + brickSize;
newDataPoints.push({content: xValue, y: [oldValue, newValue], color: "#86B402"});
oldValue = newValue;
}
} else if (difference < 0 && Math.abs(difference) > brickSize) {
for (var j = 0; j < Math.floor(Math.abs(difference) / brickSize); j++) {
newValue = oldValue - brickSize;
newDataPoints.push({content: xValue, y: [oldValue, newValue], color: "#C24642"});
oldValue = newValue;
}
}
}
var newData = [{
type: "rangeColumn",
toolTipContent: "<b>{content}</b> <br> {y[0]} - {y[1]}",
dataPoints: newDataPoints
}];
return newData;
}
//renko acima
});
</script>
<?php
}
?>
</table>
<?php
return ob_get_clean(); // Return buffered output
} else {
$conn->close();
return "Update in progress. Refresh the page in 2 minutes";
}
}
}
?>
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 8.4.12 0.009 0.009 24.07 8.4.11 0.011 0.011 20.94 8.4.10 0.010 0.011 18.98 8.4.9 0.009 0.011 20.77 8.4.8 0.011 0.009 18.66 8.4.7 0.011 0.006 19.10 8.4.6 0.013 0.009 18.54 8.4.5 0.011 0.010 20.13 8.4.4 0.013 0.007 19.32 8.4.3 0.009 0.000 20.85 8.4.2 0.019 0.003 19.53 8.4.1 0.000 0.009 19.26 8.3.25 0.011 0.007 19.14 8.3.24 0.015 0.004 17.14 8.3.23 0.004 0.005 16.58 8.3.22 0.007 0.007 18.88 8.3.21 0.012 0.006 18.27 8.3.20 0.004 0.005 16.25 8.3.19 0.012 0.008 20.98 8.3.18 0.012 0.006 19.09 8.3.17 0.013 0.006 18.84 8.3.16 0.000 0.008 16.46 8.3.15 0.012 0.006 18.60 8.3.14 0.008 0.000 18.71 8.3.13 0.008 0.000 18.31 8.3.12 0.004 0.012 20.59 8.3.11 0.008 0.004 16.40 8.3.10 0.006 0.003 16.74 8.3.9 0.005 0.003 16.61 8.3.8 0.038 0.009 30.84 8.3.7 0.042 0.006 30.84 8.3.6 0.035 0.014 30.84 8.3.5 0.011 0.007 30.84 8.3.4 0.029 0.006 30.84 8.3.3 0.031 0.008 30.84 8.3.2 0.027 0.012 30.84 8.3.1 0.032 0.007 30.84 8.3.0 0.039 0.000 30.84 8.2.29 0.006 0.002 22.26 8.2.28 0.008 0.009 19.91 8.2.27 0.015 0.004 16.85 8.2.26 0.011 0.000 16.70 8.2.25 0.017 0.003 17.45 8.2.24 0.004 0.015 16.98 8.2.23 0.000 0.009 20.94 8.2.22 0.009 0.000 24.06 8.2.21 0.000 0.008 26.77 8.2.20 0.008 0.012 30.84 8.2.19 0.031 0.010 30.84 8.2.18 0.038 0.010 30.84 8.2.17 0.044 0.012 30.84 8.2.16 0.040 0.007 30.84 8.2.15 0.050 0.000 30.84 8.2.14 0.031 0.009 30.84 8.2.13 0.029 0.006 30.84 8.2.12 0.023 0.012 30.84 8.2.11 0.037 0.003 30.84 8.2.10 0.031 0.010 30.84 8.2.9 0.041 0.008 30.84 8.2.8 0.042 0.004 30.84 8.2.7 0.034 0.009 30.84 8.2.6 0.033 0.009 30.84 8.2.5 0.030 0.007 30.84 8.2.4 0.017 0.000 30.84 8.2.3 0.029 0.010 30.84 8.2.2 0.024 0.014 30.84 8.2.1 0.025 0.014 30.84 8.2.0 0.033 0.007 30.84 8.1.33 0.011 0.007 21.85 8.1.32 0.007 0.012 17.75 8.1.31 0.010 0.007 18.16 8.1.30 0.003 0.006 20.25 8.1.29 0.035 0.007 30.84 8.1.28 0.027 0.015 30.84 8.1.27 0.034 0.014 30.84 8.1.26 0.031 0.012 30.84 8.1.25 0.028 0.007 30.84 8.1.24 0.029 0.010 30.84 8.1.23 0.033 0.008 30.84 8.1.22 0.034 0.007 30.84 8.1.21 0.031 0.010 30.84 8.1.20 0.038 0.000 30.84 8.1.19 0.035 0.003 30.84 8.1.18 0.023 0.010 30.84 8.1.17 0.027 0.010 30.84 8.1.16 0.031 0.007 30.84 8.1.15 0.028 0.009 30.84 8.1.14 0.021 0.017 30.84 8.1.13 0.026 0.007 30.84 8.1.12 0.027 0.003 30.84 8.1.11 0.017 0.000 30.84 8.1.10 0.016 0.003 30.84 8.1.9 0.041 0.003 30.84 8.1.8 0.017 0.021 30.84 8.1.7 0.034 0.003 30.84 8.1.6 0.034 0.007 30.84 8.1.5 0.034 0.008 30.84 8.1.4 0.037 0.004 30.84 8.1.3 0.039 0.003 30.84 8.1.2 0.030 0.007 30.84 8.1.1 0.022 0.004 30.84 8.1.0 0.017 0.015 30.84
preferences:dark mode live preview ace vim emacs key bindings
26.71 ms | 403 KiB | 5 Q