本文整理汇总了Python中Features.calculate_features方法的典型用法代码示例。如果您正苦于以下问题:Python Features.calculate_features方法的具体用法?Python Features.calculate_features怎么用?Python Features.calculate_features使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Features
的用法示例。
在下文中一共展示了Features.calculate_features方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_one_file
# 需要导入模块: import Features [as 别名]
# 或者: from Features import calculate_features [as 别名]
def parse_one_file(input_data):
# looking for cached results
cache_filename = input_data.infile + '.cache'
## BRANCH: parsed infile already cached
if ( USE_PCAP_CACHE and os.path.isfile(cache_filename) ):
print "Reading cache:", cache_filename
pickle_input = open(cache_filename, 'rb')
senders = pickle.load(pickle_input)
pickle_input.close()
## BRANCH: no cache
else:
## * parse pcap file *
senders = Pcap_Parser.parse(input_data.infile, PACKETS) # 100000
## caching parser results
if ( USE_PCAP_CACHE ):
pickle_output = open(cache_filename, 'wb')
pickle.dump(senders, pickle_output, pickle.HIGHEST_PROTOCOL)
pickle_output.close()
##
# types = ( Storage_Classes.Sender.TYPE.AP, \
# Storage_Classes.Sender.TYPE.STATION, \
# Storage_Classes.Sender.TYPE.UNKNOWN)
types = ( Storage_Classes.Sender.TYPE.AP, )
# ## FIXME at the moment "s.show(addr)" is important for proper functionality
for t in types:
for addr in senders:
s = senders[addr]
if ( s.type == t ):
# s.show(addr)
s.set_addr(addr)
## Visualization
# Visualization.show_biggest_ap(senders)
## Units
sender = get_biggest_ap(senders)
# sender = get_biggest_ap(senders)
print
print "Using:"
sender.show()
# window sizes
# UNIT_WINDOW = 0.1
UNIT_WINDOW = 1.0
DATA_POINT_WINDOW = 6.0
# DATA_POINT_WINDOW = 5.0
# SKIP_FRONT = 20
SKIP_FRONT = 0
OVERLAPPING = True
## Data Grouping ##
units = Data_Grouping.build_units(sender, input_data.annotation, UNIT_WINDOW, SKIP_FRONT)
print "created units:", len(units), "(" + str(len(units) * units[0].length) + "s)"
parts = Data_Grouping.separation(units)
part = parts[0]
part.windows = Data_Grouping.windowing(part, DATA_POINT_WINDOW, OVERLAPPING)
part.features = Features.calculate_features(part)
# ## XXX
# for x in units:
# print x.show()
## XXX
# for x in part.features:
# if ( not x.invalid ):
# print "|||", x
print "new features:", len(part.features)
## plot into file
prepare_dir(input_data.group.plot_base_dir)
filename = input_data.group.plot_base_dir + "/" + os.path.splitext(os.path.basename(input_data.infile))[0] + ".pdf"
## XXX do pickles in the plot dir, too
if ( PICKLE_FEATURES ):
pick_path = input_data.group.plot_base_dir + "/" + os.path.splitext(os.path.basename(input_data.infile))[0] + "_features.pickle"
pickle_output = open(pick_path, 'wb')
pickle.dump(part, pickle_output, pickle.HIGHEST_PROTOCOL)
pickle_output.close()
## xlim = [units[0].start, 200]
# xlim = [20, 200]
#.........这里部分代码省略.........