forked from 0x2620/pandora
update random in transaction. timeline sorting
This commit is contained in:
parent
5c827f11af
commit
4c21387335
3 changed files with 16 additions and 11 deletions
|
@ -7,6 +7,7 @@ import random
|
||||||
random
|
random
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.db import connection, transaction
|
||||||
from ox.utils import ET
|
from ox.utils import ET
|
||||||
from celery.task import task, periodic_task
|
from celery.task import task, periodic_task
|
||||||
|
|
||||||
|
@ -16,6 +17,7 @@ import models
|
||||||
@periodic_task(run_every=timedelta(days=1))
|
@periodic_task(run_every=timedelta(days=1))
|
||||||
def cronjob(**kwargs):
|
def cronjob(**kwargs):
|
||||||
update_random_sort()
|
update_random_sort()
|
||||||
|
update_random_clip_sort()
|
||||||
|
|
||||||
def update_random_sort():
|
def update_random_sort():
|
||||||
if filter(lambda f: f['id'] == 'random', settings.CONFIG['itemKeys']):
|
if filter(lambda f: f['id'] == 'random', settings.CONFIG['itemKeys']):
|
||||||
|
@ -29,14 +31,13 @@ def update_random_sort():
|
||||||
|
|
||||||
def update_random_clip_sort():
|
def update_random_clip_sort():
|
||||||
if filter(lambda f: f['id'] == 'random', settings.CONFIG['itemKeys']):
|
if filter(lambda f: f['id'] == 'random', settings.CONFIG['itemKeys']):
|
||||||
from django.db import connection, transaction
|
with transaction.commit_on_success():
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
cursor.execute('DROP TABLE clip_random;')
|
cursor.execute('DROP TABLE clip_random;')
|
||||||
cursor.execute('CREATE TABLE "clip_random" AS SELECT id AS clip_id, row_number() OVER (ORDER BY random()) AS random FROM "clip_clip"')
|
cursor.execute('CREATE TABLE "clip_random" AS SELECT id AS clip_id, row_number() OVER (ORDER BY random()) AS random FROM "clip_clip"')
|
||||||
cursor.execute('ALTER TABLE "clip_random" ADD UNIQUE ("clip_id")')
|
cursor.execute('ALTER TABLE "clip_random" ADD UNIQUE ("clip_id")')
|
||||||
cursor.execute('CREATE INDEX "clip_random_clip_id_idx" ON "clip_random" ("clip_id")')
|
cursor.execute('CREATE INDEX "clip_random_clip_id_idx" ON "clip_random" ("clip_id")')
|
||||||
cursor.execute('CREATE INDEX "clip_random_random_idx" ON "clip_random" ("random")')
|
cursor.execute('CREATE INDEX "clip_random_random_idx" ON "clip_random" ("random")')
|
||||||
transaction.commit_unless_managed()
|
|
||||||
|
|
||||||
@task(ignore_results=True, queue='default')
|
@task(ignore_results=True, queue='default')
|
||||||
def update_poster(itemId):
|
def update_poster(itemId):
|
||||||
|
|
|
@ -7,10 +7,12 @@ from glob import glob
|
||||||
import Image
|
import Image
|
||||||
|
|
||||||
import ox
|
import ox
|
||||||
|
from utils import sorted_strings
|
||||||
|
|
||||||
|
|
||||||
def getTiles(timeline_prefix, height=64):
|
def getTiles(timeline_prefix, height=64):
|
||||||
files = glob('%s%sp*.png' % (timeline_prefix, height))
|
files = glob('%s%sp*.png' % (timeline_prefix, height))
|
||||||
return sorted(filter(lambda f: f!='%s%sp.png' % (timeline_prefix, height), files))
|
return sorted_strings(filter(lambda f: f!='%s%sp.png' % (timeline_prefix, height), files))
|
||||||
|
|
||||||
def loadTimeline(timeline_prefix, height=64):
|
def loadTimeline(timeline_prefix, height=64):
|
||||||
files = getTiles(timeline_prefix, height)
|
files = getTiles(timeline_prefix, height)
|
||||||
|
@ -35,7 +37,7 @@ def makeTiles(timeline_prefix, height=16, width=3600):
|
||||||
timeline = Image.new("RGB", (width, height))
|
timeline = Image.new("RGB", (width, height))
|
||||||
|
|
||||||
pos = 0
|
pos = 0
|
||||||
for f in sorted(files):
|
for f in sorted_strings(files):
|
||||||
part = Image.open(f)
|
part = Image.open(f)
|
||||||
part_width = int(part.size[0] / fps)
|
part_width = int(part.size[0] / fps)
|
||||||
part = part.resize((part_width, height), Image.ANTIALIAS)
|
part = part.resize((part_width, height), Image.ANTIALIAS)
|
||||||
|
|
|
@ -7,7 +7,7 @@ import unicodedata
|
||||||
import ox
|
import ox
|
||||||
|
|
||||||
def safe_filename(filename):
|
def safe_filename(filename):
|
||||||
filename = filename.replace('_ ', ': ')
|
filename = filename.replace(': ', '_ ')
|
||||||
filename = filename.replace('/', '_')
|
filename = filename.replace('/', '_')
|
||||||
filename = filename.replace('\\', '_')
|
filename = filename.replace('\\', '_')
|
||||||
if filename.endswith('.'):
|
if filename.endswith('.'):
|
||||||
|
@ -54,6 +54,8 @@ def sort_string(string):
|
||||||
string = re.sub('(\d+)', lambda x: '%010d' % int(x.group(0)), string)
|
string = re.sub('(\d+)', lambda x: '%010d' % int(x.group(0)), string)
|
||||||
return unicodedata.normalize('NFKD', string)
|
return unicodedata.normalize('NFKD', string)
|
||||||
|
|
||||||
|
def sorted_strings(strings):
|
||||||
|
return sorted(strings, cmp=lambda a, b: cmp(sort_string(a), sort_string(b)))
|
||||||
|
|
||||||
def sort_title(title):
|
def sort_title(title):
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue