def setUp(self): self.data_stats = DataStats(minimum=0.03276, maximum=0.44241, median=0.22399, mean=0.21448, standard_deviation=0.12923, variance=0.01670, sum=3.2, count=4) self.metric_definition = MetricDefinition( name="my_metric", plugin_key="vamp-example-plugins:amplitudefollower:amplitude", function="none", kwargs={"param1": 2.0}) self.metric_value = MetricValue("0f961f20-b036-5740-b526-013523dd88c7", self.metric_definition, self.data_stats)
def test_should_turn_into_serializable_form_and_back(self): serializable_form = self.metric_value.to_serializable() assert_that(serializable_form).is_not_none() assert_that(serializable_form["task_id"]).is_equal_to( "0f961f20-b036-5740-b526-013523dd88c7") assert_that(serializable_form["stats"]["minimum"]).is_equal_to(0.03276) assert_that( serializable_form["definition"]["name"]).is_equal_to("my_metric") deserialized_form = MetricValue.from_serializable(serializable_form) assert_that(deserialized_form).is_equal_to(self.metric_value)
class MetricValueModelTest(unittest.TestCase): def setUp(self): self.data_stats = DataStats(minimum=0.03276, maximum=0.44241, median=0.22399, mean=0.21448, standard_deviation=0.12923, variance=0.01670, sum=3.2, count=4) self.metric_definition = MetricDefinition( name="my_metric", plugin_key="vamp-example-plugins:amplitudefollower:amplitude", function="none", kwargs={"param1": 2.0}) self.metric_value = MetricValue("0f961f20-b036-5740-b526-013523dd88c7", self.metric_definition, self.data_stats) def test_should_turn_into_serializable_form_and_back(self): serializable_form = self.metric_value.to_serializable() assert_that(serializable_form).is_not_none() assert_that(serializable_form["task_id"]).is_equal_to( "0f961f20-b036-5740-b526-013523dd88c7") assert_that(serializable_form["stats"]["minimum"]).is_equal_to(0.03276) assert_that( serializable_form["definition"]["name"]).is_equal_to("my_metric") deserialized_form = MetricValue.from_serializable(serializable_form) assert_that(deserialized_form).is_equal_to(self.metric_value) def test_should_serialize_to_json_and_back_without_errors(self): json_form = json.dumps(self.metric_value.to_serializable()) assert_that(json_form).is_not_empty() back_to_object = MetricValue.from_serializable(json.loads(json_form)) assert_that(back_to_object).is_equal_to(self.metric_value)
def _map_to_object(self, entity: Metric) -> MetricValue: definition_object = self.definition_repository.get_by_id( entity.definition_id) if not definition_object: raise ValueError( "Could not find metric definition with id {} for metric {}". format(entity.definition_id, entity.task_id)) data_stats = DataStats(minimum=entity.minimum, maximum=entity.maximum, median=entity.median, mean=entity.mean, standard_deviation=entity.standard_deviation, variance=entity.variance, sum=entity.sum, count=entity.count) return MetricValue(task_id=entity.task_id, definition=definition_object, stats=data_stats)
def setUp(self): self.metric_definition_example = MetricDefinition( name="first_metric", plugin_key="vamp-example-plugins:amplitudefollower:amplitude", function="select_row", kwargs={"row_index": 3}) self.metric_value_1 = MetricValue( "0f961f20-b036-5740-b526-013523dd88c7", self.metric_definition_example, DataStats(minimum=0.03276, maximum=0.44241, median=0.22399, mean=0.21448, standard_deviation=0.12923, variance=0.01670, sum=10.1, count=8)) self.plugin_example = VampyPlugin("vamp-example-plugins", "amplitudefollower", "amplitude", "") self.plugin_repo_mock = Mock(VampyPluginRepository) self.definition_repo_mock = Mock(MetricDefinitionRepository) self.metric_value_repo = MetricValueRepository( self.session_provider, self.definition_repo_mock)
def extract_metric_value(task_id: str, definition: MetricDefinition, transformation: MetricTransformation, feature: VampyFeatureAbstraction) -> MetricValue: data_vector = transformation.call(feature) metric_stats = _extract_data_stats(data_vector) return MetricValue(task_id, definition, metric_stats)
def test_should_serialize_to_json_and_back_without_errors(self): json_form = json.dumps(self.metric_value.to_serializable()) assert_that(json_form).is_not_empty() back_to_object = MetricValue.from_serializable(json.loads(json_form)) assert_that(back_to_object).is_equal_to(self.metric_value)