Removed Most/Least Active time (Too ambiguous)

A single stat saying "Most Active Time is Sunday, 2 AM" unfortunately
does not convey what I originally would have liked in the context it is
presented in.

This is because it is not possible to easily figure out what day
session occurred - The sessions are right next to the stat so this would
bring confusion as the user is not able to easily verify the result.

This stat might be re-introduced to Online Activity Overview tab some
time in the future, since the day names are easily checked from
Punchcard or Calendar.
This commit is contained in:
Rsl1122 2019-08-23 16:48:34 +03:00
parent 4af2601c44
commit f41a6fbbce
6 changed files with 52 additions and 27 deletions

View File

@ -16,6 +16,8 @@
*/
package com.djrapitops.plan.db.sql.parsing;
import java.util.concurrent.TimeUnit;
/**
* Duplicate String reducing utility class for SQL language Strings.
*/
@ -44,12 +46,28 @@ public interface Sql {
return "varchar(" + length + ')';
}
/**
* Parse day of week to epoch ms.
* <p>
* 1st of January 1970 (Epoch) is Thursday (-2).
*
* @param day 1 = Sunday, 2 = Monday etc.. 7 = Saturday
* @return Milliseconds since epoch for this day to be given by {@link java.text.SimpleDateFormat} "EEEE"
*/
static long getDayEpochMs(int day) {
return TimeUnit.DAYS.toMillis(day + 2);
}
String epochSecondToDate(String sql);
String dateToEpochSecond(String sql);
String dateToDayStamp(String sql);
String dateToDayOfWeek(String sql);
String dateToHour(String sql);
// https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html
class MySQL implements Sql {
@ -68,6 +86,15 @@ public interface Sql {
return "DATE(" + sql + ')';
}
@Override
public String dateToDayOfWeek(String sql) {
return "DAYOFWEEK(" + sql + ')';
}
@Override
public String dateToHour(String sql) {
return "HOUR(" + sql + ") % 24";
}
}
// https://h2database.com/html/functions.html
@ -84,10 +111,14 @@ public interface Sql {
}
@Override
public String dateToDayStamp(String sql) {
return "DATE(" + sql + ')';
public String dateToDayOfWeek(String sql) {
return "DAY_OF_WEEK(" + sql + ')';
}
@Override
public String dateToHour(String sql) {
return "HOUR(" + sql + ')';
}
}
// https://sqlite.org/lang_datefunc.html
@ -108,5 +139,14 @@ public interface Sql {
return "strftime('%Y-%m-%d'," + sql + ')';
}
@Override
public String dateToDayOfWeek(String sql) {
return "strftime('%w'," + sql + ")+1";
}
@Override
public String dateToHour(String sql) {
return "strftime('%H'," + sql + ')';
}
}
}

View File

