Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

## 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,

image text in transcribed

## 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", line 129, in process_event_history temp = ([billing_date.year][billing_date.month]).append(find_customer_by_number(data['src_number'],customer_list)) IndexError: list index out of range "

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:

  1. 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).

  2. 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 dictionary. The List contains all the customers that exist in the xlog> dictionary Construct Call objects from and register the Call into the corresponding customer's call history Hint: You must advance all customers to a new month using the new month( function, everytime a new month is detected for the current event you are extracting Preconditions: ALL calls are ordered chronologically (based on the call 's date and time), when retrieved from the dictionary, as specified in the handout. - The argument guarantees that there is no "gap" month with zero activity for ALL customers, as specified in the handout - The dictionary is in the correct format, as defined in the handout. - The . # TODO : Implement this method . We are giving you the first few lines of code billing_date - datetime.datetime.strptime (logl'events'][ ]['time', "%Y-%m-%d %H:%M : %S") billing month- billing date.month # start recording the bills from this date # Note: uncomment the following lines when you're ready to implement this # new month(customer list, billing date .month, billing date. year) # for event-data in log ['events'): for data in log['events']: billing-date datetine . datetine . strptime (data['tine'],"XY-Xn-%d %H : %M : %S") temp([billing_date.year] [billing_date.month]).append (find_customer_by_number(data['src_number'],customer_list)) for year in temp: for month in temp[year]: new_month (temp[year][month], month, year)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2012 Administration

Authors: Adam Jorgensen, Steven Wort

1st Edition

1118106881, 9781118106884

More Books

Students also viewed these Databases questions

Question

Does your message use defamatory language?

Answered: 1 week ago