本文整理汇总了Python中helper.Helper类的典型用法代码示例。如果您正苦于以下问题:Python Helper类的具体用法?Python Helper怎么用?Python Helper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Helper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: move
def move(self):
'''Predator is pretty dumb: if it sees a pray, it follows it to
autodestruction.
'''
# Can always do indexing on filtered instances, as it should be a pray
# always, else the game should have finished (bug?).
pray = filter(lambda x: isinstance(x, Pray), self.game.instances)[0]
# In case it sees the pray, change direction to follow it.
if BaseObject.object_sees_object(self, pray):
self.direction = Helper.get_direction_towards(self.coord, pray.coord)
# Try and find close predators and sync with them to arrive at the
# prey in the same time.
#
# The sync works the following way:
# - each predator finds the max speed and max distance to pray
# (from all predators visible from him that they follow the pray)
# - they update their speed v' = v_max * d / d_max
# where d = own distance to pray
max_speed = self.speed
own_dist = max_dist = Helper.euclidian_distance(self.coord, pray.coord)
for instance in self.game.instances:
if instance == self or not isinstance(instance, Predator):
continue
# Look only for visible predators other than myself.
if BaseObject.object_sees_object(self, instance):
dist = Helper.euclidian_distance(instance.coord, pray.coord)
max_dist = max(max_dist, dist)
max_speed = max(max_speed, instance.speed)
# Sync speed with other predators.
self.speed = max_speed * own_dist / float(max_dist)
super(Predator, self).move()
示例2: hold
def hold(target, snapshot, endpoint=''):
if endpoint == '':
command = 'zfs hold zsm {0}@{1}'.format(target, snapshot)
Helper.run_command(command, '/')
else:
command = '{0} \'zfs hold zsm {1}@{2}\''.format(endpoint, target, snapshot)
Helper.run_command(command, '/')
示例3: create_app
def create_app(config_name):
app = Flask(__name__, static_url_path='')
app.config.from_object(config[config_name])
# Configurations & Extensions
config[config_name].init_app(app)
login_manager.init_app(app)
db.init_app(app)
Helper.init_app(app)
@app.teardown_request
def shutdown_session(exception=None):
db.session.remove()
# Register Blueprint
from .main import main as main_blueprint
from .user import user as user_blueprint
from .note import note as note_blueprint
app.register_blueprint(main_blueprint)
app.register_blueprint(user_blueprint)
app.register_blueprint(note_blueprint)
return app
示例4: __init__
def __init__(self, host, user, pwd):
Helper.__init__(self, host, user, pwd);
reload(sys);
# set timeout and encoding.
sys.setdefaultencoding('utf-8');
socket.setdefaulttimeout(timeout);
示例5: release
def release(target, snapshot, endpoint=''):
if endpoint == '':
command = 'zfs release zsm {0}@{1} || true'.format(target, snapshot)
Helper.run_command(command, '/')
else:
command = '{0} \'zfs release zsm {1}@{2} || true\''.format(endpoint, target, snapshot)
Helper.run_command(command, '/')
示例6: __init__
class Vegenere:
def __init__(self):
self.helper = Helper()
def encrypt(self, plaintext, key):
plaintext = self.helper.format(plaintext)
key = self.helper.format(key)
kryptotext = ''
for index, char in enumerate(plaintext):
plain_char = ord(char) - 65
key_char = ord(key[index % len(key)]) - 65
krypto_char = ((plain_char + key_char) % 26) + 65
kryptotext += unichr(krypto_char)
return kryptotext
def decrypt(self, kryptotext, key):
kryptotext = self.helper.format(kryptotext)
key = self.helper.format(key)
plaintext = ''
for index, char in enumerate(kryptotext):
krypto_char = ord(char) - 65
key_char = ord(key[index % len(key)]) - 65
plain_char = ((krypto_char - key_char) % 26)
if plain_char < 0:
plain_char += 26
plain_char += 65
plaintext += unichr(plain_char)
return plaintext
示例7: destroy
def destroy(dataset, snapshot):
"""
Destroyes a dataset
"""
command = 'zfs destroy {0}@{1}'.format(dataset, snapshot)
Helper.run_command(command, '/')
示例8: snapshot
def snapshot(dataset, name):
"""
Takes a snapshot
"""
command = 'zfs snapshot {0}@{1}'.format(dataset, name)
Helper.run_command(command, '/')
示例9: given
def given(self, step):
'''I have prospects to move'''
browser = Helper().login()
self.browser = browser
print "creating"
Helper().add_prospects()
browser.execute_script("location.reload()")
示例10: kmeans_centroids
def kmeans_centroids(self, clusters):
'''Calculate centroids based on clusters by doing a mean between
all states within the same cluster.
'''
Helper.verbose_print('Centroids: ' + str(self.get_centroids_count(clusters)))
new_centroids = [0 for _ in range(self.k)]
for i in range(self.k):
state_sum = tuple([(0,0) for _ in range(self.coord_nr)])
nr = 0.0
for state,cluster in clusters.iteritems():
if cluster == i:
nr += 1
state_sum = self.add_states(state_sum, state)
# At least one representat for a cluster should exist.
if nr > 0:
# Now divide by the number of members in a cluster every coordinate.
new_centroids[i] = map(lambda coord: self.__divide_coord(coord, nr),
state_sum)
# Treat the case of finding no member in cluster by making it be
# infinity everywhere.
else:
new_centroids[i] = map(lambda coord: tuple([Preprocess.INFINITY
for c in coord]),
state_sum)
return new_centroids
示例11: main
def main(endings, size_limit, search_path):
# initiate global function variables
movie_list = []
longest_title = 0
# initiate options & arguments from cli
movie_endings = tuple(endings.split(", "))
movie_size_limit = int(size_limit) * 1024 * 1024 # MegaBytes
# initiate needed objects
scanner = Scan(movie_endings, movie_size_limit)
helper = Helper()
# look for all available files inside directory recursively
for root, subs, files in os.walk(search_path):
# do available files match a movie-file?
for file in files:
# is movie file?
bool_movie = scanner.is_movie(file)
if not bool_movie:
continue
# is large enough?
movie_path = os.path.join(root, file)
movie_folder = os.path.basename(root)
bool_large = scanner.is_large(movie_path)
if not bool_large:
continue
# is movie file and large enough, try to extract a valid movie name
extracted_data = scanner.extract_file_data(file, movie_folder)
# if movie has valid data, create a new movie object
if -1 in extracted_data:
print("Problem with: " + extracted_data[0] + " " + str(extracted_data[1]))
else:
# data valid, create object and append it
movie_object = Movie(extracted_data[0], extracted_data[1], movie_path, root)
movie_list.append(movie_object)
# does the current movie have the longest title?
if longest_title < len(movie_object.title):
longest_title = len(movie_object.title)
result_str = "Movies counted: {number}".format(number=len(movie_list))
print(result_str)
# try to fetch imdb rating for each movie-object
for movie in movie_list:
movie.fetch_rating()
# is current movie in top 250
movie.imdb_top = helper.is_imdb_top(movie)
# sort movies by their rating and print them
print("")
movie_list.sort(key=lambda x: x.rating, reverse=True)
for movie in movie_list:
movie.print_data(longest_title)
示例12: compute_matrix_block
def compute_matrix_block(self, start_row, start_column, num_rows, num_columns):
"""
Computes a given block of the result matrix.
The method invoked by FEP nodes.
@param start_row: the index of the first row in the block
@param start_column: the index of the first column in the block
@param num_rows: number of rows in the block
@param num_columns: number of columns in the block
@return: the block of the result matrix encoded as a row-order list of lists of integers
"""
"""
This method is searching for the elements that this node needs in order to compute his block.
Firstly finds the node from where a element should be taken, starts a thread which will obtain the element, and then
puts that element in a matrix.
Those are made twice, for each matrix.
After calculating the two matrixes, the method 'multiply' gives the result that is returning the result.
"""
A = [[0 for i in range(self.matrix_size)] for j in range(num_rows)];
B = [[0 for j in range(num_columns)] for j in range(self.matrix_size)];
for i in range(num_rows):
for j in range(self.matrix_size):
row = start_row + i;
id_row = row / self.block_size;
id_column = j / self.block_size;
node = self.nodes[(self.matrix_size / self.block_size) * id_row + id_column];
i_a = node.node_ID[0];
j_a = node.node_ID[1];
size = node.block_size;
helper = Helper(node, row - i_a * size, j - j_a * size, "a");
helper.start();
helper.join();
A[i][j] = helper.element;
for i in range(self.matrix_size):
for j in range(num_columns):
column = start_column + j;
id_row = i / self.block_size;
id_column = column / self.block_size;
node = self.nodes[(self.matrix_size / self.block_size) * id_row + id_column];
i_b = node.node_ID[0];
j_b = node.node_ID[1];
size = node.block_size;
helper = Helper(node, i - i_b * size, column - j_b * size, "b");
helper.start();
helper.join();
B[i][j] = helper.element;
return self.multiply(A, B, num_rows, num_columns);
示例13: test_get_direction_towards
def test_get_direction_towards(self):
direction = Helper.get_direction_towards((0,0), (0,10))
self.assertEqual(90, direction)
direction = Helper.get_direction_towards((0,0), (1,1))
self.assertEqual(45, direction)
direction = Helper.get_direction_towards((0,0), (-1,-1))
eps = math.sin(math.radians(225)) - math.sin(math.radians(direction))
self.assertTrue(eps < 0.001)
示例14: calculate_data_actual
def calculate_data_actual(tickets, member, daterange, total_point):
from helper import Helper
backlogs = Helper.calculate_backlog(tickets, member, daterange, "closed")
burndown = Helper.calculate_burndown_actual(backlogs, total_point)
csv = [member, burndown["Start"]]
for d in sorted(daterange):
csv.append(burndown[d])
return csv
示例15: calculate_data
def calculate_data(tickets, member, daterange):
from helper import Helper
backlogs = Helper.calculate_backlog(tickets, member, daterange, "due_assign")
burndown = Helper.calculate_burndown_estimated(backlogs)
csv = [member, burndown["Start"]]
for d in sorted(daterange):
csv.append(burndown[d])
return csv