Coder Social home page Coder Social logo

randompointsgenerator's Introduction

RandomPointsGenerator

This application creates users with points 0 when server starts and then update each user's points with random numbers which are between 0 and 100 after every minute.

It allows users to make requests whose response is json object contains users and timestamp.

Setting up the project

Prerequiste

To avoid any surprise or errors this project runs on these stacks but anything above these should work fine:

  • elixir v1.11.2
  • phoenix v1.5.6
  • postgresql v12.x

To install the above mentioned depedencies kindly follows the links and follow instructions depending on your system

Kindly note you can use asdf version manage to avoid version collisions in elixir

Once you are done with the installaton of depedency clone the project into your local machine like so:

via ssh [email protected]:okothkongo/randompointsgenerator.git
or

via https https://github.com/okothkongo/randompointsgenerator.git

How run this application

  • Install dependencies with mix deps.get
  • Create,migrate, and seed your database with mix ecto.setup
  • Run a quick test to ensure everything is working with mix test.It should be all green.
  • Start Phoenix endpoint with mix phx.server

Now you can visit localhost:4000 from your browser.

Response

The response is a json object with containing timestamp and an array of users objects like so:

{"timestamp":null,
 "users":[{"id":402,"points":70},
          {"id":405,"points":41}
         ]
}
  1. timestamp

The timestamp is a string, the value of this is a datetime in this format yyyy-mm-dd hh:mm:sec

This time is UTC based.

On initial request the value of timestamp is null like so:

{"timestamp":"2020-07-30 17:09:33"
 "users":[{"id":402,"points":70},
          {"id":405,"points":41}
         ]
}

On any other consecutive requests, the value of timestamp latest request will be the value of of time previous request request was made. For instance when you did a request on was 2020-07-30 17:09:33 and you did another request at 2021-10-30 20:00:00 .

The response will be like so:

{"timestamp":"2020-07-30 17:09:33",
 "users":[{"id":402,"points":70},
          {"id":405,"points":41}
         ]
}
  1. users

users is an array of objects with each contain user details, their id and points which are both numbers(integers).

This array can have only of maximum of two object, meaning it contain 0, 1, or two users objects.

The value of users object is determined by two things:

i. random number used to update each user

ii. random number used to query the database

i. random number used to update each user

After every minute points of each user in the database is updated to a random number whose value range between 0 and 100,the points of each user may remain the same or change depending of value of the random number used.

This will greatly affect value on users object, on request made on minute after the previous request.

ii. random number used to query the database

It is used to filter users being display,user with point greater than this number are select and the pick the first two(order is determined by user points, users with highest points will be fetched)

On each request this number can remain same or change since it is random.

randompointsgenerator's People

Contributors

okothkongo avatar

Stargazers

 avatar

Watchers

 avatar

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.