Esempio n. 1
0
def create():
    """Create all charts as cache"""

    # support vars
    different_tastes = list()
    count = 0
    size = 0

    # get whiskies
    whiskies = Whisky.query.all()
    for whisky in whiskies:
        tastes = whisky.get_tastes()
        if tastes not in different_tastes:
            different_tastes.append(tastes)
    total = len(different_tastes) * (len(different_tastes) - 1.0)

    # combination
    for reference in different_tastes:
        for whisky in different_tastes:
            if whisky != reference:
                chart = Chart(reference=reference, comparison=whisky)
                file_name = chart.cache_name(True)
                if file_name.exists():
                    file_name.remove()
                chart.cache()
                size += file_name.size()
                count += 1
                print("%s Created %s (%s)" % (
                    percent(count / total),
                    file_name.absolute(),
                    file_size(file_name.size()),
                ))
    print("%s charts created (%s)" % (count, file_size(size)))
Esempio n. 2
0
def create_chart(reference_slug, whisky_slug):

    # get whisky objects form db
    reference_obj = models.Whisky.query.filter_by(slug=reference_slug).first()
    whisky_obj = models.Whisky.query.filter_by(slug=whisky_slug).first()

    # error page if whisky doesn't exist
    if reference_obj is None or whisky_obj is None:
        return abort(404)

    # if file does not exists, create it
    chart = Chart(reference=reference_obj, comparison=whisky_obj)
    filename = chart.cache_name(True)
    if not filename.exists():
        chart.cache()

    # return the chart to the user
    return Response(filename.read_file(), mimetype='image/svg+xml')
Esempio n. 3
0
 def test_create_and_cache(self):
     base_dir = app.config['BASEDIR']
     whisky_1, whisky_2 = self.test_suite.get_whiskies()
     chart = Chart(reference=whisky_1, comparison=whisky_2)
     contents = chart.create()
     cached = chart.cache()
     sample = base_dir.child('whiskyton', 'tests', 'chart_sample.svg')
     self.assertEqual(contents, cached.read_file())
     self.assertEqual(contents, sample.read_file())
Esempio n. 4
0
def create_chart(reference_slug, whisky_slug):

    # get whisky objects form db
    reference_obj = models.Whisky.query.filter_by(slug=reference_slug).first()
    whisky_obj = models.Whisky.query.filter_by(slug=whisky_slug).first()

    # error page if whisky doesn't exist
    if reference_obj is None or whisky_obj is None:
        return abort(404)

    # if file does not exists, create it
    chart = Chart(reference=reference_obj, comparison=whisky_obj)
    filename = chart.cache_name(True)
    if not filename.exists():
        chart.cache()

    # return the chart to the user
    return Response(filename.read_file(), mimetype='image/svg+xml')
Esempio n. 5
0
 def test_create_and_cache(self):
     base_dir = app.config["BASEDIR"]
     whisky_1, whisky_2 = self.test_suite.get_whiskies()
     chart = Chart(reference=whisky_1, comparison=whisky_2)
     contents = chart.create()
     cached = chart.cache()
     sample = base_dir.child("whiskyton", "tests", "chart_sample.svg")
     self.assertEqual(contents, cached.read_file())
     self.assertEqual(contents, sample.read_file())
Esempio n. 6
0
def create():
    """Create all charts as cache"""

    # support vars
    different_tastes = list()
    count = 0
    size = 0

    # get whiskies
    whiskies = Whisky.query.all()
    for whisky in whiskies:
        tastes = whisky.get_tastes()
        if tastes not in different_tastes:
            different_tastes.append(tastes)
    total = len(different_tastes) * (len(different_tastes) - 1.0)

    # combination
    for reference in different_tastes:
        for whisky in different_tastes:
            if whisky != reference:
                chart = Chart(reference=reference, comparison=whisky)
                file_name = chart.cache_name(True)
                if file_name.exists():
                    file_name.remove()
                chart.cache()
                size += file_name.size()
                count += 1
                print(
                    "%s Created %s (%s)"
                    % (
                        percent(count / total),
                        file_name.absolute(),
                        file_size(file_name.size()),
                    )
                )
    print("%s charts created (%s)" % (count, file_size(size)))
Esempio n. 7
0
# coding: utf-8
Esempio n. 8
0
# coding: utf-8