Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add File-based Runtime Loaded peanlty file #83

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@
<classpathentry kind="lib" path="test-libs/junit-4.11.jar"/>
<classpathentry kind="lib" path="test-libs/hamcrest-core-1.3.jar"/>
<classpathentry kind="lib" path="test-libs/mockito-all-1.9.5.jar"/>
<classpathentry kind="lib" path="lib/deps/jackson-annotations-2.9.5.jar"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use only one json library, there's already another one 4 lines up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this wholeheartedly, and my next project is to strip out org.json (both the seemingly unused vendored source code and the jar & uses in the scoreboard. org.json has a weird license and is much lower level than we should really be using.

That said, I think removing org.json is a bit of an undertaking that is outside of the scope of this PR. if you'd prefer me to rewrite PenaltyCodeManager to use org.json constructs for now I can, but I would rather not do that just to undo it in a few weeks.

Also, after doing a bit of reading (and realizing that I had added a 1.3MB dependency), I swapped jackson-databind for jackson-jr, that is much lighter weight but still gives us a much nicer org.json replacement.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not the best of libraries alright.

I would rather not do that just to undo it in a few weeks.

I'd hold off on that until I've finished removing the Game directory, as that's going to have json-y impacts. Does jackson-jr permit building up json by hand like the currently library does?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, jackson-jr provides a fluent api that works very similarly to how org.json manipulates json objects.

<classpathentry kind="lib" path="lib/deps/jackson-core-2.9.5.jar"/>
<classpathentry kind="lib" path="lib/deps/jackson-jr-objects-2.9.5.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1 change: 1 addition & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@
<include name="html/images/sponsor_banner" />
<include name="lib/crg-scoreboard.jar" />
<include name="config/crg.scoreboard.properties" />
<include name="config/penalties/**" />
<include name="config/default/**" />
</zipfileset>
</zip>
Expand Down
20 changes: 20 additions & 0 deletions config/penalties/wftda2016.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"penalties": [
{ "code": "B", "verbalCues": ["Back Block"]},
{ "code": "A", "verbalCues": ["High Block"]},
{ "code": "L", "verbalCues": ["Low Block"]},
{ "code": "E", "verbalCues": ["Elbows"]},
{ "code": "F", "verbalCues": ["Forearm"]},
{ "code": "H", "verbalCues": ["Blocking with the Head"]},
{ "code": "M", "verbalCues": ["Multi-player Block"]},
{ "code": "O", "verbalCues": ["Out of Bounds Block"]},
{ "code": "C", "verbalCues": ["Clockwise Block","Stop Block"]},
{ "code": "P", "verbalCues": ["Destroying the Pack","OOP Block","Failure to..."]},
{ "code": "S", "verbalCues": ["Skating OOB"]},
{ "code": "X", "verbalCues": ["Cutting"]},
{ "code": "I", "verbalCues": ["Illegal Procedure"]},
{ "code": "N", "verbalCues": ["Insubordination"]},
{ "code": "G", "verbalCues": ["Misconduct"]},
{ "code": "Z", "verbalCues": ["Delay of Game"]}
]
}
18 changes: 18 additions & 0 deletions config/penalties/wftda2018.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"penalties": [
{ "code": "B", "verbalCues": ["Back Block"]},
{ "code": "A", "verbalCues": ["High Block"]},
{ "code": "L", "verbalCues": ["Low Block"]},
{ "code": "E", "verbalCues": ["Leg Block"]},
{ "code": "F", "verbalCues": ["Forearm"]},
{ "code": "H", "verbalCues": ["Head Block"]},
{ "code": "M", "verbalCues": ["Multiplayer"]},
{ "code": "C", "verbalCues": ["Illegal Contact","Illegal Assist","OOP Block","Early/Late Hit"]},
{ "code": "D", "verbalCues": ["Direction","Stop Block"]},
{ "code": "P", "verbalCues": ["Illegal Position","Destruction","Skating OOB","Failure to..."]},
{ "code": "X", "verbalCues": ["Cut","Illegal Re-Entry"]},
{ "code": "I", "verbalCues": ["Illegal Procedure","Star Pass Violation","Pass Interference"]},
{ "code": "N", "verbalCues": ["Interference","Delay Of Game"]},
{ "code": "G", "verbalCues": ["Misconduct","Insubordination"]}
]
}
42 changes: 27 additions & 15 deletions html/controls/pt/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 28 additions & 14 deletions html/controls/pt/ptcolor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added lib/deps/jackson-annotations-2.9.5.jar
Binary file not shown.
Binary file added lib/deps/jackson-core-2.9.5.jar
Binary file not shown.
Binary file added lib/deps/jackson-jr-objects-2.9.5.jar
Binary file not shown.
17 changes: 10 additions & 7 deletions src/com/carolinarollergirls/scoreboard/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.carolinarollergirls.scoreboard.game.*;
import com.carolinarollergirls.scoreboard.jetty.WS;
import com.carolinarollergirls.scoreboard.json.WSUpdate;

