Question
## help when I ran my code ..it shows... Traceback (most recent call last): File C:/Users/Desktop/Assignment 1/starter_code/application.py, line 143, in process_event_history(input_dictionary, customers) File C:/Users/Desktop/Assignment 1/starter_code/application.py,
## help when I ran my code ..it shows... "Traceback (most recent call last): File "C:/Users/Desktop/Assignment 1/starter_code/application.py", line 143, in
Instructions:
Your first code-writing task is to implement the process_event_history() function in the application module. The role of this function is to instantiate Call objects and store each of them in the right customer's records.
The parameter log is a dictionary containing all calls and SMSs from the dataset. Its key events contains a list of call and SMS events, which you will go through, creating Call objects out of events of type "call", and ignoring events of type "sms".
Each event you extract from the log dictionary is itself a dictionary. A call event has the following keys:
- 'type' corresponds to the type of event ("call" or "sms")
- 'src_number' corresponds to the caller's phone number
- 'dst_number' corresponds to the callee's phone number
- 'time' corresponds to the time when this call was made (for example: "2018-01-02 01:07:10")
- 'duration' corresponds to the call duration (in seconds)
- 'src_loc' corresponds to the caller's location (longitude+latitude)
- 'dst_loc' corresponds to the callee's location (longitude+latitude)
We have provided the first three lines of code in this method, to show you how to extract data from the dictionary and to give you an example of using the datetime module. You will need to familiarize yourselves with this module by reading the datetime documentation
As you go through the list of events and instantiate Call objects, you must also record these in the right Customer's records. This must be done by using the Customer class API, so please consult it to find the methods for registering incoming or outgoing calls. You will implement some of these Customer methods in the next task so calling them now will have no effect, but put the calls in. As we discussed in lectures, in order to use an API, all you need to know is the interface, not the implementation.
Additionally, as you instantiate new events, every time a new month is detected for the current event you are processing (whether it's a call or SMS!), you must advance all customers to a new month of contract. This is done using the new_month() function from the application.py module.
To help you understand this better, we define a few concepts which we will use in this assignment:
-
Advancing to a new month is the action of moving to a new month of contract, which must be done for the purposes of billing. The new_month() function in this module advances the month for every customer for each of their phonelines, according to the respective contract types (remember that customers can have multiple phone lines each, and that each phone line can be under a different type of contract).
-
Gap month is defined as a month with no activity for any customer (no calls or SMSs), despite there being activity in the month prior to the gap month, as well as in the month after the gap month.
We are making several simplifying assumptions, and enforcing them via preconditions in the code:
-
The input data is guaranteed to be sorted chronologically. Therefore, advancing to a new month of contract can be safely done. For example, once you encounter an event from February 2019, you are guaranteed the next events you process cannot be from a month before February 2019.
-
There is no gap month in the input data. This implies that for the timespan between the first event and the last event in the dataset, there is no month with zero activity from all customers. In other words, while one customer could have zero activity during a specific month X, there is at least one other customer who had some activity during that month. Therefore, according to the definition of advancing a month, customers with zero activity for a specific month will still get a Bill instance created. This bill will just have whatever baseline cost the corresponding contract specifies (more on this when we get to contracts in a later task).
Important: We are providing you with a find_customer_by_number() function. You must use it to figure out which customer a number belongs to. (Our autotesting depends on this, and you will lose marks if you don't.)
Check your work: Write pytest tests to make sure your code so far works according to specifications. It is your responsibility to write good tests!
def process event history(log: Dictrstr, List Dict customer list: List[Customer])None: "Process the calls from the
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started