def factor_variables_for_trial(self, f: Factor, t: int) -> List[int]: if not f.applies_to_trial(t): raise ValueError('Factor does not apply to trial #' + str(t) + ' f=' + str(f)) previous_trials = sum( map(lambda trial: 1 if f.applies_to_trial(trial + 1) else 0, range(t))) - 1 initial_sequence = list( map(lambda l: self.first_variable_for_level(f, l), list(filter(lambda l: (f, l) not in self.exclude, f.levels)))) offset = 0 if f.has_complex_window(): offset = len(f.levels) * previous_trials else: offset = self.variables_per_trial() * previous_trials return list(map(lambda n: n + offset + 1, initial_sequence))
def first_variable_for_level(self, factor: Factor, level: Any) -> int: if (type(level) is not SimpleLevel and type(level) is not DerivedLevel): print("Attempt to find first variable for a non-level object " + str(level)) if factor.has_complex_window(): offset = 0 complex_factors = filter(lambda f: f.has_complex_window(), self.design) for f in complex_factors: if f == factor: offset += f.levels.index(level) break else: offset += self.variables_for_factor(f) return self.grid_variables() + offset else: simple_factors = list( filter(lambda f: not f.has_complex_window(), self.design)) simple_levels = get_all_levels(simple_factors) return simple_levels.index((factor, level))