def _build_form(self): """This is a private method that builds up the form array ready for processing. There are no parameters and no return values since it use just class based instance variables. - parameters :param None: There are no parameters for this method - return :return: none - return type :rtype: not applicable """ self._username = pygame_textinput.TextInput('tahoma', 30, True, self._text_color, self._text_color, 400, 35) self._password = pygame_textinput.TextInput('tahoma', 30, True, self._text_color, self._text_color, 400, 35) # now create a field object for each one and add it to the forms array self._form.append(Field("username", self._username, 444, 345)) self._form.append(Field("password", self._password, 444, 474)) # now set the index of the form that should be input first self._form_index = 0
def project_tree(): """ Relation between topic and activity """ form = SQLFORM.factory( Field('project_name', label=T('Project Name'), comment=T('Ingrese el nombre del proyecto'), requires=IS_IN_DB(db, 'projects.id', '%(name)s')), Field('process_file', 'upload', label=T('Spreadsheet File'), comment=T('Ingresar archivo pre-formateado'), uploadfolder=UPLOAD_PATH)) if form.process().accepted: projectname = form.vars.project_name filename = form.vars.process_file file_type = None if request.vars.process_file != '': file_type = request.vars.process_file.type if file_type == EXCEL_FILE or file_type == OLD_EXCEL_FILE: excel_process(filename, projectname) response.flash = 'Archivo Procesado!' else: response.flash = 'Archivo No Reconocido!' form2 = SQLFORM.grid(db.project_tree, # create=False, ) return dict(form=form, form2=form2)
def __init__(self, name, parent): super(WSP, self).__init__(name, parent) self.myFields[Names.WSP["WSPTID"]] = Field.Field(Names.WSP["WSPTID"], self) self.myFields[Names.WSP["WSPTYPE"]] = Field.Field(Names.WSP["WSPTYPE"], self) self.myFields[Names.WSP["WSPHL"]] = Field.Field(Names.WSP["WSPHL"], self, self.encodeWSPHL) self.myFields[Names.WSP["WSPCONTTYPE"]] = Field.Field(Names.WSP["WSPCONTTYPE"], self, self.encodeDecode) self.myFields[Names.WSP["WSPHDRS"]] = Field.Field(Names.WSP["WSPHDRS"], self, self.encodeDecode)
def update(self, fieldnames, varname, value): newfieldnames = "" IEname = "" if fieldnames == "": pass else: if Names.UD["IE"] in fieldnames: IEname = Names.UD["IE"] + "%d" % (self.IEcount) newfieldnames = fieldnames newfieldnames.pop(0) newfieldnames = [IEname] + newfieldnames if Names.UD["IELEN"] in fieldnames: if Names.Common["NEEDSENCODING"] == varname: self.IEcount += 1 IEname = Names.UD["IE"] + "%d" % (self.IEcount) self.currIE = OrderedField.OrderedField( IEname, self, "", [ Names.UD["IETYPE"], Names.UD["IELEN"], Names.UD["IEDATA"] ]) self.currIE.myFields[Names.UD["IELEN"]] = Field.Field( Names.UD["IELEN"], self.currIE, self.encodeIELEN) self.currIE.myFields[Names.UD["IETYPE"]] = Field.Field( Names.UD["IETYPE"], self.currIE) self.currIE.myFields[Names.UD["IEDATA"]] = Field.Field( Names.UD["IEDATA"], self.currIE, self.encodeDecode) self.myFields[IEname] = self.currIE newfieldnames = [IEname, Names.UD["IELEN"]] else: newfieldnames = fieldnames super(UD, self).update(newfieldnames, varname, value)
def __init__(self, name, parent): super(RPDU, self).__init__(name, parent) self.myFields[Names.RPDU["RPDUMTI"]] = Field.Field( Names.RPDU["RPDUMTI"], self) self.myFields[Names.RPDU["RPDUMR"]] = Field.Field( Names.RPDU["RPDUMR"], self) RPOA = OrderedField.OrderedField( Names.RPDU["RPOA"], self, "", [Names.RPDU["RPOALEN"], Names.RPDU["RPOANO"]]) RPOA.myFields[Names.RPDU["RPOALEN"]] = Field.Field( Names.RPDU["RPOALEN"], RPOA, self.encodeRPOALength) RPOA.myFields[Names.RPDU["RPOANO"]] = Field.Field( Names.RPDU["RPOANO"], RPOA, self.encodeDecode) self.myFields[Names.RPDU["RPOA"]] = RPOA RPDA = OrderedField.OrderedField( Names.RPDU["RPDA"], self, "", [Names.RPDU["RPDALEN"], Names.RPDU["RPDANO"]]) RPDA.myFields[Names.RPDU["RPDALEN"]] = Field.Field( Names.RPDU["RPDALEN"], RPDA, self.encodeRPDALength) RPDA.myFields[Names.RPDU["RPDANO"]] = Field.Field( Names.RPDU["RPDANO"], RPDA, self.encodeDecode) self.myFields[Names.RPDU["RPDA"]] = RPDA self.myFields[Names.RPDU["RPUDL"]] = Field.Field( Names.RPDU["RPUDL"], self, self.encodeRPUDL) self.myFields[Names.RPDU["RPUDTYPE"]] = Field.Field( Names.RPDU["RPUDTYPE"], self) self.myFields[Names.RPDU["RPCAUSELEN"]] = Field.Field( Names.RPDU["RPCAUSELEN"], self, self.encodeRPCauseLength) self.myFields[Names.RPDU["RPCAUSE"]] = Field.Field( Names.RPDU["RPCAUSE"], self)
def __init__(self): self.players = [Field((0, 0), (0, 0)), Field((0, 0), (0, 0))] self.Ready = [False, False] self.moves = [None, None] self.wins = [0, 0] self.ties = 0 self.turn = 0
def __init__(self, name, parent): super(UD, self).__init__(name, parent) self.myFields[Names.UD["UDL"]] = Field.Field(Names.UD["UDL"], self, self.encodeUDL) self.myFields[Names.UD["UDHL"]] = Field.Field(Names.UD["UDHL"], self, self.encodeUDHL) self.myFields[Names.UD["USRDATA"]] = Field.Field( Names.UD["USRDATA"], self, self.encodeUD)
class SponsorBalanceChangeSchema: table_name = "SPONSOR_BALANCE_CHANGE" table_desc = "广告商余额变化表" schema_fields = [ Field("SBC_ID", Type.bigint, None), Field("SPONSOR_ID", Type.bigint, 0), Field("CHANGE_AMOUNT", Type.int, 0), Field("CHANGE_TYPE", Type.int, 0), ]
def __create_fields(self): """ :return: """ field1 = Field.Field() field2 = Field.Field() return field1, field2
class AdClickChargeUpProgressSchema: table_name = "AD_CLICK_CHARGE_UP_PROGRESS" table_desc = "" schema_fields = [ Field("ACCUP_ID", Type.int, None), Field("FIN_SYS_ID", Type.int, 0), Field("PROGRESS_ACI_ID", Type.bigint, 0), Field("MAX_LOG_TIME", Type.bigint, 0), Field("REMARK", Type.varchar, None), ]
def genFields(self): self.fields = [] lObst = self.genObst() lDirt = self.genDirts(lObst) for i in range(self.n): for j in range(self.n): if (i, j) in lObst: self.fields.append(Field((i, j), 'obstacle')) elif (i, j) in lDirt: self.fields.append(Field((i, j), 'dirt')) else: self.fields.append(Field((i, j), 'empty'))
def __init__(self, name, parent): super(SIMCmd, self).__init__(name, parent) self.myFields[Names.SIMCMD["CPL"]] = Field.Field(Names.SIMCMD["CPL"], self, self.encodeCPL) self.myFields[Names.SIMCMD["CHL"]] = Field.Field(Names.SIMCMD["CHL"], self, self.encodeCHL) self.myFields[Names.SIMCMD["SPI"]] = Field.Field(Names.SIMCMD["SPI"], self, "", self.dissectSPI) self.myFields[Names.SIMCMD["KiC"]] = Field.Field(Names.SIMCMD["KiC"], self, "", self.dissectKI) self.myFields[Names.SIMCMD["KiD"]] = Field.Field(Names.SIMCMD["KiD"], self, "", self.dissectKI) self.myFields[Names.SIMCMD["TAR"]] = Field.Field(Names.SIMCMD["TAR"], self) self.myFields[Names.SIMCMD["CNTR"]] = Field.Field(Names.SIMCMD["CNTR"], self) self.myFields[Names.SIMCMD["PCNTR"]] = Field.Field(Names.SIMCMD["PCNTR"], self) self.myFields[Names.SIMCMD["RC_CC_DS"]] = Field.Field(Names.SIMCMD["RC_CC_DS"], self) self.myFields[Names.SIMCMD["SECDATA"]] = Field.Field(Names.SIMCMD["SECDATA"], self) #, self.encodeSECDATA)
def example_protocol(): sf = StartField.StartField( 'myProtocol', 'This is an example protocol that says the second byte is the amount of wins I have if the first bit in the first byte is bigger than 8, otherwise it is the number of losses' ) sf.set_dependency_pattern('Integer') sf.set_dependency_protocol('Dependent protocol') f1 = Field.Field(1) sf.set_next_constructs([f1]) f1.set_field_info('TypeBitCheck', 'check', 'Checks first bit', 'ftypes.UINT8', 'base.HEX', '0x80', '?', 'True') ref_list = ReferenceList.ReferenceList('ref_list') ref_list.set_descriptions(['is a value']) ref_list.set_values(['13']) f1.set_ref_list(ref_list) expr1 = Expression.Expression() expr1.set_relational_operators(['>=']) expr1.set_operands(['8']) expr2 = Expression.Expression() expr2.set_relational_operators(['<']) expr2.set_operands(['8']) dc = DecisionConstruct.DecisionConstruct() dc.set_expressions([expr1, expr2]) f1.set_next_constructs([dc]) f2 = Field.Field(1) f2.set_field_info('Number of wins', 'wins', 'Is the number of wins', 'ftypes.UINT8', 'base.HEX', '0xff', '?', 'True') f3 = Field.Field(1) f3.set_field_info('Number of loses', 'loses', 'Is the number of loses', 'ftypes.UINT8', 'base.HEX', '0xff', '?', 'True') dc.set_next_constructs([f2, f3]) end_field = EndField.EndField() f2.set_next_constructs([end_field]) f3.set_next_constructs([end_field]) protocol = Protocol.Protocol() protocol_structure = protocol.get_protocol_structure(sf) return protocol_structure
def __init__(self, width = 640, height = 480): pygame.init() self.screen = pygame.display.set_mode((width, height)) self.field = Field.Field() self.field.loadFile("fieldInit.txt") self.cameraPoint = Point(width / 2, height / 2, 0) self.setupPrimitives()
def test_played(self): field = Field() field.hintRemain -= 1 # O1 => Success self.assertEqual(type(PlayResult.Success()), type(field.play(Card(cardId=0)))) # print(field.played) # O1 => Fail because the same card already played self.assertEqual(type(PlayResult.Failed()), type(field.play(Card(cardId=0)))) # print(field.played) # O3 => Fail self.assertEqual(type(PlayResult.Failed()), type(field.play(Card(cardId=5)))) # print(field.played) # O2 => Success self.assertEqual(type(PlayResult.Success()), type(field.play(Card(cardId=3)))) # print(field.played) # O3 => Success self.assertEqual(type(PlayResult.Success()), type(field.play(Card(cardId=5)))) # print(field.played) # O4 => Success self.assertEqual(type(PlayResult.Success()), type(field.play(Card(cardId=7)))) # print(field.played) # O5 => Success and recovery a hint self.assertEqual(type(PlayResult.Success()), type(field.play(Card(cardId=9)))) # print(field.played) # check if hint is recovered self.assertEqual(8, field.hintRemain)
def __init__(self, size, bl, topleft): pygame.init() pygame.display.set_caption("Hua Rong Dao") self.screen = pygame.display.set_mode(size) self.running = True self.field = Field.Field(bl, topleft, default_preset) self.test_mode = False self.select = False # whether a character has been selected self.selected_character = None self.monitor = self.get_monitor() # it should be CaoCao self.win = False self.resetButton = Block.Block("Reset", 50, (80, 560)) # reset self.resetButton.rect.width = 130 self.font = pygame.font.Font(None, 24) self.text = "Moving CaoCao to Button Mid" self.render(self.text)
def generate(self): self.clear_console() print("GENERATING NEW MAP") iteration_number = self.enter_params() field = Field.Field(self.width, self.height) obstacles = floor(self.width * self.height * self.obstacle_density / 100) for i in range(obstacles): while True: xrand = randint(0, self.width - 1) yrand = randint(0, self.height - 1) if field.objects[yrand][xrand] == '.': field.add_obstacle(xrand, yrand) break for i in range(self.predator_number): while True: xrand = randint(0, self.width - 1) yrand = randint(0, self.height - 1) if field.objects[yrand][xrand] == '.': field.add_predator(xrand, yrand) break for i in range(self.prey_number): while True: xrand = randint(0, self.width - 1) yrand = randint(0, self.height - 1) if field.objects[yrand][xrand] == '.': field.add_prey(xrand, yrand) break return field, iteration_number
def __init__(self, load_file, save_file, diff): global field, player1_roster, player2_roster, save_file_name,difficulty field = Field.Field(load_file, save_file) player1_roster = Roster.Roster(load_file, "player1") player2_roster = Roster.Roster(load_file, "player2") save_file_name = save_file difficulty = diff
def test_vf(self, w): tests = 25 sum_vf = 0 for i in range(tests): current_field_vf = Field.Field(self.n, self.m) score_vf = 0 end_vf = False tiles = [] while not end_vf: if len(tiles) == 0: tiles = [i for i in range(len(self.TILES))] tile = tiles[random.randint(0, len(tiles) - 1)] tiles.remove(tile) if not end_vf: move_vf = State.State(current_field_vf, tile).vf_move(w) if move_vf is None: end_vf = True else: (current_field_vf, my_gain, gain) = current_field_vf.successor(self.TILES[tile], move_vf) score_vf += gain sum_vf += score_vf print(str(i+1) + " done") return sum_vf / tests
def addPseudofield(self, name, width=None): if name not in self.pseudofields: field = Field.Field(name, width) self.pseudofields[name] = field self.pseudofieldList.append(field) else: pass
def learn(self): w = [0 for i in range(Field.Field(self.n, self.m).dimension())] n_episodes = 50 mod = n_episodes / 10 scores = [] sum = 0 min_score = 1000000 max_score = -1000000 for k in range(n_episodes+1): w, score = self.episode(w, math.exp(-k), 1 / (1 + 16 * math.log(k+1))) scores.append(score) sum += score min_score = min(min_score, score) max_score = max(max_score, score) if k % mod == 0: print("Iteration %d avg. score %f [%f, %f]" % (k, sum / mod, min_score, max_score)) sum = 0 min_score = 1000000 max_score = -1000000 print(w) self.w = w
def init_widget(__): import Field if Layer.field == None: Layer.field = Field.Field(__.master) Layer.field.setFixedSize(DEFAULT_MAP_LENGTH * DEFAULT_TILE_WIDTH, DEFAULT_MAP_WIDTH * DEFAULT_TILE_HEIGHT) __.config = __.ConfigLayer(__, __.tileSize, __.length, bool(__.type == Layer.GRAPHIC))
def enter(self): try: magnitude = int(self.magnitude.get()) angle = int(self.angle.get()) field = Field(magnitude, angle) self.parent.fieldList.append(field) except: print("incorrect inputs")
def __init__(self, n, m): self.n = n self.m = m self.states = {} for i in range(0, len(Tetris.TILES)): field = Field.Field(n, m) self.states[(field.representation(), i)] = State.State(field, i, self.states)
def copy_board(board): tmp = [] for i in board: for j in i: new_field = Field(j.number, j.from_example, j.row, j.column) new_field.domain = np.copy(j.domain) tmp.append(new_field) tmp_board = np.reshape(np.array(tmp), (9, 9)) return tmp_board
def addField(self, name, width=None): if name not in self.fields: field = Field.Field(name, width, self.lastPos) self.fields[name] = field self.fieldList.append(field) if width: self.lastPos += width else: pass
class LinkedinItem(Item): # define the fields for your item here like: # name = scrapy.Field() full_name = Field() first_name = Field() last_name = Field() headline_title = Field() locality = Field() industry = Field() current_roles = Field() education_institutions = Field()
def main(argv): # ________________________________________________________________________________ # Reading of the output arguments try: opts, args = getopt.getopt(argv, "hf:n:", ["file=", "xslice=", "yslice=", "zslice="]) except getopt.GetoptError: print 'Specify file name' sys.exit(2) filey = argv[0] xslice = None yslice = None zslice = None for opt, arg in opts: if opt == '-h': print 'Help page' print '-f file name' print '-n dimension nx=ny=nz=n of the case' sys.exit() elif opt in ("-f", "--file"): file = arg elif opt in ("--xslice"): xslice = float(arg) elif opt in ("--yslice"): yslice = float(arg) elif opt in ("--zslice"): zslice = float(arg) print 'Input file is ', file if xslice == None: xslice = 0 if yslice == None: yslice = 0 if zslice == None: zslice = 0 # ________________________________________________________________________________ # Creation of an object field from the file field = Field(file) fig = plt.figure(figsize=(13, 9)) gs = gridspec.GridSpec(2, 2) ax0 = plt.subplot(gs[0, 0]) ax1 = plt.subplot(gs[1, 0]) ax2 = plt.subplot(gs[0, 1]) field.plot(fig, ax0, slice='x', slice_pos=xslice) field.plot(fig, ax1, slice='y', slice_pos=yslice) field.plot(fig, ax2, slice='z', slice_pos=zslice) fig.tight_layout() plt.show()
def update(self, fieldnames, varname, value): newfieldnames = "" SimpleTLVname = "" if fieldnames == "": if varname == Names.ENVELOPE["LASTSIMPLETLVLENFLAG"]: self.lastSimpleTLVLenFlag = value else: if Names.ENVELOPE["SIMPLETLV"] in fieldnames: SimpleTLVname = Names.ENVELOPE["SIMPLETLV"] + "%d" % ( self.SimpleTLVcount) newfieldnames = fieldnames newfieldnames.pop(0) newfieldnames = [SimpleTLVname] + newfieldnames if Names.ENVELOPE["SIMPLETLVTAG"] in fieldnames: #if Names.Common["NEEDSENCODING"] == varname: self.SimpleTLVcount += 1 SimpleTLVname = Names.ENVELOPE["SIMPLETLV"] + "%d" % ( self.SimpleTLVcount) self.currSimpleTLV = OrderedField.OrderedField( SimpleTLVname, self, "", [ Names.ENVELOPE["SIMPLETLVTAG"], Names.ENVELOPE["SIMPLETLVLEN"], Names.ENVELOPE["SIMPLETLVVAL"] ]) self.currSimpleTLV.myFields[ Names.ENVELOPE["SIMPLETLVTAG"]] = Field.Field( Names.ENVELOPE["SIMPLETLVTAG"], self.currSimpleTLV, "", self.dissectSimpleTLV) self.currSimpleTLV.myFields[ Names.ENVELOPE["SIMPLETLVLEN"]] = Field.Field( Names.ENVELOPE["SIMPLETLVLEN"], self.currSimpleTLV, self.encodeSimpleTLVLen) self.currSimpleTLV.myFields[ Names.ENVELOPE["SIMPLETLVVAL"]] = Field.Field( Names.ENVELOPE["SIMPLETLVVAL"], self.currSimpleTLV) self.myFields[SimpleTLVname] = self.currSimpleTLV newfieldnames = [ SimpleTLVname, Names.ENVELOPE["SIMPLETLVTAG"] ] else: newfieldnames = fieldnames super(Envelope, self).update(newfieldnames, varname, value)
def start(self, algorithm=1): variables = deque() if (self.task == 0): # N queens array = np.zeros(shape=self.size, dtype=int) array[:] = [x - 10 for x in array] def forwardchecking(*args): return self.forwardchecking_queens(args[0], args[1]) def backtracking(*args): return self.backtracking_queens(args[0], args[1]) for i in range(self.size): variables.append(Field.Field(0, i, self.size, 0)) else: # Latin square array = np.zeros(shape=(self.size, self.size), dtype=int) def forwardchecking(*args): return self.forwardchecking_latin(args[0], args[1]) def backtracking(*args): return self.backtracking_latin(args[0], args[1]) for i in range(self.size): for j in range(self.size): variables.append(Field.Field(i, j, self.size, 1)) if algorithm == 0: forwardchecking(copy.deepcopy(array), copy.deepcopy(variables)) iterations = self.iterations_fc elif algorithm == 1: backtracking(array, variables) iterations = self.iterations_bt else: print("normal bt") self.singlebacktrackqueens(copy.deepcopy(array), copy.deepcopy(variables)) random.shuffle(variables) print("random bt") self.iterations_bt = 0 self.singlebacktrackqueens(array, variables) iterations = -1 return (self.results, iterations)