mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-16 05:01:43 +01:00
Content-type html header to all responses
Highcharts Players Online graph.
This commit is contained in:
parent
50e3d839e3
commit
85e6817e87
@ -91,6 +91,8 @@ public class ActivityPart extends RawData {
|
|||||||
addValue("datascatterweek", weekScatter);
|
addValue("datascatterweek", weekScatter);
|
||||||
addValue("datascattermonth", monthScatter);
|
addValue("datascattermonth", monthScatter);
|
||||||
|
|
||||||
|
addValue("playersonlineseries", PlayerActivityGraphCreator.buildSeriesDataString(tpsData));
|
||||||
|
|
||||||
addValue("%playersgraphcolor%", Settings.HCOLOR_ACT_ONL + "");
|
addValue("%playersgraphcolor%", Settings.HCOLOR_ACT_ONL + "");
|
||||||
addValue("%playersgraphfill%", Settings.HCOLOR_ACT_ONL_FILL + "");
|
addValue("%playersgraphfill%", Settings.HCOLOR_ACT_ONL_FILL + "");
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,13 @@ public class PlayerActivityGraphCreator {
|
|||||||
throw new IllegalStateException("Utility class");
|
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) {
|
public static String buildScatterDataString(List<TPS> tpsData, long scale) {
|
||||||
long now = MiscUtils.getTime();
|
long now = MiscUtils.getTime();
|
||||||
List<Point> points = tpsData.stream()
|
List<Point> points = tpsData.stream()
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
@ -79,14 +79,15 @@ public class WebServer {
|
|||||||
try {
|
try {
|
||||||
URI uri = exchange.getRequestURI();
|
URI uri = exchange.getRequestURI();
|
||||||
String target = uri.toString();
|
String target = uri.toString();
|
||||||
|
Headers responseHeaders = exchange.getResponseHeaders();
|
||||||
|
responseHeaders.set("Content-Type", "text/html;");
|
||||||
WebUser user = null;
|
WebUser user = null;
|
||||||
if (usingHttps) {
|
if (usingHttps) {
|
||||||
user = getUser(exchange.getRequestHeaders());
|
user = getUser(exchange.getRequestHeaders());
|
||||||
|
|
||||||
// Prompt authorization
|
// Prompt authorization
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
Headers responseHeaders = exchange.getResponseHeaders();
|
|
||||||
responseHeaders.set("WWW-Authenticate", "Basic realm=\"/\";");
|
responseHeaders.set("WWW-Authenticate", "Basic realm=\"/\";");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -342,7 +342,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</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
|
<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>
|
class="fa fa-user-circle-o" aria-hidden="true"></i> Unique/Day: %avguniquejoinsday%</p>
|
||||||
</div>
|
</div>
|
||||||
@ -723,12 +724,54 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script src="https://www.kryogenix.org/code/browser/sorttable/sorttable.js"></script>
|
<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.bundle.js"></script>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.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>
|
||||||
// Script for Players Online charts using Chart.js
|
// Script for Players Online charts using Chart.js
|
||||||
var ctxday = document.getElementById("playerChartDay");
|
//var ctxday = document.getElementById("playerChartDay");
|
||||||
var ctxday2 = document.getElementById("playerChartDay2");
|
var ctxday2 = document.getElementById("playerChartDay2");
|
||||||
var ctxweek = document.getElementById("playerChartWeek");
|
var ctxweek = document.getElementById("playerChartWeek");
|
||||||
var ctxmonth = document.getElementById("playerChartMonth");
|
var ctxmonth = document.getElementById("playerChartMonth");
|
||||||
@ -807,7 +850,7 @@
|
|||||||
data: %datascattermonth% ,
|
data: %datascattermonth% ,
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
var playersChartDay = new Chart(ctxday, {
|
/*var playersChartDay = new Chart(ctxday, {
|
||||||
type: 'scatter',
|
type: 'scatter',
|
||||||
data: dataday,
|
data: dataday,
|
||||||
options: {
|
options: {
|
||||||
@ -834,7 +877,7 @@
|
|||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}); */
|
||||||
var playersChartDay2 = new Chart(ctxday2, {
|
var playersChartDay2 = new Chart(ctxday2, {
|
||||||
type: 'scatter',
|
type: 'scatter',
|
||||||
data: dataday,
|
data: dataday,
|
||||||
@ -1808,6 +1851,7 @@
|
|||||||
openFunc(slideIndex)();
|
openFunc(slideIndex)();
|
||||||
gmPie();
|
gmPie();
|
||||||
activityPie();
|
activityPie();
|
||||||
|
playersChart();
|
||||||
countUpTimer();
|
countUpTimer();
|
||||||
|
|
||||||
function openFunc(i) {
|
function openFunc(i) {
|
||||||
|
Loading…
Reference in New Issue
Block a user