Coder Social home page Coder Social logo

koroibos's Introduction

README

This is a brief code-challenge outlined here.

The data is taken from here

The app is deployed here.

Available endpoints are:

GET api/v1/olympians

Optional Query Parameters: age=youngest & age=oldest

Responses

With no query string:

Multiple olympians returned

With query string:

Single olympian returned

Status: 200
Body:

{
  "olympians":
    [
      {
        "name": "Maha Abdalsalam",
        "team": "Egypt",
        "age": 18,
        "sport": "Diving"
        "total_medals_won": 0
      },
      {...},
      {...}
    ]
}

With invalid query string:

Status: 404
Body: {"message": "Invalid Parameter"}

GET api/v1/events

Responses

Status:200
Body:

{
  "events":
    [
      {
        "sport": "Archery",
        "events": [
          "Archery Men's Individual",
          "Archery Men's Team",
          "Archery Women's Individual",
          "Archery Women's Team"
        ]
      },
      {
        "sport": "Badminton",
        "events": [
          "Badminton Men's Doubles",
          "Badminton Men's Singles",
          "Badminton Women's Doubles",
          "Badminton Women's Singles",
          "Badminton Mixed Doubles"
        ]
      },
      {...}
    ]
}

GET api/v1/events/:event_id/medalists

Responses

With valid event_id

Status: 200
Body:

{
  "event": "Badminton Mixed Doubles",
  "medalists": [
      {
        "name": "Tontowi Ahmad",
        "team": "Indonesia-1",
        "age": 29,
        "medal": "Gold"
      },
      {
        "name": "Chan Peng Soon",
        "team": "Malaysia",
        "age": 28,
        "medal": "Silver"
      }
    ]
}

(Note, many medalists are missing, this is an incomplete data set)

With invalid event_id

Status: 404
Body: {"message": "Invalid Parameter"}

koroibos's People

Contributors

wipegup avatar

Watchers

 avatar

koroibos's Issues

GET api/v1/olympians?age=youngest/oldest

If age parameter is added to the olympians endpoint and is set equal to either "youngest" or "oldest", then return the record for a single olympian who is either the oldest or youngest.

e.g.

GET api/v1/olympians?age=youngest
RETURN:
Status 300;

{
"olympians":
  [
    {
      "name": "Ana Iulia Dascl",
      "team": "Romania",
      "age": 13,
      "sport": "Swimming"
      "total_medals_won": 0
    }
  ]
}

If age is not set to "oldest" or "youngest":
Return
Status 404

{"message":"Invalid Parameter"}

Create Database

Tables:

Athlete

  • Sex : Enumerable
  • Age: Int
  • Height: int
  • Weight - int
  • Team

Games

  • Year: int
  • Season: Enumerable

Sport

  • Name: String

Event

  • Sport: Refernces
  • Name: String

AthleteEvent

  • Event: References
  • Athlete: References
  • Game: References
  • Medal: Enumerable [0- NA, 1-Gold, 2-Silver 3-Bronze]

Olympians Functions

Class method age - Take two arguments, string / symbol of ASC DESC and number or desired records.

For example, the call to return the oldest olympian would take :desc, 1 as parameters.
RETURN Active Record Relation

Class Method avg_weight, take one argument, string / symbol of F/M. Will return average weight of athletes in that class. If argument blank, provide average weight of all athletes. RETURN: Float

Class Method avg_age, Take same arguments as avg_weight. RETURN: Float

Instance Method total_medals. No arguments return total number of non "NA" medals for an athlete. RETURN INT

Event Serialization

For each SPORT collect a list of EVENTS.

Sport Instance Method events - Return Active Record Relation of all events in that sport. May be taken care of by belongs_to, has_one.

Event Methods

Instance Method medalists - Return ARRelation of Athletes who gained a non-"NA" medal in specified event.

GET api/v1/events

No headers, params, or body
Return serialized list of events for each SPORT.

e.g.
RETURN
Status 200

{
  "events":
    [
      {
        "sport": "Archery",
        "events": [
          "Archery Men's Individual",
          "Archery Men's Team",
          "Archery Women's Individual",
          "Archery Women's Team"
        ]
      },
      {
        "sport": "Badminton",
        "events": [
          "Badminton Men's Doubles",
          "Badminton Men's Singles",
          "Badminton Women's Doubles",
          "Badminton Women's Singles",
          "Badminton Mixed Doubles"
        ]
      },
      {...}
    ]
}

GET api/v1/olympian_stats

No parameter/header/body

Return serialized stats from the database.

e.g.
RETURN
Status 200

 {
    "olympian_stats": {
      "total_competing_olympians": 3120
      "average_weight:" {
        "unit": "kg",
        "male_olympians": 75.4,
        "female_olympians": 70.2
      }
      "average_age:" 26.2
    }
  }

Add Testing

Add RSPEC gem
Install Rspec

Add factory-bot
Add simplecov
add shoulda-matchers
Add pry

GET api/v1/olympians

No body/headers/params needed.

Upon success return:
STATUS 200

{
  "olympians":
    [
      {
        "name": "Maha Abdalsalam",
        "team": "Egypt",
        "age": 18,
        "sport": "Diving"
        "total_medals_won": 0
      },
      {
        "name": "Ahmad Abughaush",
        "team": "Jordan",
        "age": 20,
        "sport": "Taekwondo"
        "total_medals_won": 1
      },
      {...}
    ]
}

Create Serializer

Create Gem to act as a customizable serializer

  • Define syntax for specifying structure of serialized data
  • Link directly to Database with AR
  • Save as Gem, upload to RubyGems.

Get api/v1/events/:id/medalists

No header/params/body.
Event ID passed within URI.

Return All medalists from a given event

Given a valid event id:
RESPONSE
Status 200:
Body:

{
  "event": "Badminton Mixed Doubles",
  "medalists": [
      {
        "name": "Tontowi Ahmad",
        "team": "Indonesia-1",
        "age": 29,
        "medal": "Gold"
      },
      {
        "name": "Chan Peng Soon",
        "team": "Malaysia",
        "age": 28,
        "medal": "Silver"
      }
    ]
}

If invalid event id:
RESPONSE
Status 404

{"message":"invalid parameters"}

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.