def test_toCheckEpisodeAddsEpisodeObjectID(self): self.ep.setEpisodeID("EA1004H") self.assertEqual(Episode.getShowID(self.ep.episodeID), '1004') self.ep.setEpisodeID("EASP06H") self.assertEqual(Episode.getShowID(self.ep.episodeID), '1506') self.ep.setEpisodeID("EA1G02") self.assertEqual(Episode.getShowID(self.ep.episodeID), '0702')
def test_toCheckEpisodeForSeason(self): self.ep.setEpisodeID("EA1004H") self.assertEqual(Episode.getSeasonNumber(self.ep.episodeID), 10) self.ep.setEpisodeID("EASP06H") self.assertEqual(Episode.getSeasonNumber(self.ep.episodeID), 15) self.ep.setEpisodeID("EA1G02") self.assertEqual(Episode.getSeasonNumber(self.ep.episodeID), 7) self.ep.setEpisodeID("") self.assertEqual(Episode.getSeasonNumber(self.ep.episodeID), 0)
def test_toCheckEpisodeForSeasonEpisodeNumber(self): self.ep.setEpisodeID("EA1004H") self.assertEqual(Episode.getSeasonEpisodeNumber(self.ep.episodeID), 4) self.ep.setEpisodeID("EASP06H") self.assertEqual(Episode.getSeasonEpisodeNumber(self.ep.episodeID), 6) self.ep.setEpisodeID("EA1G02") self.assertEqual(Episode.getSeasonEpisodeNumber(self.ep.episodeID), 2) self.ep.setEpisodeID("") self.assertEqual(Episode.getSeasonEpisodeNumber(self.ep.episodeID), None)
def setUp(self): self.ep = Episode('dummyTitle')
class TestEpisode(unittest.TestCase): """docstring for TestEpisode""" def setUp(self): self.ep = Episode('dummyTitle') # Sanity check test def test_Sanity(self): self.assertEqual(True, True) # Check Episode Constructor # def test_EpisodeForID(self): # self.assertEqual(self.ep.showID, "dummyID") # Check for Episode Title def test_EpisodeForTitle(self): self.assertEqual(self.ep.showTitle, "dummyTitle") # Check for Show Number def test_toCheckEpisodeNumberRemovesOrdinalEnding(self): # check removes 'st' from 'x1st' self.ep.setEpisodeNumber('21st') self.assertEqual(self.ep.episodeNumber, '21') self.ep.setEpisodeNumber('1ST') self.assertEqual(self.ep.episodeNumber, '1') # check removes 'nd' from 'x2nd' self.ep.setEpisodeNumber('92nd') self.assertEqual(self.ep.episodeNumber, '92') # check removes 'rd' from 'x3rd' self.ep.setEpisodeNumber('33rd') self.assertEqual(self.ep.episodeNumber, '33') # check removes 'th' from 'x[4-9]th' self.ep.setEpisodeNumber('24th') self.assertEqual(self.ep.episodeNumber, '24') # Check for xxx(st|nd|rd|th) followed by other text self.ep.setEpisodeNumber('199th Note: If the cranberry episode, Cran Opening, had aired in the US during the same season as it was created, this would have been the 200th episode in the USA.') self.assertEqual(self.ep.episodeNumber, '199') # Check for topics list def test_toCreateListFromAddedTopics(self): self.ep.addTopics("Turkeys, Brining, Electric Knives, Stuffing, Basting, Probe Thermometers") self.assertEqual(self.ep.topicList, sorted(["Turkeys","Brining","Electric", "Knives","Stuffing","Basting","Probe", "Thermometers"])) self.ep.addTopics("Bread Pudding, Bread Stalling, Amylose, Half & Half") self.assertEqual(self.ep.topicList, sorted(["Bread", "Pudding", "Stalling", "Amylose", "Half"])) # Check for recipe list def test_toCreateListfromAddedRecipes(self): self.ep.addRecipes("1) Beef Tenderloin in Salt Crust 2) Perfect Fingerling Potatoes 3) Salt Roasted Shrimp 4) Sauerkraut") self.assertEqual(self.ep.recipeList, ["Beef Tenderloin in Salt Crust","Perfect Fingerling Potatoes","Salt Roasted Shrimp","Sauerkraut"]) self.ep.addRecipes("1. Dan Dan Noodles 2. Ants in Trees 3. Thai Shrimp Spring Rolls") self.assertEqual(self.ep.recipeList, ["Dan Dan Noodles","Ants in Trees","Thai Shrimp Spring Rolls"]) self.ep.addRecipes("None given at FN.com") self.assertEqual(self.ep.recipeList,[]) self.ep.addRecipes("--none--") self.assertEqual(self.ep.recipeList,[]) self.ep.addRecipes("") self.assertEqual(self.ep.recipeList,[]) self.ep.addRecipes(".") self.assertEqual(self.ep.recipeList,[]) # Check for air date def test_toCheckEpisodeForOriginalAirDate(self): self.ep.addAirDate("02.10.2011") self.assertEqual(self.ep.airDate, "2011-02-10T00:00:00") self.ep.addAirDate("7.11.2001") self.assertEqual(self.ep.airDate, "2001-07-11T00:00:00") self.ep.addAirDate("07.??.1998: WTTW, Ch. 11, Chicago, IL 07.07.1999: FoodTV") self.assertEqual(self.ep.airDate, "1999-07-07T00:00:00") self.ep.addAirDate("11.14.1999 (During Season 1)") self.assertEqual(self.ep.airDate, "1999-11-14T00:00:00") self.ep.addAirDate("12.08.2008 in the US 05.26.2008 (maybe) in Canada") self.assertEqual(self.ep.airDate, "2008-12-08T00:00:00") self.ep.addAirDate("10.10.2009 at 10:00 pm") self.assertEqual(self.ep.airDate, "2009-10-10T00:00:00") self.ep.addAirDate("10.26..2009") self.assertEqual(self.ep.airDate, "2009-10-26T00:00:00") # Check for transcript ID def test_toCheckEpisodeForTranscriptID(self): self.ep.addTranscriptID("Turn On the Dark") self.assertEqual(self.ep.transcriptID, "Turn On the Dark") self.ep.addTranscriptID("") self.assertEqual(self.ep.transcriptID, "") # Check if correct season is set def test_toCheckEpisodeForEpisodeID(self): self.ep.setEpisodeID("EA1004H") self.assertEqual(self.ep.episodeID, "EA1004H") # self.ep.setEpisodeID("EASP06H") # self.ep.setEpisodeID("EA1G02") def test_toCheckEpisodeForSeason(self): self.ep.setEpisodeID("EA1004H") self.assertEqual(Episode.getSeasonNumber(self.ep.episodeID), 10) self.ep.setEpisodeID("EASP06H") self.assertEqual(Episode.getSeasonNumber(self.ep.episodeID), 15) self.ep.setEpisodeID("EA1G02") self.assertEqual(Episode.getSeasonNumber(self.ep.episodeID), 7) self.ep.setEpisodeID("") self.assertEqual(Episode.getSeasonNumber(self.ep.episodeID), 0) def test_toCheckEpisodeForSeasonEpisodeNumber(self): self.ep.setEpisodeID("EA1004H") self.assertEqual(Episode.getSeasonEpisodeNumber(self.ep.episodeID), 4) self.ep.setEpisodeID("EASP06H") self.assertEqual(Episode.getSeasonEpisodeNumber(self.ep.episodeID), 6) self.ep.setEpisodeID("EA1G02") self.assertEqual(Episode.getSeasonEpisodeNumber(self.ep.episodeID), 2) self.ep.setEpisodeID("") self.assertEqual(Episode.getSeasonEpisodeNumber(self.ep.episodeID), None) def test_AddingEpisodeTranscript(self): self.ep.addTranscript("This is some placeholder text") self.assertEqual(self.ep.transcriptContent, "This is some placeholder text") def test_toCheckEpisodeAddsEpisodeObjectID(self): self.ep.setEpisodeID("EA1004H") self.assertEqual(Episode.getShowID(self.ep.episodeID), '1004') self.ep.setEpisodeID("EASP06H") self.assertEqual(Episode.getShowID(self.ep.episodeID), '1506') self.ep.setEpisodeID("EA1G02") self.assertEqual(Episode.getShowID(self.ep.episodeID), '0702')
delimiter=',') readData = csv.reader(open('/'.join([filePath[0], inputFileName[1]]), 'r', encoding='utf-8'), delimiter=',') writeData = open('/'.join([filePath[1], outputFileName[0]]), 'w', encoding='utf-8') # Data Structure to hold network node and connectivity information nodesList, linksList, nodeIDs = [], [], [] episodeList, jsonEpisodeList = {}, {} # Create Episode instances and store into dict using showID for line in readMetadata: episode = Episode(line['Title']) episode.setEpisodeID(line['Show #']) episode.addTranscriptID(line['Transcript']) # print(episode.__dict__) episodeList[Episode.getShowID(line['Show #'])] = episode nodeIDs.append(Episode.getShowID(line['Show #'])) # break # Add 'another show' as an extra show as it is always referenced # in the show but never really links anywhere, so put it as a dead-end link episode = Episode('Referenced Mystery Show') episode.setEpisodeID('EA0000') episode.addTranscriptID('Another Show') episodeList[Episode.getShowID('EA0000')] = episode nodeIDs.append(Episode.getShowID('EA0000')) print(nodeIDs)
import csv from EpisodeClass import Episode from collections import OrderedDict, defaultdict filePath = ['../Data', '../DataCleaned'] readFiles = ['goodEatsMetadata.csv', 'goodEatsData.csv'] writeFiles = ['goodEatsJSONData.json'] metadataReader = csv.DictReader(open('/'.join([filePath[0], readFiles[0]]), 'r', encoding='utf-8'), delimiter=',') dataReader = csv.reader(open('/'.join([filePath[0], readFiles[1]]), 'r', encoding='utf-8'), delimiter=',') jsonWriter = open('/'.join([filePath[1], writeFiles[0]]), 'w', encoding='utf-8') # tempvars for debugging and short termination of loops count = 0 episodeList = defaultdict(list) for line in metadataReader: episode = Episode(line['Title']) episode.setEpisodeID(line['Show #']) episode.setEpisodeNumber(line['Show No.']) episode.addAirDate(line['Original Air Date']) episode.addTopics(line['Topics']) episode.addRecipes(line['Recipes']) episode.addTranscriptID(line['Transcript']) if episode.getSeasonNumber(line['Show #']) in episodeList: episodeList[episode.getSeasonNumber(line['Show #'])].append(episode.__dict__) else : episodeList[episode.getSeasonNumber(line['Show #'])] = [episode.__dict__] json.dump(episodeList, jsonWriter)
encoding='utf-8'), delimiter=',') dataReader = csv.reader(open('/'.join([filePath[0], readFiles[1]]), 'r', encoding='utf-8'), delimiter=',') jsonWriter = open('/'.join([filePath[1], writeFiles[0]]), 'w', encoding='utf-8') # tempvars for debugging and short termination of loops count = 0 episodeList = defaultdict(list) for line in metadataReader: episode = Episode(line['Title']) episode.setEpisodeID(line['Show #']) episode.setEpisodeNumber(line['Show No.']) episode.addAirDate(line['Original Air Date']) episode.addTopics(line['Topics']) episode.addRecipes(line['Recipes']) episode.addTranscriptID(line['Transcript']) if episode.getSeasonNumber(line['Show #']) in episodeList: episodeList[episode.getSeasonNumber(line['Show #'])].append( episode.__dict__) else: episodeList[episode.getSeasonNumber( line['Show #'])] = [episode.__dict__] json.dump(episodeList, jsonWriter)
""" MetaData operations for force graph""" # for line in metadataReader: # rNodesList, nodesList = [],[] # linksList = [] # rNodesList.append({'name': Episode.getShowID(line['Show #']), 'group' : Episode.getSeasonNumber(line['Show #'])}) # nodesListLength = len(rNodesList) # for i in range(0, nodesListLength): # nodesList.append(rNodesList[nodesListLength - i - 1]) # if i > 0: # linksList.append({'source' : i - 1, 'target' : i, 'value' : 1}) # json.dump({ 'nodes' : nodesList, 'links' : linksList}, jsonWriter) """ CSV Data-Subset for visualization """ dataset = {} csvWriter.writeheader() for line in metadataReader: episode = Episode(line['Title']) episode.setEpisodeID(line['Show #']) episode.setEpisodeNumber(line['Show No.']) episode.addAirDate(line['Original Air Date']) csvWriter.writerow(episode.__dict__)
# tempvar for debugging count = 0 # Use @staticmethod getShowID as key for EpisodeList and TranscriptList Dictionaries # episodeList = OrderedDict() # transcriptList = {} """ MetaData operations for force graph""" # for line in metadataReader: # rNodesList, nodesList = [],[] # linksList = [] # rNodesList.append({'name': Episode.getShowID(line['Show #']), 'group' : Episode.getSeasonNumber(line['Show #'])}) # nodesListLength = len(rNodesList) # for i in range(0, nodesListLength): # nodesList.append(rNodesList[nodesListLength - i - 1]) # if i > 0: # linksList.append({'source' : i - 1, 'target' : i, 'value' : 1}) # json.dump({ 'nodes' : nodesList, 'links' : linksList}, jsonWriter) """ CSV Data-Subset for visualization """ dataset = {} csvWriter.writeheader() for line in metadataReader: episode = Episode(line['Title']) episode.setEpisodeID(line['Show #']) episode.setEpisodeNumber(line['Show No.']) episode.addAirDate(line['Original Air Date']) csvWriter.writerow(episode.__dict__)