How to use the typer.models.TypedDie function in typer

To help you get started, we’ve selected a few typer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github andrew-gardner / django-monkeys / typer / views.py View on Github external
def adminStatisticsView(request, dieName):
    """
    """
    dieObject = Die.objects.filter(name=dieName)[0]

    # Get how many fields and how many have been typed
    allFields = TypedDie.objects.filter(Q(dieImage__die=dieObject))
    typedFields = TypedDie.objects.filter(Q(dieImage__die=dieObject) & ~Q(typedField=""))

    # Get a list of who's on first
    scoreboard = list()
    for user in User.objects.all():
        userTyped = TypedDie.objects.filter(~Q(typedField="") & Q(submitter=user) & Q(dieImage__die=dieObject))
        scoreboard.append( (user, len(userTyped)) )
    sortedScores = sorted(scoreboard, key=lambda tup: tup[1], reverse=True)

    context = {
                  'die' : dieObject,
                  'allFieldCount' : len(allFields),
                  'allTypedCount' : len(typedFields),
                  'scoreboard' : sortedScores
              }
    return render(request, 'typer/adminStatistics.html', context)
github andrew-gardner / django-monkeys / typer / views.py View on Github external
"""
    This view displays a randomly choosen DieImage for a given Die.  Secret
    data about which die has been randomly chosen passes through to the POST
    method since this view decides it dynamically.

    Note:
    allAvailableFields = allAvailableFields.exclude(Q(dieImage=tuht.dieImage))
    Resulted in large AND NOT query after adding many entries
    Instead two separate queries and subtract out manually
    """
    userIsStaff = request.user.is_staff

    if request.method == 'GET':
        # Standard page display
        dieObject = Die.objects.filter(name=dieName)[0]
        allAvailableFields = TypedDie.objects.filter(Q(typedField="") & Q(dieImage__die=dieObject))

        thingsUserHasTyped = TypedDie.objects.filter(~Q(typedField="") & Q(submitter=request.user) & Q(dieImage__die=dieObject))
        setTyped = [td.dieImage_id for td in thingsUserHasTyped]
        usableFields = list(filter(lambda x: x.dieImage_id not in setTyped, allAvailableFields))
        #print 'avail', len(allAvailableFields)
        #print 'typed', len(setTyped)
        #print 'usable', len(usableFields)

        if not usableFields:
            return HttpResponse("All fields have been typed for this die. Check back later to see if there are other dies to type.")

        # Choose a random field to display
        randomField = random.randint(0, len(usableFields)-1)
        randomId = usableFields[randomField].id

        # Display the random page
github andrew-gardner / django-monkeys / tools / time_view.py View on Github external
# Time per view
    print 'Querying...'
    
    users = None
    if USER == '*':
        print 'User: all individual'
        users = active_users()
        print '%d active users' % len(users)
    elif USER:
        print 'User: %s' % USER 
    else:
        print 'User: all aggregate'
    times = {}
    entries = 0
    for td in TypedDie.objects.all():
        if not interesting(td):
            continue
        #subfreq[td.submitter] = subfreq.get(td.submitter, 0) + 1
        #print date_mils(td.submitDate)
        #delta = td.submitDate - td.submitDate
        #print delta.total_seconds()
        k = str(td.submitter)
        if k in times:
            l = times[k]
        else:
            l = []
            times[k] = l
        l.append(td.submitDate)
        entries += 1

    def run_user(user):
github andrew-gardner / django-monkeys / tools / freq_dist.py View on Github external
def run(user, image, verbose=False):
    stats.USER = user
    stats.IMG = image

    buckets = {}

    print 'Querying...'
    for tdi, td in enumerate(TypedDie.objects.all()):

        if not interesting(td):
            if tdi % 256 == 0:
                sys.stdout.write('.')
                sys.stdout.flush()
            continue
        if tdi % 256 == 0:
            sys.stdout.write('+')
            sys.stdout.flush()

        # td.typedField
        #addk(subfreq, td.submitter)
        k = str(td.dieImage.image)
        if k in buckets:
            m = buckets[k]
        else:
github andrew-gardner / django-monkeys / tools / db2bin.py View on Github external
def get_dist(img_want):
    dist = {}
    matches = 0
    for tdi, td in enumerate(TypedDie.objects.all()):
        if not isimg(td, img_want):
            if tdi % 256 == 0:
                sys.stdout.write('.')
                sys.stdout.flush()
            continue
        if tdi % 256 == 0:
            sys.stdout.write('+')
            sys.stdout.flush()

        # sega_315-5571_xpol/sega_315-5571_xpol_01_09.png
        fn = str(td.dieImage.image)
        m = re.match(r'.*/(.*)_([0-9]*)_([0-9]*).png', fn)
        if not m:
            raise Exception()
        #print fn
        matches += 1
github andrew-gardner / django-monkeys / tools / stats.py View on Github external
def active_users():
    users = set()
    for td in TypedDie.objects.all():
        if not td.submitter:
            continue
        if not interesting(td):
            continue
        users.add(str(td.submitter))
    return users
github andrew-gardner / django-monkeys / typer / views.py View on Github external
def imageInput(request, fieldId, error=None, fieldData=None):
    """
    Helper function for the indexView - responsible for creating the page
    that features the input interface & possible error messages.
    """
    # Recover the requested die image and its corresponding die
    dieField = get_object_or_404(TypedDie, id=fieldId)
    di = dieField.dieImage
    d = di.die

    # Populate the form with the raw data from the previous submit if there was an error
    if error and fieldData:
        form = MonkeyTyperForm(instance=dieField, initial={'typedField': fieldData})
    else:
        form = MonkeyTyperForm(instance=dieField)

    # Prune off just the filename from the dieImage url
    dieImageBasename = os.path.basename(dieField.dieImage.image.url)

    # Display the input page
    context = {
                  'die': d,
                  'dieImage': di,
github andrew-gardner / django-monkeys / typer / admin.py View on Github external
from django.contrib import admin

from .models import Die, DieImage, TypedDie

admin.site.register(Die)
admin.site.register(DieImage)
admin.site.register(TypedDie)