From 9bd5d128743f4034f25328c046a35b820340987e Mon Sep 17 00:00:00 2001 From: j Date: Fri, 30 Jan 2026 18:45:26 +0100 Subject: [PATCH] fragment stats --- render.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/render.py b/render.py index d49abc9..f656321 100644 --- a/render.py +++ b/render.py @@ -1147,3 +1147,52 @@ def unused_tags(): for tag in sorted(unused_tags): count = unused_items.filter(data__tags__contains=tag).count() fd.write("%s (%d unused video clips)\n" % (tag, count)) + +def fragment_statistics(): + import itemlist.models + import item.models + stats = {} + for l in itemlist.models.List.objects.filter(status='featured').order_by('name'): + if l.name.split(' ')[0].isdigit(): + fragment_id = l.name.split(' ')[0] + fragment = { + 'id': fragment_id, + 'name': l.name, + 'tags': [], + 'anti-tags': [], + 'description': l.description + } + for con in l.query['conditions']: + if "conditions" in con: + for sub in con["conditions"]: + if sub['key'] == "tags" and sub['operator'] == '==': + fragment['tags'].append(sub['value'].lower().strip()) + elif sub['key'] == "tags" and sub['operator'] == '!=': + fragment['tags'].append(sub['value'].lower().strip()) + elif sub['key'] == 'type' and sub['value'] in ('source', ''): + pass + else: + print(l.name, 'unknown sub condition', sub) + elif con.get('key') == "tags" and con['operator'] == '==': + fragment['tags'].append(con['value'].lower().strip()) + elif con.get('key') == "tags" and con['operator'] == '!=': + fragment['anti-tags'].append(con['value'].lower().strip()) + + if fragment_id not in stats: + stats[fragment_id] = {} + for tag in fragment['tags']: + stats[fragment_id][tag] = 0 + + for item in l.get_items(l.user).all(): + item_tags = [t.lower().strip() for t in item.get('tags')] + if set(item_tags) & set(fragment['anti-tags']): + continue + for tag in set(fragment['tags']): + if tag in item_tags: + stats[fragment_id][tag] += 1 + with open("/srv/pandora/static/power/fragments.txt", "w") as fd: + for fragment, data in stats.items(): + fd.write("%s\n" % fragment) + for tag in sorted(data): + fd.write(" %s: %s\n" % (tag, data[tag])) + return stats