fragment stats
This commit is contained in:
parent
3c4119fc77
commit
9bd5d12874
1 changed files with 49 additions and 0 deletions
49
render.py
49
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue