def main(): colors = {'BACKGROUND': '#28283c', 'TEXT': 'white', 'INPUT': '#505066'} sg.SetOptions(background_color=colors['BACKGROUND'], text_element_background_color=colors['BACKGROUND'], element_background_color=colors['BACKGROUND'], text_color=colors['TEXT'], input_elements_background_color=colors['INPUT'], input_text_color=colors['TEXT']) layout = [[sg.Text('Name of map,'), sg.InputText()], [sg.Text('Size of map in number of blocks:')], [sg.Text('X'), sg.InputText()], [sg.Text('Y'), sg.InputText()], [sg.OK(bind_return_key=True), sg.Cancel()]] window = sg.Window('Map Creator', layout) while True: event, values = window.Read() if event in (None, 'Cancel'): break if event in (None, 'OK'): if not (len(values[0]) != 0 and helper.is_int(values[1]) and helper.is_int(values[2])): sg.Popup("Ensure all fields are properly filled out first") else: window.Close() map_creator(values[0], int(values[1]), int(values[2])) break
def add_peer(ip_port): ''' Description : Adds a peer to an existing network or starts a new network if ip_port is an empty string Input : ip_port -- a string containing the ip address and port: 'ip port' Output : (peer, comments) peer = {None, 'ip port'} None -- this means an error occurred and no peer was added to the network 'ip port' -- this is the ip address and port number of the newly added peer comments = {[], ['error comment 1', ...]} [] -- this means no errors occurred ['.', ''] -- A list of error messages ''' peer = None comments = [] (rc, out, err, timeout) = execute_command('./addpeer {}'.format(ip_port)) if rc != 0: comments.append('[addpeer] Return Code is: {}'.format(rc)) if err != '': comments.append('[addpeer] Error String: {}'.format(err)) if timeout != False: comments.append('[addpeer] Timed Out!') return (peer, comments) ################# # Checking for proper output format: ip_address port sp = out.split() if len(sp) != 2: comments.append( '[addpeer] Invalid return string: {}; expecting 2 elements but there are {} elements' .format(out, len(sp))) else: ip = sp[0] port = sp[1] ip_sp = ip.split('.') if len(ip_sp) != 4: comments.append('[addpeer] Invalid IP returned: {}'.format(ip)) else: # debug_msg(ip_sp) if not is_int(port) or not is_int(ip_sp[0]) or not is_int( ip_sp[1]) or not is_int(ip_sp[2]) or not is_int(ip_sp[3]): comments.append( '[addpeer] IP and Port must be integers {} {}'.format( ip, port)) # Checking for any errors found above if len(comments) == 0: # No errors peer = out return (peer, comments)
def play_transactions(request): try: if request.user.is_staff: card_id = request.GET.get("card_id", "") if not card_id: error = { "code": 400, "message": _("Card id field is required."), "fields": "card_id" } return Response(error, status=400) filter_id = request.GET.get("filter_id", "") sub_query = "" if filter_id: if not helper.is_int(filter_id): errors = { "code": 400, "message": _("This value must be is integer."), "fields": "filter_id" } return Response(errors, status=400) filter_object = Transaction_Type.objects.get(pk=filter_id) sub_query = " WHERE transaction_type like '" + filter_object.name + "'" cursor = connections['sql_db'].cursor() query_str = """ WITH PLAY_TRANSACTION AS (SELECT PT.Transaction_DateTime, PT.Transaction_Amount, GD.Game_Description, (CASE WHEN GD.Game_Group_Id = 0 THEN 'Refund' ELSE 'Play' END) AS transaction_type FROM Play_Transactions PT LEFT JOIN Game_Swipers GS ON PT.Game_Id = GS.Game_Id LEFT JOIN Game_Details GD ON GS.Game_ML_Id = GD.Game_ML_Id WHERE PT.Card_Barcode = {0}) SELECT TOP 50 * FROM PLAY_TRANSACTION {1} ORDER BY Transaction_DateTime DESC""" print query_str.format(card_id, sub_query) cursor.execute(query_str.format(card_id, sub_query)) result = utils.play_transactions_mapper(cursor.fetchall()) return Response(result) else: error = { "code": 400, "message": _("You don't have permission to access."), "fields": "" } return Response(error, status=400) except Exception, e: error = {"code": 500, "message": "%s" % e, "fields": ""} return Response(error, status=500)
def GET(self, urlpath): """ View single page """ if helper.is_int(urlpath): page = cms_sqlite_model.get_content_by_id(int(urlpath)) else: page = cms_sqlite_model.get_content_by_url(urlpath) if not page: raise web.seeother('/') params = {'cmspagedata':page} return cms_themerender.render('/cms/view','cms_view', 'cms','',params)
def entertainment_detail(request, id_or_key_query): try: if helper.is_int(id_or_key_query): entertainment_detail = Entertainment.objects.get( pk=id_or_key_query) else: entertainment_detail = Entertainment.objects.get( key_query=id_or_key_query) serializer = EntertainmentDetailSerializer(entertainment_detail, many=False) return Response(serializer.data) except Entertainment.DoesNotExist, e: error = {"code": 400, "message": "%s" % e, "fields": "id"} return Response(error, status=400)
def all_keys(ip_port): ''' Description : Returns all keys stored on a peer Input : ip_port ip_port -- a string containing the ip address and port: 'ip port' Output : (keys, comments) key = {None, [], ['key1', ...]} None -- this means an error occurred and no peer was added to the network [] -- this means that no content is stored on this peer ['key1', ...] -- this is the list of content that is stored on this peer comments = {[], ['error comment 1', ...]} [] -- this means no errors occurred ['.', ''] -- A list of error messages ''' keys = None comments = [] (rc, out, err, timeout) = execute_command('./allkeys {}'.format(ip_port)) if rc != 0: comments.append('[allkeys] Return Code is: {}'.format(rc)) if err != '': comments.append('[allkeys] Error String: {}'.format(err)) if timeout != False: comments.append('[allkeys] Timed Out!') return (keys, comments) if out == '': keys = [] else: sp = out.split() passed_test = True for s in sp: if not is_int(s): passed_test = False break if not passed_test: comments.append( '[allkeys] All keys must be integers: {}'.format(out)) else: keys = sp return (keys, comments)
def post_detail(request, id_or_key_query): try: if helper.is_empty(id_or_key_query): error = { "code": 400, "message": "This field is required.", "fields": "id_or_key_query" } return Response(error, status=400) if helper.is_int(id_or_key_query): post_item = Post.objects.get(pk=id_or_key_query) else: post_item = Post.objects.get(key_query=id_or_key_query) serializer = PostsSerializer(post_item, many=False) return Response(serializer.data) except Post.DoesNotExist, e: error = {"code": 400, "message": "%s" % e, "fields": "id_or_key_query"} return Response(error, status=400)
def promotions(request): try: category_id = request.GET.get("category_id") lst_item = Promotion.objects.filter(is_draft=False) if category_id: if helper.is_int(category_id): lst_item = lst_item.filter(promotion_category_id=category_id) else: errors = { "code": 400, "message": _("This value must be is integer."), "fields": "category_id" } return Response(errors, status=400) serializer = PromotionsSerializer(lst_item, many=True) return Response(serializer.data) except Exception, e: error = {"code": 500, "message": "%s" % e, "fields": ""} return Response(error, status=500)
def add_content(ip_port, content): ''' Description : Adds content to an existing network Input : ip_port, content ip_port -- a string containing the ip address and port: 'ip port' content -- a string containing some content to be added to the network Output : (key, comments) key = {None, 'int'} None -- this means an error occurred and no peer was added to the network 'int' -- this is the unique key given for that content comments = {[], ['error comment 1', ...]} [] -- this means no errors occurred ['.', ''] -- A list of error messages ''' key = None comments = [] (rc, out, err, timeout) = execute_command('./addcontent {} "{}"'.format( ip_port, content)) if rc != 0: comments.append('[addcontent] Return Code is: {}'.format(rc)) if err != '': comments.append('[addcontent] Error String: {}'.format(err)) if timeout != False: comments.append('[addcontent] Timed Out!') return (key, comments) if not is_int(out): comments.append( '[addcontent] Output string must be a integer key: {}'.format(out)) else: # No errors key = out return (key, comments)
def main(): args = sys.argv debug = False i = 0 #check for -v (debug) or too many args if len(args) == 3: while i < len(args): if args[i] == "-v": debug = True del args[i] i = 0 i += 1 if len(args) != 2: print("invalid number/type of arguments") return False #allow user to choose how long the scramble is if sys.argv[1] == "-r": number = input("How many moves would you like to scramble? ") while not helper.is_int(number): print( "please provide a positive integer number for how many moves you want generated" ) number = input("How many moves would you like to scramble? ") demo_cube = cube.Cube() print("Starting Cube:", demo_cube) run_cube(demo_cube, demo_cube.scramble(int(number)), 1, debug) #default random 20 move scramble elif sys.argv[1] == "-d": demo_cube = cube.Cube() print("Starting Cube:", demo_cube) run_cube(demo_cube, demo_cube.scramble(20), 1, debug) #runs the scramble 100 times with given amount of moves elif sys.argv[1] == "-avg": if debug: print( "debug method cannot be run in conjunction with pretty print!") number = input("How many moves would you like to scramble? ") while not helper.is_int(number): print( "please provide a positive integer number for how many moves you want generated" ) number = input("How many moves would you like to scramble? ") average_100(number) elif sys.argv[1] == "-p": if debug: print( "debug method cannot be run in conjunction with pretty print!") pretty_print() #take user input for how to scramble the cube else: instructions = sys.argv[1] split_instructions = instructions.split() for instruction in split_instructions: if len(instruction) not in (1, 2): print( "{} is not a correct instruction (length in correct), please try again" .format(instruction)) exit() if instruction[0] not in ('F', 'B', 'R', 'L', 'U', 'D'): print( "{} is not a correct instruction (first character incorrect), please try again" .format(instruction)) exit() if len(instruction) == 2: if instruction[1] not in ('2', '\''): print( "{} is not a correct instruction (second character incorrect), please try again" .format(instruction)) exit() demo_cube = cube.Cube() print("Starting Cube:", demo_cube) run_cube(demo_cube, split_instructions, 0, debug)
line = line.replace("}", "") line = line.replace("{", "") parameters_array = line.split(",") my_types = [] my_dict = {} for s in parameters_array: parameters += s.split(":") # Get the value and name of the parameters for i in range(len(parameters)): if i % 2 == 0: name.append(parameters[i]) else: value.append(parameters[i]) for parameter_name in name: formatted_name = parameter_name.replace('"', '') my_dict[formatted_name] = "" for parameter_value in value: if '"' in parameter_value: my_types.append("String") elif helper.is_int(parameter_value): my_types.append("Int") elif helper.is_float(parameter_value): my_types.append("Double") elif helper.is_bool(parameter_value): my_types.append("Bool") script_generator.generate_script(file_name, my_dict, my_types)
y_train = cp.array(y_train) y_test = cp.array(y_test) return num_in, num_out, X_train.T, X_test.T, y_train.T, y_test.T DEBUG = 1 if DEBUG == 0: dname = sys.argv[1] hidden_layers = sys.argv[2].strip('[]').split(',') hidden_layers = [int(h) for h in hidden_layers] activation_functions = sys.argv[3].strip('[]').split(',') learning_params = sys.argv[4].strip('[]').split(',') learning_params = [ int(l) if is_int(l) else float(l) for l in learning_params ] else: dname = 'mnist.csv' #'IRIS.csv' hidden_layers = [30] activation_functions = ['sigmoid', 'softmax'] #,'softmax'] learning_params = [150, 0.01, 2, 0.0] neurons_per_layer = hidden_layers num_in, num_out, X_train, X_test, y_train, y_test = create_sets(dname) neurons_per_layer.append(num_out) neurons_per_layer.insert(0, num_in) #net = ANN(neurons_per_layer,activation_functions, X_train,y_train) net = DNN(neurons_per_layer,
def filter_nulls(row): for i, _ in enumerate(row): if types[i] == 'num' and (not helper.is_int(row[i])): return False return True