def run(n_alternatives, n_criteria, output_file): # preference functions to be considered preference_functions = [ 'usual', 'quasi-criterion', 'linear', 'gaussian', 'level', 'linear_with_indifference' ] input_mat = utils.random_matrix(n_criteria, n_alternatives) input_weight = utils.random_array(n_criteria) input_preference = [ preference_functions[random.randint(0, 5)] for x in range(n_criteria) ] input_param = { 'p': utils.random_number(), 'q': utils.random_number(), 'sigma': utils.random_number() } if input_param['p'] < input_param['q']: input_param['p'], input_param['q'] = input_param['q'], input_param['p'] algorithmPromethee = Promethee(input_mat, input_weight, input_preference, input_param) utils.write_table_to_csv(algorithmPromethee.getPairwiseComparisonMatrix(), output_file)
def passport(bgr_image, x_y: Tuple = (50, 200), width_height: Tuple = (500, 100)): ''' added random passport type MRZ to the input image. Args: bgr_image: image. x_y: top-left coordinates of wanted MRZ location. width_height: param of how much long MRZ you want. Returns: tuple of: image, top_left coordinate of mrz and width and height of it. ''' org_width = bgr_image.shape[1] org_height = bgr_image.shape[0] random_fr_name = names.get_first_name() random_ls_name = names.get_last_name() p_number = random_number(7) br_date = random_date() gen = genre() expiry_date = random_date() id = 'ID' + random_number(8) doc_char_number = 44 extra_scale = 1.41 text_size = int(np.round( (width_height[0] * extra_scale) / doc_char_number)) # in ID's mrz there are 30 chars each line img_with_mrz = add_mrz_passport( bgr_image, coords=x_y, doc_type='P', # country=c_code, surname=random_ls_name, name=random_fr_name, passport_number=p_number, # nationality=nationality, birth_date=br_date, genre=gen, expiry_date=expiry_date, id=id, text_size=text_size) dim = (org_width, org_height) img_with_mrz = cv2.resize(img_with_mrz, dim, interpolation=cv2.INTER_AREA) epsilon = 4 # to make sure that box does not cover letters and is lower h = 2 * text_size + epsilon w = doc_char_number * int(text_size * 0.75) + epsilon width_height = (w, h) return img_with_mrz, x_y, width_height
def test_invite(self): """ """ self.ip.src = utils.random_ip() self.udp.sport = utils.random_port() self.message.uri = 'sip:{0}@{1}'.format(utils.random_data(20), utils.random_data(15)) self.message.method = 'INVITE' self.message.headers = { 'Call-ID': utils.random_tag(), 'CSeq': '0 INVITE', 'From': '"{0}" <sip:{1}@{2}>;tag={3}'.format(utils.random_data(10), utils.random_data(20), utils.random_data(15), utils.random_tag()), 'Max-Forwards': '{0}'.format(utils.random_number(2)), 'To': '<sip:{0}@{1}>'.format(utils.random_data(20), utils.random_data(15)), 'Via': 'SIP/2.0/UDP {0}:{1};branch={2};rport'.format( utils.random_ip(), utils.random_port(), utils.random_tag()), 'Content-Length': '0', 'User-Agent': '{0}'.format(utils.random_data(30)), 'Contact': '<sip:{0}@{1}:{2};transport=UDP>;' 'q=1.00;agentid="{3}";' 'methods="INVITE,NOTIFY,MESSAGE,ACK,BYE,CANCEL";' 'expires={4}'.format(utils.random_data(20), utils.random_ip(), utils.random_data(20), utils.random_tag(), utils.random_number(2)), 'Authorization': 'Digest username="******", ' 'realm="{2}", ' 'nonce="{3}", ' 'uri="sip:{4}", ' 'qop=auth, nc=00000001, ' 'cnonce="{5}", ' 'response="{6}", ' 'opaque=""'.format(utils.random_data(20), utils.random_data(15), utils.random_data(15), utils.random_tag(), utils.random_data(15), utils.random_tag(), utils.random_data(32)) }
def generate(self): number_of_request = int(random_number(self.vl_params)) for i in range(number_of_request): time = random_number(self.ia_params) job = self.generate_job() self.jobs = self.jobs.append({ 'id': job.id, 'time': time }, ignore_index=True) self.env.process(self.send_job(job, time)) self.jobs.to_csv('datasim/log/workload_' + datetime.now().strftime("%Y%m%d%H%M%S") + '.csv')
def draw(): number_list = [] for a in range(1, 6): number_list.append(random_number()) #tvorba listu o 5 číslech #print(number_list) return number_list
def send(self, originator, recipient, message): route_id = self._get_route_id(recipient) data = { 'originator': originator, 'recipient': recipient, 'body': message, 'reference': utils.random_number(), 'routeId': route_id, } xml_resp = self.connection.request(xml=data, type=RequestType.single_message) resp = xmltodict.parse(xml_resp) if not resp.get('xaresponse').get('message').get('id'): raise Exception('Message send failed') return True
def _random_register(self): url = 'http://www.mobivate.com/do_signup.php' email = utils.random_number() + '@mailinator.com' password = utils.random_salt() data = { 'company': '', 'currency': 'USD', # must be USD or API will return less routes 'email': email, 'fullname': utils.random_salt(), 'mobile': '447' + utils.random_number(), 'password': password, 'password2': password, } r = requests.post(url, data=data) json_resp = json.loads(r.text) if json_resp.get('ok'): # registration successful user = { 'email': email, 'password': password, } return user else: # registration failed return {}
def __init__(self, env, cp_params): self.env = env self.in_pipe = Store(self.env) # TODO: define capacity in cp_params self.pending_jobs = {} self.response_times = [] self.interarrivals = [] self.queue_times = [] self.num_cores = cp_params['num_cores'] self.used_cores = 0 self.core_speed = random_number(cp_params['core_speed']) self.cores = Resource(self.num_cores) self.name = cp_params['name'] self.jobs_completed = 0 self.sim_components = None self.data_res = [] self.idle_time = 0 self.time_last_arrival = None
def id_cards(bgr_image, x_y: Tuple = (50, 280), width_height: Tuple = (512, 100)): ''' added random ID card MRZ to the input image. Args: bgr_image: image. x_y: top-left coordinates of wanted MRZ location. width_height: param of how much long MRZ you want. Returns: tuple of: image, top_left coordinate of mrz and width and height of it. ''' random_fr_name = names.get_first_name() random_ls_name = names.get_last_name() doc_number = random_char(3) + random_number(6) br_date = random_date() gen = genre() expiry_date = random_date() doc_char_number = 30 extra_scale = 1.35 text_size = int(np.round( (width_height[0] * extra_scale) / doc_char_number)) # in ID's mrz there are 30 chars each line img_with_mrz = add_mrz_id_card(bgr_image, coords=x_y, doc_type='ID', country='ESP', doc_number=doc_number, birth_date=br_date, sex=gen, expiry_date=expiry_date, nationality='ESP', surname=random_ls_name, given_name=random_fr_name, text_size=text_size) epsilon = 4 # to make sure that box does not cover letters and is lower h = 3 * text_size + epsilon w = doc_char_number * int(text_size * 0.75) + epsilon width_height = (w, h) return img_with_mrz, x_y, width_height
def post(self): uname = self.get_argument("uname", "") cell = self.get_argument("cell", "") upass = self.get_argument("upass", "") upass2 = self.get_argument("upass2", "") # if upass2 is not upass: if upass2 != upass: self.write({'code': 'error', 'reason': 'pass2'}) return salt = random_string(16) authcode = random_number(6) password = hashlib.sha1((upass + salt).encode('ascii')).hexdigest() info = {} user = User( username=uname, password=password, status=0, type=2, salt=salt, reg_date=datetime_str(), courses='', info=info) self.db.add(user) self.db.commit() if user.id: self.set_secure_cookie("userinfo", json.dumps({ 'type': user.type, 'name': user.username, 'id': user.id}) ) # TODO: 发短信 jobq.enqueue("job_send_sms_auth.tpl_send_sms", "#code#=%s" % authcode, cell) self.write({'code': 'ok', 'id': user.id}) else: self.write({'code': 'error'})
def display_result(update, context): genre_code = None for genre in genre_dict: if genre['name'] == update.message.text: genre_code = genre['id'] break response = get_movie(genre_code) movie_list = response['results'] image_path = 'https://www.themoviedb.org/t/p/w600_and_h900_bestv2/' max_movie_num = len(response['results']) print(max_movie_num) if max_movie_num != 0: random_movie_id = random_number(0, max_movie_num) poster_path = image_path + response['results'][random_movie_id][ 'poster_path'] title = response['results'][random_movie_id]["original_title"] overview = response['results'][random_movie_id]['overview'] overview_zh = translator.translate(overview, lang_tgt='zh-tw') # else: # overview = '未能提供' print(poster_path) release_date = response['results'][random_movie_id]["release_date"] message = '或者你可以試下睇呢套《{}》 \n 上映日期: {} \n 故事簡介(英文): {} \n 故事簡介(中文翻譯—試用): {}'.format( title, release_date, overview, overview_zh) update.message.reply_text(message) context.bot.send_photo(chat_id=update.message.chat.id, photo=poster_path) update.message.reply_text('唔啱?禁 /discover 睇下一套。') else: update.message.reply_text('我搵唔到你想睇嘅戲⋯⋯ 重新嚟過? /start ')
def get_movie(genre): url = 'https://api.themoviedb.org/3/discover/movie' page_num = random_number(1, 500) query = { 'api_key': TMDB_API_KEY, # 'year' : year, 'page': page_num, 'with_genres': genre, 'vote_average.gte': 0.8, } print(page_num) response = requests.get(url, params=query).json() # movie_name = [result['original_title'] for result in response['results']] # keys = range(len(movie_name)) # movies = {} # for i in keys: # movies[i] = movie_name[i] # return movies, response return response
def test_upper_smaller_correction(self): wrong_upper_bound = 0 wrong_lower_bound = 2 random_val = utils.random_number(wrong_upper_bound, wrong_lower_bound) self.assertTrue(0 <= random_val and random_val < 2)
def test_in_range(self): random_val = utils.random_number(0, 2) self.assertTrue(0 <= random_val and random_val < 2)