Skip to content

Commit

Permalink
测速结果增加线性图表
Browse files Browse the repository at this point in the history
  • Loading branch information
BadApple9 committed Dec 22, 2020
1 parent 885038b commit 9f8bf65
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 244 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ Jetbrains 全家桶教育许可,正规国内大学渠道,9.9 元,购买地

## 更新记录

**2020/12/22**

> 测速结果增加线性图表([@HuJK](https://github.com/HuJK))
**2020/12/10**

> 增加可配置项 `SAME_IP_MULTI_LOGS`,可设置是否允许同一IP记录多条测速结果
Expand Down
4 changes: 2 additions & 2 deletions backend/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* 最多保存多少条测试记录
*/
const MAX_LOG_COUNT = 10000;
const MAX_LOG_COUNT = 100;

/**
* IP运营商解析服务:(1) ip.sb | (2) ipinfo.io (如果1解析ip异常,请切换成2)
Expand All @@ -13,4 +13,4 @@
/**
* 是否允许同一IP记录多条测速结果
*/
const SAME_IP_MULTI_LOGS = true;
const SAME_IP_MULTI_LOGS = false;
96 changes: 45 additions & 51 deletions chart.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
position: relative;
flex-grow: 1;
min-height: 0;
width: 100%;
height:100%;
}
div {
width:100%;
height:100%;
}

</style>
div {
width:100%;
height:100%;
}
</style>
</head>

<body>
Expand All @@ -32,11 +32,11 @@

async function mainfunc() {
var color = Chart.helpers.color;
// console.log(color)
//console.log(color)
var datareq = await fetch('backend/results-api.php');
// console.log(datareq)
//console.log(datareq)
var dataraw = await datareq.text();
// console.log(dataraw)
//console.log(dataraw)
try {
dataraw = JSON.parse(dataraw);
} catch {
Expand Down Expand Up @@ -73,18 +73,18 @@
for (const [i, data] of datasets.entries()) {
if (i === 0) {
datasets[i]["borderColor"] = window.chartColors["red"];
datasets[i]["backgroundColor"] = color(datasets[i]["borderColor"]).alpha(0.9).rgbString()
datasets[i]["backgroundColor"] = color(datasets[i]["borderColor"]).alpha(0.9).rgbString()
} else if (i === 1) {
datasets[i]["borderColor"] = "rgb(12, 176, 42)";
datasets[i]["backgroundColor"] = color(datasets[i]["borderColor"]).alpha(0.9).rgbString()
datasets[i]["backgroundColor"] = color(datasets[i]["borderColor"]).alpha(0.9).rgbString()
} else if (i === 2) {
datasets[i]["borderColor"] = "rgb(2, 104, 219)";
datasets[i]["backgroundColor"] = color(datasets[i]["borderColor"]).alpha(0.9).rgbString()
datasets[i]["backgroundColor"] = color(datasets[i]["borderColor"]).alpha(0.9).rgbString()
}
else{
else{
datasets[i]["borderColor"] = window.chartColors["gray"];;
datasets[i]["backgroundColor"] = color(window.chartColors["gray"]).alpha(0.1).rgbString()
}
}
}
console.log(datasets);
scatterChartData = {
Expand All @@ -99,55 +99,50 @@
display: true,
text: 'ISP Speed Chart'
},
tooltips: {
mode: 'nearest',
callbacks: {
title: function(TooltipItem, data){
// console.log(TooltipItem);
// console.log(data);
// console.log(data["datasets"][TooltipItem[0]["datasetIndex"]]["label"])
tooltips: {
mode: 'nearest',
callbacks: {
title: function(TooltipItem, data){
// console.log(TooltipItem);
// console.log(data);
// console.log(data["datasets"][TooltipItem[0]["datasetIndex"]]["label"])
return data["datasets"][TooltipItem[0]["datasetIndex"]]["label"]
},
label:function(TooltipItem, data){
label:function(TooltipItem, data){
return data["datasets"][TooltipItem["datasetIndex"]]["data"][TooltipItem["index"]]["label"]["isp"];
},
footer: function(TooltipItem, data){
// console.log(TooltipItem);
// console.log(data);
displaydata = data["datasets"][TooltipItem[0]["datasetIndex"]]["data"][TooltipItem[0]["index"]]["label"];
showdict = {
location: displaydata["addr"],
Download: displaydata["dspeed"],
Upload: displaydata["uspeed"],
Ping: displaydata["ping"],
Jitter: displaydata["jitter"],
IP: displaydata["ip"],
},
footer: function(TooltipItem, data){
// console.log(TooltipItem);
// console.log(data);
displaydata = data["datasets"][TooltipItem[0]["datasetIndex"]]["data"][TooltipItem[0]["index"]]["label"];
showdict = {
location: displaydata["addr"],
Download: displaydata["dspeed"],
Upload: displaydata["uspeed"],
Ping: displaydata["ping"],
Jitter: displaydata["jitter"],
IP: displaydata["ip"],
Time: displaydata["created"],
// ISP: displaydata["isp"],
};
// ISP: displaydata["isp"],
};
let showtext = ""
for (const k of Object.keys(showdict)){
showtext += k + ": " + showdict[k] + "\n";
}
return showtext
},


},
footerFontStyle: 'normal'
},

scales: {

},
footerFontStyle: 'normal'
},
scales: {
yAxes: [{
type: 'logarithmic',
type: 'linear',
position: 'bottom',
ticks: {
userCallback: function(tick) {
var remain = tick / (Math.pow(10, Math.floor(Chart.helpers.log10(tick))));
if (remain === 1 || remain === 2 || remain === 5) {
return tick.toString() + 'Mbps';
}
return '';
},
},
scaleLabel: {
Expand All @@ -161,10 +156,9 @@
userCallback: function(tick) {
return tick.toString() + ':00';
},
beginAtZero: true,
beginAtZero: true,
stepSize: 3,
max: 24

max: 24
},
scaleLabel: {
labelString: 'Time',
Expand All @@ -173,7 +167,7 @@
}]
},
responsive: true,
maintainAspectRatio: false
maintainAspectRatio: false
}
});

Expand Down
188 changes: 0 additions & 188 deletions chart_linear.html

This file was deleted.

2 changes: 0 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,6 @@ <h1>Speedtest-X</h1>
</div>
</div>
<p><a href="./results.html" target="_blank">查看测速记录</a></p>
<p><a href="./chart_linear.html" target="_blank">查看测速记录圖表(線性刻度)</a></p>
<p><a href="./chart.html" target="_blank">查看测速记录圖表(對數刻度)</a></p>
<p><a href="https://github.com/BadApple9/speedtest-x" target="_blank">speedtest-x 项目地址</a></p>
<script type="text/javascript">
initUI();
Expand Down
Loading

0 comments on commit 9f8bf65

Please sign in to comment.