Beispiel #1
0
def export(file):
    filename = open("export.txt", "w")
    filename.write(str(reports.get_most_played("game_stat.txt")) + "\n")
    filename.write(str(reports.sum_sold("game_stat.txt")) + "\n")
    filename.write(str(reports.get_selling_avg("game_stat.txt")) + "\n")
    filename.write(str(reports.count_longest_title("game_stat.txt")) + "\n")
    filename.write(str(reports.get_date_avg("game_stat.txt")) + "\n")
Beispiel #2
0
def main():
    running = True
    while running:
        print("1. What is the title of the most played game?\n2. How many copies have been sold total?\n3. What is the"
              "average selling?\n4. How many characters long is the longest title?\n5. What is the average of the relea"
              "se dates?\n6. What properties has a game?")
        question_number = input("Please choose the number of your question: ")

        if question_number == '1':
            print("The most played game is {0}.".format(reports.get_most_played('game_stat.txt')))
        elif question_number == '2':
            print("{0} million copies were sold in total.".format(reports.sum_sold('game_stat.txt')))
        elif question_number == '3':
            print("The average selling is {0}.".format(reports.get_selling_avg('game_stat.txt')))
        elif question_number == '4':
            print("The longest title is {0} characters long.".format(reports.count_longest_title('game_stat.txt')))
        elif question_number == '5':
            print("The average of the release dates is {0}.".format(reports.get_date_avg('game_stat.txt')))
        elif question_number == '6':
            game = input("Which game's properties are you interested in?\n")
            print("Total copies sold(million): {0}\nRelease date: {1}\nGenre: {2}\nPublisher: {3}".format(
                reports.get_game('game_stat.txt', game)[1], reports.get_game('game_stat.txt', game)[2],
                reports.get_game('game_stat.txt', game)[3], reports.get_game('game_stat.txt', game)[4]
            ))
        else:
            running = False

    return
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)
Beispiel #4
0
def export_get_most_played():
    """Export to file: the title of the most played game (sold the most copies)."""
    title_game = reports.get_most_played(filename)
    message = "Title of most played game in {}: {}\n".format(
        filename, title_game)
    export_to_file(message)
    print("DATA TRANSFERRED TO A FILE: exported_answers.txt!\n")
Beispiel #5
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"
        ))
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()
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 #8
0
def print_judy_answers_part2():
    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", 'Minecraft'))
Beispiel #9
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 print_datas(fname, title):
    getmost = reports.get_most_played(fname)
    sumsold = reports.sum_sold(fname)
    getsavg = reports.get_selling_avg(fname)
    countlongest = reports.count_longest_title(fname)
    getdateavg = reports.get_date_avg(fname)
    getgame = reports.get_game(fname, gametitle)
    return [getmost, sumsold, getsavg, countlongest, getdateavg, getgame]
def reports_answers_prints(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))
    return
def pprinter(file_name):
    pp = pprint.PrettyPrinter(indent=1, width=80, depth=None, stream=None)
    pp.pprint(reports.get_most_played('game_stat.txt'))
    pp.pprint(reports.sum_sold('game_stat.txt'))
    pp.pprint(reports.get_selling_avg('game_stat.txt'))
    pp.pprint(reports.count_longest_title('game_stat.txt'))
    pp.pprint(reports.get_date_avg('game_stat.txt'))
    pp.pprint(reports.get_game('game_stat.txt', 'Minecraft'))
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)))
Beispiel #14
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))
Beispiel #15
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())
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 questions_to_txt(file_name, title, export_file='export_file.txt'):
    file = open(export_file, 'w')
    file.write("The most played game is: {}\n".format(reports.get_most_played(file_name)))
    file.write("The summary of copies: {}\n".fomrat(reports.sum_sold(file_name)))
    file.write("The avarge of sold copies: {}\n".format(reports.get_selling_avg(file_name)))
    file.write("The longest title has so many characters: {}\n".format(reports.count_longest_title(file_name)))
    file.write("The avarge of the year of publication: {}\n".format(reports.get_date_avg(file_name)))
    file.write("The properties of the given game name: {}\n".format(reports.get_game(file_name, title)))
    file.close()
    return export_file
# Export functions
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))))
Beispiel #21
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()
Beispiel #22
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():
    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 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 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 #26
0
def judy_answers_part2():
    file = open("game_stat_judy_answers_2.txt", "w")
    file.write(str(reports.get_most_played("game_stat.txt")))
    file.write("\n")
    file.write(str(reports.sum_sold("game_stat.txt")))
    file.write("\n")
    file.write(str(reports.get_selling_avg("game_stat.txt")))
    file.write("\n")
    file.write(str(reports.count_longest_title("game_stat.txt")))
    file.write("\n")
    file.write(str(reports.get_date_avg("game_stat.txt")))
    file.write("\n")
    file.write(str(reports.get_game("game_stat.txt", "Minecraft")))
Beispiel #27
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 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 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")
Beispiel #30
0
def main():
    while True:
        try:
            print("What do you wanna know?")
            print(
                "1.The title of the most played game (i.e. sold the most copies)"
            )
            print("2.Copies sold total")
            print("3.The average selling")
            print("4.How many characters long is the longest title")
            print("5.Average of the release dates")
            print("6.Properties of selected game")
            print("0.To exit")
            choose = int(input())
            if choose == 1:
                file = input("enter the name of the file")
                print(get_most_played(file))
                continue
            if choose == 2:
                file = input("enter the name of the file")
                print(sum_sold(file))
                continue
            if choose == 3:
                file = input("enter the name of the file")
                print(get_selling_avg(file))
                continue
            if choose == 4:
                file = input("enter the name of the file")
                print(count_longest_title(file))
                continue
            if choose == 5:
                file = input("enter the name of the file")
                print(get_date_avg(file))
                continue
            if choose == 6:
                x = input("enter name of the game")
                file = input("enter the name of the file")
                print(get_game(file, x))
                continue
            elif choose == 0:
                exit("bb")
            else:
                print("wrong input try again")
                continue
        except ValueError:
            print("wrong input")
        except FileNotFoundError:
            print("Can't find this file")
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())
Beispiel #32
0
 def test_1_get_most_played(self):
     result = reports.get_most_played(self.input_file)
     self.assertEqual(result, "Minecraft")
     if result == "Minecraft":
         self.points += 2
         print("Function 'get_most_played' is passed. 2 points.")
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()