Content-type html header to all responses

Highcharts Players Online graph.
This commit is contained in:
Rsl1122 2017-07-29 23:05:19 +03:00 committed by Fuzzlemann
parent 323b92fe76
commit e76e3d0f52
5 changed files with 141 additions and 7 deletions

View File

@ -91,6 +91,8 @@ public class ActivityPart extends RawData {
addValue("datascatterweek", weekScatter);
addValue("datascattermonth", monthScatter);
addValue("playersonlineseries", PlayerActivityGraphCreator.buildSeriesDataString(tpsData));
addValue("%playersgraphcolor%", Settings.HCOLOR_ACT_ONL + "");
addValue("%playersgraphfill%", Settings.HCOLOR_ACT_ONL_FILL + "");
}

View File

@ -22,6 +22,13 @@ public class PlayerActivityGraphCreator {
throw new IllegalStateException("Utility class");
}
public static String buildSeriesDataString(List<TPS> tpsData) {
List<Point> points = tpsData.stream()
.map(tps -> new Point(tps.getDate(), tps.getPlayers()))
.collect(Collectors.toList());
return SeriesCreator.seriesGraph(points, true);
}
public static String buildScatterDataString(List<TPS> tpsData, long scale) {
long now = MiscUtils.getTime();
List<Point> points = tpsData.stream()

View File

@ -0,0 +1,80 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package main.java.com.djrapitops.plan.ui.html.graphs;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.utilities.analysis.DouglasPeuckerAlgorithm;
import main.java.com.djrapitops.plan.utilities.analysis.Point;
import main.java.com.djrapitops.plan.utilities.comparators.PointComparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Abstract scatter graph creator used by other graph creators.
*
* @author Rsl1122
* @since 3.5.2
*/
public class SeriesCreator {
/**
* Constructor used to hide the public constructor
*/
private SeriesCreator() {
throw new IllegalStateException("Utility class");
}
public static String seriesGraph(List<Point> points, boolean reduceGapTriangles) {
return seriesGraph(points, reduceGapTriangles, true);
}
public static String seriesGraph(List<Point> points, boolean reduceGapTriangles, boolean reducePoints) {
StringBuilder arrayBuilder = new StringBuilder("[");
if (reducePoints) {
points = DouglasPeuckerAlgorithm.reducePoints(points, 0);
}
if (reduceGapTriangles) {
Point lastPoint = null;
Set<Point> toAdd = new HashSet<>();
for (Point point : points) {
if (Verify.notNull(point, lastPoint)) {
long date = (long) point.getX();
long lastDate = (long) lastPoint.getX();
double y = point.getY();
double lastY = lastPoint.getY();
if (Double.compare(y, lastY) != 0 && Math.abs(lastY - y) > 0.5) {
if (lastDate < date - TimeAmount.MINUTE.ms() * 10L) {
toAdd.add(new Point(lastDate + 1, lastY));
toAdd.add(new Point(date - 1, lastY));
}
}
}
lastPoint = point;
}
points.addAll(toAdd);
points.sort(new PointComparator());
}
int size = points.size();
for (int i = 0; i < size; i++) {
Point point = points.get(i);
double y = point.getY();
long date = (long) point.getX();
arrayBuilder.append("[").append(date).append(",").append(y).append("]");
if (i < size - 1) {
arrayBuilder.append(",");
}
}
arrayBuilder.append("]");
return arrayBuilder.toString();
}
}

View File

@ -80,14 +80,15 @@ public class WebServer {
try {
URI uri = exchange.getRequestURI();
String target = uri.toString();
Headers responseHeaders = exchange.getResponseHeaders();
responseHeaders.set("Content-Type", "text/html;");
WebUser user = null;
if (usingHttps) {
user = getUser(exchange.getRequestHeaders());
// Prompt authorization
if (user == null) {
Headers responseHeaders = exchange.getResponseHeaders();
responseHeaders.set("WWW-Authenticate", "Basic realm=\"/\";");
}
}

View File

@ -342,7 +342,8 @@
</div>
</div>
</div>
<canvas id="playerChartDay" width="1000" height="350" style="width: 95%;"></canvas>
<!--<canvas id="playerChartDay" width="1000" height="350" style="width: 95%;"></canvas>-->
<div id="playerChartDay" style="width=100%; height=350px;"></div>
<p><i class="fa fa-user-circle" aria-hidden="true"></i> Unique Players: %uniquejoinsday% | <i
class="fa fa-user-circle-o" aria-hidden="true"></i> Unique/Day: %avguniquejoinsday%</p>
</div>
@ -723,12 +724,54 @@
</div>
</div>
<script src="https://www.kryogenix.org/code/browser/sorttable/sorttable.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.bundle.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.js"></script>
<script>
// Data Variables
var playersOnlineSeries = {
name: 'Players Online',
data: %playersonlineseries%,
type: 'spline',
tooltip: {
valueDecimals: 0
}
};
</script>
<script>
function playersChart() {
var myChart = Highcharts.stockChart('playerChartDay', {
rangeSelector: {
selected: 1,
buttons: [{
type: 'hour',
count: 12,
text: '12h'
},{
type: 'hour',
count: 24,
text: '24h'
},{
type: 'day',
count: 7,
text: '7d'
},{
type: 'month',
count: 1,
text: '30d'
},{
type: 'all',
text: 'All'
}]
},
title: {text: 'Players Online'},
series: [playersOnlineSeries]
});
}
</script>
<script>
// Script for Players Online charts using Chart.js
var ctxday = document.getElementById("playerChartDay");
//var ctxday = document.getElementById("playerChartDay");
var ctxday2 = document.getElementById("playerChartDay2");
var ctxweek = document.getElementById("playerChartWeek");
var ctxmonth = document.getElementById("playerChartMonth");
@ -807,7 +850,7 @@
data: %datascattermonth% ,
}]
}
var playersChartDay = new Chart(ctxday, {
/*var playersChartDay = new Chart(ctxday, {
type: 'scatter',
data: dataday,
options: {
@ -834,7 +877,7 @@
}]
}
}
});
}); */
var playersChartDay2 = new Chart(ctxday2, {
type: 'scatter',
data: dataday,
@ -1808,6 +1851,7 @@
openFunc(slideIndex)();
gmPie();
activityPie();
playersChart();
countUpTimer();
function openFunc(i) {