Added valid target objectives to the session create/edit form

This commit is contained in:
Dana Van Aken 2019-10-09 00:15:31 -04:00
parent 2b9f199c6f
commit dcb3152ec5
8 changed files with 51 additions and 20 deletions

View File

@ -254,7 +254,7 @@ class PostgresParserTests(BaseParserTests, TestCase):
super().test_convert_dbms_metrics() super().test_convert_dbms_metrics()
target_obj = target_objectives.THROUGHPUT target_obj = target_objectives.THROUGHPUT
target_obj_instance = target_objectives.get_target_objective_instance( target_obj_instance = target_objectives.get_instance(
self.test_dbms.dbms_id, target_obj) self.test_dbms.dbms_id, target_obj)
txns_counter = target_obj_instance.transactions_counter txns_counter = target_obj_instance.transactions_counter

View File

@ -143,7 +143,7 @@ class SessionViewsTests(TestCase):
'name': 'test_create_basic_session', 'name': 'test_create_basic_session',
'description': 'testing create basic session...', 'description': 'testing create basic session...',
'tuning_session': 'no_tuning_session', 'tuning_session': 'no_tuning_session',
'target_objective': target_objectives.get_default_target_objective(), 'target_objective': target_objectives.default(),
'algorithm': 1, 'algorithm': 1,
'cpu': '2', 'cpu': '2',
'memory': '16', 'memory': '16',

View File

@ -197,7 +197,7 @@ class BaseParser:
raise ValueError( raise ValueError(
'Unknown metric type for {}: {}'.format(name, metadata.metric_type)) 'Unknown metric type for {}: {}'.format(name, metadata.metric_type))
target_objective_instance = target_objectives.get_target_objective_instance( target_objective_instance = target_objectives.get_instance(
self.dbms_id, target_objective) self.dbms_id, target_objective)
metric_data[target_objective] = target_objective_instance.compute( metric_data[target_objective] = target_objective_instance.compute(
base_metric_data, observation_time) base_metric_data, observation_time)

View File

@ -4,6 +4,7 @@
# Copyright (c) 2017-18, Carnegie Mellon University Database Group # Copyright (c) 2017-18, Carnegie Mellon University Database Group
# #
import copy
import logging import logging
from collections import OrderedDict from collections import OrderedDict
@ -44,6 +45,10 @@ class BaseTargetObjective(BaseMetric):
super().__init__(name=name, pprint=pprint, unit=unit, short_unit=short_unit, super().__init__(name=name, pprint=pprint, unit=unit, short_unit=short_unit,
improvement=improvement, scale=scale) improvement=improvement, scale=scale)
@property
def label(self):
return '{} ({})'.format(self.pprint, self.short_unit)
def compute(self, metrics, observation_time): def compute(self, metrics, observation_time):
raise NotImplementedError() raise NotImplementedError()
@ -106,16 +111,26 @@ class TargetObjectives:
metadata.insert(0, (target_objective, target_objective_instance)) metadata.insert(0, (target_objective, target_objective_instance))
return OrderedDict(metadata) return OrderedDict(metadata)
def get_default_target_objective(self): def default(self):
return self._default_target_objective return self._default_target_objective
def get_target_objective_instance(self, dbms_id, target_objective): def get_instance(self, dbms_id, target_objective):
if not self.registered(): if not self.registered():
self.register() self.register()
dbms_id = int(dbms_id) dbms_id = int(dbms_id)
instance = self._registry[dbms_id][target_objective] instance = self._registry[dbms_id][target_objective]
return instance return instance
def get_all(self, dbms_id=None):
if not self.registered():
self.register()
if dbms_id is None:
res = copy.deepcopy(self._registry)
else:
dbms_id = int(dbms_id)
res = copy.deepcopy(self._registry[dbms_id])
return res
def __repr__(self): def __repr__(self):
s = 'TargetObjectives = (\n' s = 'TargetObjectives = (\n'
for dbms_id, entry in self._registry.items(): # pylint: disable=not-an-iterable for dbms_id, entry in self._registry.items(): # pylint: disable=not-an-iterable

View File

