def update(self, refresh=False): if refresh: if self._metric['name'][0][0] != "*": value = InternalMetrics().metrics # Navigate status json to desired metric for i in range(0, len(self._metric['name'])): if self._metric['name'][i] in value: value = value[self._metric['name'][i]] else: # Interrupt update if desired metric is not found return else: # Get computed metric value = InternalMetrics().metrics[self._metric['name'][0]] value = value[-1] is_true = (value == self._metric['target_value'] if self._metric['operator'] == '=' else (value > self._metric['target_value'] if self._metric['operator'] == '>' else (value < self._metric['target_value'] if self._metric['operator'] == '<' else False))) if is_true != self._is_true: if is_true: self._label.setText(self._evaluation['true']['text']) self._label.setStyleSheet( 'QLabel{' + self._evaluation['true']['stylesheet'] + '}') else: self._label.setText(self._evaluation['false']['text']) self._label.setStyleSheet( 'QLabel{' + self._evaluation['false']['stylesheet'] + '}') self._label.adjustSize() self._is_true = is_true
def update(self, refresh = False): if refresh: if self._metric[0][0] != "*": value = InternalMetrics().metrics # Navigate status json to desired metric for i in range(0, len(self._metric)): if self._metric[i] in value: value = value[self._metric[i]] else: # Interrupt update if desired metric is not found return else: # Get computed metric value = InternalMetrics().metrics[self._metric[0]] # Update Graph if self._first: value = self._elem.setHistory(value) self._first = False else: value = self._elem.setValue(value[-1]) self._elem.update() # Update Label self._elem_label.updateDirect(value) if self._layout == 0: scalar = (self._geometry[3] - self._elem_label.height()) / (self._elem._bounds_range) self._elem_label.move( self._elem_label.x(), (self._geometry[1] + self._geometry[3] - self._half_elem_label_height) - (value - self._elem._bounds[0]) * scalar ) # Update Max and Min Labels self._elem_max_label.updateDirect(self._elem._bounds[1]) self._elem_min_label.updateDirect(self._elem._bounds[0])
def update(self, refresh = False): if refresh: if self._metric[0][0] != "*": value = InternalMetrics().metrics # Navigate status json to desired metric for i in range(0, len(self._metric)): if self._metric[i] in value: value = value[self._metric[i]] else: # Interrupt update if desired metric is not found return else: # Get computed metric value = InternalMetrics().metrics[self._metric[0]] value = value[-1] self._elem_t.transition(value, self._transition_frames) if not self._elem_t.isDone(): self._elem.setValue(self._elem_t.update()) self._elem.update()
def update(self, refresh=False): if refresh: if self._metric['name'][0][0] != "*": value = InternalMetrics().metrics # Navigate status json to desired metric for i in range(0, len(self._metric['name'])): if self._metric['name'][i] in value: value = value[self._metric['name'][i]] else: # Interrupt update if desired metric is not found return else: # Get computed metric value = InternalMetrics().metrics[self._metric['name'][0]] value = value[-1] # Enforce value to be within bounds if 'bounds' in self._metric: value = min(max(value, self._metric['bounds'][0]), self._metric['bounds'][1]) self.updateDirect(value)
def prepare(path: str, ui_file: str = None, preloadedSettings=None): # Open settings and ui files if preloadedSettings == None: file = open(path + '/settings.json', 'r') settings = json.loads(file.read()) file.close() else: settings = preloadedSettings if ui_file == None: ui_file = settings['ui'][ 'initial_page'] if 'initial_page' in settings[ 'ui'] else 'ui.json' file = open(path + '/' + ui_file, 'r') ui = json.loads(file.read()) file.close() # Fill in variables in ui file ## UI section pos = ui['ui'][0]['geometry'][0:2].copy() new_pos = pos.copy() for entry in ui['ui']: # Positioning if 'geometry' in entry: update_pos = [True, True] for i in range(2): if isinstance(entry['geometry'][i], str): if entry['geometry'][i][0] != "d": new_pos[i] = pos[i] + int(entry['geometry'][i]) else: update_pos[i] = False if len(entry['geometry'][i]) > 1: new_pos[i] = pos[i] + int( entry['geometry'][i][1:]) else: new_pos[i] = pos[i] else: new_pos[i] = entry['geometry'][i] entry['geometry'][0:2] = new_pos.copy() if update_pos[0]: pos[0] = new_pos[0] if update_pos[1]: pos[1] = new_pos[1] # Fill in variables if entry['type'] == 'StaticLabel': # Check if label message is tied to variable in settings entry['text'] = ConfigurationParser._concatTextWithVariables( entry['text'], settings['ui']['variables']) elif (entry['type'] == 'DynamicLabel' or entry['type'] == 'ProgressBar' or entry['type'] == 'RoundProgressBar' or entry['type'] == 'CornerProgressBar'): # Ensure element has bounds entry (This is optional for DynamicLabel) if 'bounds' in entry['metric']: for i in range(2): entry['metric']['bounds'][ i] = ConfigurationParser._fillFieldFormula( entry['metric']['bounds'][i], settings['ui']['variables']) elif entry['type'] == 'Graph': if 'bounds' in entry['metric']: for i in range(2): # Check if bound is a list (if it is it means we have a dynamic bound with a limit) if isinstance(entry['metric']['bounds'][i], list): entry['metric']['bounds'][i][ 1] = ConfigurationParser._fillFieldFormula( entry['metric']['bounds'][i][1], settings['ui']['variables']) # Check if bound is a formula elif isinstance(entry['metric']['bounds'][i], str): # Ensure we are looking at a formula and not dynamic bound without a limit if entry['metric']['bounds'][i] != 'dynamic': entry['metric']['bounds'][ i] = ConfigurationParser._fillFieldFormula( entry['metric']['bounds'][i], settings['ui']['variables']) ## Unit converters section if 'unit_converters' in ui: for entry in ui['unit_converters']: entry = ui['unit_converters'][entry] entry['divisor'] = ConfigurationParser._fillFieldFormula( entry['divisor'], settings['ui']['variables']) if isinstance(entry['unit'], list): for index in range(len(entry['unit'])): entry['unit'][ index] = ConfigurationParser._concatTextWithVariables( entry['unit'][index], settings['ui']['variables']) else: entry[ 'unit'] = ConfigurationParser._concatTextWithVariables( entry['unit'], settings['ui']['variables']) # Initialization if preloadedSettings == None: if 'additional_metrics' in settings['services']['data_provider']: InternalMetrics().setSettings( settings['services']['data_provider'] ['additional_metrics'], settings['services']['data_provider']['log_n_samples']) RyderClient().setup( settings['services']['data_provider']['ip'], settings['services']['data_provider']['port'], settings['services']['data_provider']['password']) if 'hyperion' in settings['services']: Hyperion().setUrl(settings['services']['hyperion']['ip'], settings['services']['hyperion']['port']) Hyperion().getState() Monitor() return settings['ui']['fps'], ui, settings, ui_file
def _newStatus(self, data): self._status = data[1] InternalMetrics().update(self._status)