Better handling of settings for charts
Change-Id: I6cbe04abb1d498a5222510aeb57038e4814a3e2d
This commit is contained in:
parent
ab767a61b0
commit
34788178c7
@ -137,11 +137,8 @@ class PerformanceView(base.TemplateView):
|
|||||||
node_uuid = kwargs.get('node_uuid')
|
node_uuid = kwargs.get('node_uuid')
|
||||||
node = api.node.Node.get(request, node_uuid)
|
node = api.node.Node.get(request, node_uuid)
|
||||||
|
|
||||||
average = used = 0
|
|
||||||
tooltip_average = ''
|
|
||||||
unit = ''
|
unit = ''
|
||||||
series = []
|
series = []
|
||||||
start_datetime = end_datetime = ''
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ip_addr = node.driver_info['ip_address']
|
ip_addr = node.driver_info['ip_address']
|
||||||
@ -212,26 +209,12 @@ class PerformanceView(base.TemplateView):
|
|||||||
util['unit'] = '%'
|
util['unit'] = '%'
|
||||||
series = [util]
|
series = [util]
|
||||||
|
|
||||||
if series and barchart:
|
|
||||||
average, used, tooltip_average = (
|
|
||||||
metering_utils.get_barchart_stats(series, unit))
|
|
||||||
|
|
||||||
if date_from:
|
|
||||||
start_datetime = date_from.strftime("%Y-%m-%dT%H:%M:%S")
|
|
||||||
if date_to:
|
|
||||||
end_datetime = date_to.strftime("%Y-%m-%dT%H:%M:%S")
|
|
||||||
|
|
||||||
json_output = metering_utils.create_json_output(
|
json_output = metering_utils.create_json_output(
|
||||||
series,
|
series,
|
||||||
start_datetime,
|
barchart,
|
||||||
end_datetime)
|
unit,
|
||||||
|
date_from,
|
||||||
if series and barchart:
|
date_to)
|
||||||
json_output = metering_utils.add_barchart_settings(
|
|
||||||
json_output,
|
|
||||||
average,
|
|
||||||
used,
|
|
||||||
tooltip_average)
|
|
||||||
|
|
||||||
return http.HttpResponse(json.dumps(json_output),
|
return http.HttpResponse(json.dumps(json_output),
|
||||||
mimetype='application/json')
|
mimetype='application/json')
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
import copy
|
||||||
|
|
||||||
from datetime import datetime # noqa
|
from datetime import datetime # noqa
|
||||||
from datetime import timedelta # noqa
|
from datetime import timedelta # noqa
|
||||||
@ -24,6 +25,39 @@ from horizon import exceptions
|
|||||||
from openstack_dashboard.api import ceilometer
|
from openstack_dashboard.api import ceilometer
|
||||||
from openstack_dashboard.dashboards.admin.metering import views as metering
|
from openstack_dashboard.dashboards.admin.metering import views as metering
|
||||||
|
|
||||||
|
SETTINGS = {
|
||||||
|
'settings': {
|
||||||
|
'renderer': 'StaticAxes',
|
||||||
|
'xMin': None,
|
||||||
|
'xMax': None,
|
||||||
|
'higlight_last_point': True,
|
||||||
|
'auto_size': False,
|
||||||
|
'auto_resize': False,
|
||||||
|
'axes_x': False,
|
||||||
|
'axes_y': True,
|
||||||
|
'axes_y_label': False,
|
||||||
|
'bar_chart_settings': {
|
||||||
|
'orientation': 'vertical',
|
||||||
|
'used_label_placement': 'left',
|
||||||
|
'width': 30,
|
||||||
|
'color_scale_domain': [0, 80, 80, 100],
|
||||||
|
'color_scale_range': [
|
||||||
|
'#0000FF',
|
||||||
|
'#0000FF',
|
||||||
|
'#FF0000',
|
||||||
|
'#FF0000'
|
||||||
|
],
|
||||||
|
'average_color_scale_domain': [0, 100],
|
||||||
|
'average_color_scale_range': ['#0000FF', '#0000FF']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'stats': {
|
||||||
|
'average': None,
|
||||||
|
'used': None,
|
||||||
|
'tooltip_average': None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#TODO(lsmola) this should probably live in Horizon common
|
#TODO(lsmola) this should probably live in Horizon common
|
||||||
def query_data(request,
|
def query_data(request,
|
||||||
@ -159,42 +193,28 @@ def get_barchart_stats(series, unit):
|
|||||||
return average, used, tooltip_average
|
return average, used, tooltip_average
|
||||||
|
|
||||||
|
|
||||||
def create_json_output(series, start_datetime, end_datetime):
|
def create_json_output(series, barchart, unit, date_from, date_to):
|
||||||
return {
|
start_datetime = end_datetime = ''
|
||||||
'series': series,
|
if date_from:
|
||||||
'settings': {
|
start_datetime = date_from.strftime("%Y-%m-%dT%H:%M:%S")
|
||||||
'renderer': 'StaticAxes',
|
if date_to:
|
||||||
'yMin': 0,
|
end_datetime = date_to.strftime("%Y-%m-%dT%H:%M:%S")
|
||||||
'xMin': start_datetime,
|
|
||||||
'xMax': end_datetime,
|
|
||||||
'higlight_last_point': True,
|
|
||||||
'auto_size': False,
|
|
||||||
'auto_resize': False,
|
|
||||||
'axes_x': False,
|
|
||||||
'axes_y': True,
|
|
||||||
'axes_y_label': False,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
|
settings = copy.deepcopy(SETTINGS)
|
||||||
|
settings['settings']['xMin'] = start_datetime
|
||||||
|
settings['settings']['xMax'] = end_datetime
|
||||||
|
|
||||||
def add_barchart_settings(ret, average, used, tooltip_average):
|
if series and barchart:
|
||||||
ret['settings']['bar_chart_settings'] = {
|
average, used, tooltip_average = get_barchart_stats(series, unit)
|
||||||
'orientation': 'vertical',
|
settings['settings']['yMin'] = 0
|
||||||
'used_label_placement': 'left',
|
settings['settings']['yMax'] = 100
|
||||||
'width': 30,
|
settings['stats']['average'] = average
|
||||||
'color_scale_domain': [0, 80, 80, 100],
|
settings['stats']['used'] = used
|
||||||
'color_scale_range': [
|
settings['stats']['tooltip_average'] = tooltip_average
|
||||||
'#0000FF',
|
else:
|
||||||
'#0000FF',
|
del settings['settings']['bar_chart_settings']
|
||||||
'#FF0000',
|
del settings['stats']
|
||||||
'#FF0000'
|
|
||||||
],
|
json_output = {'series': series}
|
||||||
'average_color_scale_domain': [0, 100],
|
json_output = dict(json_output.items() + settings.items())
|
||||||
'average_color_scale_range': ['#0000FF', '#0000FF']
|
return json_output
|
||||||
}
|
|
||||||
ret['stats'] = {
|
|
||||||
'average': average,
|
|
||||||
'used': used,
|
|
||||||
'tooltip_average': tooltip_average,
|
|
||||||
}
|
|
||||||
return ret
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user