@ -169,7 +169,7 @@ class MyRocksParser(BaseParser):
raise ValueError( raise ValueError(
'Unknown metric type for {}: {}'.format(name, metadata.metric_type)) 'Unknown metric type for {}: {}'.format(name, metadata.metric_type))
target_objective_instance = target_objectives.get_target_objective_instance( target_objective_instance = target_objectives.get_instance(
self.dbms_id, target_objective) self.dbms_id, target_objective)
metric_data[target_objective] = target_objective_instance.compute( metric_data[target_objective] = target_objective_instance.compute(
base_metric_data, observation_time) base_metric_data, observation_time)

View File

@ -3,13 +3,10 @@
# #
# Copyright (c) 2017-18, Carnegie Mellon University Database Group # Copyright (c) 2017-18, Carnegie Mellon University Database Group
# #
'''
Created on Jul 25, 2017
@author: dvanaken
'''
from django import forms from django import forms
from .db import target_objectives
from .models import Session, Project, Hardware, SessionKnob from .models import Session, Project, Hardware, SessionKnob
from .types import StorageType from .types import StorageType
@ -73,12 +70,19 @@ class SessionForm(forms.ModelForm):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.fields['description'].required = False self.fields['description'].required = False
self.fields['target_objective'].required = False self.fields['target_objective'].required = True
self.fields['tuning_session'].required = True self.fields['tuning_session'].required = True
self.fields['cpu'].initial = 4 self.initial.update(cpu=4, memory=16, storage=32,
self.fields['memory'].initial = 16 storage_type=StorageType.SSD)
self.fields['storage'].initial = 32
self.fields['storage_type'].initial = StorageType.SSD target_objs = target_objectives.get_all()
choices = set()
for entry in target_objs.values():
for name, obj in entry.items():
choices.add((name, obj.label))
target_obj_choices = sorted(choices)
self.fields['target_objective'].widget = forms.Select(
choices=target_obj_choices)
def is_valid(self): def is_valid(self):
valid = super().is_valid() valid = super().is_valid()
@ -91,6 +95,19 @@ class SessionForm(forms.ModelForm):
if user_sessions.exists(): if user_sessions.exists():
valid = False valid = False
self._errors['name'] = ["Session '{}' already exists.".format(new_name)] self._errors['name'] = ["Session '{}' already exists.".format(new_name)]
if valid:
dbms = self.cleaned_data['dbms']
assert dbms is not None
target_obj_name = self.cleaned_data['target_objective']
try:
target_objectives.get_instance(dbms.pk, target_obj_name)
except KeyError:
self._errors['target_objective'] = \
["Invalid target objective '{}' for dbms {}.".format(
target_obj_name, dbms.full_name)]
valid = False
return valid return valid
def save(self, commit=True): def save(self, commit=True):
@ -121,8 +138,7 @@ class SessionForm(forms.ModelForm):
widgets = { widgets = {
'name': forms.TextInput(attrs={'required': True}), 'name': forms.TextInput(attrs={'required': True}),
'description': forms.Textarea(attrs={'maxlength': 500, 'description': forms.Textarea(attrs={'maxlength': 500, 'rows': 5}),
'rows': 5}),
} }
labels = { labels = {
'dbms': 'DBMS', 'dbms': 'DBMS',

View File

@ -159,11 +159,11 @@ class Session(BaseModel):
verbose_name='session type') verbose_name='session type')
target_objective = models.CharField( target_objective = models.CharField(
max_length=64, default=target_objectives.get_default_target_objective()) max_length=64, default=target_objectives.default())
def clean(self): def clean(self):
if self.target_objective is None: if self.target_objective is None:
self.target_objective = target_objectives.get_default_target_objective() self.target_objective = target_objectives.default()
def delete(self, using=DEFAULT_DB_ALIAS, keep_parents=False): def delete(self, using=DEFAULT_DB_ALIAS, keep_parents=False):
SessionKnob.objects.get(session=self).delete() SessionKnob.objects.get(session=self).delete()

View File

@ -330,7 +330,7 @@ def create_or_edit_session(request, project_id, session_id=''):
'dbms': DBMSCatalog.objects.get( 'dbms': DBMSCatalog.objects.get(
type=DBMSType.POSTGRES, version='9.6'), type=DBMSType.POSTGRES, version='9.6'),
'algorithm': AlgorithmType.GPR, 'algorithm': AlgorithmType.GPR,
'target_objective': target_objectives.get_default_target_objective(), 'target_objective': target_objectives.default(),
}) })
form = SessionForm(**form_kwargs) form = SessionForm(**form_kwargs)
context = { context = {