Best Python code snippet using hypothesis
player.py
Source: player.py
1#!/usr/bin/env python32# -*- coding:utf-8 -*-3from game.define.store_define import TN_P_PLAYER4from store.store import StoreObj5from game import Game6import config7class ModelPlayer(StoreObj):8 """ç©å®¶æ°æ®"""9 TABLE_NAME = TN_P_PLAYER10 def init(self):11 self.id = None # rid12 self.account = '' #è´¦å·13 self.password = '' #å¯ç 14 self.gm = 0 if int(config.serverNo) >= 60000 else 1 #æ¯å¦gm å
é»è®¤é½æ¯GM15 self.newTime = 0 # å建æ¶é´16 self.loginTime = 0 # æåä¸æ¬¡ç»å½æ¶é´17 self.logoutTime = 0 # æåä¸æ¬¡éåºæ¶é´18 self.itemTranceNo = 0 #ç¨äºçæç©åå¯ä¸idçèªå¢å¼19 self.mailTranceNo = 0 #ç¨äºçæé®ä»¶å¯ä¸idçèªå¢å¼20 self.petTranceNo = 0 # ç¨äºçæå® ç©å¯ä¸idçèªå¢å¼21 self.loginNum = 0 #è§è²åå²ç»é次æ°22 self.shutuped = False # ç¦è¨23 self.blocked = False # å°å·24 self.onlineTimeTotal = 0 # 累计å¨çº¿æ¶é¿25 self.channel = 0 # ç©å®¶æ¸ é26 self.platform = "" # android ios27 self.baseDict = {} #è§è²åºç¡æ°æ®28 self.attrDict = {} # è§è²å±æ§29 self.historyDict = {} # åå²ç»è®¡30 self.bagDict = {} # è§è²èå
31 self.walletDict = {} # è§è²é±å
32 self.rankDict = {} # è§è²æè¡33 self.battleArrayDict = {} # è§è²åºæéµå34 self.mapDict = {} # è§è²å°å¾35 self.niudanDict = {} # æè36 self.chargeDict = {} # å
å¼37 self.chargeDailyDict = {} # å
å¼æ¥å¸¸38 self.zhuanpanDict = {} # 转ç39 self.shopDict = {} # ååº40 self.rescueDict = {} # ææ´é41 self.vipDict = {} # vip42 self.totemDict = {} # å¾è
¾43 self.petDict = {} # è§è²å® ç©44 self.marryDict = {} # å©å§»45 self.houseDict = {} # æ¿å46 self.examDict = {} # çé¢47 self.bossDict = {} # boss ååä¸48 self.chenghaoDict = {} # 称å·49 self.myheadDict = {} # 头å50 self.relationshipDict = {} # è¿å ç¾ç» éä¼å æ51 self.daoguanDict = {} #éé¦52 self.taskDict = {} # ä»»å¡53 self.fubenDict = {} #å¯æ¬54 self.zhudaoxunliDict = {} #诸å²å·¡ç¤¼55 self.daylypvpDict = {} # æ¥å¸¸pvpæ¢å¤º56 self.hetiDict = {} #åä½57 self.chatDict = {} #ç©å®¶è天58 self.gongchengDict = {} #æ»å59 self.guildDict = {} #å
¬ä¼60 self.yabiaoDict = {} #æ¼é61 self.diaoyuDict = {} #éé±¼62 def set_owner(self, owner):63 self.owner = owner64 def to_save_dict(self, copy=False, forced=False):65 save = {}66 save['id'] = self.id67 save['account'] = self.account68 save['password'] = self.password69 save['gm'] = self.gm70 save['newTime'] = self.newTime71 save['loginTime'] = self.loginTime72 save['logoutTime'] = self.logoutTime73 save['itemTranceNo'] = self.itemTranceNo74 save['mailTranceNo'] = self.mailTranceNo75 save['petTranceNo'] = self.petTranceNo76 save['loginNum'] = self.loginNum77 save['shutuped'] = self.shutuped78 save['blocked'] = self.blocked79 save['onlineTimeTotal'] = self.onlineTimeTotal80 save['channel'] = self.channel81 save['platform'] = self.platform82 save['baseDict'] = self.owner.base.to_save_dict(forced=forced) #è§è²åºç¡ä¿¡æ¯83 save['attrDict'] = self.owner.attr.to_save_dict(forced=forced) # è§è²å±æ§84 save['historyDict'] = self.owner.history.to_save_dict(forced=forced) # åå²ç»è®¡85 save['bagDict'] = self.owner.bag.to_save_dict(forced=forced) # è§è²èå
86 save['walletDict'] = self.owner.wallet.to_save_dict(forced=forced) # è§è²é±å
87 save['rankDict'] = self.owner.rank.to_save_dict(forced=forced) # è§è²æè¡88 save['battleArrayDict'] = self.owner.battle_array.to_save_dict(forced=forced) # è§è²åºæéµå89 save['mapDict'] = self.owner.map.to_save_dict(forced=forced) # å°å¾90 save['niudanDict'] = self.owner.niudan.to_save_dict(forced=forced) # æè91 save['chargeDict'] = self.owner.charge.to_save_dict(forced=forced) # å
å¼92 save['chargeDailyDict'] = self.owner.chargeDaily.to_save_dict(forced=forced) # å
å¼æ¥å¸¸93 save['zhuanpanDict'] = self.owner.zhuanpan.to_save_dict(forced=forced) # 转ç94 save['shopDict'] = self.owner.shop.to_save_dict(forced=forced) # ååº95 save['rescueDict'] = self.owner.rescue.to_save_dict(forced=forced) # ææ´é96 save['vipDict'] = self.owner.vip.to_save_dict(forced=forced) # vip97 save['totemDict'] = self.owner.totem.to_save_dict(forced=forced) # å¾è
¾98 save['petDict'] = self.owner.pet.to_save_dict(forced=forced) # è§è²å® ç©99 save["marryDict"] = self.owner.marry.to_save_dict(forced=forced) # å©å§»100 save["houseDict"] = self.owner.house.to_save_dict(forced=forced) # æ¿å101 save["examDict"] = self.owner.exam.to_save_dict(forced=forced) # çé¢102 save['bossDict'] = self.owner.boss.to_save_dict(forced=forced) # boss ååä¸103 save['chenghaoDict'] = self.owner.chenghao.to_save_dict(forced=forced) # 称å·104 save['myheadDict'] = self.owner.myhead.to_save_dict(forced=forced) # 头å105 save['relationshipDict'] = self.owner.relationship.to_save_dict(forced=forced) # è¿å ç¾ç» éä¼å æ106 save["daoguanDict"] = self.owner.daoguan.to_save_dict(forced=forced) # éé¦107 save['fubenDict'] = self.owner.fuben.to_save_dict(forced=forced) # å¯æ¬108 save['zhudaoxunliDict'] = self.owner.zhudaoxunli.to_save_dict(forced=forced) # 诸å²å·¡ç¤¼109 save["daylypvpDict"] = self.owner.daylypvp.to_save_dict(forced=forced) # æ¥å¸¸pvpæ¢å¤º110 save['hetiDict'] = self.owner.heti.to_save_dict(forced=forced) # åä½111 save["chatDict"] = self.owner.chat.to_save_dict(forced=forced) # ç©å®¶è天112 save['gongchengDict'] = self.owner.gongcheng.to_save_dict(forced=forced) # æ»å113 save['guildDict'] = self.owner.guild.to_save_dict(forced=forced) # ä»»å¡114 save['yabiaoDict'] = self.owner.yabiao.to_save_dict(forced=forced) # æ¼é115 save['diaoyuDict'] = self.owner.diaoyu.to_save_dict(forced=forced) # éé±¼116 # save['taskDict'] = self.owner.task.to_save_dict(forced=forced) # ä»»å¡117 return save118 #overwrite119 def save(self, store, forced=False, no_let=False):120 StoreObj.save(self,store, forced=forced, no_let=no_let)121 self.owner.base.cleanDirty() # è§è²åºç¡ä¿¡æ¯122 self.owner.attr.cleanDirty() # è§è²å±æ§123 self.owner.history.cleanDirty() # åå²ç»è®¡124 self.owner.bag.cleanDirty() # è§è²èå
125 self.owner.wallet.cleanDirty() # è§è²é±å
126 self.owner.rank.cleanDirty() # è§è²æè¡127 self.owner.battle_array.cleanDirty() # è§è²åºæéµå128 self.owner.map.cleanDirty() # å°å¾129 self.owner.niudan.cleanDirty() # æè130 self.owner.charge.cleanDirty() # å
å¼131 self.owner.chargeDaily.cleanDirty() # å
å¼æ¥å¸¸132 self.owner.zhuanpan.cleanDirty() # 转ç133 self.owner.shop.cleanDirty() # ååº134 self.owner.rescue.cleanDirty() # ææ´é135 self.owner.vip.cleanDirty() # vip136 self.owner.totem.cleanDirty() # å¾è
¾137 self.owner.pet.cleanDirty() # è§è²å® ç©138 self.owner.marry.cleanDirty() #å©å§»139 self.owner.house.cleanDirty() #æ¿å140 self.owner.exam.cleanDirty() # çé¢141 self.owner.boss.cleanDirty() # boss ååä¸142 self.owner.chenghao.cleanDirty() # 称å·143 self.owner.myhead.cleanDirty() # 头å144 self.owner.relationship.cleanDirty() # è¿å ç¾ç» éä¼å æ145 self.owner.daoguan.cleanDirty() # éé¦146 self.owner.fuben.cleanDirty() # å¯æ¬147 self.owner.zhudaoxunli.cleanDirty() # 诸å²å·¡ç¤¼148 self.owner.daylypvp.cleanDirty() # æ¥å¸¸pvpæ¢å¤º149 self.owner.heti.cleanDirty() # åä½150 self.owner.chat.cleanDirty() # ç©å®¶è天151 self.owner.gongcheng.cleanDirty() # æ»å152 self.owner.guild.cleanDirty() # å
¬ä¼153 self.owner.yabiao.cleanDirty() # æ¼é154 self.owner.diaoyu.cleanDirty() # éé±¼155 # self.owner.task.cleanDirty() # ä»»å¡156 def GetLoginTime(self):157 return self.loginTime158 def GetLogoutTime(self):159 return self.logoutTime160 def SetLoginTime(self, iTime):161 self.loginTime = iTime162 self.modify()163 def SetLogoutTime(self, iTime):164 self.logoutTime = iTime165 self.onlineTimeTotal += self.logoutTime - self.loginTime166 if self.onlineTimeTotal < 0:167 self.onlineTimeTotal = 0168 self.modify()169 def AddLoginNum(self):170 self.loginNum += 1171 self.modify()172 def IsGm(self):173 return self.gm174 def GenerateItemTranceNo(self):175 self.itemTranceNo += 1176 self.modify()177 return self.itemTranceNo178 def GeneratePetTranceNo(self):179 self.petTranceNo += 1180 self.modify()181 return self.petTranceNo182 @classmethod183 def name_to_id(cls, name):184 rs = Game.store.values(cls.TABLE_NAME, None, dict(name=name))185 if rs:186 return rs[0]['id']187 @classmethod188 def id_to_name(cls, pid):189 rs = Game.store.values(cls.TABLE_NAME, ['name'], dict(id=pid))190 if rs:...
DebugDataConsumer.py
Source: DebugDataConsumer.py
1#!/usr/bin/env python2# -*- coding: utf-8 -*-3# This file is part of Beremiz, a Integrated Development Environment for4# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.5#6# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD7#8# See COPYING file for copyrights details.9#10# This program is free software; you can redistribute it and/or11# modify it under the terms of the GNU General Public License12# as published by the Free Software Foundation; either version 213# of the License, or (at your option) any later version.14#15# This program is distributed in the hope that it will be useful,16# but WITHOUT ANY WARRANTY; without even the implied warranty of17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the18# GNU General Public License for more details.19#20# You should have received a copy of the GNU General Public License21# along with this program; if not, write to the Free Software22# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.23from __future__ import absolute_import24import datetime25# -------------------------------------------------------------------------------26# Date and Time conversion function27# -------------------------------------------------------------------------------28SECOND = 1000000 # Number of microseconds in one second29MINUTE = 60 * SECOND # Number of microseconds in one minute30HOUR = 60 * MINUTE # Number of microseconds in one hour31DAY = 24 * HOUR # Number of microseconds in one day32# Date corresponding to Epoch (1970 January the first)33DATE_ORIGIN = datetime.datetime(1970, 1, 1)34def get_microseconds(value):35 """36 Function converting time duration expressed in day, second and microseconds37 into one expressed in microseconds38 @param value: Time duration to convert39 @return: Time duration expressed in microsecond40 """41 return float(value.days * DAY +42 value.seconds * SECOND +43 value.microseconds)44def generate_time(value):45 """46 Function converting time duration expressed in day, second and microseconds47 into a IEC 61131 TIME literal48 @param value: Time duration to convert49 @return: IEC 61131 TIME literal50 """51 microseconds = get_microseconds(value)52 # Get absolute microseconds value and save if it was negative53 negative = microseconds < 054 microseconds = abs(microseconds)55 # TIME literal prefix56 data = "T#"57 if negative:58 data += "-"59 # In TIME literal format, it isn't mandatory to indicate null values60 # if no greater non-null values are available. This variable is used to61 # inhibit formatting until a non-null value is found62 not_null = False63 for val, format in [64 (int(microseconds) / DAY, "%dd"), # Days65 ((int(microseconds) % DAY) / HOUR, "%dh"), # Hours66 ((int(microseconds) % HOUR) / MINUTE, "%dm"), # Minutes67 ((int(microseconds) % MINUTE) / SECOND, "%ds")]: # Seconds68 # Add value to TIME literal if value is non-null or another non-null69 # value have already be found70 if val > 0 or not_null:71 data += format % val72 # Update non-null variable73 not_null = True74 # In any case microseconds have to be added to TIME literal75 data += "%gms" % (microseconds % SECOND / 1000.)76 return data77def generate_date(value):78 """79 Function converting time duration expressed in day, second and microseconds80 into a IEC 61131 DATE literal81 @param value: Time duration to convert82 @return: IEC 61131 DATE literal83 """84 return (DATE_ORIGIN + value).strftime("DATE#%Y-%m-%d")85def generate_datetime(value):86 """87 Function converting time duration expressed in day, second and microseconds88 into a IEC 61131 DATE_AND_TIME literal89 @param value: Time duration to convert90 @return: IEC 61131 DATE_AND_TIME literal91 """92 return (DATE_ORIGIN + value).strftime("DT#%Y-%m-%d-%H:%M:%S.%f")93def generate_timeofday(value):94 """95 Function converting time duration expressed in day, second and microseconds96 into a IEC 61131 TIME_OF_DAY literal97 @param value: Time duration to convert98 @return: IEC 61131 TIME_OF_DAY literal99 """100 microseconds = get_microseconds(value)101 # TIME_OF_DAY literal prefix102 data = "TOD#"103 for val, format in [104 (int(microseconds) / HOUR, "%2.2d:"), # Hours105 ((int(microseconds) % HOUR) / MINUTE, "%2.2d:"), # Minutes106 ((int(microseconds) % MINUTE) / SECOND, "%2.2d."), # Seconds107 (microseconds % SECOND, "%6.6d")]: # Microseconds108 # Add value to TIME_OF_DAY literal109 data += format % val110 return data111# Dictionary of translation functions from value send by debugger to IEC112# literal stored by type113TYPE_TRANSLATOR = {114 "TIME": generate_time,115 "DATE": generate_date,116 "DT": generate_datetime,117 "TOD": generate_timeofday,118 "STRING": lambda v: "'%s'" % v,119 "WSTRING": lambda v: '"%s"' % v,120 "REAL": lambda v: "%.6g" % v,121 "LREAL": lambda v: "%.6g" % v}122# -------------------------------------------------------------------------------123# Debug Data Consumer Class124# -------------------------------------------------------------------------------125class DebugDataConsumer(object):126 """127 Class that implements an element that consumes debug values128 Value update can be inhibited during the time the associated Debug Viewer is129 refreshing130 """131 def __init__(self):132 """133 Constructor134 """135 # Debug value and forced flag136 self.Value = None137 self.Forced = False138 # Store debug value and forced flag when value update is inhibited139 self.LastValue = None140 self.LastForced = False141 # Value IEC data type142 self.DataType = None143 # Flag that value update is inhibited144 self.Inhibited = False145 def Inhibit(self, inhibit):146 """147 Set flag to inhibit or activate value update148 @param inhibit: Inhibit flag149 """150 # Save inhibit flag151 self.Inhibited = inhibit152 # When reactivated update value and forced flag with stored values153 if not inhibit and self.LastValue is not None:154 self.SetForced(self.LastForced)155 self.SetValue(self.LastValue)156 # Reset stored values157 self.LastValue = None158 self.LastForced = False159 def SetDataType(self, data_type):160 """161 Set value IEC data type162 @param data_type: Value IEC data type163 """164 self.DataType = data_type165 def NewValues(self, tick, values, raw="BOOL"):166 """167 Function called by debug thread when a new debug value is available168 @param tick: PLC tick when value was captured169 @param value: Value captured170 @param forced: Forced flag, True if value is forced (default: False)171 @param raw: Data type of values not translated (default: 'BOOL')172 """173 value, forced = values174 # Translate value to IEC literal175 if self.DataType != raw:176 value = TYPE_TRANSLATOR.get(self.DataType, str)(value)177 # Store value and forced flag when value update is inhibited178 if self.Inhibited:179 self.LastValue = value180 self.LastForced = forced181 # Update value and forced flag in any other case182 else:183 self.SetForced(forced)184 self.SetValue(value)185 def SetValue(self, value):186 """187 Update value.188 May be overridden by inherited classes189 @param value: New value190 """191 self.Value = value192 def GetValue(self):193 """194 Return current value195 @return: Current value196 """197 return self.Value198 def SetForced(self, forced):199 """200 Update Forced flag.201 May be overridden by inherited classes202 @param forced: New forced flag203 """204 self.Forced = forced205 def IsForced(self):206 """207 Indicate if current value is forced208 @return: Current forced flag209 """...
forcedvel.py
Source: forcedvel.py
1'''2Created on 17 Sep 20143@author: sm61104The module contains methods to define the velocity at the beam support.5The methods are equivalent to those implemented in the subroutine:6 module: input7 input_forcedvel (NumNodes,Time,ForcedVel,ForcedVelDot)8 9of the original Fortran beam solver. The output variables are:10 ForcedVel (NumSteps+1,6) ! Forced velocities at the support.11 ForcedVelDot(NumSteps+1,6) ! Derivatives of the forced velocities at the support.12these describe velocities and accelerations of the support at NumSteps, evenly 13spaced, times-steps.14'''15import numpy as np16#-------------------------------------------------- Methods from input_forcedved17def set_zero(Time):18 # VelAmp=0.d019 20 NumSteps = len(Time)-121 22 ForcedVel = np.zeros( (NumSteps+1,6), dtype='float', order='F' )23 ForcedVelDot = np.zeros( (NumSteps+1,6), dtype='float', order='F' )24 25 return ForcedVel, ForcedVelDot 26def set_sin(Time, Omega, TrAmpl, RotAmpl ):27 ''' 28 Sinusoidal oscillation of frequency Omega and amplitudes TrAmpl29 (translational dof) and MomAmpl (rotational dof), such that the final support30 motion will be:31 32 Tr/Rot = {TrAmpl/RotAmpl}*sin(Omega Time)33 34 '''35 36 NumSteps = len(Time)-1 37 38 ForcedVel = np.zeros( (NumSteps+1,6), dtype='float', order='F' )39 ForcedVelDot = np.zeros( (NumSteps+1,6), dtype='float', order='F' )40 Time = Omega*Time41 ForcedVel[:,:3] = np.sin(Time).reshape((NumSteps+1,1)) * TrAmpl42 ForcedVel[:,3:] = np.sin(Time).reshape((NumSteps+1,1)) * RotAmpl 43 44 ForcedVelDot[:,:3]= Omega * np.cos(Time).reshape((NumSteps+1,1)) * TrAmpl45 ForcedVelDot[:,3:]= Omega * np.cos(Time).reshape((NumSteps+1,1)) * RotAmpl46 47 return ForcedVel, ForcedVelDot 48def set_ramp( Time, Tfull, TrAmp, RotAmp ):49 '''50 Tfull: time-step at which the full load amplitude is reached.51 '''52 53 if Tfull > Time[-1]:54 raise NameError('Tfull has to be less-equal then Time[-1]') 55 56 NumSteps = len(Time)-157 ForcedVel = np.empty( (NumSteps+1,6), dtype='float', order='F' )58 ForcedVelDot = np.empty( (NumSteps+1,6), dtype='float', order='F' )59 vel_shape = np.ones( (NumSteps+1,1), dtype=float, order='F' )60 acc_shape = np.zeros( (NumSteps+1,1), dtype=float, order='F' )61 62 NSfull = np.sum(Time < Tfull) # 1st time-step with full load63 for ii in range(NSfull): # NSfull is excluded64 vel_shape[ii]= Time[ii]/Tfull65 acc_shape[ii]= 1.0/Tfull66 67 ForcedVel[:,:3] = vel_shape * TrAmp68 ForcedVel[:,3:] = vel_shape * RotAmp69 70 ForcedVelDot[:,:3] = acc_shape * TrAmp71 ForcedVelDot[:,3:] = acc_shape * RotAmp 72 73 return ForcedVel, ForcedVelDot74def set_rampsin( Time, Tfull, Omega, TrAmpl, RotAmpl ):75 '''76 Tfull: time-step at which the full load amplitude is reached.77 omega: sine frequency78 '''79 80 v1 = np.ones(3)81 82 vel_sin, acc_sin = set_sin(Time,Omega, TrAmpl, RotAmpl )83 vel_ramp1, acc_ramp1 = set_ramp( Time, Tfull, v1, v1 )84 85 ForcedVel = vel_sin * vel_ramp186 ForcedVelDot = acc_sin*vel_ramp1 + vel_sin*acc_ramp187 88 return ForcedVel, ForcedVelDot 89if __name__=='__main__':90 91 import matplotlib.pyplot as plt92 93 Time = np.linspace(0,5,500) # sec94 Omega = 2.0*np.pi*2.0 # 2Hz 95 TrAmpl =np.array([1.,10.,100.])96 RotAmpl=np.array([2.,20.,200.]) 97 Tfull = 3.098 99 #ForcedVel, ForcedVelDot = set_sin(Time, Omega, TrAmpl, RotAmpl )100 #ForcedVel, ForcedVelDot = set_ramp(Time, Tfull, TrAmpl, RotAmpl )101 ForcedVel, ForcedVelDot = set_rampsin(Time, Tfull, Omega, TrAmpl, RotAmpl )102 103 104 for ii in range(3):105 plt.plot(Time,ForcedVel[:,ii],'r')106 plt.plot(Time,ForcedVel[:,ii+3],'k')107 plt.title('Velocities of Tr and Rot no. %d' %(ii))108 plt.show()109 110 plt.plot(Time,ForcedVelDot[:,ii],'r')111 plt.plot(Time,ForcedVelDot[:,ii+3],'k')112 plt.title('Accelerations of Tr and Rot no. %d' %(ii))113 plt.show() 114 115 116 117 ...
Check out the latest blogs from LambdaTest on this topic:
When I started writing tests with Cypress, I was always going to use the user interface to interact and change the application’s state when running tests.
When it comes to UI components, there are two versatile methods that we can use to build it for your website: either we can use prebuilt components from a well-known library or framework, or we can develop our UI components from scratch.
In today’s data-driven world, the ability to access and analyze large amounts of data can give researchers, businesses & organizations a competitive edge. One of the most important & free sources of this data is the Internet, which can be accessed and mined through web scraping.
Howdy testers! June has ended, and it’s time to give you a refresher on everything that happened at LambdaTest over the last month. We are thrilled to share that we are live with Cypress testing and that our very own LT Browser is free for all LambdaTest users. That’s not all, folks! We have also added a whole new range of browsers, devices & features to make testing more effortless than ever.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!