{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "15527" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Work.objects.count()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2271" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "User.objects.count()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(0, {})" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "NB_WORKS_LIMIT = Work.objects.count()\n", "NB_USERS_LIMIT = User.objects.count()\n", "\n", "SearchIssue.objects.all().delete()\n", "# Profile.objects.all().delete() # Keeping some profiles would be better\n", "Suggestion.objects.all().delete()\n", "Recommendation.objects.all().delete()\n", "Pairing.objects.all().delete()\n", "SocialApp.objects.all().delete()\n", "Session.objects.all().delete()\n", "ContentType.objects.all().delete()\n", "# Reference.objects.all().delete()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from collections import Counter\n", "nb = Counter(Rating.objects.values_list('work_id', flat=True))\n", "if NB_WORKS_LIMIT:\n", " work_ids = list(Work.objects.values_list('id', flat=True))\n", " work_ids.sort(key=lambda work_id: -nb[work_id])\n", " Work.objects.exclude(id__in=work_ids[:NB_WORKS_LIMIT]).delete()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": true }, "outputs": [], "source": [ "if NB_WORKS_LIMIT:\n", " bundle = []\n", " for artist_ids in Work.objects.values_list('artists'):\n", " bundle.extend(artist_ids)\n", " kept_artist_ids = list(set([x for x in bundle if x is not None]))\n", " Artist.objects.exclude(id__in=kept_artist_ids).delete()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2403" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Artist.objects.count()" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "15527" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Work.objects.count()" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "334390" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Rating.objects.count()" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": true }, "outputs": [], "source": [ "max_user_id = max(User.objects.values_list('id', flat=True))" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(0, {})" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import random\n", "chosen = User.objects.order_by('?')[:NB_USERS_LIMIT]\n", "kept_ids = chosen.values_list('id', flat=True)\n", "User.objects.exclude(id__in=kept_ids).delete()" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2271" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "User.objects.count()" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "from django.utils import timezone\n", "new_ids = random.sample(range(max_user_id + 1, max_user_id + NB_USERS_LIMIT + 1), NB_USERS_LIMIT)\n", "for user, new_id in zip(User.objects.all(), new_ids):\n", " old_id = user.id\n", " user.pk = new_id\n", " user.username = str(new_id)\n", " user.is_superuser = False\n", " user.set_password('mangaki')\n", " user.email = '%d@mangaki.fr' % new_id\n", " user.date_joined = timezone.now()\n", " user.last_login = timezone.now()\n", " user.save()\n", " old_user = User.objects.get(id=old_id)\n", " old_user.rating_set.update(user=user)\n", " # old_user.profile.user = user\n", " old_user.delete()" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ ", , , , , , , , , , , , , , , , , , , , '...(remaining elements truncated)...']>" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "User.objects.all()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now, please make ``./mangaki/manage.py dumpdata > fixtures/seed_data.json``" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Counter({'auth.user': 200,\n", " 'irl.event': 38,\n", " 'irl.location': 2,\n", " 'irl.partner': 12,\n", " 'mangaki.artist': 48,\n", " 'mangaki.artistspelling': 48,\n", " 'mangaki.category': 3,\n", " 'mangaki.editor': 24,\n", " 'mangaki.genre': 34,\n", " 'mangaki.page': 4,\n", " 'mangaki.rating': 3161,\n", " 'mangaki.reference': 30,\n", " 'mangaki.role': 5,\n", " 'mangaki.staff': 100,\n", " 'mangaki.studio': 50,\n", " 'mangaki.top': 3,\n", " 'mangaki.work': 40})" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from collections import Counter\n", "import json\n", "j = json.load(open('../fixtures/seed_data.json'))\n", "# Currently\n", "\"\"\"Counter({'auth.group': 1,\n", " 'auth.user': 2271,\n", " 'irl.event': 84,\n", " 'irl.location': 2,\n", " 'irl.partner': 12,\n", " 'mangaki.artist': 2403,\n", " 'mangaki.artistspelling': 2394,\n", " 'mangaki.category': 3,\n", " 'mangaki.editor': 167,\n", " 'mangaki.extlanguage': 60,\n", " 'mangaki.faqentry': 1,\n", " 'mangaki.faqtheme': 1,\n", " 'mangaki.genre': 34,\n", " 'mangaki.language': 51,\n", " 'mangaki.page': 4,\n", " 'mangaki.profile': 2271,\n", " 'mangaki.rating': 334390,\n", " 'mangaki.reference': 10112,\n", " 'mangaki.role': 5,\n", " 'mangaki.staff': 8597,\n", " 'mangaki.studio': 55,\n", " 'mangaki.tag': 84,\n", " 'mangaki.taggedwork': 103,\n", " 'mangaki.top': 13,\n", " 'mangaki.work': 15527,\n", " 'mangaki.worktitle': 1114,\n", " 'sites.site': 1})})\"\"\"\n", "Counter(entry['model'] for entry in j)" ] } ], "metadata": { "kernelspec": { "display_name": "Django Shell-Plus", "language": "python", "name": "django_extensions" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.2" } }, "nbformat": 4, "nbformat_minor": 1 }