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, def __init__(self,
n: int, n: int,
src_pes: ProfileElementSequence, src_pes: ProfileElementSequence,
params: list[ParamAndSrc]=None, params: list[ParamAndSrc]=[],
csv_rows: Generator=None, csv_rows: Generator=None,
): ):
""" """
@@ -71,10 +71,10 @@ class BatchPersonalization:
copied. copied.
params: list of ParamAndSrc instances, defining a ConfigurableParameter and corresponding ParamSource to fill in params: list of ParamAndSrc instances, defining a ConfigurableParameter and corresponding ParamSource to fill in
profile values. profile values.
csv_rows: A list or generator producing all CSV rows one at a time, starting with a row containing the column csv_rows: A generator (or iter(list_of_rows)) producing all CSV rows one at a time, starting with a row
headers. This is compatible with the python csv.reader. Each row gets passed to 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. ParamSource.get_next(), such that ParamSource implementations can access the row items. See
See param_source.CsvSource. param_source.CsvSource.
""" """
self.n = n self.n = n
self.params = params or [] 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'. # This name should be short but descriptive, useful for a user interface, like 'random decimal digits'.
name = "none" 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 @classmethod
def from_str(cls, s:str): def from_str(cls, s:str):
"""Subclasses implement this: """Subclasses implement this:
@@ -48,13 +53,12 @@ class ParamSource:
This default implementation is an empty source.""" This default implementation is an empty source."""
raise ParamSourceExhaustedExn() raise ParamSourceExhaustedExn()
class ConstantSource(ParamSource): class ConstantSource(ParamSource):
"""one value for all""" """one value for all"""
name = "constant" name = "constant"
def __init__(self, val:str): def __init__(self, input_val:str):
self.val = val self.val = input_val
def get_next(self, csv_row:dict=None): def get_next(self, csv_row:dict=None):
return self.val return self.val
@@ -92,7 +96,7 @@ class DecimalRangeSource(ParamSource):
last_str = None last_str = None
first_value = int(first_str) 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) return cls(num_digits=len(first_str), first_value=first_value, last_value=last_value)
class RandomDigitSource(DecimalRangeSource): class RandomDigitSource(DecimalRangeSource):