Change-Id: Iedf5d9f772a10d9bcbcc0ee3faec56ed7a9fa5d2
This commit is contained in:
Neels Hofmeyr
2026-03-10 23:17:40 +01:00
parent a65886ca3f
commit c16ce298e8
2 changed files with 13 additions and 9 deletions

View File

@@ -62,7 +62,7 @@ class BatchPersonalization:
def __init__(self,
n: int,
src_pes: ProfileElementSequence,
params: list[ParamAndSrc]=None,
params: list[ParamAndSrc]=[],
csv_rows: Generator=None,
):
"""
@@ -71,10 +71,10 @@ class BatchPersonalization:
copied.
params: list of ParamAndSrc instances, defining a ConfigurableParameter and corresponding ParamSource to fill in
profile values.
csv_rows: A list or generator producing all CSV rows one at a time, starting with a row containing the column
headers. This is compatible with the python csv.reader. Each row gets passed to
ParamSource.get_next(), such that ParamSource implementations can access the row items.
See param_source.CsvSource.
csv_rows: A generator (or iter(list_of_rows)) producing all CSV rows one at a time, starting with a row
containing the column headers. This is compatible with the python csv.reader. Each row gets passed to
ParamSource.get_next(), such that ParamSource implementations can access the row items. See
param_source.CsvSource.
"""
self.n = n
self.params = params or []

View File

@@ -34,6 +34,11 @@ class ParamSource:
# This name should be short but descriptive, useful for a user interface, like 'random decimal digits'.
name = "none"
def __init__(self, input_val:str):
"""Subclasses must implement a constructor with this signature. The input_val is typically a user entered string
value, and the subclass chooses how to store it; for example ConstantSource() just does self.val = input_val."""
pass
@classmethod
def from_str(cls, s:str):
"""Subclasses implement this:
@@ -48,13 +53,12 @@ class ParamSource:
This default implementation is an empty source."""
raise ParamSourceExhaustedExn()
class ConstantSource(ParamSource):
"""one value for all"""
name = "constant"
def __init__(self, val:str):
self.val = val
def __init__(self, input_val:str):
self.val = input_val
def get_next(self, csv_row:dict=None):
return self.val
@@ -92,7 +96,7 @@ class DecimalRangeSource(ParamSource):
last_str = None
first_value = int(first_str)
last_value = int(last_str) if last_str is not None else "9" * len(first_str)
last_value = int(last_str if last_str is not None else "9" * len(first_str))
return cls(num_digits=len(first_str), first_value=first_value, last_value=last_value)
class RandomDigitSource(DecimalRangeSource):