Coder Social home page Coder Social logo

python-phase-3-game-tracker-mock's Introduction

Object Relations Code Challenge - Game Tracker

(Original from https://github.com/emileypalmquist/python-phase-3-practice-challenges)

For this assignment, we'll be working with a game tracking domain.

We have three models: Game, Player, and Result.

For our purposes, a Game has many Results, a Player has many Results, and a Result belongs to a Player and to a Game.

Game - Player is a many to many relationship.

Note: You should draw your domain on paper or on a whiteboard before you start coding. Remember to identify a single source of truth for your data.

Topics

  • Classes and Instances
  • Class and Instance Methods
  • Variable Scope
  • Object Relationships
  • lists and list Methods

Instructions

To get started, run pipenv install while inside of this directory.

Build out all of the methods listed in the deliverables. The methods are listed in a suggested order, but you can feel free to tackle the ones you think are easiest. Be careful: some of the later methods rely on earlier ones.

Remember! This code challenge has tests to help you check your work. You can run pytest to make sure your code is functional before submitting.

We've provided you with a tool that you can use to test your code. To use it, run python debug.py from the command line. This will start a ipdb session with your classes defined. You can test out the methods that you write here. You can add code to the debug.py file to define variables and create sample instances of your objects.

Writing error-free code is more important than completing all of the deliverables listed - prioritize writing methods that work over writing more methods that don't work. You should test your code in the console as you write.

Similarly, messy code that works is better than clean code that doesn't. First, prioritize getting things working. Then, if there is time at the end, refactor your code to adhere to best practices. When you encounter duplicated logic, extract it into a shared helper method.

Before you submit! Save and run your code to verify that it works as you expect. If you have any methods that are not working yet, feel free to leave comments describing your progress.

Deliverables

Write the following methods in the classes in the files provided. Feel free to build out any helper methods if needed.

Initializers and Properties

Game

  • Game __init__(self, title)
    • Game is initialized with a title (string)
    • Title cannot be changed after the Game is initialized
  • Game property title
    • Returns the Game's title
    • Titles must be strings greater than 0 characters
    • if you are using exceptions comment out the test on lines 25 - 32 in the game_test.py and uncomment lines 34 - 38

Player

  • Player __init__(self, username)
    • Player is initialized with a username (string)
    • Usernames can be changed after the Player is initialized
  • Player property username
    • Returns the Player's username
    • Usernames must be strings between 2 and 16 characters, inclusive
    • if you are using exceptions comment out the test on lines 25 - 29 in the player_test.py and uncomment lines 37 - 44

Result

  • Result __init__(self, player, game, score)
    • Result is initialized with a Player instance, a Game instance, and a score (number)
  • Result property score
    • Returns the score for the Result instance
    • Scores must be integers between 1 and 5000, inclusive

Object Relationship Attributes and Properties

Result

  • Result property player
    • Returns the player for the Result
    • Players must be Player instances
  • Result property game
    • Returns the game that was played
    • Games must be Game instances

Player

  • Player results()
    • Returns a list of Result instances associated with the Player instance.
  • Player games_played()
    • Returns a list of Game instances played by the Player instance.

Game

  • Game results()
    • Returns a list of all the Result instances for the Game.
  • Game players()
    • Returns a list of all of the Player instances that played the Game.

Aggregate and Association Methods

Player

  • Player played_game(game)
    • Returns True if the Player has played this Game (if there is a Result instance that has this Player and Game), returns False otherwise
  • Player num_times_played(game)
    • Returns the number of times the Player instance has played (Result instance created) the Game instance
  • Player add_result(game, score)
    • A Game instance and a score (number) are passed in as arguments
    • This method should create a new Result instance with that Player instance, Game instance, and score

Game

  • Game average_score(player)
    • Returns the average of all the player's scores for the Game instance
    • To average scores, add all result scores together for the player and divide by the total number of results for the player.

Bonus: Aggregate and Association Method

  • Player classmethod highest_scored(game)
    • Returns the Player instance with the highest average game score.
    • hint: will need a way to remember all Player objects
    • hint: do you have a method to get the average score on a game for a particular player?

python-phase-3-game-tracker-mock's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.