def test_that_log_is_returned_correctly_from_IIVLM(self): vessel = Vessel() expected = 12220.52 nmea_string = '$IIVLW,12220.52,N,0.00,N*49' vessel.NMEAInput(nmea_string) actual = vessel.log self.assertEqual(expected, actual)
def test_that_apparent_wind_speed_is_returned_correctly_from_IIVWR(self): vessel = Vessel() expected = 35.0 nmea_string = '$IIVWR,44.8,L,35.0,N,18.0,M,64.9,K*5B' vessel.NMEAInput(nmea_string) actual = vessel.AWS self.assertEqual(expected, actual)
def test_that_sog_is_returned_correctly_from_IIVTG(self): vessel = Vessel() expected = 9.9 nmea_string = '$IIVTG,309.90,T,310.90,M,9.9,N,18.3,K,A*06' vessel.NMEAInput(nmea_string) actual = vessel.sog self.assertEqual(expected, actual)
def test_vessel_correctly_reports_boat_speed_from_IIVHW(self): vessel = Vessel() expected = 9.5 nmea_string = '$IIVHW,298.2,T,301.0,M,9.5,N,17.5,K*69' vessel.NMEAInput(nmea_string) actual = vessel.boat_speed_knots self.assertEqual(expected, actual)
def test_that_true_wind_speed_is_returned_correctly_from_IIVWT(self): vessel = Vessel() expected = 27.8 nmea_string = '$IIVWT,59.0,L,27.8,N,14.3,M,51.6,K*54' vessel.NMEAInput(nmea_string) actual = vessel.TWS self.assertEqual(expected, actual)
def test_vessel_correctly_reports_magnetic_heading_from_IIVHW(self): vessel = Vessel() expected = 301.0 nmea_string = '$IIVHW,298.2,T,301.0,M,9.5,N,17.5,K*69' vessel.NMEAInput(nmea_string) actual = vessel.heading_mag self.assertEqual(expected, actual)
def test_vessel_correctly_converts_east_longitude_from_IIGLL(self): vessel = Vessel() expected = 1.11689 nmea_string = '$IIGLL,5047.3904,N,00107.0134,E,162649.99,A,3*18' vessel.NMEAInput(nmea_string) actual = vessel.longitude self.assertEqual(expected, actual)
def test_vessel_correctly_sets_timestamp_from_IIGLL(self): vessel = Vessel() expected = datetime.strptime('162649.99', '%H%M%S.%f') nmea_string = '$IIGLL,5047.3904,N,00107.0134,W,162649.99,A,3*18' vessel.NMEAInput(nmea_string) actual = vessel.time self.assertEqual(expected, actual)
def test_that_water_temp_is_returned_correctly_from_IIMTW(self): vessel = Vessel() expected = 9.32 nmea_string = '$IIMTW,9.32,C*1B' vessel.NMEAInput(nmea_string) actual = vessel.water_temp self.assertEqual(expected, actual)
def test_that_keel_is_returned_correctly_from_IIDPT(self): vessel = Vessel() expected = -2.9 nmea_string = '$IIDPT,14.7,-2.9,*78' vessel.NMEAInput(nmea_string) actual = vessel.keel self.assertEqual(expected, actual)
def test_that_target_boat_speed_is_set_correctly_in_NMEAInput(self): vessel = Vessel(FakePolarFile()) nmea_string = '$IIVWR,44.8,R,10.0,N,18.0,M,64.9,K*5B' expected = 10 * 45 vessel.NMEAInput(nmea_string) actual = vessel.target_boat_speed self.assertEqual(expected, actual)
def test_that_polar_data_is_updated_when(self): vessel = Vessel(FakePolarFile()) SWS = 10 SWA = 90 expected = SWS * SWA actual = vessel.get_target(SWS, SWA) self.assertEqual(expected, actual)
def test_vessel_correctly_converts_south_latitude_from_IIGLL(self): vessel = Vessel() expected = -50.78984 nmea_string = '$IIGLL,5047.3904,S,00107.0134,W,162649.99,A,3*18' vessel.NMEAInput(nmea_string) actual = vessel.latitude self.assertEqual(expected, actual)
def test_vessel_power_status_racing_is_set_correctly(self): vessel = Vessel() nmea_string = '$XXPWR,R' vessel.NMEAInput(nmea_string) expected = 'Racing' actual = vessel.power_status self.assertEqual(expected, actual)
def test_that_depth_is_returned_correctly_from_IIDBT(self): vessel = Vessel() expected = 14.7 nmea_string = '$IIDBT,48.2,f,14.7,M,8.0,F*15' vessel.NMEAInput(nmea_string) actual = vessel.depth self.assertEqual(expected, actual)
def test_that_date_is_updated_if_GPRMC_is_present(self): vessel = Vessel() expected = datetime.strptime('190317', '%d%m%y') nmea_string = \ '$GPRMC,150558.00,A,5040.73877,N,00058.58538,W,9.712,124.01,190317,,,A*75' vessel.NMEAInput(nmea_string) actual = vessel.date self.assertEqual(expected, actual)
def test_that_rudder_is_returned_correctly_from_IIXDR(self): vessel = Vessel() expected = 8.0 nmea_string = \ '$IIXDR,A,33.8,D,HEEL,A,11.2,D,TRIM,P,1.005,B,BAROIIXDR,A,8.0,D,RUDDER*4E' vessel.NMEAInput(nmea_string) actual = vessel.rudder self.assertEqual(expected, actual)
def test_that_no_change_boat_speed_indicator_is_returned_correctly(self): vessel = Vessel() expected = '' nmea_string = '$IIVHW,298.2,T,301.0,M,9.5,N,17.5,K*69' vessel.NMEAInput(nmea_string) nmea_string = '$IIVHW,298.2,T,301.0,M,9.5,N,17.5,K*69' vessel.NMEAInput(nmea_string) actual = vessel.boat_speed_indicator self.assertEqual(expected, actual)
def test_vessel_correctly_calculates_TWD_calc_2(self): vessel = Vessel() nmea_string = '$IIVHW,348.2,T,301.0,M,9.5,N,17.5,K*69' vessel.NMEAInput(nmea_string) nmea_string = '$IIVTG,10,T,310.90,M,9.9,N,18.3,K,A*06' vessel.NMEAInput(nmea_string) nmea_string = '$IIVWR,44.8,R,35.0,N,18.0,M,64.9,K*5B' vessel.NMEAInput(nmea_string) expected = 31.5 actual = vessel.TWA_calc self.assertEqual(expected, actual)
def test_vessel_correctly_calculates_AWD_is_negative(self): vessel = Vessel() #heading = 38.2 nmea_string = '$IIVHW,38.2,T,301.0,M,9.5,N,17.5,K*69' vessel.NMEAInput(nmea_string) #AWA = -44.8 nmea_string = '$IIVWR,44.8,L,35.0,N,18.0,M,64.9,K*5B' vessel.NMEAInput(nmea_string) #AWD = H + AWA expected = 353.4 actual = vessel.AWD self.assertEqual(expected, actual)
def test_vessel_correctly_calculates_AWD(self): vessel = Vessel() #heading = 298.2 nmea_string = '$IIVHW,298.2,T,301.0,M,9.5,N,17.5,K*69' vessel.NMEAInput(nmea_string) #AWA = 44.8 nmea_string = '$IIVWR,44.8,R,35.0,N,18.0,M,64.9,K*5B' vessel.NMEAInput(nmea_string) #AWD = H + AWA = 343 expected = 343 actual = vessel.AWD self.assertEqual(expected, actual)
def test_vessel_correctly_calculates_AWD_when_result_greater_then_360( self): vessel = Vessel() #heading = 348.2 nmea_string = '$IIVHW,348.2,T,301.0,M,9.5,N,17.5,K*69' vessel.NMEAInput(nmea_string) #AWA = 44.8 nmea_string = '$IIVWR,44.8,R,35.0,N,18.0,M,64.9,K*5B' vessel.NMEAInput(nmea_string) #AWD = H + AWA - 360 expected = 33 actual = vessel.AWD self.assertEqual(expected, actual)
def test_that_boat_speed_list_is_maintained_correctly(self): vessel = Vessel() expected = 2 #Outside time limit nmea_string = '$IIGLL,5047.3904,N,00107.0134,W,162649.00,A,3*18' vessel.NMEAInput(nmea_string) nmea_string = '$IIVHW,298.2,T,301.0,M,100,N,17.5,K*69' vessel.NMEAInput(nmea_string) #Inside time limit nmea_string = '$IIGLL,5047.3904,N,00107.0134,W,162650.00,A,3*18' vessel.NMEAInput(nmea_string) nmea_string = '$IIVHW,298.2,T,301.0,M,9.5,N,17.5,K*69' vessel.NMEAInput(nmea_string) nmea_string = '$IIGLL,5047.3904,N,00107.0134,W,162700.00,A,3*18' vessel.NMEAInput(nmea_string) nmea_string = '$IIVHW,298.2,T,301.0,M,10.5,N,17.5,K*69' vessel.NMEAInput(nmea_string) actual = len(vessel.boat_speed_list) self.assertEqual(expected, actual)
def test_that_a_ten_second_average_boat_speed_is_calculated_correctly( self): vessel = Vessel() expected = 10 #Outside time limit nmea_string = '$IIGLL,5047.3904,N,00107.0134,W,162649.00,A,3*18' vessel.NMEAInput(nmea_string) nmea_string = '$IIVHW,298.2,T,301.0,M,100,N,17.5,K*69' vessel.NMEAInput(nmea_string) #Inside time limit nmea_string = '$IIGLL,5047.3904,N,00107.0134,W,162650.00,A,3*18' vessel.NMEAInput(nmea_string) nmea_string = '$IIVHW,298.2,T,301.0,M,9.5,N,17.5,K*69' vessel.NMEAInput(nmea_string) nmea_string = '$IIGLL,5047.3904,N,00107.0134,W,162700.00,A,3*18' vessel.NMEAInput(nmea_string) nmea_string = '$IIVHW,298.2,T,301.0,M,10.5,N,17.5,K*69' vessel.NMEAInput(nmea_string) actual = vessel.boat_speed_avg self.assertEqual(expected, actual)
def test_that_today_is_used_as_defualt_date_at_init(self): vessel = Vessel() expected = date.today() actual = vessel.date self.assertEqual(expected, actual)
from modules.weather import wind_forecast_nc from modules.vessel import Vessel from modules.vessel import FileAccessWrapper from race_details.RORC_De_Guingand_Bowl_Race_2017.course_details \ import CourseDetails TIDE_FILE = \ 'race_details/RORC_De_Guingand_Bowl_Race_2017/Grib/Tide/' WIND_FILE = \ 'race_details/RORC_De_Guingand_Bowl_Race_2017/Grib/Weather/wind-speed-and-direction.nc' course = CourseDetails().course polar_file = FileAccessWrapper('modules/process/inter_polar.csv') vessel = Vessel(polar_file) def clear_terminal(): print(chr(27) + "[2J") #Clear terminal def print_there(x, y, text): sys.stdout.write("\x1b7\x1b[%d;%df%s\x1b8" % (x, y, text)) #sys.stdout.flush() def print_course_details(anchor, course): clear_terminal()
import datetime import sys import os import modules.navigation as nav from modules.vessel import Vessel from modules.vessel import FileAccessWrapper from race_details.RORC_De_Guingand_Bowl_Race_2017.course_details \ import CourseDetails course = CourseDetails().course polar_file = FileAccessWrapper('modules/process/inter_polar.csv') vessel = Vessel(polar_file) def clear_terminal(): print(chr(27) + "[2J") #Clear terminal def print_there(x, y, text): sys.stdout.write("\x1b7\x1b[%d;%df%s\x1b8" % (x, y, text)) #sys.stdout.flush() def print_course_details(anchor, course): clear_terminal() waypoint_count = len(course.waypoints) #Get column widths name_width = 0 for key, value in course.waypoints.items():
def test_that_vessel_excepts_a_NMEA_string(self): vessel = Vessel() expected = 'abcd' vessel.NMEAInput(expected) actual = vessel.LastNmeaInput self.assertEqual(expected, actual)