Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete TODOs please import datetime import json from contract import Contract from customer import Customer from phoneline import PhoneLine from visualizer import Visualizer def import_data()

Complete TODOs please

import datetime import json from contract import Contract from customer import Customer from phoneline import PhoneLine from visualizer import Visualizer def import_data() -> dict[str, list[dict]]: """ Open the file  which stores the json data, and return a dictionary that stores this data in a format as described in the A1 handout. Precondition: the dataset file must be in the json format. """ with open("dataset.json") as o: log = json.load(o) return log def create_customers(log: dict[str, list[dict]]) -> list[Customer]: """ Returns a list of Customer instances for each customer from the input dataset from the dictionary . Precondition: - The  dictionary contains the input data in the correct format, matching the expected input format described in the handout. """ customer_list = [] for cust in log['customers']: customer = Customer(cust['id']) for line in cust['lines']: # TODO: # comment out the following three lines of code only when you get # to implement task 3. These lines are provided as a placeholder so # that your visualization works when you have only completed up to # and including task 2. Never instantiate the abstract class # "Contract" as below. # Remove this TODO list when you're done. contract = Contract(datetime.datetime.now()) contract.new_month = lambda *args: None contract.bill_call = lambda *args: None # TODO: # 1) Uncomment the piece of code below once you've implemented # all types of contracts. # 2) Make sure to import the necessary contract classes in this file # and remove any unused imports to pass PyTA. # 3) Do not change anything in the code below besides uncommenting it # 4) Remove this TODO list when you're done. """ contract = None if line['contract'] == 'prepaid': # start with $100 credit on the account contract = PrepaidContract(datetime.date(2017, 12, 25), 100) elif line['contract'] == 'mtm': contract = MTMContract(datetime.date(2017, 12, 25)) elif line['contract'] == 'term': contract = TermContract(datetime.date(2017, 12, 25), datetime.date(2019, 6, 25)) else: print("ERROR: unknown contract type") """ line = PhoneLine(line['number'], contract) customer.add_phone_line(line) customer_list.append(customer) return customer_list def find_customer_by_number(number: str, customer_list: list[Customer]) \ -> Customer: """ Return the Customer with the phone number  in the list of customers . If the number does not belong to any customer, return None. """ cust = None for customer in customer_list: if number in customer: cust = customer return cust def new_month(customer_list: list[Customer], month: int, year: int) -> None: """ Advance all customers in  to a new month of their contract, as specified by the  and  arguments. """ for cust in customer_list: cust.new_month(month, year) def process_event_history(log: dict[str, list[dict]], customer_list: list[Customer]) -> None: """ Process the calls from the  dictionary. The  list contains all the customers that exist in the  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  already contains all the customers from the . """ # TODO: Implement this method. We are giving you the first few lines of code billing_date = datetime.datetime.strptime(log['events'][0]['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']: # # ... if __name__ == '__main__': v = Visualizer() print("Toronto map coordinates:") print(" Lower-left corner: -79.697878, 43.576959") print(" Upper-right corner: -79.196382, 43.799568") input_dictionary = import_data() customers = create_customers(input_dictionary) process_event_history(input_dictionary, customers) # ---------------------------------------------------------------------- # NOTE: You do not need to understand any of the implementation below, # to be able to solve this assignment. However, feel free to # read it anyway, just to get a sense of how the application runs. # ---------------------------------------------------------------------- # Gather all calls to be drawn on screen for filtering, but we only want # to plot each call only once, so only plot the outgoing calls to screen. # (Each call is registered as both an incoming and outgoing) all_calls = [] for c in customers: hist = c.get_history() all_calls.extend(hist[0]) print(" -----------------------------------------") print("Total Calls in the dataset:", len(all_calls)) # Main loop for the application. # 1) Wait for user interaction with the system and processes everything # appropriately # 2) Take the calls from the results of the filtering and create the # drawables and connection lines for those calls # 3) Display the calls in the visualization window events = all_calls while not v.has_quit(): events = v.handle_window_events(customers, events) connections = [] drawables = [] for event in events: connections.append(event.get_connection()) drawables.extend(event.get_drawables()) # Put the connections on top of the other sprites drawables.extend(connections) v.render_drawables(drawables) import python_ta python_ta.check_all(config={ 'allowed-import-modules': [ 'python_ta', 'typing', 'json', 'datetime', 'visualizer', 'customer', 'call', 'contract', 'phoneline' ], 'allowed-io': [ 'create_customers', 'import_data' ], 'generated-members': 'pygame.*' }) 

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

Step: 3

blur-text-image

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

1 2 3 Data Base Techniques

Authors: Dick Andersen

1st Edition

0880223464, 978-0880223461

More Books

Students also viewed these Databases questions

Question

15. Calculate 93 , 96 , 7 2 , 7 5 , 10 7 .

Answered: 1 week ago