def display_get_date_ordered(): """Display ordered list of the games by date and alphabet order.""" ordered_games = reports.get_date_ordered(filename) print("Ordered games by date and by alphabet:") for title in ordered_games: print(title) print()
def printing(): fallback_file_name = "game_stat.txt" file_name = input("Which file should I analyze? (default: game_stat.txt) ") if not file_name: file_name = fallback_file_name try: file_name = check_file(file_name, fallback_file_name) except FileNotFoundError as e: print("No such file. Exiting...") else: print("1.", reports.get_most_played(file_name)) print("2.", reports.sum_sold(file_name)) print("3.", reports.get_selling_avg(file_name)) print("4.", reports.count_longest_title(file_name)) print("5.", reports.get_date_avg(file_name)) title = input("6. Which game? ") print(" ", reports.get_game(file_name, title)) print("B-1.") count_by_genre = reports.count_grouped_by_genre(file_name) for key in count_by_genre: print(" ", count_by_genre[key], key) titles_ordered_by_date = reports.get_date_ordered(file_name) print("B-2.") for title in titles_ordered_by_date: print(" ", title)
def main(): EXPORT_FILE = "reports.txt" FILE_NAME = "game_stat.txt" with open(EXPORT_FILE, "w") as file: file.write("The top played game is {0:s}.\n".format( r.get_most_played())) file.write("Total game copies sold: {0:.3f} million.\n".format( r.sum_sold())) file.write("The average selling was {0:.3f} million.\n".format( r.get_selling_avg())) file.write("The longest game title is {0:d} characters long.\n".format( r.count_longest_title())) file.write("The average of the release dates is {0:d}\n".format( r.get_date_avg())) game_to_examine = input( "Which games' properties would you like to see?: ") file.write("Properties of {0:s}:\n".format(game_to_examine)) write_list_tabbed(r.get_game(FILE_NAME, game_to_examine), file) file.write("\nTotal games by genre:\n") genres = r.count_grouped_by_genre() for k in genres: file.write("\t{0:s} : {1:d}\n".format(k, genres.get(k))) file.write("\nAvailable games sorted by release date: \n") write_list_tabbed(r.get_date_ordered(), file)
def test_bonus_2_get_date_ordered(self): result = reports.get_date_ordered(self.input_file) expected_result = get_date_ordered() self.assertEqual(result, expected_result) if result == expected_result: print("Bonus function 'get_date_ordered' is passed.")
def printing_reports(): print( reports.get_most_played( "/home/daniel/codecool/3rd_si/pbwp-3rd-si-game-statistics-flachdaniel/part2/game_stat.txt" )) print( reports.sum_sold( "/home/daniel/codecool/3rd_si/pbwp-3rd-si-game-statistics-flachdaniel/part2/game_stat.txt" )) print( reports.get_selling_avg( "/home/daniel/codecool/3rd_si/pbwp-3rd-si-game-statistics-flachdaniel/part2/game_stat.txt" )) print( reports.count_longest_title( "/home/daniel/codecool/3rd_si/pbwp-3rd-si-game-statistics-flachdaniel/part2/game_stat.txt" )) print( reports.get_date_avg( "/home/daniel/codecool/3rd_si/pbwp-3rd-si-game-statistics-flachdaniel/part2/game_stat.txt" )) print( reports.get_game( "/home/daniel/codecool/3rd_si/pbwp-3rd-si-game-statistics-flachdaniel/part2/game_stat.txt", "Minecraft")) print( reports.count_grouped_by_genre( "/home/daniel/codecool/3rd_si/pbwp-3rd-si-game-statistics-flachdaniel/part2/game_stat.txt" )) print( reports.get_date_ordered( "/home/daniel/codecool/3rd_si/pbwp-3rd-si-game-statistics-flachdaniel/part2/game_stat.txt" ))
def printing_get_date_ordered(file_name): """returns date ordered list of the titles""" result = reports.get_date_ordered(file_name) print ("Date ordered (descending) list of titles:") for nr, game in enumerate(result, 1): print (nr, ".", game) print()
def test_bonus_2_get_date_ordered(self): result = reports.get_date_ordered(self.input_file) expected_result = get_date_ordered() self.assertEqual(result, expected_result) if result == expected_result: self.points += 1 print("Bonus function 'get_date_ordered' is passed. 1 points.")
def export_the_reports(export_file_name, file_name, title): results = [reports.get_most_played(file_name), reports.sum_sold(file_name), reports.get_selling_avg(file_name), reports.count_longest_title(file_name), reports.get_date_avg(file_name), reports.get_game(file_name, title), reports.count_grouped_by_genre(file_name), reports.get_date_ordered(file_name)] with open(export_file_name, "w") as export_file: for item in results: export_file.write("%s\n" % item)
def main(): print(reports.get_most_played()) print(reports.sum_sold()) print(reports.get_selling_avg()) print(reports.count_longest_title()) print(reports.get_date_avg()) print(reports.get_game("game_stat.txt", "Half-Life 2")) print(reports.count_grouped_by_genre()) print(reports.get_date_ordered())
def print_the_answers(file_name, title): print(reports.get_most_played(file_name)) print(reports.sum_sold(file_name)) print(reports.get_selling_avg(file_name)) print(reports.count_longest_title(file_name)) print(reports.get_date_avg(file_name)) print(reports.get_game(file_name, title)) print(reports.count_grouped_by_genre(file_name)) print(reports.get_date_ordered(file_name))
def main(data_file): os.system('clear') printer(reports.get_most_played(data_file), str(reports.sum_sold(data_file)), str(round(reports.get_selling_avg(data_file), 2)), str(reports.count_longest_title(data_file)), str(reports.get_date_avg(data_file)), title_input(data_file), str(reports.count_grouped_by_genre(data_file)), str(reports.get_date_ordered(data_file)))
def main(): print(reports.get_most_played("game_stat.txt"), reports.sum_sold("game_stat.txt"), reports.get_selling_avg("game_stat.txt"), reports.count_longest_title("game_stat.txt"), reports.get_date_avg("game_stat.txt"), reports.get_game("game_stat.txt", "Doom 3"), reports.count_grouped_by_genre("game_stat.txt"), reports.get_date_ordered("game_stat.txt"), sep="\n")
def printing_reports(): import reports print(reports.get_most_played("game_stat.txt")) print(reports.sum_sold("game_stat.txt")) print(reports.get_selling_avg("game_stat.txt")) print(reports.count_longest_title("game_stat.txt")) print(reports.get_date_avg("game_stat.txt")) print(reports.get_game("game_stat.txt", "World of Warcraft")) print(reports.count_grouped_by_genre("game_stat.txt")) print(reports.get_date_ordered("game_stat.txt"))
def export_to_txt(file_name, title, exp_file="answers.txt"): with open(exp_file, "w") as text_file: text_file.write("{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n".format( str(reports.get_most_played(file_name)), str(reports.sum_sold(file_name)), str(reports.get_selling_avg(file_name)), str(reports.count_longest_title(file_name)), str(reports.get_date_avg(file_name)), str(reports.get_game(file_name, title)), str(reports.count_grouped_by_genre(file_name)), str(reports.get_date_ordered(file_name))))
def export(): fallback_file_name = "game_stat.txt" file_name = input("Which file should I analyze? (default: game_stat.txt) ") if not file_name: file_name = fallback_file_name try: file_name = check_file(file_name, fallback_file_name) except FileNotFoundError as e: print("No such file. Exiting...") else: title = input('6. "What properties has a game?" Which game? ') open( "export.txt", 'w').close() # clearing export.txt if exists or creating it if not with open("export.txt", 'a') as export_file: export_file.write( "1. What is the title of the most played game? " + reports.get_most_played(file_name) + '\n') export_file.write("2. How many copies have been sold total? " + str(reports.sum_sold(file_name)) + '\n') export_file.write("3. What is the average selling? " + str(reports.get_selling_avg(file_name)) + '\n') export_file.write( "4. How many characters long is the longest title? " + str(reports.count_longest_title(file_name)) + '\n') export_file.write("5. What is the average of the release dates? " + str(reports.get_date_avg(file_name)) + '\n') export_file.write("6. What properties has %s?" % title + '\n') export_file.write(" Name: " + reports.get_game(file_name, title)[0] + '\n') export_file.write(" Million sold: " + str(reports.get_game(file_name, title)[1]) + '\n') export_file.write(" Release date: " + str(reports.get_game(file_name, title)[2]) + '\n') export_file.write(" Genre: " + reports.get_game(file_name, title)[3] + '\n') export_file.write(" Publisher: " + reports.get_game(file_name, title)[4] + '\n') export_file.write( "B-1. How many games are there grouped by genre?" + '\n') count_by_genre = reports.count_grouped_by_genre(file_name) for key in count_by_genre: export_file.write(" " + str(count_by_genre[key]) + " " + key + '\n') del count_by_genre export_file.write( "B-2. What is the date ordered list of the games?" + '\n') titles_ordered_by_date = reports.get_date_ordered(file_name) for title in titles_ordered_by_date: export_file.write(" " + title + '\n') print("Exported answers into export.txt")
def export_reports_answers(file_name, title, export_file="export_reports2.txt"): file = open(export_file, "w") file.write("The most played game is: {}\n".format(reports.get_most_played(file_name))) file.write("The total number of the copies have been sold is: {}\n".format(reports.sum_sold(file_name))) file.write("The average selling is: {}\n".format(reports.get_selling_avg(file_name))) file.write("The longest title cosists of {} characters.\n".format(reports.count_longest_title(file_name))) file.write("The average of the release dates is: {}\n".format(reports.get_date_avg(file_name))) file.write("The properties of the game is: {}\n".format(reports.get_game(file_name, title))) file.write("The number of games sorted by genre: {}\n".format(reports.count_grouped_by_genre(file_name))) file.write("Date ordered list of the games: {}\n".format(reports.get_date_ordered(file_name))) file.close()
def export_answers(file_name='export_judy.txt'): with open(file_name, "w") as txt: lines_of_text = [reports.get_most_played('game_stat.txt'), \ str(reports.sum_sold('game_stat.txt')),\ str(reports.get_selling_avg('game_stat.txt')), \ str(reports.count_longest_title('game_stat.txt')), \ str(reports.get_date_avg('game_stat.txt')),\ str(reports.get_game('game_stat.txt', 'Age of Empires')),\ str(reports.count_grouped_by_genre('game_stat.txt')),\ str(reports.get_date_ordered('game_stat.txt'))] for item in lines_of_text: txt.write('%s\n' % item)
def main(data_file): os.system('clear') exporter(export_name(), reports.get_most_played(data_file), str(reports.sum_sold(data_file)), str(round(reports.get_selling_avg(data_file), 2)), str(reports.count_longest_title(data_file)), str(reports.get_date_avg(data_file)), title_input(data_file), str(reports.count_grouped_by_genre(data_file)), str(reports.get_date_ordered(data_file))) print("Export was successfull!")
def export(): fw = open("reports.txt", "w") fw.writelines([ str(r.count_grouped_by_genre("game_stat.txt")) + "\n", str(r.get_date_ordered("game_stat.txt")) + "\n", str(r.get_most_played("game_stat.txt")) + "\n", str(r.sum_sold("game_stat.txt")) + "\n", str(r.get_selling_avg("game_stat.txt")) + "\n", str(r.count_longest_title("game_stat.txt")) + "\n", str(r.get_date_avg("game_stat.txt")) + "\n", str(r.get_game("game_stat.txt", "Diablo III")) + "\n" ])
def get_answers(inputs): """Returns a single string for the file exporter""" file_name, title = inputs answers = (reports.get_most_played(file_name) + "\n" + str(reports.sum_sold(file_name)) + "\n" + str(reports.get_selling_avg(file_name)) + "\n" + str(reports.count_longest_title(file_name)) + "\n" + str(reports.get_date_avg(file_name)) + "\n" + str(reports.get_game(file_name, title)) + "\n" + str(reports.count_grouped_by_genre(file_name)) + "\n" + str(reports.get_date_ordered(file_name)) + "\n") return answers
def export_results(filename="results.txt"): with open(filename, "w") as export_file: export_file.write(str(reports.get_most_played("game_stat.txt")) + "\n") export_file.write(str(reports.sum_sold("game_stat.txt")) + "\n") export_file.write(str(reports.get_selling_avg("game_stat.txt")) + "\n") export_file.write( str(reports.count_longest_title("game_stat.txt")) + "\n") export_file.write(str(reports.get_date_avg("game_stat.txt")) + "\n") export_file.write( str(reports.get_game("game_stat.txt", "World of Warcraft")) + "\n") export_file.write( str(reports.count_grouped_by_genre("game_stat.txt")) + "\n") export_file.write( str(reports.get_date_ordered("game_stat.txt")) + "\n")
def print_results(): print(reports.get_most_played(open_file('game_stat.txt'))) print(reports.sum_sold(open_file('game_stat.txt'))) print(reports.get_selling_avg(open_file('game_stat.txt'))) print(reports.count_longest_title(open_file('game_stat.txt'))) print(reports.get_date_avg(open_file('game_stat.txt'))) print(reports.get_name(open_file('game_stat.txt'), 'Minecraft')) print(reports.count_grouped_by_genre(open_file('game_stat.txt'))) print(reports.get_date_ordered(open_file('game_stat.txt')))
def export_file(file_name): file = open(file_name, "w", newline='') writer = csv.writer(file, quoting=csv.QUOTE_MINIMAL) data = [ reports.get_most_played("game_stat.txt"), reports.sum_sold("game_stat.txt"), reports.get_selling_avg("game_stat.txt"), reports.count_longest_title("game_stat.txt"), reports.get_date_avg("game_stat.txt"), reports.get_game("game_stat.txt", "Minecraft"), reports.count_grouped_by_genre("game_stat.txt"), reports.get_date_ordered("game_stat.txt") ] for answer in data: writer.writerow([answer]) file.close()
def exporting_answers(): import reports with open("export_answers_2.txt", "w") as f: f.write(str(reports.get_most_played("game_stat.txt"))) f.write("\n") f.write(str(reports.sum_sold("game_stat.txt"))) f.write("\n") f.write(str(reports.get_selling_avg("game_stat.txt"))) f.write("\n") f.write(str(reports.count_longest_title("game_stat.txt"))) f.write("\n") f.write(str(reports.get_date_avg("game_stat.txt"))) f.write("\n") f.write(str(reports.get_game("game_stat.txt", "World of Warcraft"))) f.write("\n") f.write(str(reports.count_grouped_by_genre("game_stat.txt"))) f.write("\n") f.write(str(reports.get_date_ordered("game_stat.txt")))
def reports_answers_prints(file_name, title): pp = pprint.PrettyPrinter(indent=1, compact=False) print("The most played game is: {}".format( reports.get_most_played(file_name))) print("The total number of the copies have been sold is: {}".format( reports.sum_sold(file_name))) print("The average selling is: {}".format( reports.get_selling_avg(file_name))) print("The longest title cosists of {} characters.".format( reports.count_longest_title(file_name))) print("The average of the release dates is: {}".format( reports.get_date_avg(file_name))) print("The properties of the game is: {}".format( reports.get_game(file_name, title))) print("The number of games sorted by genre: ") pp.pprint(reports.count_grouped_by_genre(file_name)) print("Date ordered list of the games: ") pp.pprint(reports.get_date_ordered(file_name)) return
def export(source_file_name,output_file_name): reports_export = open(output_file_name, "w+") reports_export.writelines("What is the title of the most played game?:" + "\n") reports_export.writelines(reports.get_most_played(source_file_name) + "\n") reports_export.writelines("How many copies have been sold total?:" + "\n") reports_export.writelines(str(reports.sum_sold(source_file_name))+ "\n") reports_export.writelines("What is the average selling?:" + "\n") reports_export.writelines(str(reports.get_selling_avg(source_file_name))+ "\n") reports_export.writelines("How many characters long is the longest title?:" + "\n") reports_export.writelines(str(reports.count_longest_title(source_file_name))+ "\n") reports_export.writelines("What is the average of the release dates?:" + "\n") reports_export.writelines(str(reports.get_date_avg(source_file_name))+ "\n") reports_export.writelines("What properties has a game?:" + "\n") reports_export.writelines(str(reports.get_game(source_file_name,"Counter-Strike"))+ "\n") reports_export.writelines("How many games are there grouped by genre?:" + "\n") reports_export.writelines(str(reports.count_grouped_by_genre(source_file_name))+ "\n") reports_export.writelines("What is the date ordered list of the games?:" + "\n") reports_export.writelines(reports.get_date_ordered(source_file_name)) reports_export.close()
def file_export(export_file_name, title): with open(export_file_name, 'w') as f: f.write("1. What is the most played game?\n") f.write(str(reports.get_most_played(file_name)) + "\n") f.write("2. How many copies have been sold total?\n") f.write(str(reports.sum_sold(file_name)) + "\n") f.write("3. What is the average selling??\n") f.write(str(reports.get_selling_avg(file_name)) + "\n") f.write("4. How many characters long is the longest title? \n") f.write(str(reports.count_longest_title(file_name)) + "\n") f.write("5. What is the average of the release dates? \n") f.write(str(reports.get_date_avg(file_name)) + "\n") f.write("6. What properties has a game? Title =" + title + "\n") f.write(str(reports.get_game(file_name, title)) + "\n") f.write("------------------------------------\n" + "Extra\n") f.write("1. How many games are there grouped by genre?\n") f.write(str(reports.count_grouped_by_genre(file_name)) + '\n') f.write( "2. What is the date ordered list of the games in descending order?\n" ) f.write(str(reports.get_date_ordered(file_name)) + '\n')
def printing(file_name, repo): # Exercise 1 print_exercise(1) print('Title of the most played game: {}'.format(reports.get_most_played(file_name))) print('Title of the most played game: {}'.format(repo.get_most_played())) # Exercise 2 print_exercise(2) print('Total copies sold: {}'.format(reports.sum_sold(file_name))) print('Total copies sold: {}'.format(repo.sum_sold())) # Exercise 3 print_exercise(3) print('Average of the sellings: {}'.format(reports.get_selling_avg(file_name))) print('Average of the sellings: {}'.format(repo.get_selling_avg())) # Exercise 4 print_exercise(4) print('Longest title in the statistics: {}'.format(reports.count_longest_title(file_name))) print('Longest title in the statistics: {}'.format(repo.count_longest_title())) # Exercise 5 print_exercise(5) print('The average of the release dates: {}'.format(reports.get_date_avg(file_name))) print('The average of the release dates: {}'.format(repo.get_date_avg())) # Exercise 6 print_exercise(6) print('What are the properties of the given game?') title = input('Please give the title of the game: ') try: print(reports.get_game(file_name, title)) print(repo.get_game(title)) except ValueError: print('There is no game with the title {}'.format(title)) # Exercise 7 print_exercise(7) print('Genres in the statistics: ') print(reports.count_grouped_by_genre(file_name)) print(repo.count_grouped_by_genre()) # Exercise 8 print_exercise(8) print('Date ordered games: ') print(reports.get_date_ordered(file_name)) print(repo.get_date_ordered())
def main(): exporting = open('export.txt', 'w') exporting.write("The most played game: ") exporting.write(str(reports.get_most_played('game_stat.txt'))) exporting.write('\n') exporting.write('\n') exporting.write("Games total sold :") exporting.write(str(reports.sum_sold('game_stat.txt'))) exporting.write('\n') exporting.write('\n') exporting.write("Average Selling: ") exporting.write(str(reports.get_selling_avg("game_stat.txt"))) exporting.write('\n') exporting.write('\n') exporting.write("Longest title is (character long): ") exporting.write(str(reports.count_longest_title("game_stat.txt"))) exporting.write('\n') exporting.write('\n') exporting.write("Average release date is: ") exporting.write(str(reports.get_date_avg("game_stat.txt"))) exporting.write('\n') exporting.write('\n') exporting.write("The games asked properties: ") exporting.write(str(reports.get_game("game_stat.txt", "Minecraft"))) exporting.write('\n') exporting.write('\n') exporting.write("Count each genre:") exporting.write(str(reports.count_grouped_by_genre("game_stat.txt"))) exporting.write('\n') exporting.write('\n') exporting.write("Date ordered list of games: ") exporting.write(str(reports.get_date_ordered("game_stat.txt"))) exporting.write('\n') exporting.write('\n') return
import reports test1 = reports.get_most_played("game_stat.txt") print(test1) test2 = reports.sum_sold("game_stat.txt") print(test2) test3 = reports.get_selling_avg("game_stat.txt") print(test3) test4 = reports.count_longest_title("game_stat.txt") print(test4) test5 = reports.get_date_avg("game_stat.txt") print(test5) test6 = reports.get_game("game_stat.txt", "World of Warcraft") print(test6) test7 = reports.count_grouped_by_genre("game_stat.txt") print(test7) test8 = reports.get_date_ordered("game_stat.txt") print(test8) # Printing functions
import reports filename = input("Please give the name of the file: ") print("The most played game is:") print(reports.get_most_played(filename)) print("Total games sold: ") print(reports.sum_sold(filename)) print("Average sales: ") print(reports.get_selling_avg(filename)) print("The longest title has xx characters: ") print(reports.count_longest_title(filename)) print("The average release date is : ") print(reports.get_date_avg(filename)) title = input("Which game you want to know more about?:") print(reports.get_game(filename, title)) print("Number of games in genre:") print(reports.count_grouped_by_genre(filename)) print("Date ordered game list:") print(reports.get_date_ordered(filename))
from reports import sum_sold, get_selling_avg, count_longest_title from reports import get_date_avg, get_game,count_grouped_by_genre,get_date_ordered # Printing functions print(get_date_ordered('game_stat.txt'))
import reports '''file_name = 'game_stat.txt' title = "Counter-Strike"''' # uncomment for testing report_part2 = open("report_part2.txt", "w") report_part2.write(str(reports.get_most_played(file_name)) + "\n") report_part2.write(str(reports.sum_sold(file_name)) + "\n") report_part2.write(str(reports.get_selling_avg(file_name)) + "\n") report_part2.write(str(reports.count_longest_title(file_name)) + "\n") report_part2.write(str(reports.get_date_avg(file_name)) + "\n") report_part2.write(str(reports.get_game(file_name, title)) + "\n") report_part2.write(str(reports.count_grouped_by_genre(file_name)) + "\n") report_part2.write(str(reports.get_date_ordered(file_name)) + "\n") report_part2.close()