MCPcopy Create free account
hub / github.com/Breakthrough/PySceneDetect / ScoreWeightsValue

Class ScoreWeightsValue

scenedetect/_cli/config.py:197–230  ·  view source on GitHub ↗

Validator for score weight values (currently a tuple of four numbers).

Source from the content-addressed store, hash-verified

195
196
197class ScoreWeightsValue(ValidatedValue):
198 """Validator for score weight values (currently a tuple of four numbers)."""
199
200 _IGNORE_CHARS = (",", "/", "(", ")")
201 """Characters to ignore."""
202
203 def __init__(self, value: str | ContentDetector.Components):
204 if isinstance(value, ContentDetector.Components):
205 self._value = value
206 else:
207 translation_table = str.maketrans(
208 {char: " " for char in ScoreWeightsValue._IGNORE_CHARS}
209 )
210 values = value.translate(translation_table).split()
211 if not len(values) == 4:
212 raise ValueError("Score weights must be specified as four numbers!")
213 self._value = ContentDetector.Components(*(float(val) for val in values))
214
215 @property
216 def value(self) -> ContentDetector.Components:
217 return self._value
218
219 def __str__(self) -> str:
220 return "{:.3f}, {:.3f}, {:.3f}, {:.3f}".format(*self.value)
221
222 @staticmethod
223 def from_config(config_value: str, default: "ScoreWeightsValue") -> "ScoreWeightsValue":
224 try:
225 return ScoreWeightsValue(config_value)
226 except ValueError as ex:
227 raise OptionParseFailure(
228 "Score weights must be specified as four numbers in the form (H,S,L,E),"
229 " e.g. (0.9, 0.2, 2.0, 0.5). Commas/brackets/slashes are ignored."
230 ) from ex
231
232
233class KernelSizeValue(ValidatedValue):

Callers 2

from_configMethod · 0.85
config.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected