Web M&M
https://mam.matfyz.cz
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
177 lines
8.0 KiB
177 lines
8.0 KiB
# -*- coding: utf-8 -*-
|
|
|
|
import datetime
|
|
import random
|
|
import django.contrib.auth
|
|
from django.db import transaction
|
|
import unidecode
|
|
|
|
from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, PrilohaReseni, Nastaveni, Soustredeni, Soustredeni_Ucastnici
|
|
|
|
from django.contrib.flatpages.models import FlatPage
|
|
from django.contrib.sites.models import Site
|
|
|
|
User = django.contrib.auth.get_user_model()
|
|
|
|
@transaction.atomic
|
|
def create_test_data(size = 6, rnd = None):
|
|
assert size >= 1
|
|
# pevna pseudo-nahodnost
|
|
rnd = rnd or random.Random(x=42)
|
|
|
|
# static URL stranky
|
|
# FIXME: nakopirovat sem vsechny z produkcni databaze
|
|
s = Site.objects.filter(name="example.com")
|
|
f = FlatPage.objects.create(url="/", title="Seminář M&M", content = "<p>Vítejte na stránce semináře MaM!</p>")
|
|
f.sites.add(s[0])
|
|
f.save()
|
|
|
|
# users
|
|
admin = User.objects.create_superuser(username='admin', email='', password='admin')
|
|
|
|
usernames = ['anet', 'bara', 'cyril', 'david', 'eva', 'filip']
|
|
orgs = []
|
|
for org in usernames[:size]:
|
|
o = User.objects.create_user(username=org, password=org)
|
|
o.first_name = org.capitalize()
|
|
o.save()
|
|
orgs.append(o)
|
|
|
|
# skoly
|
|
skoly = []
|
|
skoly.append(Skola.objects.create(mesto = 'Praha', stat='CZ', psc='101 00', ulice='Krátká 5',
|
|
nazev='První ZŠ', je_zs=True, je_ss=False))
|
|
skoly.append(Skola.objects.create(mesto = 'Praha', stat='CZ', psc='101 00', ulice='Krátká 5',
|
|
nazev='První SŠ', je_zs=False, je_ss=True))
|
|
skoly.append(Skola.objects.create(mesto = 'Praha', stat='CZ', psc='102 00', ulice='Dlouhá 5',
|
|
nazev='Druhá SŠ', je_zs=False, je_ss=True))
|
|
skoly.append(Skola.objects.create(mesto = 'Praha', stat='CZ', psc='103 00', ulice='Široká 3',
|
|
nazev='Třetí SŠ a ZŠ', je_zs=True, je_ss=True))
|
|
skoly.append(Skola.objects.create(mesto = 'Ostrava', stat='CZ', psc='700 00', ulic='Hluboká 42',
|
|
nazev='Hutní gympl', je_zs=False, je_ss=True))
|
|
skoly.append(Skola.objects.create(mesto = 'Humenné', stat='SK', psc='012 34', ulice='Pltká 1',
|
|
nazev='Sredná škuola', je_zs=False, je_ss=True))
|
|
#FIXME pridat kontaktni osobu alespon nekde
|
|
skoly.append(zlinska = Skola.objects.create(mesto = 'Zlín', stat='CZ', psc='76001',
|
|
ulice='náměstí T.G. Masaryka 2734-9', nazev='Gymnázium a Střední jazyková škola s právem SJZ',
|
|
kratky_nazev="GaSJŠspSJZ", je_zs=True, je_ss=True))
|
|
|
|
# osoby
|
|
jmena_m = ['Aleš', 'Tomáš', 'Martin', 'Jakub', 'Petr', 'Lukáš', 'Cyril', 'Pavel Karel']
|
|
jmena_f = ['Eva', 'Karolína', 'Zuzana', 'Sylvie', 'Iva', 'Jana', 'Marie', 'Marta Iva', 'Shu Shan']
|
|
prijmeni_m = ['Novotný', 'Svoboda', 'Pecha', 'Kořen', 'Holan', 'Uhlíř', 'Chytráček', 'Pokora',
|
|
'Koch', 'Szegedy', 'Rudý', "von Neumann", "d'Este"]
|
|
prijmeni_f = ['Novotná', 'Svobodová', 'Machová', 'Zelená', 'Yu-Xin', 'Mlsná', 'Dubná', 'Mrkvová',
|
|
'Suchá', 'Lovelace', 'Holcová', 'Rui']
|
|
prezdivka = ['Kaki', 'Hurdur', 'Maracuja', 'Bobbo', None, None, None, None, None, None, None,
|
|
'Riki', 'Sapa', None, '', '---', 'Koko']
|
|
domain = ['example.com', 'dolujeme.eu', 'mff.cuni.cz', 'strcprstskrzkrk.cz', 'british.co.uk',
|
|
'splachni.to', 'haha.org']
|
|
seznam_ulic = ['Krátká', 'Vlhká', 'Jungmanova', '17. listopadu', '4. října', 'Roztocká',
|
|
'Forstova', 'Generála Františka Janouška', 'Náměstí Války', 'Svratecké náměstí',
|
|
'Zelená lhota', 'Z Plynu', 'K Jezeru', 'U Kocourkova', 'Uštěpačná', 'Ostrorepská',
|
|
'Zubří']
|
|
seznam_mest = ['Praha', 'Brno', 'Ostrava', 'Horní Jelení', 'Dolní Zábrdovice', 'Prdelkov',
|
|
'Stará myslivna', 'Kocourkov', 'Šalingrad', 'Medvědí hora', 'Basilej',
|
|
'Unterschiedlich', 'Old York', 'Lancastershire', 'Vóloďháza']
|
|
|
|
osoby = []
|
|
for i in range(3 * size):
|
|
pohlavi = rnd.randint(0,1)
|
|
jmeno = rnd.choice([jmena_m, jmena_f][pohlavi])
|
|
prijmeni = rnd.choice([prijmeni_m, prijmeni_f][pohlavi])
|
|
prezdivka = rnd.choice(prezdivka)
|
|
email = "@".join([unidecode.unidecode(jmeno), rnd.choice(domain)])
|
|
telefon = [rnd.choice([k for k in range(10)]) for i in range(10)]
|
|
narozeni = datetime.date(rnd.randint(1980, 2020), rnd.randint(1, 12), rnd.randint(1, 28))
|
|
ulic = rnd.choice([seznam_ulic])
|
|
cp = rnd.int(1, 99)
|
|
ulice = " ".join(ulic, cp)
|
|
mesto = rnd.choice([seznam_mest])
|
|
psc = [rnd.choice([k for k in range(10)]) for i in range(6)]
|
|
osoby.append(Osoba.objects.create(jmeno = jmeno, prijmeni = prijmeni, prezdivka = prezdivka,
|
|
pohlavi_muz = pohlavi, email = email, telefon = telefon, datum_narozeni = narozeni,
|
|
ulice = ulice, mesto = mesto, psc = psc,
|
|
datum_registrace = datetime.date(rnd.randint(2019, 2029), rnd.randint(1, 12),
|
|
rnd.randint(1, 28))))
|
|
#TODO pridat foto male a velke. Jak?
|
|
|
|
# resitele a organizatori
|
|
last_rocnik = 25
|
|
resitele = []
|
|
organizatori = []
|
|
for os in osoby:
|
|
rand = rnd.randint(0, 8)
|
|
if not (rand % 8 == 0):
|
|
resitele.append(Resitel.objects.create(osoba = os, skola = rnd.choice([skoly]),
|
|
rok_maturity = rnd.randint(2019, 2029),
|
|
zasilat = rnd.choice(Resitel.ZASILAT_CHOICES)))
|
|
else:
|
|
pusobnost = rnd.randint(1, last_rocnik)
|
|
od = 1993 + last_rocnik - pusobnost
|
|
do = od + rnd.randint(1, 8)
|
|
# aktualni organizatori jeste nemaji vyplnene organizuje_do
|
|
if do > datetime.now().year:
|
|
do = None
|
|
organizatori.append(Organizator.objects.create(osoba = os, organizuje_od = od,
|
|
organizuje_do = do))
|
|
|
|
# rocniky
|
|
for ri in range(min(last_rocnik - size, 1), last_rocnik + 1):
|
|
r = Rocnik.objects.create(prvni_rok = 1993 + ri, rocnik = ri)
|
|
|
|
# cisla
|
|
cisel = rnd.randint(4, 8)
|
|
|
|
slovnik_cisel = {}
|
|
for ci in range(1, cisel + 1):
|
|
if ci >= 3:
|
|
vydano = datetime.date(r.prvni_rok, ci + 6, rnd.randint(1, 28))
|
|
deadline = datetime.date(r.prvni_rok, ci + 8, rnd.randint(1, 28))
|
|
else:
|
|
vydano = datetime.date(r.druhy_rok, ci - 3, rnd.randint(1, 28))
|
|
# posledni 2 cisla v rocniku nemaji deadline
|
|
if (ci + 2 > cisel):
|
|
deadline = datetime.date(r.druhy_rok, ci - 1, rnd.randint(1, 28))
|
|
else:
|
|
deadline = None
|
|
cislo = Cislo.objects.create(rocnik = r, cislo = str(ci), datum_vydani=vydano,
|
|
datum_deadline=deadline, verejne_db=True)
|
|
slovnik_cisel[ci] = cislo
|
|
|
|
# FIXME: misto typu ruzne typy objektu a vnoreni do sebe
|
|
# TODO: vytvorit temata s ruznymi vlakny
|
|
# TODO: nagenerovat starsim rocnikum pohadku
|
|
|
|
# problemy resene v ci
|
|
# seq='#ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
|
# if ci >= 3:
|
|
# for pi in range(1, ((size + 1) // 2) + 1):
|
|
# p = Problem.objects.create(autor = rnd.choice(orgs), cislo_zadani=cs[ci-2],
|
|
# cislo_reseni=cs[ci], opravovatel = rnd.choice(orgs), kod = str(pi),
|
|
# nazev = u'Dummy úloha %s-%s' % (seq[ci], seq[pi]),
|
|
# stav = Problem.STAV_ZADANY, typ = Problem.TYP_ULOHA, body = rnd.randint(1, 5))
|
|
# p.text_problemu = (u"<p>Text problému <strong>%s.%s %s</strong><em> [id %d]</em> za %d body.</p>" %
|
|
# (p.cislo_zadani.kod(), p.kod, p.nazev, p.id, p.body))
|
|
# p.text_problemu_org = u"<p><strong>Neveřejný</strong> text problému.</p>"
|
|
# p.save()
|
|
#
|
|
# poc_reseni = rnd.randint(size // 2, size * 2)
|
|
# res_sel = rnd.sample(resitele, min(poc_reseni, len(resitele) - 2))
|
|
# for resitel in res_sel:
|
|
# res = Reseni.objects.create(problem = p, resitel = resitel,
|
|
# body = rnd.randint(0, p.body), cislo_body = cs[ci])
|
|
#
|
|
# TODO: nahodne nagenerovat problemum reseni a prilohy reseni, hodnoceni
|
|
|
|
|
|
# TODO: vice soustredeni a k nim nahodne podmnoziny organizatoru a ucastniku
|
|
sous = Soustredeni.objects.create(rocnik=Rocnik.objects.first(), verejne_db=True, misto=u'Někde',
|
|
datum_zacatku=datetime.date(2000, 11, 23), datum_konce=datetime.date(2000, 11, 27))
|
|
for res in rnd.sample(resitele, 6):
|
|
Soustredeni_Ucastnici.objects.create(resitel=res, soustredeni=sous)
|
|
sous.save()
|
|
|
|
nastaveni = Nastaveni.objects.create(aktualni_rocnik = Rocnik.objects.last(),
|
|
aktualni_cislo = Cislo.objects.all()[1])
|
|
|
|
|