Allow custom labels to be added to a log file analysis.

master
Pacman Ghost 4 years ago
parent 685888fddd
commit 720c491265
  1. 6
      vasl_templates/webapp/lfa.py
  2. 8
      vasl_templates/webapp/static/lfa.js
  3. BIN
      vasl_templates/webapp/tests/fixtures/analyze-vlog/custom-labels.vlog
  4. 39
      vasl_templates/webapp/tests/test_lfa.py
  5. BIN
      vassal-shim/release/vassal-shim.jar
  6. 16
      vassal-shim/src/vassal_shim/VassalShim.java
  7. 31
      vassal-shim/src/vassal_shim/lfa/CustomLabelEvent.java

@ -131,6 +131,12 @@ def parse_analysis_report( fname, logger=None ):
"turnNo": elem.attrib[ "turnNo" ],
"phase": elem.attrib[ "phase" ]
} )
elif elem.tag == "customLabelEvent":
# found a CUSTOM label
events.append( {
"eventType": "customLabel",
"caption": elem.text
} )
else:
if logger:
logger.warn( "Found an unknown analysis event: %s", elem.tag )

@ -684,6 +684,10 @@ function updateTimePlotChart( currWindowSize )
// we have a Turn Track event - use the phase description as the next label
nextLabel = evt.side + " " + evt.turnNo + " " + evt.phase ;
},
onCustomLabelEvent: function( evt ) {
// we have a custom label event - use the caption as the next label
nextLabel = evt.caption ;
},
onRollEvent: function( evt ) {
// we have a DR/dr roll - check if we want to include it
if ( rollType === "" ) {
@ -1672,6 +1676,10 @@ function onDownloadData()
// save the phase (it will be included in the next row of data)
nextLabel = evt.side + " " + evt.turnNo + " " + evt.phase ;
},
onCustomLabelEvent: function( evt ) {
// save the custom label (it will be included in the next row of data)
nextLabel = evt.caption ;
},
onRollEvent: function( evt ) {
// generate the next row of data
if ( nextLogFilename ) {

@ -509,6 +509,45 @@ def test_download_data( webapp, webdriver ):
# ---------------------------------------------------------------------
@pytest.mark.skipif( not pytest.config.option.vasl_mods, reason="--vasl-mods not specified" ) #pylint: disable=no-member
@pytest.mark.skipif( not pytest.config.option.vassal, reason="--vassal not specified" ) #pylint: disable=no-member
def test_custom_labels( webapp, webdriver ):
"""Test custom labels in the log file."""
# initialize
control_tests = init_webapp( webapp, webdriver, vlog_persistence=1, lfa_persistence=1 )
def do_test(): #pylint: disable=missing-docstring
# analyze the log file
_analyze_vlogs( "custom-labels.vlog" )
# download the data
marker = set_stored_msg_marker( "_lfa-download_" )
find_child( "#lfa button.download" ).click()
wait_for( 2, lambda: get_stored_msg("_lfa-download_") != marker )
data = get_stored_msg( "_lfa-download_" )
# check the results
data = data.split( "\n" )
rows = list( csv.reader( data, quoting=csv.QUOTE_NONNUMERIC ) )
assert rows == [
[ "Log file", "Phase", "Player", "Type", "Die 1", "Die 2" ],
[ "custom-labels.vlog", "", "test", "Other", 5, 3 ],
[ "", "", "test", "Other", 3, "" ],
[ "", "Custom Label 1", "test", "Other", 6, 6 ],
[ "", "", "test", "RS", 6, "" ],
[ "", "Axis 1 PFPh", "test", "Other", 4, 4 ],
[ "", "", "test", "RS", 6, "" ],
[ "", "Custom label 2", "test", "Other", 2, 1 ],
[ "", "", "test", "RS", 1, "" ]
]
# run the test
_run_tests( control_tests, do_test, False )
# ---------------------------------------------------------------------
def _analyze_vlogs( fnames ):
"""Analyze log file(s)."""

@ -223,9 +223,12 @@ public class VassalShim
Pattern diceRoll3EventPattern = Pattern.compile(
config.getProperty( "LFA_PATTERN_DICE3_ROLL", "^\\*\\*\\* 3d6 = (?<d1>\\d),(?<d2>\\d),(?<d3>\\d) \\*\\*\\*\\s+\\<(?<player>.+?)\\>" )
) ;
Pattern turnTrackEventPatter = Pattern.compile(
Pattern turnTrackEventPattern = Pattern.compile(
config.getProperty( "LFA_PATTERN_TURN_TRACK", "^\\* New: (?<side>.+?) Turn (?<turn>\\d+) - (?<phase>.+?) \\*" )
) ;
Pattern customLabelEventPattern = Pattern.compile(
config.getProperty( "LFA_PATTERN_CUSTOM_LABEL", "!!vt-label (?<label>.+)$" )
) ;
// check if we've found an event we're interested in
if ( cmd instanceof LogCommand ) {
@ -255,13 +258,22 @@ public class VassalShim
}
// check if we've found a Turn Track change
if ( event == null ) {
matcher = turnTrackEventPatter.matcher( msg ) ;
matcher = turnTrackEventPattern.matcher( msg ) ;
if ( matcher.find() ) {
// yup - add it to the list
event = new TurnTrackEvent( matcher.group("side"), matcher.group("turn"), matcher.group("phase") ) ;
logger.debug( "- Matched TurnTrackEvent: " + event ) ;
}
}
// check if we've found a custom label
if ( event == null ) {
matcher = customLabelEventPattern.matcher( msg ) ;
if ( matcher.find() ) {
// yup - add it to the list
event = new CustomLabelEvent( matcher.group("label") ) ;
logger.debug( "- Matched CustomLabelEvent: " + event ) ;
}
}
// add the event to the list
if ( event != null )
events.add( event ) ;

@ -0,0 +1,31 @@
package vassal_shim.lfa ;
import org.w3c.dom.Document ;
import org.w3c.dom.Element ;
// --------------------------------------------------------------------
public class CustomLabelEvent implements Event
{
String customLabel ;
public CustomLabelEvent( String customLabel )
{
// initialize the CustomLabelEvent
this.customLabel = customLabel ;
}
public Element makeXmlElement( Document doc )
{
// create an XML element for the CustomLabelEvent
Element elem = doc.createElement( "customLabelEvent" ) ;
elem.setTextContent( customLabel ) ;
return elem ;
}
public String toString()
{
// return the CustomLabelEvent as a string
return "<CustomLabelEvent:" + customLabel + ">" ;
}
}
Loading…
Cancel
Save