- Python 3.7+
- Postgresql
Create models for aggregating subscription usage metrics which will be used for generating metrics and small reports.
We have two types of usage - data usage and voice usage. The raw usage records usage types for these exist in the DataUsageRecord and VoiceUsageRecord tables. Create models that will use the data from these two tables and store aggregated metrics segmented by date.
NOTE: You are not required to write the query to populate the new models you create with data from the raw usage records tables. Those raw usage record tables are there for reference.
Create one or both of the APIs below:
Create an API that accepts a price limit as a request parameter. Find any subscriptions that have reached the price limit on either data and/or voice (check both usage types). Return a list of the subscription id, type(s) of usage that exceeded the price limit, and by how much it's exceeded the limit.
Create an API that fetches data usage metrics and voice usage metrics by subscription id. This endpoint should accept a from date, to date, and usage type request parameter. Return a list of the subscription id, total price of usage for the given dates, and total usage for any subscriptions that had usage during the given from and to dates.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Write a query to efficiently populate your aggregated usage models from the raw usage record tables.
HINT: Optimize for high volumes of raw usage records, but not long retention periods.
- Improve and optimize the existing code where you see fit.
- Write tests!