Code Monkey home page Code Monkey logo

backend-interview's Introduction

Luma Technical Interview

Given patient demographics and behavioral data (see sample-data/patients.json), create an algorithm that will process a set of historical patient data and compute a score for each patient that (1 as the lowest, 10 as the highest) that represents the chance of a patient accepting the offer off the waitlist. Take in consideration that patients who have little behavior data should be randomly added to the top list as to give them a chance to be selected. Expose an api that takes a facility's location as input and returns an ordered list of 10 patients who will most likely accept the appointment offer.

Installation

  1. Clone the repository
git clone https://github.com/ymoreiratiti/backend-interview.git
cd backend-interview
  1. Install NPM Packages
npm ci
  1. Build the package
npm run build

Usage/Examples

//  Import Library
const { PatientScoringAlgorithm } = require("./lib");

//  Import Patients Sample Data
const sampleDate = require("./sample-data/patients.json");

//  Create a new instance of PatientScoringAlgorithm using the sample data
const patientScoringAlgorithm = new PatientScoringAlgorithm({
  dataset: sampleDate,
});

//  Get the patient list
const result = patientScoringAlgorithm.getPatientList({
  latitude: "48.7120",
  longitude: "-60.1170",
});
console.table(result);

Run Locally

Install this package

node example.js

Running Tests

To run tests, run the following command

npm run test

Coverage

npm run test:cov

Mutation Test

npm run test:mutant

How this algorith works:

This algorithm can be broken down into several key steps designed to ensure data validation, normalize input for comparison, and ultimately return a balanced list of users based on behavior data and scoring. Here’s a concise summary:

  1. Data Validation:
  • Validate dataset structure and contents to ensure they conform to expected formats, given Node.js is not strongly typed.
  • Validate the geographic coordinates (latitude/longitude) to prevent unexpected behavior.
  1. Offer Calculation:
  • Compute the total number of offers (accepted + rejected) for each user to assess the amount of behavioral data available.
  1. Distance Calculation:
  • Use the distance formula to calculate the distance between users and a facility. This is done for simplicity and practicality.
  1. Normalization:
  • Normalize different data fields to a 0-1 scale for easier comparison across various units (e.g., distance vs. age).
  1. Score Calculation:
  • Apply predefined weights to the normalized values to calculate a score for each user, adding a new column to the dataset.
  1. List Generation:
  • Generate two lists: one prioritizing users with fewer behavioral data points and another ordered by the calculated scores.
  • Randomly determine how many users from the "less data" list should be selected, and fill in the remainder from the "higher score" list.
  1. Result Return:
  • Return a balanced list that accounts for users with less behavioral data, ensuring they have a fair chance to be considered.

This approach balances the need to consider both data-rich and data-poor users by combining scoring with a randomized selection process.

Acknowledgements

Authors

backend-interview's People

Contributors

jahmezz avatar ymoreiratiti avatar marcelocoliveira avatar dbeam16 avatar jamesthesnake 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.