analytics: Add python api to get relation path
A new api `Mtd.relation_path()` is added to get relation chain between two Mtd in RelationMeta. Usage: ``` for i in mtd1.relation_path(mtd2, max_span=4, relation_type=...): pass ``` Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8556>
This commit is contained in:
parent
476bd6109e
commit
e68eb7bb23
@ -50,6 +50,9 @@ class Mtd(GstAnalytics.Mtd):
|
|||||||
return _gi_gst_analytics.AnalyticsMtdDirectRelatedIterator(
|
return _gi_gst_analytics.AnalyticsMtdDirectRelatedIterator(
|
||||||
sys.modules[__name__], self, relation, mtd_type)
|
sys.modules[__name__], self, relation, mtd_type)
|
||||||
|
|
||||||
|
def relation_path(self, mtd, max_span = 0, reltype = GstAnalytics.RelTypes.ANY):
|
||||||
|
return _gi_gst_analytics.AnalyticsMtdRelationPath(
|
||||||
|
sys.modules[__name__], self, mtd.get_id(), max_span, reltype);
|
||||||
|
|
||||||
__all__.append('Mtd')
|
__all__.append('Mtd')
|
||||||
|
|
||||||
|
@ -219,7 +219,43 @@ _gst_analytics_relation_meta_iterator_next (_GstAnalyticsRelationMetaIterator *
|
|||||||
return py_result;
|
return py_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_gi_gst_analytics_mtd_relation_path (PyObject * self, PyObject * args)
|
||||||
|
{
|
||||||
|
PyObject *py_module = NULL;
|
||||||
|
PyObject *py_mtd;
|
||||||
|
guint id;
|
||||||
|
guint max_span;
|
||||||
|
GstAnalyticsRelTypes reltype;
|
||||||
|
GArray *relation_path;
|
||||||
|
GstAnalyticsMtd *mtd;
|
||||||
|
PyObject *pathList;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTuple (args, "OOIII", &py_module, &py_mtd, &id, &max_span,
|
||||||
|
&reltype)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
relation_path = g_array_new (FALSE, FALSE, sizeof (guint));
|
||||||
|
mtd = (GstAnalyticsMtd *) pygobject_get (py_mtd);
|
||||||
|
gst_analytics_relation_meta_exist (mtd->meta, mtd->id, id,
|
||||||
|
max_span, reltype, &relation_path);
|
||||||
|
|
||||||
|
pathList = PyList_New (relation_path->len);
|
||||||
|
for (guint i = 0; i < relation_path->len; i++) {
|
||||||
|
guint id = g_array_index (relation_path, guint, i);
|
||||||
|
PyList_SetItem (pathList, i, PyLong_FromUnsignedLong (id));
|
||||||
|
}
|
||||||
|
g_array_free (relation_path, TRUE);
|
||||||
|
|
||||||
|
return pathList;
|
||||||
|
}
|
||||||
|
|
||||||
static PyMethodDef _gi_gst_analytics_functions[] = {
|
static PyMethodDef _gi_gst_analytics_functions[] = {
|
||||||
|
{"AnalyticsMtdRelationPath",
|
||||||
|
(PyCFunction) _gi_gst_analytics_mtd_relation_path,
|
||||||
|
METH_VARARGS,
|
||||||
|
"Returns the relation path between two Mtd"},
|
||||||
{NULL, NULL, 0, NULL}
|
{NULL, NULL, 0, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -325,3 +325,13 @@ class TestAnalyticsRelationMetaIterator(TestCase):
|
|||||||
|
|
||||||
assert(count == 2)
|
assert(count == 2)
|
||||||
|
|
||||||
|
# Create a relation path as od_mtd -> cls_mtd -> trk_mtd -> seg_mtd
|
||||||
|
rmeta.set_relation(GstAnalytics.RelTypes.NONE, od_mtd.id, trk_mtd.id) # clear relation
|
||||||
|
rmeta.set_relation(GstAnalytics.RelTypes.RELATE_TO, cls_mtd.id, trk_mtd.id)
|
||||||
|
rmeta.set_relation(GstAnalytics.RelTypes.RELATE_TO, trk_mtd.id, seg_mtd.id)
|
||||||
|
count = 0
|
||||||
|
expected_rel_ids = [od_mtd.id, cls_mtd.id, trk_mtd.id, seg_mtd.id]
|
||||||
|
for i in od_mtd.relation_path(seg_mtd, max_span=4):
|
||||||
|
assert i == expected_rel_ids[count]
|
||||||
|
count += 1
|
||||||
|
assert(count == 4)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user