Mixtape Application
Python version 3.6
Description
Mixtape Application reads data from mixtape-data.json, loads it to memory.
Also reads changes.json, loads to memory and applies them to mixtape-data.json and produces output.json
Input File Formats:
mixtape-data.json - JSON
changes.json - JSON
Output File Format:
output.json - JSON
Usage:
Tested and Verified in Windows, expected to work in Linux, Mac
Takes two arguments mixtape-data.sjon, changes.json
python mixtape-app.py mixtape-data.json changes.json
Supported Operations:
-
Add a new playlist
Create a dictionary object with song_ids, user_id, action: "add"
-
Add a new song to an existing playlist
Create a dictionary object with playlist id, song_id, action: "update" Supports only one song update at a time, can be easily expanded to support multiple songs by changing the data type
-
Remove a playlist
Create a dictionary object with id, action: "delete" Supports to remove only one playlist at a time, can be easily expanded to remove multiple playlists by changing the data type
Sample changes.json File:
{
"playlists":
[
{
"action": "add",
"user_id": "7",
"song_ids": [
"3",
"6"
]
},
{
"action": "update",
"id": "2",
"song_id": "20"
},
{
"action": "remove",
"id": "1"
}
]
}
Time Complexity:
Now all the operations are done in O(1)
Scaling
As the files get larger, memory will be an issue and reading, writing to a file will not be efficient.
mixtape-data.json is the reference file, needs to be loaded somewhere first before applying changes.json one change at a time.
As there are relations between playlists, user, song, it would be efiicient to store it in a Relational DB like MySQL,
distributed DB(if needed)
If changes.json gets larger, can be read in chunks and apply the changes iteratively to the mixtape-data.json file.
Instaed of json, needs to be jsonl. changes.jsonl will have the json inputs in lines.
Assumptions
mixtape-data.json will always have some songs, users, playlists