def base_stations_init(cls, bs_params, slice_params): base_stations = [] i = 0 usage_patterns = {} for name, s in slice_params.items(): usage_patterns[name] = Distributor( name, get_dist(s['usage_pattern']['distribution']), *s['usage_pattern']['params']) for bs in bs_params: slices = [] ratios = bs['ratios'] capacity = bs['capacity_bandwidth'] for name, s in slice_params.items(): s_cap = capacity * ratios[name] s = Slice(name, ratios[name], 0, s['client_weight'], s['delay_tolerance'], s['qos_class'], s['bandwidth_guaranteed'], s['bandwidth_max'], s_cap, usage_patterns[name]) s.capacity = Container(init=s_cap, capacity=s_cap) slices.append(s) base_station = BaseStation( i, Coverage((bs['x'], bs['y']), bs['coverage']), capacity, slices) base_stations.append(base_station) i += 1 return base_stations
def run_function(self, inp): with Coverage() as cov: try: result = super().run_function(inp) except Exception as exc: self._coverage = cov.coverage() raise exc self._coverage = cov.coverage() return result
def population_coverage(population, function): cumulative_coverage = [] all_coverage = set() for s in population: with Coverage() as cov: with ExpectError(mute=True): with ExpectTimeout(1, mute=True): function(s) all_coverage |= cov.coverage() cumulative_coverage.append(len(all_coverage)) return all_coverage, cumulative_coverage
if __package__ is None or __package__ == "": from Grammars import CGI_GRAMMAR else: from .Grammars import CGI_GRAMMAR if __name__ == "__main__": cgi_fuzzer = GrammarFuzzer(CGI_GRAMMAR) if __name__ == "__main__": trials = 100 coverage = {} for i in range(trials): cgi_input = cgi_fuzzer.fuzz() with Coverage() as cov: cgi_decode(cgi_input) coverage[cgi_input] = cov.coverage() if __name__ == "__main__": coverage_slice = [ cgi_input for cgi_input in coverage if ('cgi_decode', 25) in coverage[cgi_input] ] if __name__ == "__main__": print(coverage_slice) if __name__ == "__main__": len(coverage_slice) / trials
if __name__ == "__main__": print('\n## Covering Code by Covering Grammars') # ### CGI Grammars if __name__ == "__main__": print('\n### CGI Grammars') if __package__ is None or __package__ == "": from Coverage import Coverage, cgi_decode else: from .Coverage import Coverage, cgi_decode if __name__ == "__main__": with Coverage() as cov_max: cgi_decode('+') cgi_decode('%20') cgi_decode('abc') try: cgi_decode('%?a') except: pass if __name__ == "__main__": f = GrammarCoverageFuzzer(CGI_GRAMMAR, max_nonterminals=2) coverages = {} trials = 100 for trial in range(trials): f.reset_coverage()
def __init__(self, coverage, line, covered=False): Coverage.__init__(coverage, line, covered)
def create_cust_data(): start_time = datetime.now() print('\tcreate_cust_data started: ', datetime.now()) #Create 2 mySQL connections cnx = mysql.connector.connect(user=database['USER'], password=database['PASSWORD'], host=database['HOST'], database=database['DATABASE']) mycursor = cnx.cursor() cnx1 = mysql.connector.connect(user=database['USER'], password=database['PASSWORD'], host=database['HOST'], database=database['DATABASE']) mycursor1 = cnx1.cursor() #Delete and re-create master customer data as required if table_exists(mycursor, 'master_customer_data'): mycursor.execute("SELECT COUNT(*) FROM master_customer_data") current_customers = mycursor.fetchone() print("\t\tMaster Customer Data: ", current_customers[0]) sql = "DROP TABLE master_customer_data" mycursor.execute(sql) print("\t\tDeleted OLD Master Customer Data...") cnx.commit() sql = ('CREATE TABLE master_customer_data (' '`End Customer Global Ultimate Name` TEXT,' '`End Customer Global Ultimate Company Target ID` TEXT,' '`Qty of N9300 PIDs ordered` TEXT,' '`Qty of N9500 PIDs ordered` TEXT,' '`Qty of APIC PIDs ordered` TEXT,' '`Qty of C3 PIDs ordered` TEXT,' '`Qty of NFM PIDs ordered` TEXT,' '`Qty of Tetration PIDs ordered` TEXT,' '`Sales Agent Name` TEXT,' '`Assigned PSS` TEXT,' '`Assigned TSA` TEXT,' '`Reference Customer ?` TEXT,' '`Target as ACI to Production by end of Q1 ?` TEXT,' '`Equipment Status ?` TEXT,' '`Next Steps` TEXT,' '`Customer Vertical` TEXT,' '`Target for Competitive Pursuit ?` TEXT,' '`Other PSS` TEXT,' '`Sales Level 1` TEXT,' '`Sales Level 2` TEXT,' '`Sales Level 3` TEXT,' '`Sales Level 4` TEXT,' '`Sales Level 5` TEXT,' '`MultipleBookings` TEXT,' '`FirstDateBooked` DATE,' '`LastDateBooked` DATE,' '`Last Refresh` TEXT)') mycursor.execute(sql) cnx.commit() # Load the interesting Product ID list and create two dicts (one by ProdID and one by ProdFam) mycursor.execute("SELECT * FROM pids") products = mycursor.fetchall() prod_id_dict = {} prod_fam_dict = {} for product in products: prod_id_dict[product[1]] = (product[0], product[2]) prod_fam_dict[product[0]] = (product[1], product[2]) #Get each unique Customer Name sql = ( 'SELECT DISTINCT `End Customer Global Ultimate Name` FROM `master_bookings_data`' 'ORDER BY `End Customer Global Ultimate Name` ASC') mycursor.execute(sql) customers = mycursor.fetchall() print("\t\tCustomers Found: ", len(customers)) # Create a the Team Coverage Object my_coverage = Coverage() progress = 0 for customer in customers: #Gather this customers orders sql = ( "SELECT * FROM `master_bookings_data` WHERE `End Customer Global Ultimate Name` = %s " "ORDER BY `Date Booked` ASC") query_values = (customer) mycursor.execute(sql, query_values) orders = mycursor.fetchall() # Init per customer counters and variables n9300_PID = 0 n9500_PID = 0 APIC_PID = 0 C3_PID = 0 EMBRANE_PID = 0 TETR_PID = 0 pss = '' tsa = '' first_date_booked = date(2030, 3, 1) #Random Date in the future last_date_booked = date(1900, 3, 1) #Default earliest date for Excel for order in orders: # Init per customer counters and variables current_customer = order[16] current_customer_id = order[17] account_mgr = order[11] # Set the first and last date booked if first_date_booked > order[4]: first_date_booked = order[4] if last_date_booked < order[4]: last_date_booked = order[4] # Do we count this PID ? If not skip it # order[14] has ProdFam, order[15] has ProdID if order[14] == "TETR": TETR_PID += 1 elif order[14] == "C3": C3_PID += 1 elif prod_id_dict.get(order[15]) is not None: if prod_id_dict[order[15]][0] == 'N9300': n9300_PID += 1 elif prod_id_dict[order[15]][0] == 'N9500': n9500_PID += 1 elif prod_id_dict[order[15]][0] == 'APIC': APIC_PID += 1 elif prod_id_dict[order[15]][0] == 'EMBRANE': EMBRANE_PID += 1 else: continue # Get the next order since this is not interesting # Get the territory this booked in sales_lv1 = order[5] sales_lv2 = order[6] sales_lv3 = order[7] sales_lv4 = order[8] sales_lv5 = order[9] sales_str = order[5] + order[6] + order[7] + order[8] + order[9] #Find the team(s) that cover this customer in this territory teams = my_coverage.find_team(sales_str) pss = ' '.join(teams[0]) tsa = ' '.join(teams[1]) # We are done with this customer # Create a summary customer record sql = ( 'INSERT INTO master_customer_data ' ' (`End Customer Global Ultimate Name`,' ' `End Customer Global Ultimate Company Target ID`,' ' `Qty of N9300 PIDs ordered`,' ' `Qty of N9500 PIDs ordered`,' ' `Qty of APIC PIDs ordered`,' ' `Qty of C3 PIDs ordered`,' ' `Qty of NFM PIDs ordered`,' ' `Qty of Tetration PIDs ordered`,' ' `Sales Agent Name`,' ' `Assigned PSS`,' ' `Assigned TSA`,' ' `Reference Customer ?`,' ' `Target as ACI to Production by end of Q1 ?`,' ' `Equipment Status ?`,' ' `Next Steps`,' ' `Customer Vertical`,' ' `Target for Competitive Pursuit ?`,' ' `Other PSS`,' ' `Sales Level 1`,' ' `Sales Level 2`,' ' `Sales Level 3`,' ' `Sales Level 4`,' ' `Sales Level 5`,' ' `MultipleBookings`,' ' `FirstDateBooked`,' ' `LastDateBooked`,' ' `Last Refresh`)' ' VALUES' ' ("' + current_customer + '",' '"' + current_customer_id + '",' '"' + str(n9300_PID) + '",' '"' + str(n9500_PID) + '",' '"' + str(APIC_PID) + '",' '"' + str(C3_PID) + '",' '"' + str(EMBRANE_PID) + '",' '"' + str(TETR_PID) + '",' '"' + account_mgr + '",' '"' + pss + '",' # Assigned PSS name '"' + tsa + '",' # Assigned TSA name '"Reference Customer ?",' '"Target as ACI to Production by end of Q1",' '"Equipment Status ?",' '"Next Steps",' '"Customer Vertical",' '"Target for Competitive Pursuit ?",' '"Other PSS",' '"' + sales_lv1 + '",' # Sales Level 1 '"' + sales_lv2 + '",' # Sales Level 2 '"' + sales_lv3 + '",' # Sales Level 3 '"' + sales_lv4 + '",' # Sales Level 4 '"' + sales_lv5 + '",' # Sales Level 5 '"' + str(first_date_booked != last_date_booked) + '",' # Multiple Bookings '"' + str(first_date_booked) + '",' # First Date Booked '"' + str(last_date_booked) + '",' # Last Date Booked '"Last Refresh")') mycursor1.execute(sql) cnx1.commit() #Show progress for every 1000 customers processed progress = progress + 1 if progress % 1000 == 0: print("\t\t Customers Processed: ", progress) #Clean up and Close out cnx.close() cnx1.close() end_time = datetime.now() print('\t\trun time: ', end_time - start_time) print('\tcreate_cust_data module complete: ', datetime.now())
def main(*args, **kwargs): cover = Coverage(*args, **kwargs) jobs = cover.run() return (jobs)