本文整理汇总了Python中stats.Stats类的典型用法代码示例。如果您正苦于以下问题:Python Stats类的具体用法?Python Stats怎么用?Python Stats使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Stats类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: NPC
class NPC(object):
def __init__(self, name):
self.stats = Stats()
self.name = name
def show_hp(self):
print "HP:", self.stats.hit_points
def attack(self, enemy):
mod = np.random.uniform(0.9, 1, 1)[0]
a = self.stats.level*0.3
b = (float(self.stats.attack)*4/enemy.stats.defense)*4.0
c = mod
damage = max(int(a*b*c), 1)
enemy.stats.hit_points -= damage
print "BAM!", enemy.name, "was hit for", damage
enemy.stats.hit_points = max(enemy.stats.hit_points, 0)
return damage
def level_up(self):
if self.stats.level < 99:
self.stats.level += 1
self.stats.max_hit_points = self.stats.level*8
rem_points = 3
stat_selector = []
stat_selector.extend(self.stats.stats_names)
while(rem_points > 0):
rand_stat = np.random.choice(stat_selector, 1)
rand_stat_increase = np.random.randint(1,rem_points+1)
self.stats.modify_stat(rand_stat, rand_stat_increase)
stat_selector.remove(rand_stat)
rem_points -= rand_stat_increase
def level_to(self, lvl):
if lvl > 99:
lvl = 99
while(self.stats.level < lvl):
self.level_up()
def show_stats(self):
print "/"*20
print self.name, " (LV. " , self.stats.level , ")"
print self.stats.hit_points , "/", self.stats.max_hit_points
aux_hp = int((float(self.stats.hit_points)/ self.stats.max_hit_points)*20)
txt_hp = "+"*aux_hp
print "[{0:20}]".format(txt_hp)
print "Att: ", self.stats.attack
print "Def: ", self.stats.defense
print "Lck: ", self.stats.luck
print "/"*20
def cure(self, hp):
a = self.stats.hit_points + hp
if a > self.stats.max_hit_points:
result = self.stats.max_hit_points - self.stats.hit_points
self.stats.hit_points = self.stats.max_hit_points
else:
result = hp
self.stats.hit_points = a
return result
开发者ID:ltdicai,项目名称:testing-ground,代码行数:60,代码来源:npc.py
示例2: Simulation
class Simulation(object):
def __init__(self, aggregator, strategy, reserved_resources, sleep_time=0):
self.aggregator = aggregator
self.strategy = strategy
# 2 year warm up, and 10 year run
self.stats = Stats(24, 120)
self.company = Company(20, reserved_resources, self.strategy, self.stats)
self.sleep_time = sleep_time
self.reserved_resources = reserved_resources
print(sim_to_key(self))
def run(self):
for t in range(self.stats.runs):
self.stats.start_month()
projects = [generate_project() for _ in range(sample.project_count())]
self.company.decide_projects(projects)
used_resources = self.company.workflow.work()
self.stats.end_month(used_resources, self.company.workflow.average_workload())
if self.sleep_time > 0:
sleep(self.sleep_time)
#print(self.stats.monthly_report())
self.aggregator.add_result(self)
开发者ID:acrespo,项目名称:Simulaciones,代码行数:35,代码来源:sim.py
示例3: process
def process(infile, algorithm_name, support, confidence, m, random, partial):
stats = Stats()
transactions = TransactionsList(infile)
stats.record_post_large_sets()
stats.record_post_rules()
last_total_time = stats.real_time
last_user_time = stats.user_time
stats = Stats()
if algorithm_name == 'apriori':
algorithm = Apriori(transactions, support)
else:
algorithm = Dic(transactions, support, m, random, partial)
large_sets, counter = algorithm.get_large_sets_and_counter()
stats.record_post_large_sets()
rules = RulesGenerator.generate_rules(large_sets, confidence, counter, transactions)
stats.record_post_rules()
large_len = len(large_sets)
total_time = stats.real_time - last_total_time
user_time = stats.user_time - last_user_time
large_sets_time = stats.set_gen_time - last_total_time
last_total_time = stats.real_time
last_user_time = stats.user_time
memory = stats.memory_use
rules_no = len(rules)
print "{infile}\t{algorithm_name}\t{support}\t{confidence}\t{m}\t{rules_no}\t{large_len}\t{memory}\t{total_time}\t{user_time}\t{large_sets_time}\t{partial}\t{random}".format(**locals())
开发者ID:powerllamas,项目名称:associative_rules,代码行数:26,代码来源:collect_data.py
示例4: do_mark
def do_mark(self, subcmd, opts, bamfile, amplicons):
"""${cmd_name}: Mark reads matching amplicons and optionally clip.
Walk a BAM file and mark any matching amplicons using the AM tag.
Outputs a modified BAM. Use 'clip' if you want only reads matching
amplicons in the output.
${cmd_usage}
BAMFILE: input reads (use - for stdin)
AMPLICONS: a file listing amplicons and trim locations.
${cmd_option_list}
"""
samfile = pysam.Samfile(bamfile, "rb")
stats = Stats(" ".join(sys.argv))
amplicons = load_amplicons(design, stats, opts, samfile=samfile)
outfile = pysam.Samfile(opts.outfile, "wb", template=samfile)
# we need to reopen the file here to get sequential access after computin the pileups
samfile = pysam.Samfile(bamfile, "rb")
for read in samfile:
# TODO: optimisation of the list of amplicons that are considered
for amp in amplicons:
if amp.matches(read):
amp.clip(read)
amp.mark(read)
outfile.write(read)
stats.report(sys.stderr)
开发者ID:ian1roberts,项目名称:amptools,代码行数:30,代码来源:main.py
示例5: on_shutter
def on_shutter(self, state):
print '-----'
print 'Time to Start'
total = Stats()
for method_name, stats in state.time_to_start.items():
print "%s avg:%.2fs, max:%.2fs, min: %.2fs" % (method_name, stats.average() or -1.0 , stats.maximum or -1.0, stats.minimum or -1.0)
total += stats
print ''
print 'Time to Process'
total = Stats()
for method_name, stats in state.time_to_process.items():
print "%s avg:%.2fs, max:%.2fs, min: %.2fs" % (method_name, stats.average() or -1.0, stats.maximum or -1.0, stats.minimum or -1.0)
total += stats
print "Total: avg:%.2fs, max:%.2fs, min: %.2fs" % (total.average() or -1.0, total.maximum or -1.0, total.minimum or -1.0)
print ''
print 'Event Totals'
for method_name, totals in state.totals.items():
for total_name, total in totals.items():
print "%s[%s]: %d" % (method_name, total_name, total)
print ''
print 'Queue Sizes'
print 'Waiting Tasks: %d' % len(state.waiting_tasks)
print 'Running Tasks: %d' % len(state.running_tasks)
print ''
print ''
开发者ID:bpc,项目名称:celery-cloudwatch,代码行数:30,代码来源:print_camera.py
示例6: main
def main():
filename = sys.argv[1]
graph = Graph()
parser = Parser()
#parse gdf file
parser.parse(filename, graph)
# print graph.__str__()
stats = Stats(graph)
#compute popularity
popularities = stats.computePopularity()
print "Popularidad"
print "********************************"
stats.showPopularities(popularities)
#compute influences
influences = stats.computeInfluences()
print ""
print "Influencias"
print "********************************"
stats.showInfluences(influences)
#obtain recomendations
print ""
print "Recomendaciones"
print "********************************"
recommendations = stats.computeRecommendations()
stats.showRecommendations(recommendations)
开发者ID:aandrea,项目名称:TDA1,代码行数:32,代码来源:main.py
示例7: __init__
def __init__(self, ciphertext, stats_filenames, dict_file, max_pop = 10, params = default_params, alphabet = default_alphabet, stat_file = None, naive_key = True):
self.params = params
self.alphabet = alphabet
self.single_stats_filename, self.double_stats_filename = stats_filenames
self.ciphertext = ciphertext
self.max_pop = max_pop
self.exp_stats = Stats(self.alphabet)
self.exp_stats.load_singlef_from_file(self.single_stats_filename)
self.exp_stats.load_doublef_from_file(self.double_stats_filename)
self.ciph_stats = Stats(self.alphabet)
self.ciph_stats.process_text(self.ciphertext)
self.initialize(naive_key)
self.stat_file = None
if stat_file != None:
self.stat_file = open(stat_file, "w")
self.stat_file.write("gen\tworst\tavg\tbest\tderiv\n")
self.sliding_table = []
self.end = False
self.dictionary = Dictionary(dict_file)
self.temp_stats = Stats(self.alphabet)
signal.signal(signal.SIGINT, self.signal_handler)
开发者ID:pinkeen,项目名称:subst-cracker,代码行数:29,代码来源:pool.py
示例8: __getattr__
def __getattr__(self, name):
if name == 'stats':
stats = Stats()
for effect in self.effects:
stats.add_stats(effect.stats)
return stats
else:
raise AttributeError
开发者ID:Allexit,项目名称:Adragaria-2,代码行数:8,代码来源:effect.py
示例9: possible
def possible(self, row, col):
if (row == col):
return Stats.possible(self, row, col) & self.diag0
elif (row + col) == 8:
return Stats.possible(self, row, col) & self.diag8
else:
return Stats.possible(self, row, col)
开发者ID:szopenfx,项目名称:code,代码行数:9,代码来源:diagonal.py
示例10: test_tb
def test_tb(self):
"""
Total bases test
:return:
"""
# ichiro suzuki(2004)
single = Stats.single(262, 8, 24, 5)
tb = Stats.tb(single, 8, 24, 5)
self.assertEqual(tb, 320)
开发者ID:Shinichi-Nakagawa,项目名称:tsubuyaki_league_draft_list_script,代码行数:9,代码来源:tests.py
示例11: __getattr__
def __getattr__(self, name):
if name == 'stats':
stats = Stats()
for item in self.equipment:
if self.equipment[item]:
stats.add_stats(self.equipment[item].stats)
return stats
else:
raise AttributeError
开发者ID:Allexit,项目名称:Adragaria-2,代码行数:9,代码来源:inventory.py
示例12: test_rc
def test_rc(self):
"""
Run created test
:return:
"""
# ichiro suzuki(2004)
single = Stats.single(262, 8, 24, 5)
rc = Stats.rc(262, 49, 4, 11, 6, 3, 2, 36, 63, 704, 19, single, 24, 5, 8)
self.assertEqual(rc, 136.5)
开发者ID:Shinichi-Nakagawa,项目名称:tsubuyaki_league_draft_list_script,代码行数:9,代码来源:tests.py
示例13: setUp
def setUp(self):
self.st = Stats()
self.expect = Stats()
self.expect.sumsq = 425.1641
self.expect.sum = 55.84602
self.expect.min = 0.333
self.expect.max = 9.678
self.expect.n = 10
开发者ID:shackijj,项目名称:lcthw,代码行数:9,代码来源:stats_tests.py
示例14: home
def home(request):
log.info('Request: home')
stats = Stats()
return render(request, 'binary/home.html', {
'q_values': stats.q.data,
'runs_latest': stats.runs[-30:],
'time_frames': stats.summarizeTimeFrames(),
'trade_bases': stats.summarizeTradeBases(),
'trade_aims': stats.summarizeTradeAims(),
})
开发者ID:vishnuvr,项目名称:trading,代码行数:12,代码来源:views.py
示例15: main
def main(args):
states = read_states(args.input)
stats = Stats(sys.argv)
cipher = Spritz()
settings = Settings(args)
prompt_step = max(1, len(states) // 20)
i = 0
for initial_state, revealed_state, prefix_length in states:
if args.verbosity > 1 and i % prompt_step == 0:
print('test #:', i)
i += 1
KNOWN_KEYSTREAM_SIZE = 3 * initial_state.size
cipher.initialize_state(initial_state.state)
known_keystream = cipher.keystream(prefix_length + KNOWN_KEYSTREAM_SIZE)
settings.prefix_length = prefix_length
# in case we want to skip less keystream than revealed_state is
# generate in, we cut off beginning of keystream and move
# initial_state apropriatelly
if args.input and args.force_prefix_length and args.force_prefix_length < prefix_length:
new_prefix_length = args.force_prefix_length
new_start_offset = prefix_length - new_prefix_length
settings.prefix_length = new_prefix_length
known_keystream = known_keystream[new_start_offset:]
cipher.initialize_state(initial_state.state)
cipher.keystream(new_start_offset)
initial_state = SpritzState(cipher.state)
cipher.initialize_state(initial_state.state)
cipher.keystream(prefix_length)
found_state, round_stats = backtrack.kpa(
known_keystream,
revealed_state,
settings,
)
if found_state and initial_state != found_state:
print('incorrect result, this should not happen')
assert False
stats.add(round_stats)
stats.print_stats(args.verbosity)
# dump pickled stats object
if not args.no_stats_log:
timestamp = datetime.datetime.today().strftime('%y%m%d_%H%M%S_%f')
os.makedirs('stats/', exist_ok=True)
with open('stats/' + timestamp, 'wb') as f:
pickle.dump(stats, f)
开发者ID:mgabris,项目名称:state-recovery-backtrack,代码行数:53,代码来源:benchmark.py
示例16: operations_test
def operations_test():
st = Stats()
for sample in samples:
st.sample(sample)
print st
assert_float_equal(expect.sum, st.sum)
assert_float_equal(expect.sumsq, st.sumsq)
assert_equal(expect.n, st.n)
assert_float_equal(expect.min, st.min)
assert_float_equal(expect.max, st.max)
开发者ID:Micaiah-Chang,项目名称:LCTHW,代码行数:13,代码来源:stats_tests.py
示例17: __init__
def __init__(self, data):
quartiles = data[:]
quartiles.sort()
middle = Stats.median(quartiles)
split = ListUtils.middleSplit(quartiles)
leftBound = Stats.median(split[0])
rightBound = Stats.median(split[1])
self.__quartileBounds = [leftBound, middle, rightBound]
leftSplit = ListUtils.middleSplit(split[0])
rightSplit = ListUtils.middleSplit(split[1])
self.__quartiles = [leftSplit[0], leftSplit[1], rightSplit[0], rightSplit[1]]
开发者ID:kahgoh,项目名称:Python-AFL-Dream-Team-Selector,代码行数:14,代码来源:Quartiles.py
示例18: test_edges
def test_edges(self):
s = Stats('[%s/%f/%t/%r/%p]', None, None)
self.assertEqual(s.format(), '[0/0/0/0/ --- ]')
s.started = 3
s.total = 5
s.finished = 1
self.assertEqual(s.format(), '[3/1/5/2/ 60.0]')
s.started = 5
s.finished = 5
self.assertEqual(s.format(), '[5/5/5/0/100.0]')
开发者ID:dpranke,项目名称:pyn,代码行数:11,代码来源:stats_test.py
示例19: delete_node
def delete_node(sender, **kwargs):
""" update user node count when a node is deleted """
node = kwargs['instance']
Stats.update_or_create(node.user, 'nodes')
# email notifications
#@receiver(node_status_changed)
#def notify_status_changed(sender, **kwargs):
# """ TODO: write desc """
# node = sender
# old_status = kwargs['old_status']
# new_status = kwargs['new_status']
# notification_type = EmailNotification.determine_notification_type(old_status, new_status, 'Node')
# EmailNotification.notify_users(notification_type, node)
#node_status_changed.connect(notify_status_changed)
开发者ID:codeforeurope,项目名称:nodeshot,代码行数:15,代码来源:__init__.py
示例20: __init__
def __init__(self, fight, src = None):
''' Конструктор.
Fight fight - битва, в которой участвует файтер.
src - документ.
'''
if src:
self.__dict__.update(src)
self.deck = [Card.js_load(c) for c in self.deck]
self.hand = [Card.js_load(c) for c in self.hand]
self.stats = Stats(self.stats)
self.effects = [Effect.js_load(eff, self) for eff in self.effects]
else:
self.id = unique_id()
self.stats = Stats()
self.fight = fight
开发者ID:alexbft,项目名称:Karty-RPG,代码行数:15,代码来源:fighter.py
注:本文中的stats.Stats类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论