#
# OtterTune - target_objective.py
#
# Copyright (c) 2017-18, Carnegie Mellon University Database Group
#

from website.types import DBMSType
from ..base.target_objective import BaseTargetObjective, BaseThroughput, LESS_IS_BETTER


class DBTime(BaseTargetObjective):

    def __init__(self):
        super().__init__(name='db_time', pprint='DB Time', unit='seconds', short_unit='s',
                         improvement=LESS_IS_BETTER)

    def compute(self, metrics, observation_time):
        return float(metrics['global.sys_time_model.db time']) / observation_time / 1000.


target_objective_list = tuple((DBMSType.ORACLE, target_obj) for target_obj in [  # pylint: disable=invalid-name
    BaseThroughput(transactions_counter=('global.sysstat.user commits',
                                         'global.sysstat.user rollbacks')),
    DBTime(),
])
