Skip to content

Commit

Permalink
Merge 0445ea1 into a8f13ce
Browse files Browse the repository at this point in the history
  • Loading branch information
bb511 committed Aug 2, 2019
2 parents a8f13ce + 0445ea1 commit c0aad72
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
20 changes: 20 additions & 0 deletions fitbenchmarking/resproc/misc.py
Expand Up @@ -27,9 +27,11 @@
from __future__ import (absolute_import, division, print_function)
import os

import re
from resproc import visual_pages



def display_name_for_minimizers(names):
"""
Converts minimizer names into their "display names". For example
Expand Down Expand Up @@ -97,3 +99,21 @@ def build_items_links(comparison_type, comp_dim, using_errors):
items_link = ''

return items_link

def find_ranking_strings(rst_table):
"""
Selects the position of the string ':ranking-number:' from the output tables
and puts them in an array.
@param rst_table :: the restructured text table containing the results.
@returns :: array of tuples containing the starting and ending index
where every ':ranking-number:' is.
"""

expression = re.compile('(:ranking)(.*?)(:)')
iterator = expression.finditer(rst_table)
matches = []
for match in iterator: matches.append(match.span())

return matches
11 changes: 11 additions & 0 deletions fitbenchmarking/resproc/tests/test_misc.py
Expand Up @@ -13,6 +13,7 @@
from resproc.misc import display_name_for_minimizers
from resproc.misc import weighted_suffix_string
from resproc.misc import build_items_links
from resproc.misc import find_ranking_strings


class MiscTests(unittest.TestCase):
Expand Down Expand Up @@ -98,6 +99,16 @@ def test_buildItemsLinks_return_empty_itemsLinks_invalid_comparison(self):

self.assertEqual(items_link_expected, items_link)

def test_findRankingStrings_get_ranking_strings(self):

rst_table = "something something :ranking-9 example: something"

matches = find_ranking_strings(rst_table)
# This is where the ':ranking-9 example:' start and end positions.
expected_matches = [(20,39)]

self.assertListEqual(expected_matches, matches)


if __name__ == "__main__":
unittest.main()
30 changes: 29 additions & 1 deletion fitbenchmarking/results_output.py
Expand Up @@ -31,6 +31,7 @@
from resproc import numpy_restables
from resproc import rst_table
from resproc import visual_pages
from resproc.misc import find_ranking_strings
from utils import create_dirs

# Some naming conventions for the output files
Expand Down Expand Up @@ -72,6 +73,10 @@ def save_results_tables(software_options, results_per_test, group_name,
runtime_tbl = create_runtime_tbl(minimizers, linked_problems, norm_runtimes,
use_errors, color_scale)

combined_table = create_combined_table(acc_tbl, runtime_tbl)

save_tables(tables_dir, combined_table, use_errors, group_name,
"combined_table")
save_tables(tables_dir, acc_tbl, use_errors, group_name,
FILENAME_SUFFIX_ACCURACY)
save_tables(tables_dir, runtime_tbl, use_errors, group_name,
Expand All @@ -80,7 +85,6 @@ def save_results_tables(software_options, results_per_test, group_name,
# Shut down logging at end of run
logging.shutdown()


def generate_tables(results_per_test, minimizers):
"""
Generates accuracy and runtime normalised tables and summary tables.
Expand Down Expand Up @@ -132,6 +136,30 @@ def create_runtime_tbl(minimizers, linked_problems, norm_runtimes, use_errors,
return tbl_runtime_indiv


def create_combined_table(acc_tbl, runtime_tbl):
"""
Combines the accuracy and runtime tables by giving the accuracy table
the colours found in the timeline table.
@param acc_tbl :: accuracy table
@param runtime_tbl :: runtime table
@returns :: combined table with the accuracy table results but
with the timing table colours.
"""
matches_acc = find_ranking_strings(acc_tbl)
matches_tim = find_ranking_strings(runtime_tbl)

combined_table = acc_tbl[:matches_acc[0][0]] + \
runtime_tbl[matches_tim[0][0]:matches_tim[0][1]]

for idx in range(0, len(matches_acc)-1):
combined_table += acc_tbl[matches_acc[idx][1]:matches_acc[idx+1][0]] + \
runtime_tbl[matches_tim[idx+1][0]:matches_tim[idx+1][1]]

combined_table += acc_tbl[matches_acc[-1][1]:]
return combined_table

def save_tables(tables_dir, table_data, use_errors, group_name, metric):
"""
Helper function that saves the rst table both to html and to text.
Expand Down

0 comments on commit c0aad72

Please sign in to comment.