Added Landing Craft.

master
Pacman Ghost 6 years ago
parent 5597781069
commit 113b67ad3e
  1. 56
      vasl_templates/webapp/data/vehicles/landing-craft.json
  2. 4
      vasl_templates/webapp/static/snippets.js
  3. 18
      vasl_templates/webapp/templates/vo-report.html
  4. 13
      vasl_templates/webapp/tests/fixtures/vo-reports/landing-craft.txt
  5. 45
      vasl_templates/webapp/tests/test_vo_reports.py
  6. 20
      vasl_templates/webapp/vo.py

@ -0,0 +1,56 @@
[
{ "name": "LCP(L)",
"CS#": 4,
"damage_points": 2,
"note_number": "1\u2020",
"notes": [ "A\u2020<sup>1</sup>", "B\u2020<sup>3</sup>", "C\u2020<sup>2</sup>", "D" ]
},
{ "name": "LCA",
"CS#": 6,
"damage_points": 3,
"note_number": "2\u2020"
},
{ "name": "LCVP",
"CS#": 5,
"damage_points": 3,
"note_number": "3\u2020",
"notes": [ "B\u2020<sup>2</sup>", "C\u2020<sup>1</sup>" ]
},
{ "name": "LCV",
"CS#": 5,
"damage_points": 3,
"note_number": "3\u2020"
},
{ "name": "LCM(3)",
"CS#": 6,
"damage_points": 5,
"note_number": "4\u2020",
"notes": [ "B\u2020<sup>2</sup>", "C\u2020<sup>1</sup>" ]
},
{ "name": "LCI(S)",
"CS#": 10,
"damage_points": 14,
"note_number": "5\u2020",
"notes": [ "C\u2020<sup>3</sup>", "D", "E\u2020<sup>2</sup>", "F\u2020<sup>1</sup>", "G" ]
},
{ "name": "LCT(4)",
"CS#": 9,
"damage_points": 10,
"note_number": "6\u2020",
"notes": [ "C\u2020<sup>3</sup>", "E\u2020<sup>2</sup>", "F\u2020<sup>1</sup>", "G" ]
},
{ "name": "Daihatsu",
"CS#": 4,
"damage_points": 3,
"note_number": "7\u2020",
"notes": [ "A\u2020<sup>1</sup>" ]
},
{ "name": "Shohatsu",
"CS#": 3,
"damage_points": 2,
"note_number": "8\u2020",
"notes": [ "A\u2020", "D" ]
}
]

@ -356,6 +356,10 @@ function make_capabilities( entry, nat, scenario_theater, scenario_year, scenari
capabilities.push( entry.capabilities_other[i] ) ;
}
// include damage points (for Landing Craft)
if ( "damage_points" in entry )
capabilities.push( "DP " + entry.damage_points ) ;
return capabilities.length > 0 ? capabilities : null ;
}

