From fa1f189cac1e167c693bb8433ed5c274c851da56 Mon Sep 17 00:00:00 2001 From: Andrew Grant Date: Sun, 30 May 2021 04:13:23 -0400 Subject: [PATCH] Fix regex expressions; should not impact old clients --- Client/Client.py | 14 +++++++++----- OpenBench/utils.py | 13 +++++++++---- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Client/Client.py b/Client/Client.py index b43ed37..e9e2e06 100644 --- a/Client/Client.py +++ b/Client/Client.py @@ -278,18 +278,22 @@ def run_bench(engine, outqueue): def scale_time_control(workload, nps): # Searching for X/Y+Z time controls - pattern = '(\d*.\d*)/?(\d+)?\+?(\d*.\d*)?' - time_control = workload['test']['timecontrol'] - base, repeat, inc = re.search(pattern, time_control).groups(0) + pattern = '(?P\d*(\.\d+)?)(?P/\d+)?(?P\+\d+\.\d+)?' + results = re.search(pattern, workload['test']['timecontrol']) + base, rep, inc = results.group('base', 'rep', 'inc') + + # Strip any leading / or + symbols + rep = None if rep is None else rep[1:] + inc = '0' if inc is None else inc[1:] # Scale our machine's NPS to the Server's NPS base = float(base) * int(workload['test']['nps']) / nps inc = float(inc ) * int(workload['test']['nps']) / nps # Only include repeating controls when found - if repeat == 0: + if rep is None: return '%.2f+%.2f' % (base, inc) - return ('%.2f/%d+%.2f' % (base, int(repeat), inc)) + return '%.2f/%d+%.2f' % (base, int(rep), inc) def kill_cutechess(cutechess): diff --git a/OpenBench/utils.py b/OpenBench/utils.py index e38f86f..fb4aab7 100644 --- a/OpenBench/utils.py +++ b/OpenBench/utils.py @@ -49,13 +49,18 @@ def extractOption(options, option): def parseTimeControl(timecontrol): # Searching for X/Y+Z time controls - pattern = '(\d*.\d*)/?(\d+)?\+?(\d*.\d*)?' - base, repeat, inc = re.search(pattern, timecontrol).groups(0) + pattern = '(?P\d*(\.\d+)?)(?P/\d+)?(?P\+\d+\.\d+)?' + results = re.search(pattern, timecontrol) + base, rep, inc = results.group('base', 'rep', 'inc') + + # Strip any leading / or + symbols + rep = None if rep is None else rep[1:] + inc = '0' if inc is None else inc[1:] # Only include repeating controls when found - if repeat == 0: + if rep is None: return '%.1f+%.2f' % (float(base), float(inc)) - return '%.1f/%d+%.2f' % (float(base), int(repeat), float(inc)) + return '%.1f/%d+%.2f' % (float(base), int(rep), float(inc)) def getPendingTests():