import pandas as pd from file_loader import fileloader fulldata = fileloader() def select_Time_Period(SelDate, EndDate): fulldata['Year'] = fulldata['ACCIDENT_DATE'] fulldata['Month'] = fulldata['ACCIDENT_DATE'] fulldata['Day'] = fulldata['ACCIDENT_DATE'] for line in range(len(fulldata['ACCIDENT_DATE'])): fulldata['Year'][line] = fulldata['ACCIDENT_DATE'][line].split('/')[2] fulldata['Month'][line] = fulldata['ACCIDENT_DATE'][line].split('/')[1] fulldata['Day'][line] = fulldata['ACCIDENT_DATE'][line].split('/')[0] if (line % 749 == 0): print(f'{line//749}%') StartYear = SelDate.split('/')[0] StartMonth = SelDate.split('/')[1] StartDay = SelDate.split('/')[2] EndYear = EndDate.split('/')[0] EndMonth = EndDate.split('/')[1] EndDay = EndDate.split('/')[2] toconcat = [] if (StartYear != EndYear): #middle years df0 = fulldata.loc[fulldata['Year'] > StartYear] df0 = df0.loc[df0['Year'] < EndYear] toconcat.append(df0) # first year
import unittest import pandas as pd from alcoholTimeAnalizerTestVersion import alcoholTimeAnalizer from file_loader import fileloader from file_loader import badfileLoader alteredfile = badfileLoader() emptydf = pd.DataFrame({'' : []}) emptyName = None wrongData = [1,2,3,4,5,6] emptyData = None incorrectName = 'BADNESS' # Valid Names: DAY_OF_WEEK, LIGHT_CONDITION, ALCOHOL_RELATED, SEVERITY correctName1 = 'DAY_OF_WEEK' correctName2 = 'LIGHT_CONDITION' correctName3 = 'ALCOHOL_RELATED' correctName4 = 'SEVERITY' #Valid Data: data data = fileloader() class testAlcoholTimeAnalizer(unittest.TestCase): def testCorrectDataCorrectName1(self): result = alcoholTimeAnalizer(data, correctName1) self.assertEqual(result, 'Success') def testCorrectDataCorrectName2(self): result = alcoholTimeAnalizer(data, correctName2) self.assertEqual(result, 'Success') def testCorrectDataCorrectName3(self):
emptydf = pd.DataFrame({'': []}) emptyName = None wrongData = [1, 2, 3, 4, 5, 6] emptyData = None incorrectName = 'BADNESS' # neither can have an incorrect value for the input # file 2 it is only used in a title # file 3 incorrect data will come up with no matches but will not break anything input1 = 'PED' start = '05/10/2015' end = '05/10/2016' #Valid Data: data data = fileloader() goodData = select_Time_Period(start, end) class DCACodePickerTester(unittest.TestCase): def testCorrectDataCorrectName3(self): result = DCACodePicker(goodData, input1) self.assertEqual(result, 'Success') def testCorrectDataNoName3(self): result = DCACodePicker(goodData, emptyName) self.assertEqual(result, 'No Search Term Supplied') def testEmptyDataName3(self): result = DCACodePicker(emptyData, input1) self.assertEqual(result, 'Unknown Error')