Browse Source

ResultsBrowser: ready to merge

aguryev 3 years ago
parent
commit
31e4fd9c22
6 changed files with 12 additions and 850 deletions
  1. 10 12
      README.md
  2. 2 610
      baangt/base/ResultsBrowser.py
  3. 0 0
      db_update.py
  4. 0 17
      driver.py
  5. 0 47
      query_fields.py
  6. 0 164
      test_queries.py

+ 10 - 12
README.md

@@ -1,14 +1,3 @@
-UPDATE
-------
-#### 24 Aug 2020  
-The `ResultsDB` structure was updatetd to support `ResultsBrowser` module:
-* field `number` was inrouduced to tables `TestCaseSequences` and `TestCases`
-
-To update your current DB, run
-```bash
-python db_add_number.py
-```
-
 # Welcome
 Please find the full documentation on [ReadTheDocs](https://baangt.readthedocs.io)
 
@@ -27,4 +16,13 @@ Please find the full documentation on [ReadTheDocs](https://baangt.readthedocs.i
 * Telegram Channel: [https://t.me/baangt](https://t.me/baangt)
 * Official repository for download: [https://github.com/Athos1972/baangt](https://github.com/Athos1972/baangt)
 * Nightly builds: [https://gogs.earthsquad.global/Athos/baangt](https://gogs.earthsquad.global/Athos/baangt) 
-* Binary repositories: [https://github.com/Athos1972/baangt-executables](https://github.com/Athos1972/baangt-executables)
+* Binary repositories: [https://github.com/Athos1972/baangt-executables](https://github.com/Athos1972/baangt-executables)
+
+# UPDATE: 24 Aug 2020  
+The `ResultsDB` structure was updatetd to support `ResultsBrowser` module:
+* field `number` was inrouduced to tables `TestCaseSequences` and `TestCases`
+
+To update an older DB, run
+```bash
+python db_update.py
+```

+ 2 - 610
baangt/base/ResultsBrowser.py

@@ -173,7 +173,6 @@ class ResultsBrowser:
         names = self.db.query(TestrunLog.testrunName).group_by(TestrunLog.testrunName).order_by(TestrunLog.testrunName).all()
         return [x[0] for x in names]
 
-
     def stage_list(self):
         stages = self.db.query(GlobalAttribute.value).filter_by(name=GC.EXECUTION_STAGE)\
             .group_by(GlobalAttribute.value).order_by(GlobalAttribute.value).all()
@@ -263,609 +262,6 @@ class ResultsBrowser:
 
         logger.info(f'Number of found records: {self.query_set.length}')
 
-
-    def export_old(self):
-        #
-        # export the query set to xlsx
-        #
-
-        # set labels
-        labelTetsrun = 'TestRun'
-        labelTestCaseSequence = 'Test Case Sequence'
-        labelTestCase = 'Test Cases'
-        labelStage = 'Stage'
-        labelAvgDuration = 'Avg. Duration'
-
-        # initialize workbook
-        path_to_file = self.managedPaths.getOrSetDBExportPath().joinpath(f'TestrunLogs_{"_".join(list(map(str, self.tag.values())))}.xlsx')
-        workbook = Workbook(str(path_to_file))#, {'constant_memory': True})
-        
-        # define cell formats
-        # green background
-        cellFormatGreen = workbook.add_format({'bg_color': 'green'})
-        # red background
-        cellFormatRed = workbook.add_format({'bg_color': 'red'})
-        # yellow background
-        cellFormatYellow = workbook.add_format({'bg_color': 'yellow'})
-        # bold font
-        cellFormatBold = workbook.add_format({'bold': True})
-        # bold and italic font
-        cellFormatBoldItalic = workbook.add_format({'bold': True, 'italic': True})
-
-        # summary tab
-        print('*** Summary Sheet')
-        sheet = workbook.add_worksheet('Summary')
-        sheet.set_column(first_col=0, last_col=0, width=18)
-        # title
-        sheet.write(0, 0, f'{labelTetsrun}s Summary', cellFormatBold)
-        # parameters
-        line = 1
-        for key, value in self.tag.items():
-            line += 1
-            sheet.write(line, 0, key)#, cellFormatBold)
-            sheet.write(line, 1, value)
-
-        # average duration
-        line += 2
-        sheet.write(line, 0, labelAvgDuration, cellFormatBold)
-        sheet.write(line, 1, self.average_duration())
-
-        # testcases
-        line += 2
-        sheet.write(line, 0, f'{labelTestCase}s', cellFormatBold)
-        status_style = {
-            GC.TESTCASESTATUS_SUCCESS: cellFormatGreen,
-            GC.TESTCASESTATUS_ERROR: cellFormatRed,
-            GC.TESTCASESTATUS_WAITING: None,
-        }
-        for tcs_index in range(self.size()):
-            print(f'**** TestCaseSequence-{tcs_index}')
-            # testcase sequence
-            line += 1
-            sheet.write(line, 0, labelTestCaseSequence, cellFormatYellow)
-            sheet.write(line, 1, tcs_index, cellFormatYellow)
-            #line += 1
-            #sheet.write(line, 0, labelAvgDuration)
-            #sheet.write(line, 1, self.average_duration(testcase_sequence=tcs_index)) #-----------> high resource consumption
-            # test cases
-            # header
-            line += 2
-            sheet.write(line, 0, f'{labelTetsrun} Date', cellFormatBoldItalic)
-            sheet.write(line, 1, labelTestCase, cellFormatBoldItalic)
-            line += 1            
-            for i in range(self.size(testcase_sequence=tcs_index)):
-                sheet.write(line, 1 + i, i)
-            stage_col = i + 2
-            sheet.write(line-1, stage_col, labelStage, cellFormatBoldItalic)
-            sheet.write(line-1, stage_col+1, f'{labelTetsrun} ID', cellFormatBoldItalic)
-            # status
-            tr_counter_base = line 
-            for tr in filter(lambda tr: len(tr.testcase_sequences)>tcs_index, self.query_set):
-                print(f'***** TestRun {line-tr_counter_base}: {len(tr.testcase_sequences[tcs_index].testcases)} tcases')
-                line += 1
-                sheet.write(line, 0, tr.startTime.strftime('%Y-%m-%d %H:%M:%S'))
-                #col = 1
-                for col, tc in enumerate(tr.testcase_sequences[tcs_index].testcases, 1):
-                    sheet.write(line, col, tc.status, status_style.get(tc.status))
-                    #sheet.write(line, col, tc.duration, status_style.get(tc.status))
-                    #col += 1
-                #sheet.write(line, col, tr.duration)
-                #sheet.write(line, col+1, tr.testcase_sequences[0].duration)
-                sheet.write(line, stage_col, tr.stage)
-                sheet.write(line, stage_col+1, str(tr))
-
-            line += 1
-            sheet.write(line, 0, labelAvgDuration, cellFormatBoldItalic)
-            for tc_index in range(self.size(testcase_sequence=tcs_index)):
-                sheet.write(line, tc_index+1, self.average_duration(testcase_sequence=tcs_index, testcase=tc_index))
-
-            # empty line separator
-            line += 1
-
-        '''
-        # test case tabs
-        for stage in self.stages:
-            sheet = workbook.add_worksheet(f'{stage}_JSON')
-            # write headers
-            headers = [
-                'Stage',
-                f'{labelTetsrun} ID',
-                f'{labelTestCase} ID',
-                'Attribute',
-                'Value',
-            ]
-            for index, label in enumerate(headers):
-                sheet.write(0, index, label, cellFormatBold)
-            # write data
-            line = 1
-            for tr in self.query_set:
-                # check the stage
-                if tr.stage == stage:
-                    for tcs in tr.testcase_sequences:
-                        for tc in tcs.testcases:
-                            for field in tc.fields:
-                                sheet.write(line, 0, stage)
-                                sheet.write(line, 1, str(tr))
-                                sheet.write(line, 2, str(tc))
-                                sheet.write(line, 3, field.name)
-                                sheet.write(line, 4, field.value)
-                                line += 1
-
-            # autowidth
-            for i in range(len(headers)):
-                ExcelSheetHelperFunctions.set_column_autowidth(sheet, i)
-        '''
-        # output tab
-        print('\n*** Output Sheet')
-        sheet = workbook.add_worksheet('Output')
-        # write headers
-        base_headers = [
-            'Testrun ID',
-            'TestCase ID',
-            'TestCase Number',
-        ]
-
-        base_fields = [
-            GC.EXECUTION_STAGE,
-            GC.TESTCASESTATUS,
-            GC.TIMING_DURATION,
-        ]
-        
-        field_header_dict = {field: index for index, field in enumerate(base_fields, len(base_headers))}
-        field_header_set = set(field_header_dict.keys())
-        field_counter = len(base_headers) + len(field_header_set)
-
-        for index, label in enumerate(base_headers):
-            sheet.write(0, index, label, cellFormatBold)
-        for label, index in field_header_dict.items():
-            sheet.write(0, index, label, cellFormatBold)
-        # write data
-        line = 1
-        for tr in self.query_set:
-            for tcs in tr.testcase_sequences:
-                for tc_index, tc in enumerate(tcs.testcases):
-                    sheet.write(line, 0, str(tr))
-                    sheet.write(line, 1, str(tc))
-                    sheet.write(line, 2, tc_index)
-                    #sheet.write(line, 2, tr.stage)
-                    #sheet.write(line, 3, tc.status)
-                    #sheet.write(line, 4, tc.duration)
-                    #sheet.write(line, 5, json.dumps(tc.fields_as_dict()))
-                    for field in tc.fields:
-                        if not field.name in field_header_set:
-                            sheet.write(0, field_counter, field.name, cellFormatBold)
-                            field_header_set.add(field.name)
-                            field_header_dict[field.name] = field_counter
-                            field_counter += 1
-                        sheet.write(line, field_header_dict[field.name], field.value)
-                    line += 1
-        # autowidth
-        for col in range(6):#len(base_headers)+len(field_header_set)):
-            ExcelSheetHelperFunctions.set_column_autowidth(sheet, col)
-
-
-        workbook.close()
-
-        logger.info(f'Query successfully exported to {path_to_file}')
-
-        return path_to_file
-
-    def export_sep(self):
-        #
-        # exports the query set to xlsx
-        #
-
-        # initialize workbook
-        path_to_file = self.managedPaths.getOrSetDBExportPath().joinpath(f'TestrunLogs_{"_".join(list(map(str, self.tags.values())))}.xlsx')
-        self.workbook = Workbook(str(path_to_file))#, {'constant_memory': True})
-
-        self.make_summary_sheet()
-        self.make_output_sheet()
-
-        self.workbook.close()
-
-        logger.info(f'Query successfully exported to {path_to_file}')
-
-        return path_to_file
-        
-
-    def make_summary_sheet(self):
-        #
-        # makes Summary sheet of XLSX export file 
-        #
-
-        # set labels
-        labels = {
-            'testrun': 'TestRun',
-            'testcase_sequence': 'Test Case Sequence',
-            'testcase': 'Test Case',
-            'stage': 'Stage',
-            'duration': 'Avg. Duration',
-        }
-       
-        # define cell formats
-        cformats = {
-            'bg_red': self.workbook.add_format({'bg_color': 'red'}),
-            'bg_green': self.workbook.add_format({'bg_color': 'green'}),
-            'bg_yellow': self.workbook.add_format({'bg_color': 'yellow'}),
-            'font_bold': self.workbook.add_format({'bold': True}),
-            'font_bold_italic': self.workbook.add_format({'bold': True, 'italic': True}),
-        }
-
-        # map status styles
-        status_style = {
-            GC.TESTCASESTATUS_SUCCESS: cformats.get('bg_green'),
-            GC.TESTCASESTATUS_ERROR: cformats.get('bg_red'),
-            GC.TESTCASESTATUS_WAITING: None,
-        }
-
-        # write data
-        sheet = self.workbook.add_worksheet('Summary')
-        sheet.set_column(first_col=0, last_col=0, width=18)
-        # title
-        time_start = time.time() # -------------------------> time tracker
-        sheet.write(0, 0, f'{labels.get("testrun")}s Summary', cformats.get('font_bold'))
-        # parameters
-        line = 1
-        for key, value in self.tags.items():
-            line += 1
-            sheet.write(line, 0, key, cformats.get('font_bold'))
-            sheet.write(line, 1, value)
-
-        # testruns
-        for tr_name in self.query_set.names():
-            print(f'*** Tetsrun "{tr_name}"')
-            # testrun name
-            line += 2
-            sheet.write(line, 0, labels.get('testrun'), cformats.get('font_bold'))
-            sheet.write(line, 1, tr_name)
-            
-            # average duration
-            line += 1
-            sheet.write(line, 0, labels.get('duration'), cformats.get('font_bold'))
-            sheet.write(line, 1, self.query_set.tr_avg_duration(tr_name))
-
-            # testcase sequences
-            for tcs_index in range(self.query_set.max_size(tr_name)):
-                print(f'**** TestCaseSequence-{tcs_index}')
-                # testcase sequence
-                line += 2
-                sheet.write(line, 0, labels.get('testcase_sequence'), cformats.get('font_bold'))
-                sheet.write(line, 1, tcs_index)
-
-                # test cases
-                # header
-                line += 2
-                sheet.write(line, 0, 'Run Date', cformats.get('font_bold_italic'))
-                sheet.write(line, 1, labels.get('testcase'), cformats.get('font_bold_italic'))
-                line += 1            
-                for tc_index in range(self.query_set.max_size(tr_name, tcs_index=tcs_index)):
-                    sheet.write(line, tc_index+1, tc_index)
-                # store stage column
-                stage_col = tc_index + 2
-                sheet.write(line-1, stage_col, labels.get('stage'), cformats.get('font_bold_italic'))
-                sheet.write(line-1, stage_col+1, f'{labels.get("testcase")} ID', cformats.get('font_bold_italic'))
-            
-                # testcase status
-                tr_counter_base = line 
-                for tr in self.query_set.filter(tr_name, tcs_index):
-                    print(f'***** TestRun {line-tr_counter_base}: {len(tr.testcase_sequences[tcs_index].testcases)} tcases')
-                    line += 1
-                    sheet.write(line, 0, tr.startTime.strftime('%Y-%m-%d %H:%M:%S'))
-                    
-                    #for col, tc in enumerate(tr.testcase_sequences[tcs_index].testcases, 1):
-                    #    sheet.write(line, col, tc.status, status_style.get(tc.status))
-
-                    sheet.write(line, stage_col, tr.stage)
-                    sheet.write(line, stage_col+1, str(tr))
-
-                # avg durations
-                line += 1
-                sheet.write(line, 0, labels.get('duration'), cformats.get('font_bold_italic'))
-                #for tc_index in range(self.query_set.max_size(tr_name, tcs_index=tcs_index)):
-                #    sheet.write(line, tc_index+1, self.query_set.tc_avg_duration(tr_name, (tcs_index, tc_index)))
-
-        print(f'*** EXECUTION TIME: {time.time()-time_start} seconds') # ------------------> time tracker
-
-    def make_output_sheet(self):
-        #
-        # makes output sheet
-        #
-
-        # output tab
-        print('\n*** Output Sheet')
-        sheet = self.workbook.add_worksheet('Output')
-        # format
-        cellFormatBold = self.workbook.add_format({'bold': True})
-        # write headers
-        base_headers = [
-            'Testrun ID',
-            'TestCase ID',
-            'TestCase Number',
-        ]
-
-        base_fields = [
-            GC.EXECUTION_STAGE,
-            GC.TESTCASESTATUS,
-            GC.TIMING_DURATION,
-        ]
-        
-        field_header_dict = {field: index for index, field in enumerate(base_fields, len(base_headers))}
-        field_header_set = set(field_header_dict.keys())
-        field_counter = len(base_headers) + len(field_header_set)
-
-        time_start = time.time() # -------------------------> time tracker
-        for index, label in enumerate(base_headers):
-            sheet.write(0, index, label, cellFormatBold)
-        for label, index in field_header_dict.items():
-            sheet.write(0, index, label, cellFormatBold)
-        # write data
-        line = 1
-        for tr_num, tr in enumerate(self.query_set.all()):
-            print(f'**** TR-{tr_num}')
-            for tcs in tr.testcase_sequences:
-                for tc_index, tc in enumerate(tcs.testcases):
-                    sheet.write(line, 0, str(tr))
-                    sheet.write(line, 1, str(tc))
-                    sheet.write(line, 2, tc_index)
-                    #sheet.write(line, 2, tr.stage)
-                    #sheet.write(line, 3, tc.status)
-                    #sheet.write(line, 4, tc.duration)
-                    #sheet.write(line, 5, json.dumps(tc.fields_as_dict()))
-                    for field in tc.fields:
-                        if not field.name in field_header_set:
-                            sheet.write(0, field_counter, field.name, cellFormatBold)
-                            field_header_set.add(field.name)
-                            field_header_dict[field.name] = field_counter
-                            field_counter += 1
-                        sheet.write(line, field_header_dict[field.name], field.value)
-                    line += 1
-        
-        # autowidth first columns
-        for col in range(6):#len(base_headers)+len(field_header_set)):
-            ExcelSheetHelperFunctions.set_column_autowidth(sheet, col)
-
-        print(f'*** EXECUTION TIME: {time.time()-time_start} seconds') # ------------------> time tracker
-
-
-    # Execution time of export
-    #
-    # lazy:     select  immediate   joined  subquery    | query_fields  | query_field_data
-    # name[0]:  34.24   33.81               59.68       | 33.52         | 91.46
-    # name[1]:  65.35   65.37               35.85       | 63.06         | 57.58
-    # name[2]:                                          | 871.05        | 293.13
-    # all names:                                        | 7200          | 966
-
-
-    def export_nonumber(self):
-        #
-        # exports the query set to xlsx
-        #
-
-        # initialize workbook
-        path_to_file = self.managedPaths.getOrSetDBExportPath().joinpath(f'TestrunLogs_{"_".join(list(map(str, self.tags.values())))}.xlsx')
-        workbook = Workbook(str(path_to_file))
-
-        # set labels
-        labels = {
-            'testrun': 'TestRun',
-            'testcase_sequence': 'Test Case Sequence',
-            'testcase': 'Test Case',
-            'stage': 'Stage',
-            'duration': 'Avg. Duration',
-        }
-
-        # set output headers
-        base_headers = [
-            'Testrun ID',
-            'TestCase ID',
-            'TestCase Number',
-        ]
-
-        base_fields = [
-            GC.EXECUTION_STAGE,
-            GC.TESTCASESTATUS,
-            GC.TIMING_DURATION,
-        ]
-       
-        # define cell formats
-        cformats = {
-            'bg_red': workbook.add_format({'bg_color': 'red'}),
-            'bg_green': workbook.add_format({'bg_color': 'green'}),
-            'bg_yellow': workbook.add_format({'bg_color': 'yellow'}),
-            'font_bold': workbook.add_format({'bold': True}),
-            'font_bold_italic': workbook.add_format({'bold': True, 'italic': True}),
-        }
-
-        # map status styles
-        status_style = {
-            GC.TESTCASESTATUS_SUCCESS: cformats.get('bg_green'),
-            GC.TESTCASESTATUS_ERROR: cformats.get('bg_red'),
-            GC.TESTCASESTATUS_WAITING: None,
-        }
-
-        # create sheets
-        sheets = {
-            'summary': ExportSheet(workbook.add_worksheet('Summary'), cformats.get('font_bold')),
-            'output': ExportSheet(workbook.add_worksheet('Output'), cformats.get('font_bold')),
-        }
-
-        # write summary titles
-        time_start = time.time() # -------------------------> time tracker
-        # title
-        sheets['summary'].sheet.set_column(first_col=0, last_col=0, width=18)
-        sheets['summary'].header([f'{labels.get("testrun")}s Summary'])
-        
-        # parameters
-        for key, value in self.tags.items():
-            sheets['summary'].row([
-                {
-                    'value': key,
-                    'format': cformats.get('font_bold'),
-                },
-                {
-                    'value': value,
-                }
-            ])
-
-        # write output titles
-        sheets['output'].header(base_headers + base_fields)
-
-        # write items
-        # testruns
-        for tr_name in self.query_set.names():
-            print(f'\n*** Tetsrun "{tr_name}": {len(list(self.query_set.filter(tr_name)))} records')
-            # testrun name
-            sheets['summary'].hr()
-            sheets['summary'].row([
-                {
-                    'value': labels.get('testrun'),
-                    'format': cformats.get('font_bold'),
-                },
-                {
-                    'value': tr_name,
-                }
-            ])
-            
-            # average duration
-            sheets['summary'].row([
-                {
-                    'value': labels.get('duration'),
-                    'format': cformats.get('font_bold'),
-                },
-                {
-                    'value': self.query_set.tr_avg_duration(tr_name),
-                }
-            ])
-
-            # testcase sequences
-            for tcs_index in range(self.query_set.max_size(tr_name)):
-                print(f'**** TestCaseSequence-{tcs_index}')
-                # testcase sequence
-                sheets['summary'].hr()
-                sheets['summary'].row([
-                    {
-                        'value': labels.get('testcase_sequence'),
-                        'format': cformats.get('font_bold'),
-                    },
-                    {
-                        'value': tcs_index,
-                    }
-                ])
-
-                # test cases
-                # header
-                tc_num_max = self.query_set.max_size(tr_name, tcs_index=tcs_index)
-                sheets['summary'].hr()
-                sheets['summary'].row(
-                    [
-                        {
-                            'value': 'Run Date',
-                            'format': cformats.get('font_bold_italic'),
-                        },
-                        {
-                            'value': labels.get('testcase'),
-                            'format': cformats.get('font_bold_italic'),
-                        },
-                    ] + [{} for i in range(1, tc_num_max)] +[
-                        {
-                            'value': labels.get('stage'),
-                            'format': cformats.get('font_bold_italic'),
-                        },
-                        {
-                            'value': f'{labels.get("testcase")} ID',
-                            'format': cformats.get('font_bold_italic'),
-                        },
-                    ]
-                )
-                sheets['summary'].row(
-                    [{}] + [{'value': i} for i in range(tc_num_max)]
-                )
-
-                durations =  [[.0,0] for i in range(tc_num_max)]
-                for tr_index, tr in enumerate(self.query_set.filter(tr_name, tcs_index)):
-                    tc_num = len(tr.testcase_sequences[tcs_index].testcases)
-                    print(f'***** TestRun Log {tr_index}: {tc_num} test cases')
-                    status_row = [{'value': tr.startTime.strftime('%Y-%m-%d %H:%M:%S')}] 
-                    
-                    # query testcases
-                    tcs_id = tr.testcase_sequences[tcs_index].id
-                    tc_query = self.db.query(TestCaseLog.id).filter_by(testcase_sequence_id=tcs_id)
-                    #for tc_index, tc in enumerate(tr.testcase_sequences[tcs_index].testcases):
-                    for tc_index, tc in enumerate(tc_query.yield_per(200)):
-                        #for field in tc.fields:
-                        field_query = self.db.query(TestCaseField.name, TestCaseField.value).filter_by(testcase_id=tc[0])
-                        for name, value in field_query.yield_per(200):
-                            if name == GC.TESTCASESTATUS:
-                                status_row.append({
-                                    'value': value,
-                                    'format': status_style.get(value),
-                                })
-                            elif name == GC.EXECUTION_STAGE:
-                                tr_stage = value
-                            elif name == GC.TIMING_DURATION:
-                                m = re.search(r'(?P<hours>\d+):(?P<minutes>\d+):(?P<seconds>\d[\.\d+]*)', value)
-                                if m:
-                                    factors = {
-                                        'hours': 3600,
-                                        'minutes': 60,
-                                        'seconds': 1,
-                                    }
-                                    durations[tc_index][0] += sum([factors[key]*float(value) for key, value in m.groupdict().items()])
-                                    durations[tc_index][1] += 1
-                            
-                            # write to output
-                            sheets['output'].by_header(name, value)
-                        # write testcase info to output sheet
-                        sheets['output'].row([
-                            {
-                                'value': str(tr),
-                            },
-                            {
-                                'value': str(uuid.UUID(bytes=tc[0])),
-                            },
-                            {
-                                'value': tc_index,
-                            },
-                        ])
-
-                    # write state row to summary sheet
-                    sheets['summary'].row(
-                        status_row + [{} for i in range(tc_num, tc_num_max)] + [
-                            {
-                                'value': tr_stage,
-                            },
-                            {
-                                'value': str(tr),
-                            },
-                        ]
-                    )
-
-
-                # avg durations
-                #print('*** DURATIONS:')
-                #print(durations)
-                #print(list(map(lambda d: round(d[0]/d[1], 2) if d[1] > 0 else .0, durations)))
-                sheets['summary'].row(
-                    [
-                        {
-                            'value': labels.get('duration'),
-                            'format': cformats.get('font_bold_italic'),
-                        },
-                    ] + [{'value': d} for d in map(lambda d: round(d[0]/d[1], 2) if d[1] > 0 else .0, durations)]
-                )
-        
-        # autowidth output columns
-        for col in range(len(base_headers)+len(base_fields)):
-            ExcelSheetHelperFunctions.set_column_autowidth(sheets['output'].sheet, col)
-
-        print(f'\n*** EXECUTION TIME: {time.time()-time_start} seconds\n') # ------------------> time tracker
-
-        workbook.close()
-
-        logger.info(f'Query successfully exported to {path_to_file}')
-
-        return path_to_file
         
     def export(self):
         #
@@ -944,7 +340,7 @@ class ResultsBrowser:
         # write items
         # testruns
         for tr_name in self.query_set.names():
-            print(f'\n*** Tetsrun "{tr_name}": {len(list(self.query_set.filter(tr_name)))} records')
+            logger.info(f'Exporting Tetsrun "{tr_name}": {len(list(self.query_set.filter(tr_name)))} records')
             # testrun name
             sheets['summary'].hr()
             sheets['summary'].row([
@@ -973,7 +369,6 @@ class ResultsBrowser:
             # testcase sequences
             for tcs_index in range(self.query_set.max_size(tr_name)):
                 tcs_number = tcs_index+1
-                print(f'**** TestCaseSequence-{tcs_number}')
                 # testcase sequence
                 sheets['summary'].hr()
                 sheets['summary'].row([
@@ -1018,7 +413,6 @@ class ResultsBrowser:
                 durations =  [[.0,0] for i in range(tc_num_max)]
                 for tr_index, tr in enumerate(self.query_set.filter(tr_name, tcs_index)):
                     tc_num = len(tr.testcase_sequences[tcs_index].testcases)
-                    print(f'***** TestRun Log {tr_index}: {tc_num} test cases')
                     status_row = [{'value': tr.startTime.strftime('%Y-%m-%d %H:%M:%S')}]
 
                     # query fields
@@ -1095,11 +489,9 @@ class ResultsBrowser:
         for col in range(len(base_headers)+len(base_fields)):
             ExcelSheetHelperFunctions.set_column_autowidth(sheets['output'].sheet, col)
 
-        print(f'\n*** EXECUTION TIME: {time.time()-time_start} seconds\n') # ------------------> time tracker
-
         workbook.close()
 
-        logger.info(f'Query successfully exported to {path_to_file}')
+        logger.info(f'Query successfully exported to {path_to_file} in {time.time()-time_start} seconds')
 
         return path_to_file
     

db_add_number.py → db_update.py


+ 0 - 17
driver.py

@@ -1,17 +0,0 @@
-from baangt.base.ResultsBrowser import ResultsBrowser
-from datetime import datetime
-
-names = [
-	'RSantragAll.json',
-	'heartbeat.json',
-	'kfz.xlsx',
-]
-
-q = ResultsBrowser()
-q.query(name=names[0])
-#q.query_set.data = q.query_set.data[:10]
-
-#q.query()
-#q.query_set.data = [i for i in q.query_set.data if i.testrunName in names[:2]]
-
-q.export()

+ 0 - 47
query_fields.py

@@ -1,47 +0,0 @@
-from sqlalchemy import create_engine, and_
-from sqlalchemy.orm import sessionmaker
-from baangt.base.DataBaseORM import DATABASE_URL, TestrunLog, GlobalAttribute, TestCaseLog, TestCaseSequenceLog, TestCaseField
-import time
-
-
-class QueryFields:
-
-    def __init__(self):
-        # craate session
-        engine = create_engine(DATABASE_URL)
-        self.session = sessionmaker(bind=engine)
-
-    def by_objects(self, name=None):
-        db = self.session()
-        print('Fields fetching started')
-        time_start = time.time()
-        time_mid = time_start
-        # fetch fields
-        fields = db.query(
-            TestCaseField.name,
-            TestCaseField.value,
-            TestCaseLog.number,
-        )\
-            .join(TestCaseField.testcase).join(TestCaseLog.testcase_sequence).join(TestCaseSequenceLog.testrun)\
-            .filter(and_(TestrunLog.testrunName == name, TestCaseSequenceLog.number == 1))\
-            .order_by(TestrunLog.startTime).order_by(TestCaseLog.number)
-        counter = 0
-        for fname, fvalue, tc in fields.yield_per(1000):
-            counter += 1
-            v = fvalue.replace("\n", " ")[:30]
-            print(f'{counter}\t{name}{tc:4} {fname:32}{v}')
-            
-            #if not counter%100000:
-            #   time_cur = time.time()
-            #   print(f'** {counter:,} records fetched in {time_cur-time_mid} seconds'.replace(',', ' '))
-            #   print(field)
-            #   time_mid = time_cur
-        time_elapsed = time.time() - time_start
-
-        print(f'\n*** FETCHED: {counter:,} fields'.replace(',', ' '))
-        print(f'*** EXECUTION TIME: {time_elapsed}')
-
-
-if __name__ == '__main__':
-    q = QueryFields()
-    q.by_objects(name='kfz.xlsx')

+ 0 - 164
test_queries.py

@@ -1,164 +0,0 @@
-from sqlalchemy import create_engine
-from sqlalchemy.orm import sessionmaker
-from baangt.base.DataBaseORM import DATABASE_URL, TestrunLog, GlobalAttribute, TestCaseLog, TestCaseSequenceLog, TestCaseField
-import time
-
-#{chr(746)}
-
-#name = 'RSantragAll.json'
-#name = 'heartbeat.json'
-#name = 'kfz.xlsx'
-
-
-class Query:
-
-	def __init__(self, name):
-		# craate session
-		self.engine = create_engine(DATABASE_URL)
-		self.db = sessionmaker(bind=self.engine)()
-		self.name = name
-
-	def get_logs(self):
-		if self.name:
-			return self.db.query(TestrunLog).filter_by(testrunName=self.name)
-
-		return self.db.query(TestrunLog)
-
-	def by_relationships(self):
-		# time tracker
-		time_start = time.time()
-		# query testruns
-		logs = self.get_logs()
-		print(f'\nFETCHED: {logs.count()} Testruns')
-		for tr_index, tr in enumerate(logs):
-			print(f'** Testrun-{tr_index}')
-			for tcs_index, tcs in enumerate(tr.testcase_sequences):
-				print(f'**** TestCaseSequence-{tcs_index}: {len(tcs.testcases)} test cases')
-				for tc_index, tc in enumerate(tcs.testcases):
-					#print(f'****** TestCase-{tc_index}')
-					for field in tc.fields:
-						pass
-		self.time = time.time()-time_start
-
-	def by_subqueries(self):
-		# time tracker
-		time_start = time.time()
-		# query testruns
-		logs = self.get_logs()
-		print(f'\nFETCHED: {logs.count()} Testruns')
-		for tr_index, tr in enumerate(logs):
-			print(f'** Testrun-{tr_index}')
-			for tcs_index, tcs in enumerate(tr.testcase_sequences):
-				# query testcases
-				tc_query = self.db.query(TestCaseLog).filter_by(testcase_sequence_id=tcs.id)
-				print(f'**** TestCaseSequence-{tcs_index}: {tc_query.count()} test cases')
-				for tc_index, tc in enumerate(tc_query):
-					for field in self.db.query(TestCaseField).filter_by(testcase_id=tc.id):
-						pass
-		self.time = time.time()-time_start
-
-	def by_yield_subqueries(self):
-		# time tracker
-		time_start = time.time()
-		# query testruns
-		logs = self.get_logs()
-		print(f'\nFETCHED: {logs.count()} Testruns')
-		tr_index = 0
-		for tr in logs.yield_per(10):
-			print(f'** Testrun-{tr_index}')
-			tr_index += 1
-			for tcs_index, tcs in enumerate(tr.testcase_sequences):
-				# query testcases
-				tc_query = self.db.query(TestCaseLog).filter_by(testcase_sequence_id=tcs.id)
-				print(f'**** TestCaseSequence-{tcs_index}: {tc_query.count()} test cases')
-				tc_index = 0
-				for tc in tc_query.yield_per(10):
-					for field in self.db.query(TestCaseField).filter_by(testcase_id=tc.id).yield_per(10):
-						pass
-		self.time = time.time()-time_start
-
-	def by_subqueries_fields(self):
-		# time tracker
-		time_start = time.time()
-		# query testruns
-		logs = self.get_logs()
-		print(f'\nFETCHED: {logs.count()} Testruns')
-		for tr_index, tr in enumerate(logs):
-			print(f'** Testrun-{tr_index}')
-			tcs_query = self.db.query(TestCaseSequenceLog.id).filter_by(testrun_id=tr[0])
-			for tcs_index, tcs in enumerate(tcs_query):
-				# query testcases
-				tc_query = self.db.query(TestCaseLog.id).filter_by(testcase_sequence_id=tcs[0])
-				print(f'**** TestCaseSequence-{tcs_index}: {tc_query.count()} test cases')
-				for tc_index, tc in enumerate(tc_query):
-					for name, value in self.db.query(TestCaseField.name, TestCaseField.value).filter_by(testcase_id=tc[0]):
-						pass
-		self.time = time.time()-time_start
-
-	def by_connection(self):
-		# time tracker
-		time_start = time.time()
-		with self.engine.connect() as conn:
-			# query testruns
-			logs = conn.execute(TestrunLog.__table__.select().filter_by(testrunName=self.name)).fetchall()
-			print(f'\nFETCHED: {len(logs)} Testruns')
-			for tr_index, tr in enumerate(logs):
-				print(f'** Testrun-{tr_index}')
-				for tcs_index, tcs in enumerate(tr.testcase_sequences):
-					# query testcases
-					tc_query = self.db.query(TestCaseLog).filter_by(testcase_sequence_id=tcs.id)
-					print(f'**** TestCaseSequence-{tcs_index}: {tc_query.count()} test cases')
-					for tc_index, tc in enumerate(tc_query):
-						for field in self.db.query(TestCaseField).filter_by(testcase_id=tc.id):
-							pass
-		self.time = time.time()-time_start
-
-
-	def statistics(self):
-		print(f'\nEXECUTION TIME: {self.time}')
-
-class QueryStack:
-
-	def __init__(self):
-		self.queries = []
-
-	def add(self, query):
-		self.queries.append(query)
-
-	def statistics(self):
-		fields = {
-			'name': 20,
-			'time': 10,
-		}
-		print(' '*fields.get('name') + 'Time')
-		for q in self.queries:
-			print(f'{q.name}{" "*(fields.get("name")-len(q.name))}{q.time}')
-
-
-if __name__ == '__main__':
-	name = 'RSantragAll.json'
-	q = Query(name)
-	q.by_relationships()
-
-	qstack = QueryStack()
-	name = None
-	for i in range(1):
-		q = Query(name)
-		if i == 0:
-			q.by_relationships()
-			q.name = 'Relations'
-		elif i == 1:
-			q.by_subqueries()
-			q.name = 'Subqueries'
-		elif i == 2:
-			q.by_yield_subqueries()
-			q.name = 'Yielded'
-		elif i == 3:
-			q.by_subqueries_fields()
-			q.name = 'Fields'
-
-		qstack.add(q)
-
-	qstack.statistics()
-
-