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()
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)
txns_counter = target_obj_instance.transactions_counter

View File

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

View File

@ -197,7 +197,7 @@ class BaseParser:
raise ValueError(
'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)
metric_data[target_objective] = target_objective_instance.compute(
base_metric_data, observation_time)

View File

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

View File

@ -169,7 +169,7 @@ class MyRocksParser(BaseParser):
raise ValueError(
'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)
metric_data[target_objective] = target_objective_instance.compute(
base_metric_data, observation_time)

View File

@ -3,13 +3,10 @@
#
# Copyright (c) 2017-18, Carnegie Mellon University Database Group
#
'''
Created on Jul 25, 2017
@author: dvanaken
'''
from django import forms
from .db import target_objectives
from .models import Session, Project, Hardware, SessionKnob
from .types import StorageType
@ -73,12 +70,19 @@ class SessionForm(forms.ModelForm):
super().__init__(*args, **kwargs)
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['cpu'].initial = 4
self.fields['memory'].initial = 16
self.fields['storage'].initial = 32
self.fields['storage_type'].initial = StorageType.SSD
self.initial.update(cpu=4, memory=16, storage=32,
storage_type=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):
valid = super().is_valid()
@ -91,6 +95,19 @@ class SessionForm(forms.ModelForm):
if user_sessions.exists():
valid = False
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
def save(self, commit=True):
@ -121,8 +138,7 @@ class SessionForm(forms.ModelForm):
widgets = {
'name': forms.TextInput(attrs={'required': True}),
'description': forms.Textarea(attrs={'maxlength': 500,
'rows': 5}),
'description': forms.Textarea(attrs={'maxlength': 500, 'rows': 5}),
}
labels = {
'dbms': 'DBMS',

View File

@ -159,11 +159,11 @@ class Session(BaseModel):
verbose_name='session type')
target_objective = models.CharField(
max_length=64, default=target_objectives.get_default_target_objective())
max_length=64, default=target_objectives.default())
def clean(self):
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):
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(
type=DBMSType.POSTGRES, version='9.6'),
'algorithm': AlgorithmType.GPR,
'target_objective': target_objectives.get_default_target_objective(),
'target_objective': target_objectives.default(),
})
form = SessionForm(**form_kwargs)
context = {