本文整理汇总了Python中constants.Constants类的典型用法代码示例。如果您正苦于以下问题:Python Constants类的具体用法?Python Constants怎么用?Python Constants使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Constants类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: f_prime
def f_prime(u_now0, u_now1, u_now2, u_next0, u_next1, u_next2, f_now, f_next):
u_tmp = (pow(abs(u_next2), 2) * u_next2) - (pow(abs(u_next0), 2) * u_next0) + (pow(abs(u_now2), 2) * u_now2) - (pow(abs(u_now0), 2) * u_now0)
p1 = u_now2 - 2.0 * u_now1 + u_now0
p2 = -0.5 * Constants.beta * Constants.h() * complex(0,1) * u_tmp
p3 = -1.0 * complex(0,1) * pow(Constants.h(), 2) * (f_next + f_now)
p4 = -2.0 * pow(Constants.h(), 2) * complex(0,1) * u_now1 / Constants.tau
return p1 + p2 + p3 + p4
示例2: check_user_credentials_with_credentials
def check_user_credentials_with_credentials(user_id, token):
# Check token status
status = TokenSerializer.verify_auth_token(token, user_id)
# Is token is expired?
if status == SignatureExpired:
# Yes: return error status
return Constants.error_token_expired()
# Is toke not valid?
elif status == BadSignature:
# Yes: return error status
return Constants.error_token_not_valid()
# Try to find user with received ID
person_model = PersonModel.query.filter_by(person_id=user_id).first()
# Have we user with received ID?
if person_model is None:
# No we haven't: return error status
return Constants.error_no_user_id()
# Is received token correct?
if person_model.token != token:
# No: return error status
return Constants.error_token_not_valid()
# If everything is Ok - return person model
return person_model
示例3: run_basis
def run_basis(FSS):
"""
Runs crosscorrlation vs wave plartes experiment.
"""
print 'Running diag basis with FSS', FSS.astype('|S4').tostring()
constants = Constants()
constants.FSS = FSS
experiment = Experiment(constants)
experiment.bench.setHWP(np.pi/8, np.pi/8)
experiment.bench.setLabMatrix('NBSNBS HWPHWP SS PBSPBS')
experiment.run('basis')
experiment.pcm.channel('D1D3').normalize(experiment.laser.pulse_width)
experiment.pcm.channel('D1D4').normalize(experiment.laser.pulse_width)
experiment.pcm.channel('D2D3').normalize(experiment.laser.pulse_width)
experiment.pcm.channel('D2D4').normalize(experiment.laser.pulse_width)
for key in experiment.pcm._channels:
x = experiment.pcm._channels[key].bin_edges
y = experiment.pcm._channels[key].counts
save.savedata(x, y, name = 'diag' + '_' + key + '_' + FSS.astype('|S4').tostring(), dir = 'auto_g2_v_fss_dephase2.5e10secondaty0.18')
g2 = experiment.pcm.channel('D1D3').g2
g2_cross = experiment.pcm.channel('D1D4').g2
return g2_cross
示例4: generate_rerun_params
def generate_rerun_params(self):
f = "-f \""
param = Constants.EXECUTE_PREFF + "\"" + Constants.WRT_LAUNCHR_CMD
for suite in self.suites.keys():
suite_obj = self.suites[suite]
f += "%s " % suite_obj.get_rerunxml_name()
param += " %s" % suite
f = Constants.add_right_enbrace(f)
param = Constants.add_right_enbrace(param)
return f + param + Constants.RERUN_OUTPUT
示例5: to_xml
def to_xml(self, xml_name):
print "generating plan to %s" % xml_name
root = ElementTree.Element('testplan')
for suite_name in self.suites:
suite = self.suites[suite_name]
root.append(suite.to_xml())
Constants.indent(root)
tree = ElementTree.ElementTree()
tree._setroot(root)
tree.write(xml_name, encoding="utf-8")
示例6: get_suite_param
def get_suite_param(self):
param = Constants.XMLFILE_PREFF + "\""
for suite_name in self.options.suites:
param += "%s " % suite_name
param = Constants.add_right_enbrace(param)
param += Constants.EXECUTE_PREFF + ("\" %s " % Constants.WRT_LAUNCHR_CMD)
for e_name in self.options.suites:
param += "%s " % e_name
param = Constants.add_right_enbrace(param)
return param
示例7: post
def post(self):
parser = reqparse.RequestParser()
parser.add_argument('userID', type=str, help='User ID', location='form', required=True)
parser.add_argument('userData', type=str, help='User Data', location='form', required=True)
parser.add_argument('userToken', type=str, help='User Token', location='form', required=True)
args = parser.parse_args()
user_id = args['userID']
token = args['userToken']
model = BaseResource.check_user_credentials_with_credentials(user_id, token)
if not isinstance(model, PersonModel):
# Some error happens here
return model
json_data = args['userData']
try:
json_data = json.loads(json_data)
except ValueError:
return Constants.error_wrong_json_format()
if not isinstance(json_data, list):
return Constants.error_wrong_json_structure()
print json_data
result = []
for event_dict in json_data:
if isinstance(event_dict, dict):
event_model = EventModel.find_event(event_dict.get(EventModel.k_event_id))
event_model.creator_id = user_id
event_model.configure_with_dict(event_dict)
db.session.add(event_model)
db.session.commit()
event_json = event_model.to_dict()
result.append(event_json)
time_stamp = datetime.utcnow()
response = dict()
response[Constants.k_time_stamp] = time_stamp.isoformat()
response['result'] = result
# print response
return response
示例8: get_feature
def get_feature(self, daily_sale, menu_item_index, weather_item, with_days=False):
if with_days:
return [
menu_item_index,
weather_item[Constants.JSON_TEMP],
Constants.get_weather_type(weather_item)
]
else:
return [
self.get_day_of_week(daily_sale),
menu_item_index,
weather_item[Constants.JSON_TEMP],
Constants.get_weather_type(weather_item)
]
示例9: generate_params
def generate_params(self):
f = Constants.XMLFILE_PREFF + "\""
tmp = ""
for suite in self.suites.keys():
suite_obj = self.suites[suite]
p_name = suite[0: suite.find("tests")] + "tests"
f += Constants.DEVICE_TESTS_FILE % p_name
if suite_obj.get_command().startswith(Constants.WRT_LAUNCHR_CMD):
tmp += "%s " % suite_obj.get_command()[(len(Constants.WRT_LAUNCHR_CMD) + 1):]
f = Constants.add_right_enbrace(f)
e = ""
if not tmp.isspace():
e = Constants.EXECUTE_PREFF + "\"" + Constants.WRT_LAUNCHR_CMD +" " + tmp
e = Constants.add_right_enbrace(e)
return f + " " + e
示例10: post
def post(self):
user = users.get_current_user()
if not user:
# Send the user to the login page
self.redirect(users.create_login_url(self.request.uri))
return
assert user
newKey = None
if (self.request.get(Constants.ACTION_WORDS_PARAM) and
self.request.get(Constants.REDIRECT_LINK_PARAM)):
if self.request.get(Constants.ACTION_ID_PARAM):
newAction = ndb.Key('Action', int(self.request.get(Constants.ACTION_ID_PARAM)),
parent=getAccountKey(user.user_id())).get()
else:
newAction = Action(parent=getAccountKey(user.user_id()))
newAction.user_id = user.user_id()
newAction.redirect_link = self.request.get(Constants.REDIRECT_LINK_PARAM)
newAction.actionwords = UserInput(
self.request.get(Constants.ACTION_WORDS_PARAM)).getAllActionWords()
newKey = newAction.put()
if self.request.get(Constants.AJAX_REQUEST_PARAM):
return ajaxSuccess(self)
return self.redirect(listPagePath(Constants.NEW_KEY_PARAM, str(newKey.id())))
if self.request.get(Constants.AJAX_REQUEST_PARAM):
return ajaxFailure(self)
template_values = { 'user_nickname': user.nickname(),
'Constants': Constants.instance(),
'actionwords_input': self.request.get(Constants.ACTION_WORDS_PARAM),
'redirect_link_input': self.request.get(Constants.REDIRECT_LINK_PARAM)}
template = JINJA_ENVIRONMENT.get_template('add.html')
self.response.write(template.render(template_values))
示例11: _send_request
def _send_request(self, byte, expected_response=None):
data = Constants.serialize_packet(byte)
self.ser.write(data)
response = self._get_response()
if expected_response is not None and expected_response != response:
raise PnuematicActuatorDriverResponseError(response, expected_response)
return response
示例12: init_values
def init_values(self):
"""Initialize statuses of whether or not files have been
loaded, whether shaft information displays are normalized,
and whether or not the plot needs to be refreshed. Also
initialize a class holding constants.
"""
# Holds the states of whether the necessary files have been loaded.
# The 4 required files are:
# - designs specifications
# - material properties
# - load factors
# - wind history.
self.loaded = [False, False, False, False]
# This value determines how details of the shaft sections are displayed.
# A value of 'True' scales text uniformly; A value of 'False' places
# text underneath plotted shaft sections.
self.normalized = False
# This value determines whether solutions have to be (re)solved.
# Prevents recalculating solutions if user only wants to change views.
self.reload = True
# Initialize constants.
self.c = Constants()
示例13: test_AlternativeReplacements
def test_AlternativeReplacements(self):
constantJson = {
'sets' : { },
'specials' : { },
'alternative_names' : {
'carda' : 'ca',
'card b' : ['cb', 'cb b']
}
}
with TempJson(constantJson) as json:
c = Constants(json)
self.assertEqual(c.translateAlt("ca"), "carda")
self.assertEqual(c.translateAlt("cb"), "cardb")
self.assertEqual(c.translateAlt("cc"), "cc")
示例14: write
def write(self, data):
request = Constants.deserialize_packet(data)
request = request[0]
if request == Constants.PING_REQUEST:
rospy.loginfo('Ping received')
byte = Constants.PING_RESPONSE
elif request > 0x20 and request < 0x30:
rospy.loginfo('Open port {}'.format(request - 0x20))
byte = Constants.OPEN_RESPONSE
elif request > 0x30 and request < 0x40:
rospy.loginfo('Close port {}'.format(request - 0x30))
byte = Constants.CLOSE_RESPONSE
else:
rospy.loginfo('Default')
byte = 0x00
self.buffer += Constants.serialize_packet(byte)
return len(data)
示例15: _get_response
def _get_response(self):
data = self.ser.read(2)
if len(data) != 2:
raise PnuematicActuatorTimeoutError()
response = Constants.deserialize_packet(data)
data = response[0]
chksum = response[1]
self._verify_checksum(data, chksum)
return data