Beispiel #1
0
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"
        ))
Beispiel #2
0
def display_count_grouped_by_genre():
    """Display how many games are there grouped by genre."""
    dict_of_genre = reports.count_grouped_by_genre(filename)
    print("Game grouped by genre:")
    for genre, value in dict_of_genre.items():
        print("{}: {}".format(genre, value))
    print()
Beispiel #3
0
    def test_bonus_1_count_grouped_by_genre(self):
        result = reports.count_grouped_by_genre(self.input_file)
        expected_result = get_grouped_dic()
        self.assertEqual(result, expected_result)

        if result == expected_result:
            print("Bonus function 'count_grouped_by_genre' is passed.")
Beispiel #4
0
def export_count_grouped_by_genre():
    """Export to file: how many games are there grouped by genre."""
    dict_of_genre = reports.count_grouped_by_genre(filename)
    print("Game grouped by genre:\n")
    for genre, value in dict_of_genre.items():
        export_to_file("{}: {}\n".format(genre, value))
    print("DATA TRANSFERRED TO A FILE: exported_answers.txt!\n")
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():
    input_file = 'game_stat.txt'
    export_file = open('reports.txt', 'w')

    export_file.write('What is the title of the most played game?\n')
    export_file.write(str(r.get_most_played(input_file)) + '\n\n')

    export_file.write('How many copies have been sold total?\n')
    export_file.write(str(r.sum_sold(input_file)) + '\n\n')

    export_file.write('What is the average selling?\n')
    export_file.write(str(r.get_selling_avg(input_file)) + '\n\n')

    export_file.write('How many characters long is the longest title?\n')
    export_file.write(str(r.count_longest_title(input_file)) + '\n\n')

    export_file.write('What is the average of the release dates?\n')
    export_file.write(str(r.get_date_avg(input_file)) + '\n\n')

    export_file.write('What properties has a game?\n')
    export_file.write(str(r.get_game(input_file, 'The Sims 3')) + '\n\n')

    export_file.write('How many games are there grouped by genre?\n')
    genre_count = r.count_grouped_by_genre(input_file)
    for genre in genre_count.items():
        export_file.write(str(genre))
        export_file.write('\n')

    export_file.close()
Beispiel #7
0
def writing_count_grouped_by_genre(file_name):
    """writes a dictionary where each genre is associated 
    with the count of the games of its genre"""
    result = str(reports.count_grouped_by_genre(file_name))
    with open("report_for_judy_part2.txt", "+a") as f:
        f.write(result)
        f.write("\n")
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)
Beispiel #9
0
    def test_bonus_1_count_grouped_by_genre(self):
        result = reports.count_grouped_by_genre(self.input_file)
        expected_result = get_grouped_dic()
        self.assertEqual(result, expected_result)

        if result == expected_result:
            self.points += 1
            print("Bonus function 'count_grouped_by_genre' is passed. 1 points.")
Beispiel #10
0
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 printing_count_grouped_by_genre(file_name):
    """prints a dictionary where each genre is associated 
    with the count of the games of its genre"""
    result = reports.count_grouped_by_genre(file_name)
    print ("The number of games in genres are:")
    for k in result:
        print(k, ":", result[k])
    print()
Beispiel #12
0
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())
Beispiel #13
0
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"))
Beispiel #17
0
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():
    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_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 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
Beispiel #21
0
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_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 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"
    ])
Beispiel #24
0
def main():

    input_file = 'game_stat.txt'

    print(r.get_most_played(input_file), '\n')
    print(r.sum_sold(input_file), '\n')
    print(r.get_selling_avg(input_file), '\n')
    print(r.count_longest_title(input_file), '\n')
    print(r.get_date_avg(input_file), '\n')
    print(r.get_game(input_file, 'The Sims 3'), '\n')

    genre_count = r.count_grouped_by_genre(input_file)
    for genre in genre_count.items():
        print(genre)
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 report(filename):
    savefile.write(str(reports.get_most_played(filename)))
    savefile.write('\n')
    savefile.write(str(reports.sum_sold(filename)))
    savefile.write('\n')
    savefile.write(str(reports.get_selling_avg(filename)))
    savefile.write('\n')
    savefile.write(str(reports.count_longest_title(filename)))
    savefile.write('\n')
    savefile.write(str(reports.get_date_avg(filename)))
    savefile.write('\n')
    savefile.write(str(reports.get_game(filename, title)))
    savefile.write('\n')
    savefile.write(str(reports.count_grouped_by_genre(filename)))
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()
Beispiel #29
0
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
Beispiel #31
0
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 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())
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()