Code Monkey home page Code Monkey logo

jsonparser's Introduction

Highest Scores

Usage

  1. Change directory to this folder
  2. py main.py --path=./TestCase/input.data --count=3

Problem Text:

​ Given a data file containing scored records, in your favorite programming language, write a program to output the N highest record IDs & scores by score in descending order, highest score first. The output should be correctly formatted JSON. The program should take the file path of the data file as it's first parameter, and number of scores to return as it's second parameter, like so:

./highest score_recs.data 25

​ The input data file has a record per line. Each line has the following structure:

<score>: <json string>

If the line has a score that would make it part of the highest scores, then the remainder of the line must be parsable as JSON, and there must be an "id" key at the top level of this JSON doc. ​ An example data file could look like this: ​

10622876: {"umbrella": 99180, "name": "24490249af01e145437f2f64d5ddb9c04463c033", "value": 12354, "payload": "........", "date_stamp": 58874, "time": 615416, "id": "3c867674494e4a7aac9247a9d9a2179c"}
13214012: {"umbrella": 924902, "name": "70dd4d9494d1cd0362e123ce90f4053726b29e97", "value": 976852, "payload": "........", "date_stamp": 3255, "time": 156309, "id": "085a11e1b82b441184f4a193a3c9a13c"}
11446512: {"umbrella": 727371, "name": "8e21427b2350023079835361dce03cdea95a2983", "value": 70801, "payload": "........", "date_stamp": 1730, "time": 496866, "id": "84a0ccfec7d1475b8bfcae1945aea8f0"}
11025835: === THIS IS NOT JSON and should error if this line is part of the result set, but is ok if it not ==
11269569: {"umbrella": 902167, "name": "e4898b9bf79831cf36811917a797ef0fcf3af636", "value": 593180, "payload": "........", "date_stamp": 58736, "time": 1014495, "id": "7ec85fe3aa3c4dd599e23111e7abf5c1"}
11027069: {"umbrella": 990975, "name": "8aa306fb59e275a7e39debb1d5113ff411df22ad", "value": 67842, "payload": "........", "date_stamp": 60161, "time": 225413, "id": "f812d487de244023a6a713e496a8427d"}
​

​ Note that one of the entries, for score 11025835, has a document portion that is not JSON. If this line was included in the result set, then the program should error, but if not then it should continue. ​ For example, if run with an N of 3 it would produce: ​

$ ./highest score_recs.data 3
[
    {
        "score": 13214012,
        "id": "085a11e1b82b441184f4a193a3c9a13c"
    },
    {
        "score": 11446512,
        "id": "84a0ccfec7d1475b8bfcae1945aea8f0"
    },
    {
        "score": 11269569,
        "id": "7ec85fe3aa3c4dd599e23111e7abf5c1"
    }
]

​ But when run with an N that includes that line, it would error:

$ ./highest score_recs.data 10
invalid json format No JSON object could be decoded
 THIS IS NOT JSON

​ Other requirements / things to note about the data files:

  • The ids are unique across the data set
  • Scores can repeat, but you should only count the id of the last line processed as the "winning" id.
  • Scores are non-negative 32-bit integers.
  • The id must be at the root level of the JSON object, if it is not present it is a format error.. ​ ​ Upon successful running, the program should exit with exit code 0, any other errors as described above should exit with a non 0 code.

jsonparser's People

Contributors

trilamsr avatar utkarshkhokhar avatar

Watchers

 avatar  avatar  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.