public class Game {
public Game(ScoreBoard sb) {
Expand Down Expand Up @@ -163,21 +166,21 @@ public void save() {
}

public void update(String key, Object value) {
synchronized (updateMap) {
updateMap.put(key, value);
synchronized (updates) {
updates.add(new WSUpdate(key, value));
}
}

public void updateState() {
synchronized (updateMap) {
if (updateMap.size() == 0)
synchronized (updates) {
if (updates.isEmpty())
return;
WS.updateState(updateMap);
updateMap.clear();
WS.updateState(updates);
updates.clear();
}
}

private LinkedHashMap<String, Object> updateMap = new LinkedHashMap<String, Object>();
private List<WSUpdate> updates = new ArrayList<WSUpdate>();
protected ScoreBoard sb = null;
private TeamInfo[] teams = null;
private ArrayList<PeriodStats> periods = null;
Expand Down
1 change: 1 addition & 0 deletions src/com/carolinarollergirls/scoreboard/Ruleset.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private static Ruleset initialize() {
newRule( new StringRule(false, "ScoreBoard", Clock.ID_INTERMISSION, "Unofficial", "", "Unofficial Score"));
newRule( new StringRule(false, "ScoreBoard", Clock.ID_INTERMISSION, "Official", "", "Final Score"));
newRule( new StringRule(false, "ScoreBoard", null, "BackgroundStyle", "", "bg_black"));
newRule( new StringRule(false, "ScoreBoard", null, "PenaltyDefinitionFile", "", "/config/penalties/wftda2018.json"));
newRule( new StringRule(false, "ScoreBoard", null, "BoxStyle", "", "box_flat"));
newRule( new StringRule(false, "ScoreBoard", null, "CurrentView", "", "scoreboard"));
newRule( new StringRule(false, "ScoreBoard", null, "CustomHtml", "", "/customhtml/fullscreen/example.html"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.carolinarollergirls.scoreboard.xml.*;
import com.carolinarollergirls.scoreboard.event.*;
import com.carolinarollergirls.scoreboard.model.*;
import com.carolinarollergirls.scoreboard.penalties.PenaltyCodesManager;
import com.carolinarollergirls.scoreboard.policy.OvertimeLineupTimePolicy;

public class DefaultScoreBoardModel extends DefaultScoreBoardEventProvider implements ScoreBoardModel
Expand Down Expand Up @@ -47,6 +48,7 @@ public DefaultScoreBoardModel() {
Ruleset.registerRule(settings, "ScoreBoard.SidePadding");
Ruleset.registerRule(settings, "ScoreBoard.SwapTeams");
Ruleset.registerRule(settings, "ScoreBoard.Video");
Ruleset.registerRule(settings, PenaltyCodesManager.PenaltiesFileSetting);

reset();
loadPolicies();
Expand Down
47 changes: 20 additions & 27 deletions src/com/carolinarollergirls/scoreboard/jetty/WS.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@
import org.json.JSONException;
import org.json.JSONObject;

import com.carolinarollergirls.scoreboard.ScoreBoard;
import com.carolinarollergirls.scoreboard.ScoreBoardManager;
import com.carolinarollergirls.scoreboard.json.ScoreBoardJSONListener;
import com.carolinarollergirls.scoreboard.json.WSUpdate;
import com.carolinarollergirls.scoreboard.model.ScoreBoardModel;

public class WS extends WebSocketServlet {

public WS(ScoreBoardModel s) {
sbm = s;
ScoreBoardJSONListener listener = new ScoreBoardJSONListener(s);
sbm = s;
new ScoreBoardJSONListener(s);
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Expand All @@ -62,43 +63,35 @@ protected static void unregister(Conn source) {
}

private static void updateState(String key, Object value) {
Map<String, Object> updateMap = new LinkedHashMap<String, Object>();
updateMap.put(key, value);
updateState(updateMap);
List<WSUpdate> updates = new ArrayList<WSUpdate>();
updates.add(new WSUpdate(key, value));
updateState(updates);
}

public static void updateState(Map<String, Object> updates) {
public static void updateState(List<WSUpdate> updates) {
Histogram.Timer timer = updateStateDuration.startTimer();
synchronized (sourcesLock) {
stateID++;
List<String> keys = new LinkedList<String>(updates.keySet());
List<String> deletedKeys = new LinkedList<String>(updates.keySet());
for (String k : keys) {
Object v = updates.get(k);
if (v == null) {
// Remove this and all children from state
List<String> stateKeys = new ArrayList<String>(state.keySet());
for (String key : stateKeys) {
if (key.equals(k) || key.startsWith(k + ".")) {
deletedKeys.add(key);
State s = state.get(key);
for(WSUpdate update : updates) {
if(update.getValue() == null) {
for(String stateKey: state.keySet()) {
if(stateKey.equals(update.getKey()) || stateKey.startsWith(update.getKey()+".")) {
State s = state.get(stateKey);
s.stateID = stateID;
s.value = v;
s.value = null;
}
}
} else {
State s = state.get(k);
if (s == null) {
if (v != null)
state.put(k, new State(stateID, v));
} else if (!v.equals(s.value)) {
State s = state.get(update.getKey());
if(s == null) {
state.put(update.getKey(), new State(stateID, update.getValue()));
} else if(!update.getValue().equals(s.value)) {
s.stateID = stateID;
s.value = v;
s.value = update.getValue();
}
}
}
keys.addAll(deletedKeys);


for (Conn source : sources) {
source.sendUpdates();
}
Expand Down
Loading