def render_chart(chart: Chart, data_format: str): if data_format == FORMAT_PNG: return HttpResponse(chart.render_png(), content_type='image/png') elif data_format == FORMAT_SVG: return HttpResponse(chart.render_svg(), content_type='image/svg+xml') elif data_format == FORMAT_JSON: return HttpResponse(chart.render_json(), content_type='application/json') else: raise Http404('Unknown plotting format %s.' % data_format)
def plot(self) -> Chart: df = get_fermentable_amount_range(self.fermentable) if len(df) == 0: raise NoDataException() figure = RangeBoxPlot().plot(df, 'amount_percent') return Chart(figure, 500, 350, title=self.get_chart_title())
def plot(self) -> Chart: df = FermentableAnalysis(self.fermentable).common_styles_absolute() if len(df) == 0: raise NoDataException() figure = BarChart().plot(df, 'beer_style', 'recipes', None, 'Total Number of Recipes') return Chart(figure, title=self.get_chart_title())
def plot(self) -> Chart: df = FermentableAnalysis(self.fermentable).popularity() if len(df) <= 1: # 1, because a single data point is also meaningless raise NoDataException() figure = LinesChart().plot(df, 'month', 'recipes_percent', 'fermentable', 'Month/Year', '% of All Recipes') return Chart(figure, height=Chart.DEFAULT_HEIGHT * 0.66, title=self.get_chart_title())
def plot(self) -> Chart: df = FermentableAnalysis(self.fermentable).amount_per_style() if len(df) == 0: raise NoDataException() figure = PreAggregatedBoxPlot().plot(df, 'beer_style', 'amount_percent', 'Style', '% of Weight in Recipe') return Chart(figure, title=self.get_chart_title())
def plot(self) -> Chart: df = FermentableAnalysis(self.fermentable).common_styles_relative() if len(df) == 0: raise NoDataException() figure = BarChart().plot(df, 'beer_style', 'recipes_percent', None, 'Used in % of the Style\'s Recipes') return Chart(figure, title=self.get_chart_title())
def plot(self) -> Chart: df = HopAnalysis(self.hop).amount_range() if len(df) == 0: raise NoDataException() figure = RangeBoxPlot().plot(df, 'amount_percent') return Chart(figure, 500, 350, title=self.get_chart_title())
def plot(self) -> Chart: df = HopAnalysis(self.hop).metric_histogram('beta') if len(df) == 0: raise NoDataException() figure = PreAggregateHistogramChart().plot(df, 'beta', 'count') return Chart(figure, 500, 350, title=self.get_chart_title())
def plot(self) -> Chart: df = get_style_metric_values(self.style, 'fg') if len(df) == 0: raise NoDataException() figure = PreAggregateHistogramChart().plot(df, 'fg', 'count') return Chart(figure, 500, 350, title=self.get_chart_title())
def plot(self) -> Chart: df = FermentableAnalysis(self.fermentable).metric_histogram('color_lovibond') if len(df) == 0: raise NoDataException() figure = PreAggregateHistogramChart().plot(df, 'color_lovibond', 'count') return Chart(figure, 500, 350, title=self.get_chart_title())
def plot(self) -> Chart: df = get_hop_amount_range_per_use(self.hop) if len(df) == 0: raise NoDataException() figure = PreAggregatedBoxPlot().plot(df, 'use', 'amount_percent', 'Usage', '% Amount') return Chart(figure, title=self.get_chart_title())
def plot(self) -> Chart: analysis = RecipesPopularityAnalysis(RecipeScope()) df = analysis.popularity_per_style(num_top=8, top_months=self.period_months) if len(df) <= 1: # 1, because a single data point is also meaningless raise NoDataException() figure = LinesChart(force_legend=True).plot(df, 'month', 'recipes_percent', 'beer_style', 'Month/Year', '% of All Recipes') return Chart(figure, height=Chart.DEFAULT_HEIGHT * 0.66, title=self.get_chart_title())
def plot(self) -> Chart: analysis = RecipesTrendAnalysis(RecipeScope()) df = analysis.trending_styles(trend_window_months=self.period_months) if len(df) == 0: raise NoDataException() figure = LinesChart(force_legend=True).plot(df, 'month', 'recipes_percent', 'beer_style', None, '% of All Recipes') return Chart(figure, title=self.get_chart_title())
def plot(self) -> Chart: df = get_fermentable_common_styles_relative(self.fermentable) if len(df) == 0: raise NoDataException() figure = BarChart().plot(df, 'style_name', 'recipes_percent', 'Style', 'Used in % Recipes') return Chart(figure, title=self.get_chart_title())
def plot(self) -> Chart: df = HopAnalysis(self.hop).amount_per_use() if len(df) == 0: raise NoDataException() figure = PreAggregatedBoxPlot().plot(df, 'use', 'amount_percent', 'Usage', '% of Weight in Recipe') return Chart(figure, title=self.get_chart_title())
def plot(self) -> Chart: df = get_hop_usage(self.hop) if len(df) == 0: raise NoDataException() figure = BarChart(add_margin=False).plot(df, 'use', 'recipes', None, None) return Chart(figure, 500, 350, title=self.get_chart_title())
def plot(self) -> Chart: df = get_style_popular_hops(self.style, self.get_use_filter()) if len(df) == 0: raise NoDataException() figure = PreAggregatedBoxPlot().plot(df, 'hop', 'amount_percent', 'Hops by Popularity', '% Amount') return Chart(figure, title=self.get_chart_title())
def plot(self) -> Chart: df = get_fermentable_amount_range_per_style(self.fermentable) if len(df) == 0: raise NoDataException() figure = PreAggregatedBoxPlot().plot(df, 'style', 'amount_percent', 'Style', '% Amount') return Chart(figure, title=self.get_chart_title())
def plot(self) -> Chart: df = get_fermentable_common_styles_absolute(self.fermentable) if len(df) == 0: raise NoDataException() figure = BarChart().plot(df, 'style_name', 'recipes', 'Style', 'Number Recipes') return Chart(figure, title=self.get_chart_title())
def plot(self) -> Chart: df = get_style_trending_hops(self.style) if len(df) == 0: raise NoDataException() figure = LinesChart().plot(df, 'month', 'recipes_percent', 'hop', 'Month/Year', '% Style Recipes') return Chart(figure, title=self.get_chart_title())
def plot(self) -> Chart: df = get_fermentable_pairing_fermentables(self.fermentable) if len(df) == 0: raise NoDataException() figure = PreAggregatedPairsBoxPlot().plot(df, 'pairing', 'fermentable', 'amount_percent', None, '% Amount') return Chart(figure, title=self.get_chart_title())
def plot(self) -> Chart: df = HopAnalysis(self.hop).pairings() if len(df) == 0: raise NoDataException() figure = PreAggregatedPairsBoxPlot().plot(df, 'pairing', 'hop', 'amount_percent', None, '% of Weight in Recipe') return Chart(figure, title=self.get_chart_title())
def plot(self) -> Chart: df = YeastAnalysis(self.yeast).trending_hops() if len(df) == 0: raise NoDataException() figure = LinesChart(force_legend=True).plot(df, 'month', 'recipes_percent', 'hop', None, '% of Yeast Recipes') return Chart(figure, title=self.get_chart_title())
def plot(self) -> Chart: analysis = HopAmountAnalysis(self.recipe_scope) df = analysis.per_hop(num_top=8) if len(df) == 0: raise NoDataException() figure = PreAggregatedBoxPlot().plot(df, 'hop', 'amount_percent', None, '% of Weight in Recipe') return Chart(figure, title=self.get_chart_title())
def plot(self) -> Chart: analysis = CommonStylesAnalysis(self.recipe_scope) df = analysis.common_styles_absolute(num_top=20) if len(df) == 0: raise NoDataException() figure = BarChart().plot(df, 'beer_style', 'recipes', None, 'Total Number of Recipes') return Chart(figure, title=self.get_chart_title())
def plot(self) -> Chart: analysis = CommonStylesAnalysis(self.recipe_scope) df = analysis.common_styles_relative(num_top=20) if len(df) == 0: raise NoDataException() figure = BarChart().plot(df, 'beer_style', 'recipes_percent', None, '% of the Style\'s Recipes') return Chart(figure, title=self.get_chart_title())
def plot(self) -> Chart: df = StyleAnalysis( self.style).popular_hops_amount(use_filter=self.filter_param) if len(df) == 0: raise NoDataException() figure = PreAggregatedBoxPlot().plot(df, 'hop', 'amount_percent', None, '% of Weight in Recipe') return Chart(figure, title=self.get_chart_title())
def plot(self) -> Chart: analysis = RecipesTrendAnalysis(self.recipe_scope) df = analysis.trending_hops(trend_window_months=24) if len(df) == 0: raise NoDataException() figure = LinesChart(force_legend=True).plot(df, 'month', 'recipes_percent', 'hop', None, '% of All Recipes') return Chart(figure, title=self.get_chart_title())
def plot(self) -> Chart: df = get_most_popular_hops() if len(df) <= 1: # 1, because a single data point is also meaningless raise NoDataException() figure = LinesChart().plot(df, 'month', 'recipes_percent', 'hop', 'Month/Year', '% Recipes') return Chart(figure, height=Chart.DEFAULT_HEIGHT * 0.66, title=self.get_chart_title())
def plot(self) -> Chart: (categories, types) = self.get_filter() df = get_style_popular_fermentables(self.style, categories, types) if len(df) == 0: raise NoDataException() figure = PreAggregatedBoxPlot().plot(df, 'fermentable', 'amount_percent', 'Fermentables by Popularity', '% Amount') return Chart(figure, title=self.get_chart_title())