Giter VIP home page Giter VIP logo

crazycricket's Introduction

Crazy Cricket

Proposed solution for Crazy Cricket challenge asked by Black Rock. The solution contains two modules - a Kafka Processor & a REST service. Kafka Processor consumes game events from provided broker and store them in an in-memory HSQL database. REST service exposes end points for handling expected requests for game statistics with parameter validations.

Setup & Run

mvn clean package

chmod +x bin/run.sh

bin/run.sh <your kafka broker like localhost:9092>
...
Crazy Cricket REST Service started at: http://localhost:8292 <you can modify port in src/main/resources/application.properties>
...
INFO 13896 --- [       Thread-4] o.a.k.c.c.internals.ConsumerCoordinator  : Setting newly assigned partitions [TWENTY_TWENTY-0, TEST-0, LIMITED_OVERS-0] for group test
...

One REST API & Kafka Processor is up and runnning, publish few game events in a new terminal using Black Rock's crazy-cricket-assembly:

java -cp crazy-cricket-assembly-SNAPSHOT.jar com.bfm.acs.crazycricket.SampleDataProducer --kafka-broker localhost:9092
...
INFO 13896 --- [       Thread-4] o.a.k.c.c.internals.ConsumerCoordinator  : Setting newly assigned partitions [TWENTY_TWENTY-0, TEST-0, LIMITED_OVERS-0] for group test
INFO 3172 --- [       Thread-4] c.b.a.c.data.HsqlDataStoreImpl           : Saving game: Winner-oscar(England), Loser-sachin(India), Date-2016-01-01, Type-TEST
INFO 3172 --- [       Thread-4] c.b.a.c.data.HsqlDataStoreImpl           : Game saved
...

Kafka processor consumes the newly published(does not read from beginning currently) and persists them in an in-memory HSQL database. REST API exposes the required stats as:

  • Current leaderboad:
    GET http://localhost:8292/api/leaderboard
    Output:
    [{"shubham":5},{"oscar":4},{"sachin":4},{"andrew":1},{"imran":1}]
  • Date range leaderboard:
    GET http://localhost:8292/api/leaderboard?start=20160101&end=20160101
    Output:
    [{"oscar":2},{"andrew":1},{"imran":1},{"sachin":1},{"shubham":1}]
  • Current country leaderboard:
    GET http://localhost:8292/api/national_leaderboard
    Output:
    [{"India":9},{"England":4},{"Pakistan":1},{"USA":1}]
  • Date range country leaderboard:
    GET http://localhost:8292/api/national_leaderboard?start=20160101&end=20160101
    Output:
    [{"England":2},{"India":2},{"Pakistan":1},{"USA":1}]
  • Invalid date range country leaderboard:
    GET http://localhost:8292/api/national_leaderboard?start=20160101&end=2016010
    Output:
    {"timestamp":1469570445922,"status":400,"error":"Bad Request","exception":"com.bfm.acs.crazycricket.data.InvalidDateRangeException","message":"Invalid end date, expected format: yyyyMMdd","path":"/api/national_leaderboard"}

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.