def update(id):
    data = Selfie.get_json(force=True)
    selfie = Selfie.query.filter(Selfie.id == id).first()
    if not selfie:
        abort(404)
    else:
        selife.picture = data['picture']
        db.session.commit()
        return jsonify({"status": "ok"})
예제 #2
0
def upload(request):
    if request.method == 'POST':
        form = SelfieForm(request.POST, request.FILES)
        if form.is_valid():
            instance = Selfie(photo=request.FILES['photo'])
            instance.user = request.user
            instance.info = form.cleaned_data["info"]
            instance.save()

            hist = History(selfie=instance, date=instance.pub_date, matches=0, score=1500)
            hist.save()

            img = Image.open(instance.photo.file)
            x1 = float(request.POST["x1"])
            x2 = float(request.POST["x2"])
            y1 = float(request.POST["y1"])
            y2 = float(request.POST["y2"])
            img.crop((x1, y1, x2, y2)).resize((640, 640)).save(instance.photo.file.file.name)

            print "new salfie: ", instance, "; anlisys result: ", instance.analyze()
            return HttpResponseRedirect(reverse('selfzone.panel:index'))
        return render(request, 'selfzone/uploadForm.html', {'form': form})
    else:
        form = SelfieForm()
        return render(request, 'selfzone/uploadForm.html', {'form': form})
예제 #3
0
def stats(request):
    context = {}

    # TODO: finish statistics
    # get numbers
    context["tot_selfie"] = Selfie.objects.count() - Selfie.get_unrecognized().count()
    context["tot_matches"] = Match.objects.count()

    male        = Selfie.get_tagged("male").count()
    female      = Selfie.get_tagged("female").count()
    young       = Selfie.get_tagged("young").count()
    old         = Selfie.get_tagged("old").count()
    baby        = Selfie.get_tagged("baby").count()
    neutral     = Selfie.get_tagged("neutral").count()
    sad         = Selfie.get_tagged("sad").count()
    anger       = Selfie.get_tagged("anger").count()
    happiness   = Selfie.get_tagged("happiness").count()
    surprise    = Selfie.get_tagged("surprise").count()

    data = [("gender", "percentage"), ("male", male), ("female", female)]
    chart = PieChart(SimpleDataSource(data=data), width="100%")
    context['gender_chart'] = chart

    data = [("age", "percentage"), ("baby", baby), ("young", young), ("old", old)]
    chart = PieChart(SimpleDataSource(data=data), width="100%")
    context['age_chart'] = chart

    data = [("face expression", "percentage"), ("neutral", neutral), ("sad", sad),
            ("anger", anger), ("happiness", happiness), ("surprise", surprise)]
    chart = PieChart(SimpleDataSource(data=data), width="100%")
    context['face_chart'] = chart

    context['allTimeBest']  = Selfie.objects.all().order_by("-score").all()[:3]
    context['allTimeWorst'] = reversed(Selfie.objects.all().order_by("score").all()[:3])

    day = History.objects.filter(date=timezone.now().date())
    context['todayBest']  = [h.selfie for h in day.order_by("-score").all()[:3]]
    context['todayWorst'] = reversed([h.selfie for h in day.order_by("score").all()[:3]])

    week = History.objects.filter(date__gte=timezone.now().date() - timezone.timedelta(timezone.now().weekday()))
    weeksum = week.values("selfie").annotate(totscore=Sum("score"))
    context['weekBest']  = [Selfie.objects.get(pk=h["selfie"]) for h in weeksum.order_by("-totscore").all()[:3]]
    context['weekWorst'] = reversed([Selfie.objects.get(pk=h["selfie"]) for h in weeksum.order_by("totscore").all()[:3]])

    context['day'] = timezone.now().day
    context['month'] = timezone.now().month
    context['year'] = timezone.now().year
    context['week'] = timezone.now().isocalendar()[1]
    return render(request, 'selfzone/stats.html', context)
def create():
    data = request.get_json(force=True)
    selfie = Selfie(picture=data['picture'])
    selfie = Selfie(qid=data['qid'])
    db.session.add(selfie)
    db.session.commit()