discover: more mix
This commit is contained in:
parent
00083e8362
commit
ac0c74f03f
2 changed files with 30 additions and 20 deletions
|
@ -8,7 +8,8 @@ from django.utils import timezone
|
||||||
from django.db.models import Count
|
from django.db.models import Count
|
||||||
|
|
||||||
|
|
||||||
MAX_GALLERY_ITEMS = 42
|
MAX_GALLERY_ITEMS = 64
|
||||||
|
MIN_MARKS = 3
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
|
@ -22,17 +23,25 @@ class Command(BaseCommand):
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_popular_item_ids(self, category, days):
|
def get_popular_item_ids(self, category, days):
|
||||||
self.stdout.write(f"Generating popular {category} items for {days} days...")
|
# self.stdout.write(f"Generating popular {category} items for {days} days...")
|
||||||
item_ids = [
|
item_ids = [
|
||||||
m["item_id"]
|
m["item_id"]
|
||||||
for m in ShelfMember.objects.filter(query_item_category(category))
|
for m in ShelfMember.objects.filter(query_item_category(category))
|
||||||
.filter(created_time__gt=timezone.now() - timedelta(days=days))
|
.filter(created_time__gt=timezone.now() - timedelta(days=days))
|
||||||
.values("item_id")
|
.values("item_id")
|
||||||
.annotate(num=Count("item_id"))
|
.annotate(num=Count("item_id"))
|
||||||
|
.filter(num__gte=MIN_MARKS)
|
||||||
.order_by("-num")[:MAX_GALLERY_ITEMS]
|
.order_by("-num")[:MAX_GALLERY_ITEMS]
|
||||||
]
|
]
|
||||||
return item_ids
|
return item_ids
|
||||||
|
|
||||||
|
def cleanup_shows(self, items):
|
||||||
|
seasons = [i for i in items if i.__class__ == TVSeason]
|
||||||
|
for season in seasons:
|
||||||
|
if season.show in items:
|
||||||
|
items.remove(season.show)
|
||||||
|
return items
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
if options["update"]:
|
if options["update"]:
|
||||||
cache_key = "public_gallery"
|
cache_key = "public_gallery"
|
||||||
|
@ -46,23 +55,26 @@ class Command(BaseCommand):
|
||||||
]
|
]
|
||||||
gallery_list = []
|
gallery_list = []
|
||||||
for category in gallery_categories:
|
for category in gallery_categories:
|
||||||
days = 30
|
days = 128
|
||||||
item_ids = []
|
item_ids = []
|
||||||
while len(item_ids) < MAX_GALLERY_ITEMS / 2 and days < 150:
|
while days > 4:
|
||||||
item_ids = self.get_popular_item_ids(category, days)
|
ids = [
|
||||||
days *= 3
|
i
|
||||||
items = list(
|
for i in self.get_popular_item_ids(category, days)
|
||||||
Item.objects.filter(id__in=item_ids).order_by("-created_time")
|
if i not in item_ids
|
||||||
)
|
]
|
||||||
|
if len(ids) > MAX_GALLERY_ITEMS // 5:
|
||||||
|
ids = ids[: MAX_GALLERY_ITEMS // 5]
|
||||||
|
self.stdout.write(f"{category} for last {days} days: {len(ids)}")
|
||||||
|
item_ids = ids + item_ids
|
||||||
|
days //= 2
|
||||||
|
items = list(Item.objects.filter(id__in=item_ids))
|
||||||
if category == ItemCategory.TV:
|
if category == ItemCategory.TV:
|
||||||
seasons = [i for i in items if i.__class__ == TVSeason]
|
items = self.cleanup_shows(items)
|
||||||
for season in seasons:
|
|
||||||
if season.show in items:
|
|
||||||
items.remove(season.show)
|
|
||||||
gallery_list.append(
|
gallery_list.append(
|
||||||
{
|
{
|
||||||
"name": "popular_" + category.value,
|
"name": "popular_" + category.value,
|
||||||
"title": "热门"
|
"title": ""
|
||||||
+ (category.label if category != ItemCategory.Book else "图书"),
|
+ (category.label if category != ItemCategory.Book else "图书"),
|
||||||
"items": items,
|
"items": items,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
[ -f manage.py ] || exit
|
[ -f manage.py ] || exit
|
||||||
echo Dry Run MakeMigrations:
|
echo Dry Run MakeMigrations:
|
||||||
python3 manage.py makemigrations --dry-run
|
python3 manage.py makemigrations --dry-run || exit $?
|
||||||
echo Planned Migrations:
|
echo Planned Migrations:
|
||||||
python3 manage.py migrate --plan
|
python3 manage.py migrate --plan || exit $?
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
read -p "Do you wish to continue? (yes/no) " yn
|
read -p "Do you wish to continue? (yes/no) " yn
|
||||||
|
@ -14,15 +14,13 @@ while true; do
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Generating static files..."
|
echo "Generating static files..."
|
||||||
python3 manage.py sass common/static/sass/boofilsic.sass common/static/css/boofilsic.min.css -t compressed || exit $?
|
python3 manage.py compilescss || exit $?
|
||||||
python3 manage.py sass common/static/sass/boofilsic.sass common/static/css/boofilsic.css || exit $?
|
|
||||||
python3 manage.py compilescss
|
|
||||||
python3 manage.py collectstatic --noinput || exit $?
|
python3 manage.py collectstatic --noinput || exit $?
|
||||||
|
|
||||||
echo "Migrating database..."
|
echo "Migrating database..."
|
||||||
python3 manage.py migrate || exit $?
|
python3 manage.py migrate || exit $?
|
||||||
|
|
||||||
echo "Checking..."
|
echo "Checking..."
|
||||||
python3 manage.py check
|
python3 manage.py check || exit $?
|
||||||
|
|
||||||
echo "Done. You may reload app, worker and cron"
|
echo "Done. You may reload app, worker and cron"
|
||||||
|
|
Loading…
Add table
Reference in a new issue