本文整理汇总了Python中lib.cuckoo.core.database.Database.stats_sample方法的典型用法代码示例。如果您正苦于以下问题:Python Database.stats_sample方法的具体用法?Python Database.stats_sample怎么用?Python Database.stats_sample使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.cuckoo.core.database.Database
的用法示例。
在下文中一共展示了Database.stats_sample方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import stats_sample [as 别名]
def index(request):
db = Database()
report = dict(
total_samples=db.count_samples(),
total_tasks=db.count_tasks(),
states_count={},
estimate_hour=None,
estimate_day=None,
total_urls=len(db.list_tasks(category="url")),
total_files=len(db.list_tasks(category="file")),
stats_files=db.stats_sample(),
)
states = (
TASK_PENDING,
TASK_RUNNING,
TASK_COMPLETED,
TASK_RECOVERED,
TASK_REPORTED,
TASK_FAILED_ANALYSIS,
TASK_FAILED_PROCESSING,
TASK_FAILED_REPORTING
)
for state in states:
report["states_count"][state] = db.count_tasks(state)
offset = None
# For the following stats we're only interested in completed tasks.
tasks = db.list_tasks(offset=offset, status=TASK_COMPLETED)
tasks += db.list_tasks(offset=offset, status=TASK_REPORTED)
if tasks:
# Get the time when the first task started.
started = min(timestamp(task.started_on) for task in tasks)
# Get the time when the last task completed.
completed = max(timestamp(task.completed_on) for task in tasks)
# Get the amount of tasks that actually completed.
finished = len(tasks)
hourly = 60 * 60 * finished / (completed - started)
report["estimate_hour"] = int(hourly)
report["estimate_day"] = int(24 * hourly)
return render_to_response("dashboard/index.html",
{"report" : report},
context_instance=RequestContext(request))