Skip to content

Commit

Permalink
Merge pull request #532 from frank-weinberg/feature/diagnose-export
Browse files Browse the repository at this point in the history
Add some diagnostic info for stats export
  • Loading branch information
frank-weinberg authored Sep 18, 2022
2 parents 9c908d9 + 90e1b54 commit d0e2540
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 13 deletions.
1 change: 1 addition & 0 deletions html/components/igrf-tab.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#Igrf .Variables td { text-align: left; width: 50%; }
#Igrf tr.Files > td { background: #ddd; }
#Igrf tr.Files .ui-button { margin: 1px 5px; }
#Igrf tr.Files .Warning { color: red; }

#Igrf .Expulsions th { font-size: 150%; }
#Igrf .Expulsions table { width: 100%; }
Expand Down
17 changes: 17 additions & 0 deletions html/components/igrf-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,34 @@ function createIgrfTab(tab, gameId) {
.button()
.appendTo(table.find('tr.Files>td:eq(0)'));
var jsonButton = $('<a download>').text('Download JSON').button().appendTo(table.find('tr.Files>td:eq(0)'));
var noJson = $('<span>').text(' No JSON yet ').appendTo(table.find('tr.Files>td:eq(0)'));
var xlsxButton = $('<a download>').text('Download Statsbook').button().appendTo(table.find('tr.Files>td:eq(0)'));
var noXlsx = $('<span>').text(' No Statsbook yet ').appendTo(table.find('tr.Files>td:eq(0)'));
$('<span>').text(' Last Updated: ').appendTo(table.find('tr.Files>td:eq(0)'));
var downloadDate = $('<span>').appendTo(table.find('tr.Files>td:eq(0)'));
var noBlankStatsbookWarning = $('<span>')
.text(' Blank Statsbook not set up.')
.addClass('Warning')
.appendTo(table.find('tr.Files>td:eq(0)'));

WS.Register(gamePrefix + '.Filename', function (k, v) {
jsonButton.attr('href', '/game-data/json/' + v + '.json');
xlsxButton.attr('href', '/game-data/xlsx/' + v + '.xlsx');
});
WS.Register(gamePrefix + '.JsonExists', function (k, v) {
jsonButton.toggle(isTrue(v));
noJson.toggle(!isTrue(v));
});
WS.Register(gamePrefix + '.StatsbookExists', function (k, v) {
xlsxButton.toggle(isTrue(v));
noXlsx.toggle(!isTrue(v));
});
WS.Register(gamePrefix + '.LastFileUpdate', function (k, v) {
downloadDate.text(v);
});
WS.Register('ScoreBoard.BlankStatsbookFound', function (k, v) {
noBlankStatsbookWarning.toggle(!isTrue(v));
});

$('<span>').text('Tournament: ').appendTo(table.find('tr.Event>td:eq(0)'));
WSControl(gamePrefix + '.EventInfo(Tournament)', $('<input type="text" size="50">')).appendTo(table.find('tr.Event>td:eq(0)'));
Expand Down
2 changes: 2 additions & 0 deletions html/components/settings-tab.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#ScoreBoardSettings>tr>td.ViewFrames iframe { width: 100%; height: 300px; }
#ScoreBoardSettings .EndSubSection>td { padding-bottom: 10px; }
#ScoreBoardSettings .ui-button.ui-state-active, #ScoreBoardSettings .Active { background: #3f3; color: #000; }
#ScoreBoardSettings .StatsFile.Readable::after { content: "✓"; color: green; font-size: 150%; }
#ScoreBoardSettings .StatsFile:not(.Readable)::after { content: "❌"; color: red; }

/* Intermission Control Dialog */
table.IntermissionControlDialog { width: 100%; border-spacing: 0px; }
Expand Down
23 changes: 15 additions & 8 deletions html/components/settings-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ function createNonViewRows(table) {
var statsbookFile = $('<label>Blank Statsbook File: </label>').add(
WSControl('ScoreBoard.Settings.Setting(ScoreBoard.Stats.InputFile)', $('<input type="text" size="40">'))
);
WS.Register('ScoreBoard.BlankStatsbookFound', function (k, v) {
statsbookFile.parent().addClass('StatsFile').toggleClass('Readable', isTrue(v));
});
var teamDisplayName = $('<label>Team Name for Display: </label>').add(
WSControl(
'ScoreBoard.Settings.Setting(ScoreBoard.Teams.DisplayName)',
Expand Down Expand Up @@ -258,13 +261,15 @@ function createScoreBoardViewPreviewRows(table, type) {
.attr('ApplyPreview', 'Image');

var imageScaleSelect = $('<label>Image Scaling: </label>').add(
WSControl(
'ScoreBoard.Settings.Setting(ScoreBoard.' + type + '_ImageScaling)',
$('<select>')
.attr('ApplyPreview', 'ImageScaling')
.append('<option value="contain">Scale to fit</option>')
.append('<option value="cover">Scale to fill</option>')
.append('<option value="fill">Stretch</option>')));
WSControl(
'ScoreBoard.Settings.Setting(ScoreBoard.' + type + '_ImageScaling)',
$('<select>')
.attr('ApplyPreview', 'ImageScaling')
.append('<option value="contain">Scale to fit</option>')
.append('<option value="cover">Scale to fill</option>')
.append('<option value="fill">Stretch</option>')
)
);

var videoViewSelect = $('<label>Video View: </label>')
.add(mediaSelect('ScoreBoard.Settings.Setting(ScoreBoard.' + type + '_Video)', 'videos', 'fullscreen', 'Video'))
Expand All @@ -277,7 +282,9 @@ function createScoreBoardViewPreviewRows(table, type) {
.attr('ApplyPreview', 'VideoScaling')
.append('<option value="contain">Scale to fit</option>')
.append('<option value="cover">Scale to fill</option>')
.append('<option value="fill">Stretch</option>')));
.append('<option value="fill">Stretch</option>')
)
);

var customPageViewSelect = $('<label>Custom Page View: </label>')
.add(mediaSelect('ScoreBoard.Settings.Setting(ScoreBoard.' + type + '_CustomHtml)', 'custom', 'view', 'Page'))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.carolinarollergirls.scoreboard.core.admin;

import java.nio.file.Paths;

import com.carolinarollergirls.scoreboard.core.interfaces.Clock;
import com.carolinarollergirls.scoreboard.core.interfaces.Game;
import com.carolinarollergirls.scoreboard.core.interfaces.ScoreBoard;
Expand All @@ -11,9 +13,6 @@
import com.carolinarollergirls.scoreboard.utils.StatsbookExporter;
import com.carolinarollergirls.scoreboard.utils.ValWithId;

import java.util.function.BiConsumer;
import java.util.function.Consumer;

public class SettingsImpl extends ScoreBoardEventProviderImpl<Settings> implements Settings {
public SettingsImpl(ScoreBoard s) {
super(s, "", ScoreBoard.SETTINGS);
Expand All @@ -23,8 +22,10 @@ public SettingsImpl(ScoreBoard s) {

@Override
protected void itemAdded(Child<?> prop, ValueWithId item, Source source) {
if (item != null && ScoreBoard.SETTING_STATSBOOK_INPUT.equals(item.getId()) && scoreBoard.isInitialLoadDone()) {
StatsbookExporter.preload(item.getValue());
if (item != null && ScoreBoard.SETTING_STATSBOOK_INPUT.equals(item.getId())) {
boolean found = Paths.get(item.getValue()).toFile().canRead();
getScoreBoard().set(ScoreBoard.BLANK_STATSBOOK_FOUND, found);
if (found && scoreBoard.isInitialLoadDone()) { StatsbookExporter.preload(item.getValue()); }
}
}

Expand Down
33 changes: 33 additions & 0 deletions src/com/carolinarollergirls/scoreboard/core/game/GameImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import com.carolinarollergirls.scoreboard.core.interfaces.Expulsion;
import com.carolinarollergirls.scoreboard.core.interfaces.Game;
import com.carolinarollergirls.scoreboard.core.interfaces.Jam;
import com.carolinarollergirls.scoreboard.core.interfaces.Media.MediaFile;
import com.carolinarollergirls.scoreboard.core.interfaces.Media.MediaType;
import com.carolinarollergirls.scoreboard.core.interfaces.Penalty;
import com.carolinarollergirls.scoreboard.core.interfaces.Period;
import com.carolinarollergirls.scoreboard.core.interfaces.Period.PeriodSnapshot;
Expand Down Expand Up @@ -196,6 +198,32 @@ public void scoreBoardChange(ScoreBoardEvent<?> event) {
refreshRuleset((Ruleset) event.getProvider());
}
}));

// handle file updates
scoreBoard.getMedia()
.getFormat("game-data")
.getType("json")
.addScoreBoardListener(
new ConditionalScoreBoardListener<>(MediaType.class, MediaType.FILE, new ScoreBoardListener() {
@Override
public void scoreBoardChange(ScoreBoardEvent<?> event) {
if (((MediaFile) event.getValue()).getId().equals(getFilename() + ".json")) {
set(JSON_EXISTS, true);
}
}
}));
scoreBoard.getMedia()
.getFormat("game-data")
.getType("xlsx")
.addScoreBoardListener(
new ConditionalScoreBoardListener<>(MediaType.class, MediaType.FILE, new ScoreBoardListener() {
@Override
public void scoreBoardChange(ScoreBoardEvent<?> event) {
if (((MediaFile) event.getValue()).getId().equals(getFilename() + ".xlsx")) {
set(STATSBOOK_EXISTS, true);
}
}
}));
}

@Override
Expand Down Expand Up @@ -251,6 +279,10 @@ protected Object computeValue(Value<?> prop, Object value, Object last, Source s
} else {
return checkNewFilename(newName);
}
} else if (prop == STATSBOOK_EXISTS) {
return BasePath.get().toPath().resolve("html/game-data/xlsx/" + getFilename() + ".xlsx").toFile().canRead();
} else if (prop == JSON_EXISTS) {
return BasePath.get().toPath().resolve("html/game-data/json/" + getFilename() + ".json").toFile().canRead();
} else if (prop == RULESET && value != null && !source.isFile()) {
if (get(STATE) != State.PREPARED && source == Source.WS) {
return null; // no change after game start
Expand Down Expand Up @@ -389,6 +421,7 @@ public ScoreBoardEventProvider create(Child<? extends ScoreBoardEventProvider> p
if (prop == NSO) { return new OfficialImpl(this, id, NSO); }
if (prop == REF) { return new OfficialImpl(this, id, REF); }
if (prop == EXPULSION && source.isFile()) {
if (elements.get(Penalty.class) == null) { return null; }
Penalty p = (Penalty) elements.get(Penalty.class).get(id);
if (p != null) {
Expulsion e = get(EXPULSION, p.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ public static State fromString(String s) {
public static final Value<String> FILENAME =
new Value<>(String.class, "Filename", "STATS-0000-00-00_Team1_vs_Team_2", props);
public static final Value<String> LAST_FILE_UPDATE = new Value<>(String.class, "LastFileUpdate", "Never", props);
public static final Value<Boolean> STATSBOOK_EXISTS = new Value<>(Boolean.class, "StatsbookExists", false, props);
public static final Value<Boolean> JSON_EXISTS = new Value<>(Boolean.class, "JsonExists", false, props);

public static final Child<Clock> CLOCK = new Child<>(Clock.class, "Clock", props);
public static final Child<Team> TEAM = new Child<>(Team.class, "Team", props);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.carolinarollergirls.scoreboard.event.Child;
import com.carolinarollergirls.scoreboard.event.Property;
import com.carolinarollergirls.scoreboard.event.ScoreBoardEventProvider;
import com.carolinarollergirls.scoreboard.event.Value;
import com.carolinarollergirls.scoreboard.json.JSONStateManager;
import com.carolinarollergirls.scoreboard.utils.ValWithId;

Expand Down Expand Up @@ -36,6 +37,9 @@ public interface ScoreBoard extends ScoreBoardEventProvider {

public static Collection<Property<?>> props = new ArrayList<>();

public static final Value<Boolean> BLANK_STATSBOOK_FOUND =
new Value<>(Boolean.class, "BlankStatsbookFound", false, props);

public static final Child<ValWithId> VERSION = new Child<>(ValWithId.class, "Version", props);
public static final Child<Settings> SETTINGS = new Child<>(Settings.class, "Settings", props);
public static final Child<Twitter> TWITTER = new Child<>(Twitter.class, "Twitter", props);
Expand Down

0 comments on commit d0e2540

Please sign in to comment.