コード例 #1
0
 def test_cache_name(self):
     whisky_1, whisky_2 = self.test_suite.get_whiskies()
     chart = Chart(reference=whisky_1, comparison=whisky_2)
     cache_dir_path = chart.cache_path()
     cache_file_path = chart.cache_name(True)
     cache_name = chart.cache_name()
     self.assertEqual(cache_name, "110113221101x111113210202.svg")
     self.assertEqual(cache_file_path, cache_dir_path.child(cache_name).absolute())
コード例 #2
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)))
コード例 #3
0
ファイル: test_routes.py プロジェクト: astercraker/whiskyton
 def test_valid_chart(self):
     whisky_1, whisky_2 = self.test_suite.get_whiskies()
     chart = Chart(reference=whisky_1, comparison=whisky_2)
     cache_name = chart.cache_name(True)
     if cache_name.exists():
         cache_name.remove()
     svg = "{}-{}.svg".format(whisky_1.slug, whisky_2.slug)
     resp = self.app.get("/charts/{}".format(svg))
     self.assertEqual(resp.status_code, 200)
     self.assertEqual(resp.data.decode("utf-8").count("<polygon "), 6)
     self.assertEqual(resp.data.decode("utf-8").count("<text "), 12)
     self.assertEqual(resp.data.decode("utf-8").count("<g "), 4)
     self.assertEqual(resp.data.decode("utf-8").count('id="grid"'), 1)
     self.assertEqual(resp.data.decode("utf-8").count('id="label"'), 1)
     self.assertEqual(resp.data.decode("utf-8").count('id="reference"'), 1)
     self.assertEqual(resp.data.decode("utf-8").count('id="whisky"'), 1)
コード例 #4
0
ファイル: test_routes.py プロジェクト: QuerkyBren/whiskyton
 def test_valid_chart(self):
     whisky_1, whisky_2 = self.test_suite.get_whiskies()
     chart = Chart(reference=whisky_1, comparison=whisky_2)
     cache_name = chart.cache_name(True)
     if cache_name.exists():
         cache_name.remove()
     svg = '{}-{}.svg'.format(whisky_1.slug, whisky_2.slug)
     resp = self.app.get('/charts/{}'.format(svg))
     self.assertEqual(resp.status_code, 200)
     self.assertEqual(resp.data.count('<polygon '), 6)
     self.assertEqual(resp.data.count('<text '), 12)
     self.assertEqual(resp.data.count('<g '), 4)
     self.assertEqual(resp.data.count('id="grid"'), 1)
     self.assertEqual(resp.data.count('id="label"'), 1)
     self.assertEqual(resp.data.count('id="reference"'), 1)
     self.assertEqual(resp.data.count('id="whisky"'), 1)
コード例 #5
0
ファイル: files.py プロジェクト: QuerkyBren/whiskyton
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')
コード例 #6
0
ファイル: files.py プロジェクト: vkvns/whiskyton
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')
コード例 #7
0
ファイル: charts.py プロジェクト: cuducos/whiskyton
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)))
コード例 #8
0
ファイル: charts.py プロジェクト: vkvns/whiskyton
# coding: utf-8
コード例 #9
0
ファイル: charts.py プロジェクト: QuerkyBren/whiskyton
# coding: utf-8