def create_call(): print('inserting calls') outbound = users.get('outbound') print(outbound) inbound = users.get('inbound') print(inbound) to_name = users.get('callee') from_name = users.get('caller') duration = users.get('duration') if outbound is not None: p = session.query(Call.id).filter(Call.id == item_id) if not session.query(p.exists()).scalar(): to = session.query(User).get(users.get('outbound')) call = Call(item_id, datetime.now(), to_name, from_name, duration) call.user = [to] session.add(call) else: to = session.query(User).get(users.get('outbound')) call = session.query(Call).get(item_id) call.user.append(to) elif inbound is not None: p = session.query(Call.id).filter(Call.id == item_id) if not session.query(p.exists()).scalar(): from_u = session.query(User).get(users.get('inbound')) call = Call(item_id, datetime.now(), to_name, from_name, duration) call.user = [from_u] session.add(call) else: from_u = session.query(User).get(users.get('inbound')) call = session.query(Call).get(item_id) call.user.append(from_u)
def test_sets_status(self): call = Call(self.callback_succeeds) call.join() self.assertEqual(call.status, Call.RESOLVED) call = Call(self.callback_rejects) call.join() self.assertEqual(call.status, Call.REJECTED)
def dispatch_call(self, caller): '''Assign a call to an employee. If no employees are available, queue this call. ''' call = Call(caller) self._dispatch_call(call)
def do_call(self, call_id): #If the call input is correct if call_id != '': call = Call(call_id) print("Call " + call_id + " received") #Adding call to the list of calls which are happening self.online_calls_list.addCall(call) #Flag to see if call is going to queue or not go_queue = True if self.call_queue.isEmpty(): #Look for operator available op = self.searchOperator("available") if op is not None: #Allocate call to operator print("Call " + call_id + " ringing for operator " + op.ID) self.operators.setCall(op.ID, call) go_queue = False #If is going to queue if go_queue: print("Call " + call_id + " waiting in queue") call.setStatus("waiting") self.call_queue.enqueue(call) else: print('Must specify a call id ( Call <call_id>)')
def test_bill_call_partially_free(self, t1): """ Test that a call is billed correctly even if it is longer than the number of free minutes remaining for the month. E.g. if 10 free minutes are remaining for the month and a call lasts 11 minutes, then 10 minutes should be counted as free and 1 minute should be billed normally. """ t1_mins = ceil(t1 / 60) tc = TermContract(datetime.date(2000, 9, 29), datetime.date(2007, 9, 29)) tc.new_month(10, 2007, Bill()) # make a call whose duration is longer than the number of free mins left c1 = Call(src_nr="123-4567", dst_nr="987-6543", calltime=datetime.datetime(year=2007, month=10, day=31, hour=20, minute=30, second=0), duration=t1, src_loc=(-79.45188229255568, 43.62186408875219), dst_loc=(-79.36866519485261, 43.680793196449336)) tc.bill_call(c1) # check that free mins have been maxed out self.assertEqual(tc.bill.free_min, TERM_MINS) # check that the rest of the call has been billed self.assertEqual(tc.bill.billed_min, t1_mins - TERM_MINS)
def read_in_callset(cls, **kwargs): assert "gcnv_segment_vcfs" in kwargs gcnv_segment_vcfs = kwargs["gcnv_segment_vcfs"] ref_dict = kwargs["reference_dictionary"] sample_to_calls_map = {} for vcf_file in gcnv_segment_vcfs: vcf_reader = vcf.Reader(open(vcf_file, 'r')) assert len(vcf_reader.samples) == 1 sample_name = vcf_reader.samples[0] interval_to_call_map = OrderedDict() for record in vcf_reader: interval = Interval(record.CHROM, record.POS, record.INFO['END']) event_type = EventType.gcnv_genotype_to_event_type( int(record.genotype(sample_name)['GT'])) attributes = { 'QS': int(record.genotype(sample_name)['QS']), 'QA': int(record.genotype(sample_name)['QA']), 'NP': int(record.genotype(sample_name)['NP']) } call = Call(interval=interval, sample=sample_name, event_type=event_type, call_attributes=attributes) interval_to_call_map[interval] = call sample_to_calls_map[sample_name] = FeatureCollection( interval_to_call_map) return cls(sample_to_calls_map, ref_dict)
def incoming_call(self, prm): call = Call(self.acc, call_id=prm.callId) call_prm = pj.CallOpParam() # Ringing State call_prm.statusCode = pj.PJSIP_SC_RINGING call.answer(call_prm) # Set uri call.uri = call.getInfo().remoteUri iid = call.uri.split(':')[1].split('@')[0] if msg.askquestion('Incoming Call', 'Accept call from ' + iid + ' ?', default=msg.YES): # If not exist current buddy, then create if iid not in self.buddy_list: # Initialize buddy bud = Buddy(self, iid) # Initialize configuration of buddy bud_cfg = pj.BuddyConfig() bud_cfg.uri = 'sip:' + iid + '@' + self.domain # Create buddy bud.cfg = bud_cfg bud.create(self.acc, bud.cfg) bud.subscribePresence(True) # Push into buddy_list self.buddy_list[iid] = bud self.update_buddy(bud) # If not exist current chat dialog, then create if iid not in self.chat_list: self.chat_list[iid] = Chat(self.acc, self.buddy_list[iid], self) # Inform the corresponding chat self.chat_list[iid].receive_call(call) else: call.hangup(call_prm)
def add_call(customer_id): '''Check for logged in user. Check for valid customer id. Get customer object that matches the given customer id. Get the user_id of the currently logged-in user. Get the current date-time. Get the notes from the POST request. Use the above data to create a new Call object. Save it. Redirect to the /customers/<customer_id>/ page.''' if check_for_logged_in() == True: if check_for_valid_customer_id(customer_id) == True: customer_id = customer_id c = Customer.get(customer_id) auth = Auth() current_user = auth.get_current_user() user_id = current_user['user_id'] current_dt = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") note = request.form.get('note') call_id = None new_call = Call(current_dt, note, call_id, customer_id, user_id) new_call.save() return redirect(url_for('show_customer', customer_id=customer_id)) else: return redirect(url_for('show_customers')) else: return redirect(url_for('login'))
def test_cancel_contract_positive_balance(self): """ Test that the balance is charged as the cancellation fee if the contract is cancelled while the balance is positive. """ pc = PrepaidContract(datetime.date(2000, 9, 29), 10) pc.new_month(month=10, year=2000, bill=Bill()) # make a call that costs $15 c1 = Call(src_nr="123-4567", dst_nr="987-6543", calltime=datetime.datetime(year=2000, month=10, day=31, hour=20, minute=30, second=0), duration=ceil(15 / PREPAID_MINS_COST * 60), src_loc=(-79.45188229255568, 43.62186408875219), dst_loc=(-79.36866519485261, 43.680793196449336)) pc.bill_call(c1) # since the call was very long, the balance should be positive now self.assertAlmostEqual(pc.balance, 5) cancel = pc.cancel_contract() # since the balance is positive, it should be billed, so the cost for # the month should be the balance self.assertAlmostEqual(cancel, pc.balance)
def reply(connection, username, client_address): """ responsible for sending replies on behalf host machine """ client_ip, port = client_address try: while True: data = connection.recv(1024) if data and 'dummie' in data: connection.sendall(username) break elif data and 'call' in data: call_obj = Call(vid_recv_port = 5009, vid_send_port = 5010) call_obj.start() print 'live chat started with' # videofeed.send_video_feed(client_ip) finally: # Clean up the connection if connection: connection.close()
def test_bill_call_not_free(self, t1): """ Test that a call is billed correctly if there are no free minutes remaining for the month. """ t1_mins = ceil(t1 / 60) tc = TermContract(datetime.date(2000, 9, 29), datetime.date(2007, 9, 29)) bill = Bill() tc.new_month(month=10, year=2007, bill=bill) # max out free mins so that a new call must be billed tc.bill.add_free_minutes(TERM_MINS) c1 = Call(src_nr="123-4567", dst_nr="987-6543", calltime=datetime.datetime(year=2007, month=10, day=31, hour=20, minute=30, second=0), duration=t1, src_loc=(-79.45188229255568, 43.62186408875219), dst_loc=(-79.36866519485261, 43.680793196449336)) tc.bill_call(c1) # check that the entire call has been billed self.assertAlmostEqual(tc.bill.get_cost() - TERM_MONTHLY_FEE, t1_mins * TERM_MINS_COST)
def process_event_history(log: Dict[str, List[Dict]], customer_list: List[Customer]) -> None: """ Process the calls from the <log> dictionary. The <customer_list> list contains all the customers that exist in the <log> dictionary. Construct Call objects from <log> 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 <log>, as specified in the handout. - The <log> argument guarantees that there is no "gap" month with zero activity for ALL customers, as specified in the handout. - The <log> dictionary is in the correct format, as defined in the handout. - The <customer_list> already contains all the customers from the <log>. """ # 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 current_month = billing_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) initial = 1 for event_data in log['events']: if event_data['type'] == 'call': src_nr = event_data['src_number'] dst_nr = event_data['dst_number'] calltime = datetime.datetime.strptime(event_data['time'], \ "%Y-%m-%d %H:%M:%S") duration = int(event_data['duration']) src_loc = event_data['src_loc'] dst_loc = event_data['dst_loc'] this_call = Call(src_nr, dst_nr, calltime, duration, src_loc, \ dst_loc) if initial == 1: new_month(customer_list, calltime.month, calltime.year) current_month = calltime.month initial = 0 if calltime.month != current_month: new_month(customer_list, calltime.month, calltime.year) current_month = calltime.month src = find_customer_by_number(src_nr, customer_list) dst = find_customer_by_number(dst_nr, customer_list) src.make_call(this_call) dst.make_call(this_call)
def process_event_history(log: Dict[str, List[Dict]], customer_list: List[Customer]) -> None: """ Process the calls from the <log> dictionary. The <customer_list> list contains all the customers that exist in the <log> dictionary. Construct Call objects from <log> 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 <log>, as specified in the handout. - The <log> argument guarantees that there is no "gap" month with zero activity for ALL customers, as specified in the handout. - The <log> dictionary is in the correct format, as defined in the handout. - The <customer_list> already contains all the customers from the <log>. """ 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 event_data['type'] == 'call': e = Call( event_data['src_number'], event_data['dst_number'], datetime.datetime.strptime(event_data['time'], "%Y-%m-%d %H:%M:%S"), event_data['duration'], event_data['src_loc'], event_data['dst_loc']) find_customer_by_number(event_data['src_number'], customer_list).make_call(e) find_customer_by_number(event_data['dst_number'], customer_list).receive_call(e) ############ ADVACNING NEW MONTH ############ if datetime.datetime.strptime(event_data["time"], "%Y-%m-%d %H:%M:%S").\ month != billing_month: billing_month = datetime.datetime.strptime\ (event_data["time"], "%Y-%m-%d %H:%M:%S").month billing_year = datetime.datetime.strptime\ (event_data["time"], "%Y-%m-%d %H:%M:%S").year new_month(customer_list, billing_month, billing_year)
def start_call(self, request): lvn = request.params['from'] number_insight_json = NCCOHelper.get_call_info(lvn) caller_name = number_insight_json.get("caller_name", "") call = Call(user_lvn=lvn, state=CallState.CHOOSE_ACTION, is_mobile=number_insight_json["original_carrier"]['network_type'] == "mobile") self.calls[request.params['conversation_uuid']] = call return NccoBuilder().customer_call_greeting(caller_name).with_input( self.domain + NCCOServer.NCCO_INPUT ).build()
def init(self): """register on the network""" logger.info("Turn on antenna power") logger.info("Register on the network") self.emit('provider-modified', "Charlie Telecom") self.network_strength = 100 yield tichy.Service.get('ConfigService').wait_initialized() self.config_service = tichy.Service.get("ConfigService") logger.info("got config service") self.values = self.config_service.get_items("call_forwarding") if self.values != None: self.values = dict(self.values) logger.info("realized values is none") self.SettingReason = tichy.settings.ListSetting( 'Call Forwarding', 'Reason', tichy.Text, value='unconditional', setter=self.ForwardingSetReason, options=[ "unconditional", "mobile busy", "no reply", "not reachable", "all", "all conditional" ], model=tichy.List([ ListSettingObject("unconditional", self.action), ListSettingObject("mobile busy", self.action), ListSettingObject("no reply", self.action), ListSettingObject("not reachable", self.action), ListSettingObject("all", self.action), ListSettingObject("all conditional", self.action) ]), ListLabel=[('title', 'name')]) self.SettingChannels = tichy.settings.Setting( 'Call Forwarding', 'channels', tichy.Text, value=self.ForwardingGet('class'), setter=self.ForwardingSetClass, options=["voice", "data", "voice+data", "fax", "voice+data+fax"]) self.SettingTargetNumber = tichy.settings.NumberSetting( 'Call Forwarding', 'Target Number', tichy.Text, value=self.ForwardingGet('number'), setter=self.ForwardingSetNumber) self.SettingTargetNumber = tichy.settings.NumberSetting( 'Call Forwarding', 'Timeout', tichy.Text, value=self.ForwardingGet('timeout'), setter=self.ForwardingSetTimeout) if len(self.logs) == 0: for i in range(3): call = Call('0049110', direction='out') self.logs.insert(0, call) yield None
def process_event_history(log: Dict[str, List[Dict]], customer_list: List[Customer]) -> None: """ Process the calls from the <log> dictionary. The <customer_list> list contains all the customers that exist in the <log> dictionary. Construct Call objects from <log> 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 <log>, as specified in the handout. - The <log> argument guarantees that there is no "gap" month with zero activity for ALL customers, as specified in the handout. - The <log> dictionary is in the correct format, as defined in the handout. - The <customer_list> already contains all the customers from the <log>. """ # TODO: FIX DATA TIMES IN CALL OBJECT billing_date = datetime.datetime.strptime(log['events'][0]['time'], "%Y-%m-%d %H:%M:%S") billing_month = billing_date.month billing_year = billing_date.year #new_month(customer_list,billing_month,billing_year) for sub_dict in log['events']: kind = sub_dict['type'] current_date = datetime.datetime.strptime(sub_dict['time'], "%Y-%m-%d %H:%M:%S") current_month = current_date.month current_year = current_date.year if current_month != billing_month: new_month(customer_list, current_month, current_year) billing_month = current_month if kind == 'call': caller = sub_dict['src_number'] callee = sub_dict['dst_number'] time = current_date duration = sub_dict['duration'] src_loc = sub_dict['src_loc'] dst_loc = sub_dict['dst_loc'] call_inst = Call(caller, callee, time, duration, src_loc, dst_loc) cust = find_customer_by_number(caller, customer_list) cust.make_call(call_inst) r_cust = find_customer_by_number(callee, customer_list) r_cust.receive_call(call_inst)
def __init__(self): try: self.lib = pj.Lib() except pj.Error: debug("Error initialising library.") self.calls = Call() self.cb = core_cb() self.transport = None self.acc = None self.dev = None
def process_event_history(log: Dict[str, List[Dict]], customer_list: List[Customer]) -> None: """ Process the calls from the <log> dictionary. The <customer_list> list contains all the customers that exist in the <log> dictionary. Construct Call objects from <log> 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 <log>, as specified in the handout. - The <log> argument guarantees that there is no "gap" month with zero activity for ALL customers, as specified in the handout. - The <log> dictionary is in the correct format, as defined in the handout. - The <customer_list> already contains all the customers from the <log>. """ 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']: # updating new_month curr_date = datetime.datetime.strptime(event_data['time'], "%Y-%m-%d %H:%M:%S") if (curr_date.month > billing_month) or \ (curr_date.year > billing_date.year): new_month(customer_list, curr_date.month, curr_date.year) billing_date = curr_date # creating call instances if event_data['type'] == 'call': new_call = Call( event_data["src_number"], event_data["dst_number"], datetime.datetime.strptime(event_data['time'], "%Y-%m-%d %H:%M:%S"), event_data["duration"], event_data["src_loc"], event_data["dst_loc"]) customer_making_call = find_customer_by_number( new_call.src_number, customer_list) customer_receiving_call = find_customer_by_number( new_call.dst_number, customer_list) customer_making_call.make_call(new_call) customer_receiving_call.receive_call(new_call)
def process_event_history(log: Dict[str, List[Dict]], customer_list: List[Customer]) -> None: """ Process the calls from the <log> dictionary. The <customer_list> list contains all the customers that exist in the <log> dictionary. Construct Call objects from <log> 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 <log>, as specified in the handout. - The <log> argument guarantees that there is no "gap" month with zero activity for ALL customers, as specified in the handout. - The <log> dictionary is in the correct format, as defined in the handout. - The <customer_list> already contains all the customers from the <log>. """ # 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']: new_date = datetime.datetime.strptime(event_data['time'], "%Y-%m-%d %H:%M:%S") n_month = new_date.month if n_month != billing_month: new_month(customer_list, new_date.month, new_date.year) billing_month = n_month if event_data["type"] == "call": src_num = event_data["src_number"] dst_num = event_data["dst_number"] durtn = event_data["duration"] src_loc = tuple(event_data["src_loc"]) dst_loc = tuple(event_data["dst_loc"]) our_call = Call(src_num, dst_num, new_date, durtn, src_loc, dst_loc) caller = find_customer_by_number(our_call.src_number, customer_list) callee = find_customer_by_number(our_call.dst_number, customer_list) callee.receive_call(our_call) caller.make_call(our_call)
def _make_call(self): if self.state == AudioState.DISCONNECT: # Initialize Call self.call = Call(self.acc, self.bud.cfg.uri, self) # Create paramter call_prm = pj.CallOpParam() # Enable audio call_prm.opt.audioCount = 1 # Enable video call_prm.opt.videoCount = 1 # Make call self.call.makeCall(self.bud.cfg.uri, call_prm)
def _load_logs(self): """Load all the logs""" LOGGER.info("Loading call logs") data = tichy.Persistance('calls/logs').load() if not data: return # TODO: add some checks for data consistency logs = [] for kargs in data: #print kargs call = Call(**kargs) logs.append(call) self.logs[:] = logs
def process_event_history(log: Dict[str, List[Dict]], customer_list: List[Customer]) -> None: """ Process the calls from the <log> dictionary. The <customer_list> list contains all the customers that exist in the <log> dictionary. Construct Call objects from <log> 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 <log>, as specified in the handout. - The <log> argument guarantees that there is no "gap" month with zero activity for ALL customers, as specified in the handout. - The <log> dictionary is in the correct format, as defined in the handout. - The <customer_list> already contains all the customers from the <log>. """ # 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 # what if one the event_data is an empty dictionary new_month(customer_list, billing_date.month, billing_date.year) for event_data in log['events']: bil_date = datetime.datetime.strptime(event_data['time'], "%Y-%m-%d %H:%M:%S") bil_month, bil_year = bil_date.month, bil_date.year if bil_month != billing_month: billing_month, billing_year = bil_month, bil_year new_month(customer_list, billing_month, billing_year) if event_data['type'] == 'call': time, dur = bil_date, int(event_data['duration']) src_loc = tuple(event_data['src_loc']) dst_loc = tuple(event_data['dst_loc']) call = Call(event_data['src_number'], event_data['dst_number'], time, dur, src_loc, dst_loc) # check the none return part for customer caller = find_customer_by_number(event_data['src_number'], customer_list) receiver = find_customer_by_number(event_data['dst_number'], customer_list) caller.make_call(call) receiver.receive_call(call)
def process_event_history(log: Dict[str, List[Dict]], customer_list: List[Customer]) -> None: """ Process the calls from the <log> dictionary. The <customer_list> list contains all the customers that exist in the <log> dictionary. Construct Call objects from <log> 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 <log>, as specified in the handout. - The <log> argument guarantees that there is no "gap" month with zero activity for ALL customers, as specified in the handout. - The <log> dictionary is in the correct format, as defined in the handout. - The <customer_list> already contains all the customers from the <log>. """ billing_date = datetime.datetime.strptime(log['events'][0]['time'], "%Y-%m-%d %H:%M:%S") new_month(customer_list, billing_date.month, billing_date.year) for event_data in log['events']: billing_month_per_event = datetime.datetime.strptime( event_data['time'], "%Y-%m-%d %H:%M:%S") if billing_month_per_event.month > billing_date.month and \ billing_month_per_event.year >= billing_date.year: billing_date = billing_month_per_event new_month(customer_list, billing_date.month, billing_date.year) if event_data['type'] == 'call': call = Call( event_data['src_number'], event_data['dst_number'], datetime.datetime.strptime(event_data['time'], "%Y-%m-%d %H:%M:%S"), event_data['duration'], (float(event_data['src_loc'][0]), float(event_data['src_loc'][1])), (float(event_data['dst_loc'][0]), float(event_data['dst_loc'][1]))) find_customer_by_number(event_data['src_number'], customer_list).\ make_call(call) find_customer_by_number(event_data['dst_number'], customer_list).\ receive_call(call)
def test_bill_call_free(self, t1: int, t2: int): """ Test that calls are billed as free as long as there are enough free minutes remaining. (The examples test the case the calls use all the free minutes.) """ tc = TermContract(datetime.date(2000, 9, 29), datetime.date(2007, 9, 29)) bill = Bill() tc.new_month(month=10, year=2007, bill=bill) c1 = Call(src_nr="123-4567", dst_nr="987-6543", calltime=datetime.datetime(year=2007, month=10, day=31, hour=20, minute=30, second=0), duration=t1, src_loc=(-79.45188229255568, 43.62186408875219), dst_loc=(-79.36866519485261, 43.680793196449336)) c2 = Call(src_nr="123-4567", dst_nr="987-6543", calltime=datetime.datetime(year=2007, month=10, day=31, hour=21, minute=30, second=0), duration=t2, src_loc=(-79.45188229255568, 43.62186408875219), dst_loc=(-79.36866519485261, 43.680793196449336)) tc.bill_call(c1) tc.bill_call(c2) # the calls should be free, so the only cost billed should be the # monthly fee self.assertEqual(tc.bill.get_cost() - TERM_MONTHLY_FEE, 0, (t1, t2))
def process_event_history(log: Dict[str, List[Dict]], customer_list: List[Customer]) -> None: """ Processes the calls from the <log> dictionary. The <customer_list> list contains all the customers that exist in the <log> dictionary. Construct Call objects from <log> and register the Call into the corresponding customer's call history. Preconditions: - All calls are ordered chronologically (based on the call's date and time), when retrieved from the dictionary <log>, as specified in the handout. - The <log> argument guarantees that there is no "gap" month with zero activity for ALL customers, as specified in the handout. - The <log> dictionary is in the correct format, as defined in the handout. - The <customer_list> already contains all the customers from the <log>. """ from call import Call billing_date = datetime.datetime.strptime(log['events'][0]['time'], "%Y-%m-%d %H:%M:%S") billing_month = billing_date.month for event_data in log['events']: customer_received = find_customer_by_number(event_data['dst_number'], customer_list) customer_caller = find_customer_by_number(event_data['src_number'], customer_list) if event_data['type'] == 'call': src_number = event_data['src_number'] dst_number = event_data['dst_number'] time = datetime.datetime.strptime(event_data['time'], "%Y-%m-%d %H:%M:%S") duration = event_data['duration'] src_loc = event_data['src_loc'] dst_loc = event_data['dst_loc'] call = Call(src_number, dst_number, time, duration, src_loc, dst_loc ) customer_caller.make_call(call) customer_received.receive_call(call) if datetime.datetime.strptime(event_data['time'], "%Y-%m-%d %H:%M:%S").month is not\ billing_month: billing_date = datetime.datetime.strptime(event_data['time'], "%Y-%m-%d %H:%M:%S") billing_month = billing_date.month new_month(customer_list, billing_date.month, billing_date.year)
def call(self): vms = self.voicemails vms = vms.shuffled() num = 10 print("Playing %d tattles.." % num) call = Call() path = call.write(vms[0:num]) answered = call.execute(path) answered = True if answered: self.call_in(config.call_mins_after_answer) else: self.call_in(config.call_mins_after_no_answer)
def process_event_history(log: Dict[str, List[Dict]], customer_list: List[Customer]) -> None: """ Process the calls from the <log> dictionary. The <customer_list> list contains all the customers that exist in the <log> dictionary. Construct Call objects from <log> 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 <log>, as specified in the handout. - The <log> argument guarantees that there is no "gap" month with zero activity for ALL customers, as specified in the handout. - The <log> dictionary is in the correct format, as defined in the handout. - The <customer_list> already contains all the customers from the <log>. """ # 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 billing_year = billing_date.year new_month(customer_list, billing_date.month, billing_date.year) for event_data in log['events']: check_date = datetime.datetime.strptime(event_data['time'], "%Y-%m-%d %H:%M:%S") if not (billing_month == check_date.month and billing_year == check_date.year): billing_month = check_date.month billing_year = check_date.year new_month(customer_list, billing_month, billing_year) if event_data['type'] == 'call': new_call = Call(event_data['src_number'], event_data['dst_number'], check_date, event_data['duration'], tuple(event_data['src_loc']), tuple(event_data['dst_loc'])) src_cust = find_customer_by_number(event_data['src_number'], customer_list) dst_cust = find_customer_by_number(event_data['dst_number'], customer_list) src_cust.make_call(new_call) dst_cust.receive_call(new_call)
def __preprocess(self): """ Preprocess the callset by filling the regions with no calls with EventType.NO_CALL events, thereby assigning an event to every single base. """ for sample in self.sample_names: interval_to_call_map = OrderedDict() for contig in self.ref_dict.contigs: contig_interval = self.ref_dict.get_contig_interval_for_chrom_name( contig) events_on_contig = self.sample_to_calls_map.get( sample)._get_interval_tree(contig) if not events_on_contig: continue result = events_on_contig.copy() # TODO make code aware of 1-based representation # TODO i.e. right now some events overlap by a single base # This hacky code fills potential gaps between calls that lie within interval with NO_CALL events result.addi( contig_interval.start, contig_interval.end, Call(interval=contig_interval, sample=sample, event_type=EventType.NO_CALL, call_attributes={ "QS": 0, "QA": 0 })) result.split_overlaps() for interval in events_on_contig.items(): result.remove_overlap(interval.begin, interval.end) for interval in events_on_contig.items(): result.addi(interval.begin, interval.end, Call.deep_copy(interval.data)) for t in sorted(result): if t.end - t.begin == 1 and t.data.event_type == EventType.NO_CALL: # intervaltree.split_overlaps will create single base regions which we want to discard continue call = Call.deep_copy(t.data) if t.data.event_type == EventType.NO_CALL: call.interval = Interval(contig, t.begin, t.end) interval_to_call_map[Interval(contig, t.begin, t.end)] = call self.sample_to_calls_map[sample] = FeatureCollection( interval_to_call_map)
def create_call(self, number, direction='out'): """create a new Call :Parameters: number : `TelNumber` | str The peer number of the call direction : str Indicate the direction of the call. Can be 'in' or 'out' """ LOGGER.info("create call %s" % number) call = Call(number, direction=direction) self.logs.insert(0, call) return call
def __init__(self): try: self.lib = pj.Lib() except pj.Error: debug("Error initalizing library") self.cfg = sysconfig() # Initiate class variables self.calls = Call() self.cb = core_cb() self.transport = None self.account = None self.device = None debug("Library initalized") self.state = None