This project aims to accomplish the Bitly Coding Challenge.
This project involves analyzing data files to solve the specific problem outlined in the challenge description.
The challenge uses 'encodes.csv' and 'decodes.json', representative of data encountered in Bitly's daily operations:
- 'encodes.csv' contains shortened link information.
- 'decodes.json' includes raw bitlink clicks.
These datasets are utilized to address the problem statement.
The goal is to calculate the number of clicks from 2021 for each record in the 'encodes.csv' dataset.
- Python 3 installed
-
Clone the Repository:
git clone https://github.com/srpayd/bitly_challenge.git
-
Navigate to the Project Directory:
cd bitly-coding-challenge
-
Install Dependencies (if any): Python's core libraries, such as dictionaries and lists, were utilized throughout the project. No external or third-party libraries were installed or employed.
-
Run the code Replace 'encodes.csv' and 'decodes.json' with your file paths.
python solution.py python test_solution.py
-
Read 'encodes.csv' file: Create a dictionary using 'encodes.csv' where keys are long URLs, and values are corresponding shortened URLs.
-
Read 'decodes.json' file: Parse 'decodes.json' and filter records from 2021.
-
Match shortened URLs with records from 2021: Compare the bitlinks in the filtered records from 2021 with the dictionary created from 'encodes.csv' to identify corresponding long URLs. Finally, count clicks for each long URL: Tally the number of clicks from 2021 for each long URL.
The provided code addresses the challenge by calculating the 2021 click counts for each record in 'encodes.csv' using data from 'decodes.json'.
-
Reading CSV and JSON Files: Reads 'encodes.csv' and 'decodes.json' to create dictionaries of shortened links and bitlink clicks.
-
Data Processing: Filters 2021 records in 'decodes.json' and matches bitlinks to corresponding long URLs in 'encodes.csv'.
-
Click Count Calculation: Counts 2021 clicks in descending order for each record in 'encodes.csv' by tallying matching records from 'decodes.json'.
The project includes a test suite comprising three unit tests to validate specific functionalities within the codebase.
- Purpose: This test validates the
read_encode_csv
function's behavior by checking if it correctly reads and parses the 'encodes.csv' file, creating a dictionary of encoded URLs. - Assertions:
- Ensures that the function returns a dictionary.
- Verifies that the dictionary contains the expected number of entries (6 in this case).
- Purpose: Validates the
read_decode_json
function's behavior by verifying its ability to read and parse the 'decodes.json' file, creating a list of decoded click data. - Assertions:
- Confirms that the function returns a list.
- Checks if the list contains the expected number of records (10,000 in this case).
- Purpose: This test validates the
filter_and_count_2021_clicks
function's functionality by testing its ability to filter and count clicks from 2021 for each record in the 'encodes.csv' dataset. - Assertions:
- Ensures that the function returns a dictionary.
- Verifies that the resulting dictionary contains the expected number of entries (6).
- Tests if the click count for each record in the dictionary is greater than zero.
To run the unit tests:
- Navigate to the project directory in the terminal.
- Execute the following command:
python -m unittest test_solution.py
Serap Aydogdu - linkedin | medium
Project Link: https://github.com/srpayd/bitly_challenge