@ -24,10 +24,10 @@ td { padding: 0.2em 0.5em ; }
$(document).ready( function () {
// get the vehicle listings
var url ;
if ( "{{VO_TYPE}}" == "vehicles" )
url = "{{url_for( 'get_vehicle_listings', report=1 )}}"
else
if ( "{{VO_TYPE}}" == "ordnance" )
url = "{{url_for( 'get_ordnance_listings', report=1 )}}" ;
else
url = "{{url_for( 'get_vehicle_listings', report=1 )}}" ; // nb: includes landing craft
if ( getUrlParam( "merge_common" ) === "1" )
url += "&merge_common=1" ;
$.getJSON( url, function(data) {
@ -50,8 +50,10 @@ function load_vo_listings( objs )
vo_name = decodeURIComponent( vo_name ).toLowerCase() ;
// check if there are any vehicles/ordnance for the specified nationality
if ( "{{VO_TYPE}}" === "landing-craft" )
nat = "landing-craft" ;
if ( ! (nat in objs ) ) {
$results.text( "No listings for nationality: " ) ; + nat
$results.text( "No listings for nationality: " + nat ).show() ;
return ;
}
@ -64,6 +66,10 @@ function load_vo_listings( objs )
buf.push( "<th>IF" ) ;
buf.push( "<th>Crew survival" ) ;
}
if ( "{{VO_TYPE}}" === "landing-craft" ) {
buf.push( "<th>Damage points" ) ;
buf.push( "<th>Crew survival" ) ;
}
buf.push( "<th colspan='2'>Capabilities", "<th colspan='2'>Notes" ) ;
for ( var i=0 ; i < objs[nat].length ; ++i ) {
var obj = objs[nat][i] ;
@ -81,6 +87,10 @@ function load_vo_listings( objs )
buf.push( "<td>", fmtval(has_if) ) ;
buf.push( "<td>", fmtval(make_crew_survival(obj)) ) ;
}
if ( "{{VO_TYPE}}" === "landing-craft" ) {
buf.push( "<td>", fmtval(obj.damage_points) ) ;
buf.push( "<td>", fmtval(make_crew_survival(obj)) ) ;
}
var capabilities = make_capabilities( obj, nat, theater, year, month, true, true ) ;
buf.push( "<td>", listval(capabilities) ) ;
var capabilities = make_capabilities( obj, nat, theater, year, month, true, false ) ;

@ -0,0 +1,13 @@
=== landing craft ===
Name Damage points Crew survival Capabilities (effective) # Notes
-------- --------------- --------------- -------------- ------------- --- ------------------------------------------------
LCP(L) 2 CS 4 DP 2 DP 2 1† A†<sup>1</sup> B†<sup>3</sup> C†<sup>2</sup> D
LCA 3 CS 6 DP 3 DP 3 2† n/a
LCVP 3 CS 5 DP 3 DP 3 3† B†<sup>2</sup> C†<sup>1</sup>
LCV 3 CS 5 DP 3 DP 3 3† n/a
LCM(3) 5 CS 6 DP 5 DP 5 4† B†<sup>2</sup> C†<sup>1</sup>
LCI(S) 14 CS 10 DP 14 DP 14 5† C†<sup>3</sup> D E†<sup>2</sup> F†<sup>1</sup> G
LCT(4) 10 CS 9 DP 10 DP 10 6† C†<sup>3</sup> E†<sup>2</sup> F†<sup>1</sup> G
Daihatsu 3 CS 4 DP 3 DP 3 7† A†<sup>1</sup>
Shohatsu 2 CS 3 DP 2 DP 2 8† A† D

@ -14,7 +14,7 @@ from vasl_templates.webapp.tests.utils import find_child, wait_for
# ---------------------------------------------------------------------
def test_vo_reports( webapp, webdriver ):
def test_vo_reports( webapp, webdriver ): #pylint: disable=too-many-locals
"""Check the vehicle/ordnance reports."""
# initialize
@ -46,7 +46,6 @@ def test_vo_reports( webapp, webdriver ):
for year in range(1940,1945+1):
# get the next report
buf = io.StringIO()
results = get_vo_report( webapp, webdriver, "ETO", nat, vo_type, year, 1 )
# FUDGE! The "capabilities" and "notes" columns span 2 columns each,
@ -61,7 +60,8 @@ def test_vo_reports( webapp, webdriver ):
fixup_capabilities( -3, "(effective)" )
fixup_capabilities( -2, "#" )
# output the report
# convert the report to plain-text
buf = io.StringIO()
print( "=== {}/{}/{} ===".format( vo_type, nat, year ), file=buf )
print( "", file=buf )
print(
@ -82,6 +82,35 @@ def test_vo_reports( webapp, webdriver ):
fname = os.path.join( check_dir, fname )
assert open(fname,"r",encoding="utf-8").read() == report
# get the landing craft report
url = webapp.url_for( "get_lc_report" )
webdriver.get( url )
wait_for( 2, lambda: find_child("#results").is_displayed() )
results = _parse_report( webdriver.page_source )
# convert the report to plain-text
assert results[0][-1] == "Notes"
results[0].insert( len(results[0])-1, "#" )
assert results[0][-3] == "Capabilities"
results[0].insert( len(results[0])-2, "(effective)" )
buf = io.StringIO()
print( "=== landing craft ===", file=buf )
print( "", file=buf )
print(
tabulate.tabulate( results, headers="firstrow" ),
file = buf
)
report = buf.getvalue()
# check if we should save the report
if save_dir:
with open( os.path.join(save_dir,"landing-craft.txt"), "w" ) as fp:
fp.write( report )
# check the report
fname = os.path.join( check_dir, "landing-craft.txt" )
assert open(fname,"r",encoding="utf-8").read() == report
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_vo_report( webapp, webdriver,
@ -108,6 +137,14 @@ def get_vo_report( webapp, webdriver,
webdriver.get( url )
wait_for( 2, lambda: find_child("#results").is_displayed() )
# parse the report
results = _parse_report( webdriver.page_source )
return results
def _parse_report( buf ):
"""Parse a vehicle/ordnance report."""
def tidy( cell ):
"""Tidy up a cell value."""
val = lxml.etree.tostring( cell ).decode( "utf-8" ) #pylint: disable=c-extension-no-member
@ -123,7 +160,7 @@ def get_vo_report( webapp, webdriver,
# unload the results
# NOTE: Getting each table cell via Selenium is insanely slow - we parse the HTML manually :-/
results = []
doc = lxml.html.fromstring( webdriver.page_source )
doc = lxml.html.fromstring( buf )
for row in doc.xpath( "//div[@id='results']//table//tr" ):
tag = "td" if results else "th"
cells = row.xpath( ".//{}".format( tag ) )

@ -51,14 +51,23 @@ def _do_get_listings( listings_type ): #pylint: disable=too-many-branches
with open( os.path.join(root,fname), "r" ) as fp:
listings[nat] = json.load( fp )
# merge the common entries into each Allied/Axis Minor listing
# merge common entries
if request.args.get( "merge_common" ) == "1":
# merge common Allied/Axis Minor vehicles/ordnance
for minor_type in ("allied-minor","axis-minor"):
if minor_type+"-common" not in listings:
continue
for nat in minor_nats[minor_type]:
listings[nat].extend( listings[minor_type+"-common"] )
del listings[ minor_type+"-common" ]
# merge landing craft
if listings_type == "vehicles":
for lc in listings.get("landing-craft",[]):
if lc["name"] in ("Daihatsu","Shohatsu"):
listings["japanese"].append( lc )
else:
listings["american"].append( lc )
listings["british"].append( lc )
return jsonify( listings )
@ -80,3 +89,12 @@ def get_vo_report( theater, nat, vo_type, year, month ):
YEAR = year,
MONTH = month,
)
@app.route( "/landing_craft" )
def get_lc_report():
"""Get a landing craft ordnance report."""
return render_template( "vo-report.html",
VO_TYPE = "landing-craft",
YEAR = "null",
MONTH = "null",
)

Loading…
Cancel
Save