Skip to main content

unbabel cli for application

Project description

Backend Engineering Challenge - Victor Carrillo

Welcome to my repository of the back end challenge. the readme i will divide it into 3 parts

  • How to run, build and test
  • extra notes of the implementation

How to run this Repo

How to install this repo

This repo utilizes Poetry to install Poetry please follow their guide

After having Poetry just run poetry install

Once it has been installed you can run the CLI by just calling unbabel-cli --input-file <name-of-file> for more info on how to run the CLI just call unbabel-cli --help (if for any reason that doesn't work you can call the cli by using poetry run unbabel-cli)

How to build the application?

Run poetry build (only build it if you want to install the package into your python (recommend using pipx for it))

How to test?

i have installed pytest, all the test are found in the ./test directory so to run all the test just run pytest

Notes

Hi, well i have work on this quite fast as i was told the sooner the better. still after i finish i have some after though of the implementation, So of course there is a lot of room for improvement but i think i convered all the basics of the requirements.

  • I added support for json line and json into the fiels readed because in the example of the sample json there is a json line file and not a json file so i am not quite certain what should be the expected input so i added value for both options which will read the file differently based on the type of file (described by file .json or .jsonl)

  • I was thinking of using pandas for the calculation which might be better for production as it can allow to do more calculation more organized to the events list. however due to the requirements i think it was simpler for me to build it manually than just using pandas for it now. but for a planning of scalation implementation might have been different

  • I also think that since everything comes organized we could divide the array into chunks and make them process each async which should also optimize way more the code (if the input file are large enough to be relevant) however is an overkill at the moment

Application Argument:

Example:

{
  "timestamp": "2018-12-26 18:12:19.903159",
  "translation_id": "5aa5b2f39f7254a75aa4",
  "source_language": "en",
  "target_language": "fr",
  "client_name": "airliberty",
  "event_name": "translation_delivered",
  "duration": 20,
  "nr_words": 100
}

Challenge Objective

Your mission is to build a simple command line application that parses a stream of events and produces an aggregated output. In this case, we're interested in calculating, for every minute, a moving average of the translation delivery time for the last X minutes.

If we want to count, for each minute, the moving average delivery time of all translations for the past 10 minutes we would call your application like (feel free to name it anything you like!).

unbabel_cli --input_file events.json --window_size 10

The input file format would be something like:

{"timestamp": "2018-12-26 18:11:08.509654","translation_id": "5aa5b2f39f7254a75aa5","source_language": "en","target_language": "fr","client_name": "airliberty","event_name": "translation_delivered","nr_words": 30, "duration": 20}
{"timestamp": "2018-12-26 18:15:19.903159","translation_id": "5aa5b2f39f7254a75aa4","source_language": "en","target_language": "fr","client_name": "airliberty","event_name": "translation_delivered","nr_words": 30, "duration": 31}
{"timestamp": "2018-12-26 18:23:19.903159","translation_id": "5aa5b2f39f7254a75bb3","source_language": "en","target_language": "fr","client_name": "taxi-eats","event_name": "translation_delivered","nr_words": 100, "duration": 54}

Assume that the lines in the input are ordered by the timestamp key, from lower (oldest) to higher values, just like in the example input above.

The output file would be something in the following format.

{"date": "2018-12-26 18:11:00", "average_delivery_time": 0}
{"date": "2018-12-26 18:12:00", "average_delivery_time": 20}
{"date": "2018-12-26 18:13:00", "average_delivery_time": 20}
{"date": "2018-12-26 18:14:00", "average_delivery_time": 20}
{"date": "2018-12-26 18:15:00", "average_delivery_time": 20}
{"date": "2018-12-26 18:16:00", "average_delivery_time": 25.5}
{"date": "2018-12-26 18:17:00", "average_delivery_time": 25.5}
{"date": "2018-12-26 18:18:00", "average_delivery_time": 25.5}
{"date": "2018-12-26 18:19:00", "average_delivery_time": 25.5}
{"date": "2018-12-26 18:20:00", "average_delivery_time": 25.5}
{"date": "2018-12-26 18:21:00", "average_delivery_time": 25.5}
{"date": "2018-12-26 18:22:00", "average_delivery_time": 31}
{"date": "2018-12-26 18:23:00", "average_delivery_time": 31}
{"date": "2018-12-26 18:24:00", "average_delivery_time": 42.5}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

unbabel_cli-0.1.2.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

unbabel_cli-0.1.2-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file unbabel_cli-0.1.2.tar.gz.

File metadata

  • Download URL: unbabel_cli-0.1.2.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.2 Darwin/23.2.0

File hashes

Hashes for unbabel_cli-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7087fa138e643fff91373a2d220f31303d6ca275d6a57b6028b7a94612cbda20
MD5 eae2b201c8e82bf6c99f87a1b797cc0d
BLAKE2b-256 32feab71f5a10b0fc3176f1916a9c25df1718f821cad94627023b824cded1944

See more details on using hashes here.

File details

Details for the file unbabel_cli-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: unbabel_cli-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.2 Darwin/23.2.0

File hashes

Hashes for unbabel_cli-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e7256d31e2c64c764f12c7cb5a641912f57fab20017700b90c7a813dc1e57712
MD5 d3b5544bca5a1b0c38ce11d357f1fcd3
BLAKE2b-256 d29321e6ba860ba38998834c78a2452286a901aedf345107996241436a7aa042

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page