def vin3 (): vin = "NM0KS9BN2CT099422" cont = vp.continent(vin) assert cont == "Asia", f"continent({vin}) == Europe. Got {cont}" count = vp.country(vin) assert count == "Turkey", f"country({vin}) == Turkey. Got {count}" year = vp.year(vin) assert year == 2012, f"year({vin}) == 2012. Got {year}" manuf = vp.manuf(vin) assert manuf == "Ford Turkey", f"manuf({vin}) == Ford Turkey. Got {manuf}" wmi = vp.wmi(vin) assert wmi == "NM0", f"wmi({vin}) == NM0. Got {wmi}" vis = vp.vis(vin) assert vis == "CT099422", f"vis({vin}) == CT099422. Got {vis}" assert vp.is_valid(vin), f"is_valid({vin})" return True
def vin2(): vin = "WAUAH74FX8N034074" cont = vp.continent(vin) assert cont == "Europe", f"continent({vin}) == Europe. Got {cont}" count = vp.country(vin) assert count == "Germany", f"country({vin}) == Germany. Got {count}" year = vp.year(vin) assert year == 2008, f"year({vin}) == 2008. Got {year}" manuf = vp.manuf(vin) assert manuf == "Audi", f"manuf({vin}) == Audi. Got {manuf}" wmi = vp.wmi(vin) assert wmi == "WAU", f"wmi({vin}) == WAU. Got {wmi}" vis = vp.vis(vin) assert vis == "8N034074", f"vis({vin}) == 8N034074. Got {vis}" assert vp.is_valid(vin), f"isvalid({vin})" return True
def vin1 (): vin = "3C6LD5AT8CG295248" cont = vp.continent(vin) assert cont == "North America", f"continent({vin}) == North America, got {cont}" count = vp.country(vin) assert count == "Mexico", f"country({vin}) == Mexico. Got {count}" year = vp.year(vin) assert year == 2012, f"year({vin}) == 2012. Got {year}" manuf = vp.manuf(vin) assert manuf == "Chrysler Mexico", f"manuf({vin}) == Chrysler Mexico. Got {manuf}" wmi = vp.wmi(vin) assert wmi == "3C6", f"wmi({vin}) == 3C6. Got {wmi}" vis = vp.vis(vin) assert vis == "CG295248", f"vis({vin}) == CG295248. Got {vis}" assert vp.is_valid(vin), f"is_valid({vin})" return True
def invalid(): vinl = [ "", "AAA", "JM1BL1M72C158742", "1FTEW1CM9BFA745571", "VIN6135B660801530", "IOQZZZSNZY1063363" ] for vin in vinl: cont = vp.continent(vin) assert cont == False, f"continent({vin}) == False. Got {cont}" count = vp.country(vin) assert count == False, f"country({vin}) == False. Got {count}" year = vp.year(vin) assert year == False, f"year({vin}) == False. False {year}" manuf = vp.manuf(vin) assert manuf == False, f"manuf({vin}) == False. Got {manuf}" wmi = vp.wmi(vin) assert wmi == False, f"wmi({vin}) == False. Got {wmi}" vis = vp.vis(vin) assert vis == False, f"vis({vin}) == False. Got {vis}" assert vp.is_valid(vin) == False, f"is_valid({vin})" return True
def __init__(self, folder='', csvfile='', dbcfile='', recursive=False, **kwargs): # set the csv file based on what we got; if empty, we're probably going to # be doing what's in the passed in folder self.csvfile = csvfile # set the dbcfile to be what is passed in; # if empty we will choose later # if multiple, we will look for one that matches our sensibilities self.dbcfile = dbcfile # print(f'dbcfile={self.dbcfile}') dbcdict = meta.dbcDictionary(self.dbcfile) # print(f'dbcdict={dbcdict}') self.drive = { 'filepath': self.csvfile, 'filename': os.path.basename(self.csvfile) } print(f'Reading {self.csvfile}') try: vin = meta.vin(self.csvfile) self.drive['vin'] = vin makeStr = '' wmiStr = '' # import vin_parser as vp # print('vp omg') try: if vp.check_valid(vin) == True: makeStr = vp.manuf(vin) wmiStr = vp.wmi(vin) self.drive['make'] = makeStr except: print('No valid vin..continuing as Toyota') dbc = None if len(wmiStr) > 0: dbc = dbcdict[wmiStr] # check to confirm that the dbc files match else: print('Error finding correct dbcfile, will use Toyota Version') dbc = dbcdict['2T3'] # print(f'dbc={dbc}') self.r0 = strymread(self.csvfile, dbc) self.drive['date'] = time.ctime(self.r0.dataframe["Time"][0]) duration1 = self.r0.dataframe['Time'][ len(self.r0.dataframe) - 1] - self.r0.dataframe['Time'][0] duration_str = f' Duration of this drive is {duration1} seconds ({math.trunc(int(duration1*1000)/(1000*60))} minutes {math.trunc(duration1 % 60)} seconds).' start_str = f' Starting date/time of the drive is {time.ctime(self.r0.dataframe["Time"][0])}' # get the speed timeseries information from the data file speed_ts = self.r0.speed() # turn the timeseries into a python array for integration # transform from km/hr by multiplying 1000m/1km and 1 hr/3600s to get m/s speed_ar = np.array(speed_ts['Message']) * 1000 / 3600 # speed_ar[0:-1]*1000/3600 # find the difference of the time values # dt = np.diff(np.array(speed_ts['Time'])) dt = np.diff(speed_ts['Time']) # trapezoidal integration, divide by 1000 to get total km (rather than m) # Commented out: this produces negative values that don't make sense # km_ts = np.trapz(y=speed_ar[0:-1],x=dt)/1000 km_ts = np.trapz(y=speed_ar, x=np.array(speed_ts['Time'])) / 1000 # commented out: this produces incorrect values that seem to be off by a factor of around 2, depending km_dx = np.trapz(y=speed_ar, dx=0.02) / 1000 # need to convert km/hr to km/s to get km later when integrating distance_str = f' The trip was {km_ts} km ({km_ts*3.1/5} miles)' # distance_str_dx f' The dx version is {km_dx} km ({km_dx*3.1/5} miles)' #speed_ts['Time'] #f'Total miles driven is {km_ts}' # print(duration_str) # print(start_str) # print(distance_str) # print('') # self.drive = { 'filepath': self.csvfile, 'filename': os.path.basename(self.csvfile), 'distance_km': km_ts, 'distance_miles': km_ts*3.1/5, 'duration_s': duration1, # 'date': time.ctime(self.r0.dataframe["Time"][0]) } self.drive['distance_km'] = km_ts self.drive['distance_miles'] = km_ts * 3.1 / 5 self.drive['duration_s'] = duration1 except Exception as ex: errString = f'Error processing {self.csvfile} with {self.dbcfile}, leaving note in drive (msg={ex}).' self.drive['error'] = errString