diff --git a/README.md b/README.md index 360aaff..122d3ff 100644 --- a/README.md +++ b/README.md @@ -7,4 +7,6 @@ 3. Підібрала та розробила структури даних для вирішення задач дослідження. 14.05.2017 - повністю виконано (згідно вказівок). 4. Накопичила дані та провела дослідження. - 25.05.2017 - повністю виконано (згідно вказівок). \ No newline at end of file + 25.05.2017 - повністю виконано (згідно вказівок). +5. Проаналізувала отримані результати. Оформила звіт та документацію по розробленому програмному забезпеченню. + 26.05.2017 - виконано все, крім відео презентації. \ No newline at end of file diff --git a/build/lib/examples/Example of usage of the API.py b/build/lib/examples/Example of usage of the API.py new file mode 100644 index 0000000..bf609f4 --- /dev/null +++ b/build/lib/examples/Example of usage of the API.py @@ -0,0 +1,109 @@ +from pytvdbapi import api + +db = api.TVDB("1D6897F57A08B0BA") + + +def actors(): + """ + Prints the information about actors, their roles and their photos (from "Sherlock"). + """ + result = db.search("Sherlock", "en") + show = result[0] + show.load_actors() + for actor in range(len(show.actor_objects)): + print(u"{0} - {1} - {2}".format(show.actor_objects[actor].Name, show.actor_objects[actor].Role, + show.actor_objects[actor].image_url)) + + +def seasons_and_episodes(): + """ + Prints the number of seasons in "Sherlock" and then prints the + title of every episode. + """ + result = db.search("Sherlock", "en") + show = result[0] + print("\n") + print("The number of seasons: ", len(show)) + for episode in show[2]: + print(episode.EpisodeName) + + +def show(): + """ + Prints the set of basic attributes and + the full data set from the server. + """ + result = db.search("dexter", "en") + show = result[0] + print(dir(show)) # List the set of basic attributes + show.update() # Load the full data set from the server + print(dir(show)) + + +def episode(): + """ + Prints information about 1 episode from 1 season in "Sherlock". + """ + result = db.search("Sherlock", "en") + show = result[0] + episode = show[1][2] # Get episode S01E02 + print(episode.season) + print(episode.EpisodeNumber) + print(episode.EpisodeName) + print(episode.FirstAired) + + +def languages(): + """ + Prints the list of available languages. + """ + for language in api.languages(): + print(language) + + +def search(): + """ + Searches episodes which have in their titles word + "Sherlock". Prints it. + """ + result = db.search("Sherlock", "en") + print(result[0], "\n") + for show in result: + print(show) + + +def get_series(): + """ + Finds a series by its ID. + """ + a = 79349 + show = db.get_series(a, "en") # Load Dexter + print("ID:", a, "\n", show.SeriesName) + + +def get_episode(): + """ + Finds episods by diven parameters. + """ + ep = db.get_episode("en", episodeid=308834) # id is the default method + print(ep.EpisodeName, "\n") + ep1 = db.get_episode("en", "dvd", seasonnumber=2, episodenumber=5, seriesid=79349) + print(ep1.EpisodeName, "\n") + ep2 = db.get_episode("en", "default", seasonnumber=2, episodenumber=6, seriesid=79349) + print(ep2.EpisodeName, "\n") + + +def banner(): + """ + Prints the url link to banner of a certain series. + """ + db = api.TVDB('B43FF87DE395DF56', banners=True) + show = db.get_series(79349, "en") # Dexter + show.update() + assert len(show.banner_objects) > 0 + banner = show.banner_objects[0] + print(banner.banner_url) + print(banner.Language) + + +actors() diff --git a/build/lib/examples/Example of usage of the SeriesResearch ADT.py b/build/lib/examples/Example of usage of the SeriesResearch ADT.py new file mode 100644 index 0000000..2e01a20 --- /dev/null +++ b/build/lib/examples/Example of usage of the SeriesResearch ADT.py @@ -0,0 +1,35 @@ +from modules.series_research import SeriesResearch + + +def example(): + """ + The example of usage of the SeriesResearch ADT. + """ + # Creates a new array (length = 2) + new_array = SeriesResearch(2) + + # Sets values to each element of the array. + new_array.set_item(0, "Sherlock") + new_array.set_item(1, "Doctor Who") + + # Gets values and prints it. + print("Item 0 = ", new_array.get_item(0)) + print("Item 1 = ", new_array.get_item(1)) + + # Gets lists of actors. + actors0 = new_array.get_actors(0) + actors1 = new_array.get_actors(1) + + # Prints these lists. + print(actors0) + print(actors1) + + # Finds the number of seasons in series. + seasons0 = new_array.seasons_number(0) + seasons1 = new_array.seasons_number(1) + + # Prints the number of seasons. + print("The number of seasons in", new_array.get_item(0), ":", seasons0) + print("The number of seasons in", new_array.get_item(1), ":", seasons1) + +example() diff --git a/build/lib/modules/an_array.py b/build/lib/modules/an_array.py new file mode 100644 index 0000000..fd9d446 --- /dev/null +++ b/build/lib/modules/an_array.py @@ -0,0 +1,49 @@ +import ctypes + + +class AnArray: + """ + Creates an array and gives some tools to work with it. + """ + def __init__(self, size): + """ + Creates an array with the length size. + + :param size: the size of the array. + """ + assert size > 0, "Array size must be > 0" + self._size = size + pyarraytype = ctypes.py_object * size + self._elements = pyarraytype() + for i in range(len(self)): + self._elements[i] = None + + def __len__(self): + """ + Returns the length of the array. + + :return: the size of the array. + """ + return self._size + + def __getitem__(self, index): + """ + Gets the value of the element. + + :param index: the index of element. + :return: value of the element. + """ + if not 0 <= index < self._size: + raise IndexError('Invalid index') + return self._elements[index] + + def __setitem__(self, index, value): + """ + Puts the value in the array element at index position. + + :param index: the index element. + :param value: the value of element. + """ + if not 0 <= index < self._size: + raise IndexError('Invalid index') + self._elements[index] = value diff --git a/build/lib/modules/my_research.py b/build/lib/modules/my_research.py new file mode 100644 index 0000000..9fbec0a --- /dev/null +++ b/build/lib/modules/my_research.py @@ -0,0 +1,133 @@ +from modules.work_with_a_file import WorkWithAFile +from modules.series_research import SeriesResearch + + +class MainResearch: + """ + This class represents methods which help to do some research. + """ + + def __init__(self): + """ + Reads the information from a file. + Makes an array which contains that information. + """ + file = WorkWithAFile("ratings.txt") + file1 = file.open_file() + my_lst = file.make_list(file1) + self.series = SeriesResearch(len(my_lst)) + for i in range(self.series.find_len()): + self.series.set_item(i, my_lst[i]) + + def __str__(self): + """ + Creates a string with series titles. + + :return: a string with series titles + """ + series = '' + for i in range(self.series.find_len()): + series += self.series.get_item(i) + ' , ' + return series + + def popular_actors(self): + """ + Creates a dictionary. Gets the information about all + actors from given series and adds it to the dictionary + (key - the name of an actor/actress, value - the number of series + in which that actor/actress performed). + + :return: a dictionary (key - the name of an actor/actress, value - + the number of series in which that actor/actress performed) + """ + actors = {} + for i in range(self.series.find_len()): + try: + actors_from_series = self.series.get_actors(i) + for actor in actors_from_series: + if actor not in actors: + actors[actor] = 1 + else: + actors[actor] += 1 + except IndexError: + continue + return actors + + def series_seasons(self): + """ + Creates a dictionary. Gets the information about number of seasons + in series adds it to the dictionary (key - series title, value - the number + of seasons). + + :return: a dictionary (key - series title, value - the number of seasons). + """ + seasons = {} + for i in range(self.series.find_len()): + try: + seasons[self.series.get_item(i)] = self.series.seasons_number(i) + except IndexError: + continue + return seasons + + def series_titles(self): + """ + Creates a dictionary. Gets every word from series titles and adds it + to the dictionary(key - word, value - the number of repetition in + series titles). + + :return: the dictionary(key - word, value - the number of + repetition in series titles). + """ + words = {} + for i in range(self.series.find_len()): + word = self.series.get_item(i).split() + for k in word: + if k not in words: + words[k] = 1 + else: + words[k] += 1 + return words + + +def save_info(info, filename): + """ + Creates a new file with a name filename. + Writes the information from info into this file. + + :param info: a list of tuples with the information + that should be saved. + :param filename: a name of a created file. + """ + thefile = open(filename, 'w') + for item in info: + thefile.write(str(item[1]) + " - " + str(item[0]) + '\n') + + +def main(): + """ + Makes the main research. + """ + series = MainResearch() + + # actors + actors_list = [] + allactors = series.popular_actors() + for key, val in allactors.items(): + if val > 1: + actors_list.append((key, val)) + save_info(sorted(actors_list, key=lambda x: x[1], reverse=True), "popular_actors.txt") + + # seasons + average = 0 + allseasons = series.series_seasons() + save_info(sorted(allseasons.items(), key=lambda x: x[1], reverse=True), "series_seasons.txt") + for key, val in allseasons.items(): + average += val + + # titles + alltitles = series.series_titles() + save_info(sorted(alltitles.items(), key=lambda x: x[1], reverse=True), "series_titles.txt") + return int(average / 47) + + +print(main()) diff --git a/build/lib/modules/series_research.py b/build/lib/modules/series_research.py new file mode 100644 index 0000000..06ae4ae --- /dev/null +++ b/build/lib/modules/series_research.py @@ -0,0 +1,76 @@ +from pytvdbapi import api +from modules.an_array import AnArray + +db = api.TVDB("1D6897F57A08B0BA") + + +class SeriesResearch: + """ + Implements the SeriesResearch ADT for doing + research based of the information about series. + """ + + def __init__(self, length): + """ + Creates an array. + + :param length: the length of a created array. + """ + self.length = length + self.allseries = AnArray(self.length) + + def get_item(self, index): + """ + Gets the value of the element. + + :param index: the index of the element. + :return: value of the element. + """ + return self.allseries.__getitem__(index) + + def set_item(self, index, value): + """ + Puts the value in the array element at index position. + + :param index: the index the element. + :param value: the value of the element. + """ + self.allseries.__setitem__(index, value) + + def find_len(self): + """ + Returns the length of the array. + + :return: the size of the array. + """ + return self.allseries.__len__() + + def get_actors(self, index): + """ + Gets actors from series (the value of the element is + the name of series). + + :param index: the index of the element. + :return: the list of actors. + """ + series = self.get_item(index) + actors = [] + result = db.search(str(series), "en") + show = result[0] + show.load_actors() + for actor in range(len(show.actor_objects)): + actors.append(show.actor_objects[actor].Name) + return actors + + def seasons_number(self, index): + """ + Gets the number of seasons in the given series + (the value of the element is the name of series). + + :param index: the index of the element. + :return: the number of seasons. + """ + series = self.get_item(index) + result = db.search(str(series), "en") + show = result[0] + return len(show) diff --git a/build/lib/modules/work_with_a_file.py b/build/lib/modules/work_with_a_file.py new file mode 100644 index 0000000..1ba7ce8 --- /dev/null +++ b/build/lib/modules/work_with_a_file.py @@ -0,0 +1,47 @@ +# Class WorkWithAFile is created to read information from a file +# ratings.txt and to convert it into a list of series names. + + +class WorkWithAFile: + """ + Contains functions open_file() and make_list(). + To work with this class you should specify a filename. + """ + + def __init__(self, filename): + """ + Creates an empty list. + :param filename: the name of a file. + """ + self.series = [] + self.filename = filename + + def open_file(self): + """ + Opens a file and saves all the information in a list + (split by newlines). + :return: a list with all the information from the file. + """ + all_series = [] + openfile = open(self.filename, encoding="utf-8") + whole_file = openfile.readline() + while not whole_file.endswith("Forgotten Lady (Season 5, Episode 1)"): + whole_file = openfile.readline() + all_series.append(whole_file) + return all_series + + def make_list(self, lst): + """ + Creates a list of series names. + :param lst: a list with all the information from the file. + :return: a list of series names. + """ + for i in range(0, len(lst), 5): + if i < 45: + self.series.append(lst[i][3:-1]) + else: + self.series.append(lst[i][4:-1]) + for name in range(len(self.series)): + if "(" in self.series[name]: + self.series[name] = self.series[name][:self.series[name].index("(") - 1] + return self.series diff --git a/build/scripts-3.5/my_research.py b/build/scripts-3.5/my_research.py new file mode 100644 index 0000000..9fbec0a --- /dev/null +++ b/build/scripts-3.5/my_research.py @@ -0,0 +1,133 @@ +from modules.work_with_a_file import WorkWithAFile +from modules.series_research import SeriesResearch + + +class MainResearch: + """ + This class represents methods which help to do some research. + """ + + def __init__(self): + """ + Reads the information from a file. + Makes an array which contains that information. + """ + file = WorkWithAFile("ratings.txt") + file1 = file.open_file() + my_lst = file.make_list(file1) + self.series = SeriesResearch(len(my_lst)) + for i in range(self.series.find_len()): + self.series.set_item(i, my_lst[i]) + + def __str__(self): + """ + Creates a string with series titles. + + :return: a string with series titles + """ + series = '' + for i in range(self.series.find_len()): + series += self.series.get_item(i) + ' , ' + return series + + def popular_actors(self): + """ + Creates a dictionary. Gets the information about all + actors from given series and adds it to the dictionary + (key - the name of an actor/actress, value - the number of series + in which that actor/actress performed). + + :return: a dictionary (key - the name of an actor/actress, value - + the number of series in which that actor/actress performed) + """ + actors = {} + for i in range(self.series.find_len()): + try: + actors_from_series = self.series.get_actors(i) + for actor in actors_from_series: + if actor not in actors: + actors[actor] = 1 + else: + actors[actor] += 1 + except IndexError: + continue + return actors + + def series_seasons(self): + """ + Creates a dictionary. Gets the information about number of seasons + in series adds it to the dictionary (key - series title, value - the number + of seasons). + + :return: a dictionary (key - series title, value - the number of seasons). + """ + seasons = {} + for i in range(self.series.find_len()): + try: + seasons[self.series.get_item(i)] = self.series.seasons_number(i) + except IndexError: + continue + return seasons + + def series_titles(self): + """ + Creates a dictionary. Gets every word from series titles and adds it + to the dictionary(key - word, value - the number of repetition in + series titles). + + :return: the dictionary(key - word, value - the number of + repetition in series titles). + """ + words = {} + for i in range(self.series.find_len()): + word = self.series.get_item(i).split() + for k in word: + if k not in words: + words[k] = 1 + else: + words[k] += 1 + return words + + +def save_info(info, filename): + """ + Creates a new file with a name filename. + Writes the information from info into this file. + + :param info: a list of tuples with the information + that should be saved. + :param filename: a name of a created file. + """ + thefile = open(filename, 'w') + for item in info: + thefile.write(str(item[1]) + " - " + str(item[0]) + '\n') + + +def main(): + """ + Makes the main research. + """ + series = MainResearch() + + # actors + actors_list = [] + allactors = series.popular_actors() + for key, val in allactors.items(): + if val > 1: + actors_list.append((key, val)) + save_info(sorted(actors_list, key=lambda x: x[1], reverse=True), "popular_actors.txt") + + # seasons + average = 0 + allseasons = series.series_seasons() + save_info(sorted(allseasons.items(), key=lambda x: x[1], reverse=True), "series_seasons.txt") + for key, val in allseasons.items(): + average += val + + # titles + alltitles = series.series_titles() + save_info(sorted(alltitles.items(), key=lambda x: x[1], reverse=True), "series_titles.txt") + return int(average / 47) + + +print(main()) diff --git a/dist/coursework2017-1.0.win-amd64.exe b/dist/coursework2017-1.0.win-amd64.exe new file mode 100644 index 0000000..210d9ab Binary files /dev/null and b/dist/coursework2017-1.0.win-amd64.exe differ diff --git a/dist/coursework2017-1.0.zip b/dist/coursework2017-1.0.zip new file mode 100644 index 0000000..ca60682 Binary files /dev/null and b/dist/coursework2017-1.0.zip differ diff --git a/doc/Conclusions.docx b/doc/Conclusions.docx index cd53ca4..2be73c1 100644 Binary files a/doc/Conclusions.docx and b/doc/Conclusions.docx differ