master
parent
b811c13d27
commit
73e08cfdd6
File diff suppressed because one or more lines are too long
|
@ -3,7 +3,8 @@
|
|||
from django.contrib import admin
|
||||
|
||||
|
||||
from papiezator.models import Pope, PopeVersion
|
||||
from papiezator.models import Pope, PopeVersion, PerfectPope
|
||||
|
||||
admin.site.register(Pope)
|
||||
admin.site.register(PopeVersion)
|
||||
admin.site.register(PerfectPope)
|
||||
|
|
|
@ -1,18 +1,24 @@
|
|||
from django.db import models
|
||||
|
||||
class Pope(models.Model):
|
||||
pope_path = models.CharField(max_length=200)
|
||||
pope_version = models.ForeignKey('PopeVersion')
|
||||
decimal_places = 3
|
||||
|
||||
aspect_ratio = models.DecimalField(max_digits=3, decimal_places=2)
|
||||
class Pope(models.Model):
|
||||
path = models.CharField(max_length=200)
|
||||
width = models.IntegerField()
|
||||
height = models.IntegerField()
|
||||
# Create your models here.
|
||||
aspect_ratio = models.DecimalField(max_digits=6, decimal_places=decimal_places)
|
||||
pope_version = models.ForeignKey('PopeVersion')
|
||||
|
||||
def __str__(self):
|
||||
return self.path.split('/')[-1]
|
||||
|
||||
class PopeVersion(models.Model):
|
||||
pope_id = models.AutoField(primary_key=True)
|
||||
pope_name = models.CharField(max_length=200)
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return self.pope_name
|
||||
|
||||
class PerfectPope(models.Model):
|
||||
aspect_ratio = models.DecimalField(max_digits=6, decimal_places=decimal_places)
|
||||
pope = models.ForeignKey('Pope')
|
||||
|
|
|
@ -1,12 +1,34 @@
|
|||
from papiezator.models import Pope
|
||||
from papiezator.models import Pope, PerfectPope, decimal_places
|
||||
from PIL import Image
|
||||
from os import path
|
||||
import decimal
|
||||
PREFIX = "popes"
|
||||
|
||||
|
||||
|
||||
def select_best_pope(width,height):
|
||||
return "papiez.jpg"
|
||||
def select_best_pope(aspect_ratio):
|
||||
pp = PerfectPope.objects.filter(aspect_ratio=aspect_ratio)
|
||||
if pp:
|
||||
return pp[0].pope.path
|
||||
aspect_ratio = decimal.Decimal(aspect_ratio)
|
||||
lte = Pope.objects.filter(aspect_ratio__lte=aspect_ratio).order_by('-aspect_ratio')
|
||||
gte = Pope.objects.filter(aspect_ratio__gte=aspect_ratio).order_by('aspect_ratio')
|
||||
|
||||
if not gte:
|
||||
return lte[0].path
|
||||
elif not lte:
|
||||
return gte[0].path
|
||||
elif not gte and not lte:
|
||||
return "papiez.jpg"
|
||||
else:
|
||||
r_lte = abs(aspect_ratio/lte[0].aspect_ratio)
|
||||
r_gte = abs(aspect_ratio/gte[0].aspect_ratio)
|
||||
if r_lte >= r_gte:
|
||||
pp = PerfectPope(aspect_ratio=aspect_ratio, pope=gte[0]).save()
|
||||
return gte[0].path
|
||||
else:
|
||||
pp = PerfectPope(aspect_ratio=aspect_ratio, pope=lte[0]).save()
|
||||
return lte[0].path
|
||||
|
||||
class PopeMaster:
|
||||
def __init__(self):
|
||||
|
@ -19,24 +41,5 @@ class PopeMaster:
|
|||
def parse_pope(self, pope):
|
||||
im = Image.open(pope)
|
||||
width, height = im.size
|
||||
Pope(pope, width, height)
|
||||
aspect_ratio = round(width/height, 2)
|
||||
print(pope, width, height,aspect_ratio)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import os
|
||||
|
||||
os.environ ['PYTHONPATH'] = '/home/daz/Documents/Projects/Py/django/papiez_ipsum'
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'papiez_ipsum.settings'
|
||||
|
||||
os.chdir("../")
|
||||
print(os.getcwd())
|
||||
|
||||
|
||||
pm = PopeMaster()
|
||||
|
||||
with open('popes/pope_list') as file:
|
||||
for line in file:
|
||||
pope = line.rstrip()
|
||||
pm.parse_pope(path.join(PREFIX, pope))
|
||||
aspect_ratio = round(width/height, decimal_places)
|
||||
return Pope(path=pope, width=width, height=height, aspect_ratio=aspect_ratio)
|
||||
|
|
|
@ -6,13 +6,51 @@
|
|||
<title> </title>
|
||||
<link rel="stylesheet" href="">
|
||||
</head>
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
|
||||
<script src="//code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
|
||||
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css"/>
|
||||
|
||||
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap-theme.min.css">
|
||||
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script>
|
||||
|
||||
<style>
|
||||
@media (min-width: 768px) {
|
||||
.container {
|
||||
max-width: 730px;
|
||||
}
|
||||
}
|
||||
.pope {
|
||||
display: inline;
|
||||
}
|
||||
</style>
|
||||
|
||||
<img src="{% url 'papiezator:conclave' 200 300 %}">
|
||||
<img src="{% url 'papiezator:conclave' 150 250 %}">
|
||||
<img src="{% url 'papiezator:conclave' 350 100 %}">
|
||||
<body>
|
||||
<div class="container">
|
||||
|
||||
<div class="header">
|
||||
<h3 class="text-muted">Fumata bianca</h3>
|
||||
</div>
|
||||
|
||||
<div class="jumbotron">
|
||||
Get your popes over 9000 times faster!
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-5">
|
||||
<h2>Get your popes</h2>
|
||||
<img class="pope" src="{% url 'papiezator:conclave' 255 200 %}">
|
||||
<img class="pope" src="{% url 'papiezator:conclave' 125 100 %}">
|
||||
<img class="pope" src="{% url 'papiezator:conclave' 125 100 %}">
|
||||
</div>
|
||||
<div class="col-xs-7">
|
||||
<h2>Get your popes today</h2>
|
||||
<img class="pope" src="{% url 'papiezator:conclave' 150 200 %}">
|
||||
<img class="pope" src="{% url 'papiezator:conclave' 150 200 %}">
|
||||
<img class="pope" src="{% url 'papiezator:conclave' 300 100 %}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
|
|
|
@ -16,7 +16,8 @@ def conclave(request, width, height):
|
|||
width, height = int(width), int(height)
|
||||
|
||||
|
||||
pope = select_best_pope(width, height)
|
||||
aspect_ratio = width/height
|
||||
pope = select_best_pope(aspect_ratio)
|
||||
|
||||
im = Image.open(pope)
|
||||
im = im.resize((width, height))
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
import os
|
||||
os.environ ['PYTHONPATH'] = '/home/daz/Documents/Projects/Py/django/papiez_ipsum'
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'papiez_ipsum.settings'
|
||||
#!/usr/bin/env python
|
||||
from papiezator.models import Pope, PopeVersion
|
||||
from papiezator.pope_utils import PopeMaster
|
||||
from os import path
|
||||
|
||||
PREFIX = "popes"
|
||||
|
||||
|
||||
pm = PopeMaster()
|
||||
|
||||
with open('popes/JP2_list') as file:
|
||||
jp2 = PopeVersion(0, "John Paul II")
|
||||
jp2.save()
|
||||
for line in file:
|
||||
pope = line.rstrip()
|
||||
p = pm.parse_pope(path.join(PREFIX, pope))
|
||||
p.pope_version = jp2
|
||||
p.save()
|
||||
print(p)
|
||||
|
Loading…
Reference in New Issue