def clear_table(self, segment_id): db_name = "report_data_segment_%s" % segment_id segment_db = DBManager().get_db_query(db_name) segment_db.query("""SHOW TABLES""") for table in segment_db.record: for val in table: if table[val] == 'segment_value': continue segment_db.query("""DROP TABLE IF EXISTS `%s`""" % table[val])
def __init__(self, element_id, element, formatter, segment_value): self._id = element_id self._element = element self._formatter = formatter self._segment_value = segment_value self.clear_data = [] self._db = DBManager.get_query()
def __init__(self, id, logger): self._id = id self._db = DBManager.get_query() self._data = self._get_element() config = ConfigReader() self._path = config.report_root self._logger = logger self._jfile = JFile(self._path, self._id, None)
def report_charts(self, element_id, segment_value_id, meas_time, data_set_instance_id, data, jfile, chart_id): self._db = DBManager.get_query() if chart_id: self._db.Query("""SELECT report_data_set_chart_id FROM report_data_set_chart WHERE element_id=%s AND report_data_set_chart_id = %s""", (element_id, chart_id)) else: self._db.Query("""SELECT report_data_set_chart_id FROM report_data_set_chart WHERE element_id=%s AND enabled_ind='Y'""", (element_id, )) for el in self._db.record: self.report_chart(el['report_data_set_chart_id'], element_id, segment_value_id, meas_time, data_set_instance_id, data, jfile, 'large')
def __init__(self, metric_id, interval, data, jfile, type, formatter): self.metric_id = metric_id self.interval = interval self.data = copy.deepcopy(data) self.metric_type = 'multi' self.jfile = jfile self._db = DBManager.get_query() self.chart_display_mode = '' self.type = type self.settings = self._get_chart_settings() self.formatter = formatter
def __init__(self, id, logger): self._id = id config = ConfigReader() self._db = DBManager.get_query() self._logger = logger self._data = self._get_element() if self._data['type'] == 'metric': self._path = config.metric_root else: self._path = config.multimetric_root self._jfile = JMetricFile(self._path, self._id)
def __init__(self, report_id, logger): self._id = report_id self._db = DBManager.get_query() self._data = self._get_element() self._logger = logger self._db_name = "report_data_segment_%s" % self._data['segment_id'] self._data_db = DBManager().get_db_query(self._db_name) self._structure_is_validated = False self._conf = ConfigReader() self._path = self._conf.report_root self._jfile = JFile(self._path, report_id, self._data)
def __init__(self, chart_id, element_id, data_set_instance_id, data): self._db = DBManager.get_query() self.type = 'preview_report' self.include_title = True self.legend = True """ Check if axis should be included """ self._db.Query(""" SELECT chart_layout.include_x_axis_label_ind FROM report_data_set_chart LEFT JOIN chart_layout ON chart_layout.layout_id = report_data_set_chart.layout_id WHERE report_data_set_chart.report_data_set_chart_id=%s""",(chart_id)) if self._db.record[0]['include_x_axis_label_ind'] == 'Y': self.include_axis = True else: self.include_axis = False super(PreviewReport, self).__init__(chart_id, element_id, data_set_instance_id, data)
def report_chart(self, chart_id, element_id, segment_value_id, meas_time, data_set_instance_id, data, jfile, type): from reportChart import ReportChart self._db = DBManager.get_query() self._db.Query("""SELECT report_data_set_chart_id, bars_or_lines_created_for, report_data_set_pivot_id, name FROM report_data_set_chart WHERE element_id=%s AND report_data_set_chart_id = %s""", (element_id, chart_id)) chart = self._db.record[0] if chart['report_data_set_pivot_id']: index = chart['report_data_set_pivot_id'] else: index = 0 #if not data.has_key(index): if index not in data: raise Exception("There is no source data for chart %s (%s)" % (chart['name'], chart_id)) data_chart = self._strip_total(data, chart['bars_or_lines_created_for'], index) _report_chart = ReportChart(chart_id, element_id, segment_value_id, meas_time, data_set_instance_id, data_chart, jfile, type) _report_chart.generateChart()
def __init__(self, def_date_format_id): self._def_date_display_mask_id = def_date_format_id self._db = DBManager.get_query() if not FieldFormatter._inited: FieldFormatter._inited = True #get all masks self._db.Query("""SELECT * FROM display_mask""") for format in self._db.record: if not format['display_precision_digits']: format['display_precision_digits'] = 0 if not format['prefix']: format['prefix'] = '' if not format['suffix']: format['suffix'] = '' if not format['thousands_delimiter']: format['thousands_delimiter'] = '' if not format['decimal_point_delimiter']: format['decimal_point_delimiter'] = '.' if format['mask_type'] == u'date': format['date_format_string'] = format['date_format_string'].encode('ascii') # convert mysql format to python format for k, v in date_format_replacement.iteritems(): format['date_format_string'] = format['date_format_string'].replace(k, v) FieldFormatter._display_formats[format['display_mask_id']] = format # get default int mask id res = self._db.Query("""SELECT display_mask_id FROM display_mask WHERE default_int_mask_ind='Y'""") if res: format = self._db.record[0] self._def_int_display_mask_id = format['display_mask_id'] # get default float mask id res = self._db.Query("""SELECT display_mask_id FROM display_mask WHERE default_float_mask_ind='Y'""") if res: format = self._db.record[0] FieldFormatter._def_float_display_mask_id = format['display_mask_id']
def __init__(self, element_id, segment, data_fetch_method, source_database_connection_id, web_service_credentials_id, plugin_connection_profile_id): self._conf = ConfigReader() self._db = DBManager.get_query() self._element_id = element_id self._segment = segment if segment: self._segment_id = segment['segment_id'] self._data_fetch_method = data_fetch_method #self._source_database_connection_id = source_database_connection_id #self._web_service_credentials_id = web_service_credentials_id #self._plugin_connection_profile_id = plugin_connection_profile_id self._formatter = FieldFormatter(0) self._returned_date_format = None self._current_time_sql_stmt = None if self._data_fetch_method in (u'sql', u'existing reports'): if not source_database_connection_id: raise Exception("No source_database_connection_id specified") self._connection_type = 'source_database_connection_id' self._connection_id = source_database_connection_id res = self._db.Query("""SELECT jdbc_to_mysql_date_format_string, current_time_sql_stmt FROM source_database_connection LEFT JOIN jdbc_driver ON jdbc_driver.jdbc_driver_id = source_database_connection.jdbc_driver_id WHERE `source_database_connection_id`=%s""", (source_database_connection_id, )) if not res: raise Exception("No source database record for source_database_connection_id=%s" % source_database_connection_id) preferences = self._db.record[0] if preferences['jdbc_to_mysql_date_format_string']: self._returned_date_format = preferences['jdbc_to_mysql_date_format_string'] if preferences['current_time_sql_stmt']: self._current_time_sql_stmt = preferences['current_time_sql_stmt'] elif self._data_fetch_method == u'web service': if not web_service_credentials_id: raise Exception("No web_service_credentials_id specified") self._connection_type = 'web_service_credentials_id' self._connection_id = web_service_credentials_id res = self._db.Query("""SELECT web_service_to_mysql_date_format_string, mysql_to_web_service_date_format_string FROM web_service_credentials WHERE `web_service_credentials_id`=%s""", (web_service_credentials_id, )) if not res: raise Exception("No web service credentials record for web_service_credentials_id=%s" % web_service_credentials_id) preferences = self._db.record[0] if preferences['web_service_to_mysql_date_format_string']: self._returned_date_format = preferences['web_service_to_mysql_date_format_string'] if preferences['mysql_to_web_service_date_format_string']: self._formatter.set_custom_date_format_rule(preferences['mysql_to_web_service_date_format_string']) elif self._data_fetch_method == u'plugin': if not plugin_connection_profile_id: raise Exception("No plugin_connection_profile_id specified") self._connection_type = 'plugin_connection_profile_id' self._connection_id = plugin_connection_profile_id else: raise Exception("No data_fetch_method is specified") self._unformatter = DateUnformat(self._returned_date_format)