Git Product home page Git Product logo

skedulo-be-test's Introduction

Skedulo backend-tech-test

Requirement

  • Input:

    • List of performance => performances
  • Output

    • List of optimizer performance => schedules

Detail

Write a program for Sally that takes a list of Performance objects as input and produces Sally’s optimal schedule.

An optimal schedule meets the following criteria:

  1. Sally wants to see the best performance at any given time. This may mean cutting one event short to see a higher priority performance, then returning to the original later.
  2. You can assume Sally has a teleportation device and can travel between stages instantaneously!
  3. If two performances starting at the same time have the same priority, Sally is happy to go to either one.
  4. There may also be gaps where no performances are on.

Solutions

Generic

  • Using NodeJS & TypeScript to solve
  • Model: content model to present for performance & schedule
  • Services: content OptimizerService to process input and provide output data
  • Controllers: using for calling services and provide endpoint. In case I using it's to make some unit test with jest
  • I'm using playground to test from bash file
  • Scripts: content input data, expected data, scripts to build, run & verify code.

Service Details (OptimizerService)

  • Each performances have start & finish time, then I want to create a flat array to contain them ex: [start-1, finish-1, start-2, finish-2] => events

  • With this events sort by time ASC and make this array unique by time

  • Loop through events find performances are playing on this timeline. Sort performances should be play first => earlyStarts than other by condition highest priority, if same priority compare to start time then choose the first one => performanceEvents

  • By performanceEvents compare previous and current value

    • if previous priority smaller than current priority and is playing then set previous to stop and store this change in schedule set finish time of previous to current start time and return this schedule
    • if previous and current have same priority then continue playing previous, store this previous in schedule
    • if previous priority lager than current priority then prepare to play current, set current start time is the time previous finish and store this change in schedule and return this schedule

    Note: time store in schedule convert to ISO8601 date format, other case instead return schedule return null

  • Finally have an array of schedule then make sure this array is unique by comparing each properties

Testing

  • using yarn test

yarn-test

  • using scripts
./scripts/verify.sh

script-test

Issues

  • With timezone.json input data, can process and give correct schedule but cannot return to the timezone of this file.
  • I think this conflict with requirement DateTime’s are represented as strings in ISO8601 format. => input not in ISO8601 format.
  • In real case, it should convert by user side or should clarify input timezone and output timezone.

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.