Coder Social home page Coder Social logo

jwkvam / datastructs-algorithms-interview-problems Goto Github PK

View Code? Open in Web Editor NEW

This project forked from verdigristech/datastructs-algorithms-interview-problems

0.0 2.0 0.0 3 KB

On-site interview problem for Full Stack position

Python 100.00%

datastructs-algorithms-interview-problems's Introduction

Query Batching

At Verdigris, we have database that stores data about our customers' electrical circuits.

Problem

Included in the repository is a Python API for querying the data stored on our database. Currently, the client is written to perform each query individually. Since this data query must be made over a network, the amount of time to establish a connection and perform the query is the bottleneck.

Write a batched version of the client such that we can minimize the network overhead.

To query for data, run:

python batched_queries.py

IMPORTANT: You are forbidden from just dispatching requests asynchronously without batching first.

Output

It is very important that the batched query generates the output in the EXACT same order as the non-batched version.

If the input looks like this:

queries = [
    DataQuery("Boutique Panel A15", 150),
    DataQuery("Lab Cooling Towers", 500.25),
    DataQuery("Verdigris HQ Elevator", 157),
    DataQuery("Lab Cooling Towers", 460.25),
    DataQuery("Boutique Panel A15", 140),
    DataQuery("Verdigris HQ Elevator", 7),
    DataQuery("Verdigris HQ Elevator", 1003.5),
]

Running non-batched method produces the following result:

>>> run_all_queries(queries)
[CIRCUIT] Boutique Panel A15: 0.7 Watts @ t=150
[CIRCUIT] Lab Cooling Towers: 2.7 Watts @ t=500.25
[CIRCUIT] Verdigris HQ Elevator: 1.6 Watts @ t=157
[CIRCUIT] Lab Cooling Towers: 3.7 Watts @ t=460.25
[CIRCUIT] Boutique Panel A15: 2.2 Watts @ t=140
[CIRCUIT] Verdigris HQ Elevator: 1.6 Watts @ t=7
[CIRCUIT] Verdigris HQ Elevator: 1.3 Watts @ t=1003.5

Running the batched version should also produce the same result:

>>> run_all_queries_batched(queries)
[CIRCUIT] Boutique Panel A15: 0.7 Watts @ t=150
[CIRCUIT] Lab Cooling Towers: 2.7 Watts @ t=500.25
[CIRCUIT] Verdigris HQ Elevator: 1.6 Watts @ t=157
[CIRCUIT] Lab Cooling Towers: 3.7 Watts @ t=460.25
[CIRCUIT] Boutique Panel A15: 2.2 Watts @ t=140
[CIRCUIT] Verdigris HQ Elevator: 1.6 Watts @ t=7
[CIRCUIT] Verdigris HQ Elevator: 1.3 Watts @ t=1003.5

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.