本文整理汇总了Python中analyzer.Analyzer.generate_report方法的典型用法代码示例。如果您正苦于以下问题:Python Analyzer.generate_report方法的具体用法?Python Analyzer.generate_report怎么用?Python Analyzer.generate_report使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类analyzer.Analyzer
的用法示例。
在下文中一共展示了Analyzer.generate_report方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_analyze
# 需要导入模块: from analyzer import Analyzer [as 别名]
# 或者: from analyzer.Analyzer import generate_report [as 别名]
def do_analyze(self, args_str):
parser = self._get_arg_parser()
parser.add_argument("-o", "--output",
metavar="FILE", dest="output",
help="specific output dir or file"),
parser.add_argument("-t", "--threads",
type=int, dest="threads", default=multiprocessing.cpu_count(),
help="threads number to work [default equal cpu count]")
parser.add_argument("--plot-all",
action="store_true", dest="plot_all", default=False,
help="plot all stocks, not only good ones")
parser.add_argument('codes', nargs='*')
options = self._parse_arg(parser, args_str)
if not options:
return
schemes = []
user_options = []
for k, v in self.config['analyzing']['schemes'].items():
schemes.append(v)
user_options.append(v['desc'])
select = util.select(user_options, 'please select a scheme used for analyzing')
config = schemes[select]['config']
logging.info('analyzer config:\n%s' % yaml.dump(config))
if not self.loaded:
self.do_load()
stocks = {}
if len(options.codes):
for code in options.codes:
if code in self.dm.stocks:
stocks[code] = self.dm.stocks[code]
else:
logging.error('unknown stock %s', code)
else:
stocks = self.dm.stocks
if not len(stocks):
logging.error('no stocks found in local database, please run \'load\' command first')
return
analyzer = Analyzer(stocks, self.dm.indexes, config)
logging.info('all %d available stocks will be analyzed' % len(analyzer.stocks))
logging.info('-----------invoking data analyzer module-------------')
analyzer.analyze(threads=options.threads)
logging.info('-------------------analyze done----------------------')
list = []
for result in analyzer.good_stocks:
stock = result.stock
list.append({'code': stock.code, 'name': stock.name, 'price': stock.price,
'pe': stock.pe, 'nmc': stock.nmc / 10000, 'mktcap': stock.mktcap / 10000,
'toavgd5': '%.2f%%' % stock.get_turnover_avg(5),
'toavgd30': '%.2f%%' % stock.get_turnover_avg(30),
'area': stock.area, 'industry': stock.industry
})
df = DataFrame(list)
if df.empty:
logging.info('no good stocks found')
return
logging.info('list of good %d stocks%s:' % (len(analyzer.good_stocks),
options.output and ' and save plots to %s' % options.output or ''))
print(df.to_string(
columns=('code', 'name', 'price', 'pe', 'nmc', 'mktcap', 'toavgd5', 'toavgd30', 'area', 'industry')))
logging.info('global market status: %s' % analyzer.global_status)
if options.output:
logging.info('generating html report...')
os.makedirs(options.output, exist_ok=True)
analyzer.generate_report(options.output, only_plot_good=not options.plot_all)
logging.info('done')