@ -43,8 +43,8 @@ public class SessionsOverviewJSONParser implements ServerTabJSONParser<Map<Strin
private DBSystem dbSystem;
private Formatter<Long> timeAmountFormatter;
private Formatter<Double> percentageFormatter;
private Formatter<Long> timeAmount;
private Formatter<Double> percentage;
@Inject
public SessionsOverviewJSONParser(
@ -53,8 +53,8 @@ public class SessionsOverviewJSONParser implements ServerTabJSONParser<Map<Strin
) {
this.dbSystem = dbSystem;
timeAmountFormatter = formatters.timeAmount();
percentageFormatter = formatters.percentage();
timeAmount = formatters.timeAmount();
percentage = formatters.percentage();
}
public Map<String, Object> createJSONAsMap(UUID serverUUID) {
@ -71,25 +71,22 @@ public class SessionsOverviewJSONParser implements ServerTabJSONParser<Map<Strin
Map<String, Object> insights = new HashMap<>();
insights.put("most_active_time", "Not implemented");
insights.put("least_active_time", "Not implemented");
long uptime = TimeUnit.DAYS.toMillis(30L) - tpsMutator.serverDownTime();
long occupied = tpsMutator.serverOccupiedTime();
insights.put("server_occupied", timeAmountFormatter.apply(occupied));
insights.put("server_occupied_perc", uptime != 0 ? percentageFormatter.apply(1.0 * occupied / uptime) : "-");
insights.put("server_occupied", timeAmount.apply(occupied));
insights.put("server_occupied_perc", uptime != 0 ? percentage.apply(1.0 * occupied / uptime) : "-");
Long playtime = db.query(SessionQueries.playtime(monthAgo, now, serverUUID));
Long afkTime = db.query(SessionQueries.afkTime(monthAgo, now, serverUUID));
insights.put("total_playtime", timeAmountFormatter.apply(playtime));
insights.put("afk_time", timeAmountFormatter.apply(afkTime));
insights.put("afk_time_perc", playtime != 0 ? percentageFormatter.apply(1.0 * afkTime / playtime) : "-");
insights.put("total_playtime", timeAmount.apply(playtime));
insights.put("afk_time", timeAmount.apply(afkTime));
insights.put("afk_time_perc", playtime != 0 ? percentage.apply(1.0 * afkTime / playtime) : "-");
GMTimes gmTimes = db.query(WorldTimesQueries.fetchGMTimes(monthAgo, now, serverUUID));
Optional<String> mostUsedGameMode = gmTimes.getMostUsedGameMode();
Long longestGMTime = mostUsedGameMode.map(gmTimes::getTime).orElse(-1L);
insights.put("most_active_gamemode", mostUsedGameMode.map(WordUtils::capitalizeFully).orElse("Not Known"));
insights.put("most_active_gamemode_perc", playtime != 0 ? percentageFormatter.apply(1.0 * longestGMTime / playtime) : "-");
insights.put("most_active_gamemode_perc", playtime != 0 ? percentage.apply(1.0 * longestGMTime / playtime) : "-");
return insights;
}

View File

@ -172,8 +172,6 @@ function loadSessionValues(json, error) {
data = json.insights;
element = $(tab).find('#data_insights');
$(element).find('#data_most_active_time').text(data.most_active_time);
$(element).find('#data_least_active_time').text(data.least_active_time);
$(element).find('#data_most_active_gamemode').text(data.most_active_gamemode);
$(element).find('#data_most_active_gamemode_perc').text(data.most_active_gamemode_perc);
$(element).find('#data_server_occupied').text(data.server_occupied);

View File

@ -189,8 +189,6 @@ function loadSessionValues(json, error) {
data = json.insights;
element = $(tab).find('#data_insights');
$(element).find('#data_most_active_time').text(data.most_active_time);
$(element).find('#data_least_active_time').text(data.least_active_time);
$(element).find('#data_most_active_gamemode').text(data.most_active_gamemode);
$(element).find('#data_most_active_gamemode_perc').text(data.most_active_gamemode_perc);
$(element).find('#data_server_occupied').text("~" + data.server_occupied);

View File

@ -416,10 +416,6 @@
Insights for 30 Days</h6>
</div>
<div class="card-body" id="data_insights">
<p><i class="far fa-fw fa-clock col-teal"></i> Most Active Time<span
class="float-right"><b id="data_most_active_time"></b></span></p>
<p><i class="far fa-fw fa-clock col-teal"></i> Least Active Time<span
class="float-right"><b id="data_least_active_time"></b></span></p>
<p><i class="far fa-fw fa-clock col-green"></i> Playtime<span
class="float-right" id="data_total_playtime"></span></p>
<p><i class="far fa-fw fa-clock col-grey"></i> AFK Time<span

View File

@ -565,10 +565,6 @@
Insights for 30 Days</h6>
</div>
<div class="card-body" id="data_insights">
<p><i class="far fa-fw fa-clock col-teal"></i> Most Active Time<span
class="float-right"><b id="data_most_active_time"></b></span></p>
<p><i class="far fa-fw fa-clock col-teal"></i> Least Active Time<span
class="float-right"><b id="data_least_active_time"></b></span></p>
<p><i class="fa fa-fw fa-gamepad col-teal"></i> Most Active Gamemode<span
class="float-right"><b id="data_most_active_gamemode"></b>
(<span id="data_most_active_gamemode_perc"></span>)</span></p>