Python django.db.models.aggregates.Avg() Examples

The following are code examples for showing how to use django.db.models.aggregates.Avg(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: liberator   Author: libscie   File: operations.py    Creative Commons Zero v1.0 Universal 6 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                    if isinstance(output_field, bad_fields):
                        raise NotImplementedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        )
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass 
Example 2
Project: banruo   Author: yingshang   File: operations.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass
                else:
                    if isinstance(output_field, bad_fields):
                        raise utils.NotSupportedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        ) 
Example 3
Project: PopularityBased-SearchEngine   Author: rsunder10   File: operations.py    MIT License 6 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                    if isinstance(output_field, bad_fields):
                        raise NotImplementedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        )
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass 
Example 4
Project: news_proj   Author: TheoElia   File: operations.py    MIT License 6 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass
                else:
                    if isinstance(output_field, bad_fields):
                        raise utils.NotSupportedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        )
        if isinstance(expression, aggregates.Aggregate) and len(expression.source_expressions) > 1:
            raise utils.NotSupportedError(
                "SQLite doesn't support DISTINCT on aggregate functions "
                "accepting multiple arguments."
            ) 
Example 5
Project: Bookmark   Author: AnkurRyder   File: operations.py    MIT License 6 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                    if isinstance(output_field, bad_fields):
                        raise NotImplementedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        )
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass 
Example 6
Project: EvenniaPluginSampleProject   Author: castlelorestudios   File: operations.py    BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                    if isinstance(output_field, bad_fields):
                        raise NotImplementedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        )
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass 
Example 7
Project: vue-django-element-django   Author: jonathanmusto   File: operations.py    MIT License 6 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass
                else:
                    if isinstance(output_field, bad_fields):
                        raise NotImplementedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        ) 
Example 8
Project: encarnia   Author: whitehorse-io   File: operations.py    MIT License 6 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                    if isinstance(output_field, bad_fields):
                        raise NotImplementedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        )
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass 
Example 9
Project: eperpus   Author: HilmiZul   File: operations.py    MIT License 6 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass
                else:
                    if isinstance(output_field, bad_fields):
                        raise utils.NotSupportedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        )
        if isinstance(expression, aggregates.Aggregate) and len(expression.source_expressions) > 1:
            raise utils.NotSupportedError(
                "SQLite doesn't support DISTINCT on aggregate functions "
                "accepting multiple arguments."
            ) 
Example 10
Project: Gypsy   Author: benticarlos   File: operations.py    MIT License 6 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                    if isinstance(output_field, bad_fields):
                        raise NotImplementedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        )
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass 
Example 11
Project: tribune   Author: alex-muliande   File: operations.py    MIT License 6 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                    if isinstance(output_field, bad_fields):
                        raise NotImplementedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        )
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass 
Example 12
Project: Loop   Author: JasdipChauhan   File: operations.py    Apache License 2.0 6 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                    if isinstance(output_field, bad_fields):
                        raise NotImplementedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        )
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass 
Example 13
Project: Hands-On-Application-Development-with-PyCharm   Author: PacktPublishing   File: operations.py    MIT License 6 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass
                else:
                    if isinstance(output_field, bad_fields):
                        raise utils.NotSupportedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        ) 
Example 14
Project: python   Author: Yeah-Kun   File: operations.py    Apache License 2.0 6 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                    if isinstance(output_field, bad_fields):
                        raise NotImplementedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        )
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass 
Example 15
Project: Django_To_Do   Author: IEEE-VIT   File: operations.py    MIT License 6 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass
                else:
                    if isinstance(output_field, bad_fields):
                        raise utils.NotSupportedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        )
        if isinstance(expression, aggregates.Aggregate) and len(expression.source_expressions) > 1:
            raise utils.NotSupportedError(
                "SQLite doesn't support DISTINCT on aggregate functions "
                "accepting multiple arguments."
            ) 
Example 16
Project: AyurGenomics-Viz-ML   Author: rintukutum   File: operations.py    MIT License 6 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass
                else:
                    if isinstance(output_field, bad_fields):
                        raise utils.NotSupportedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        )
        if isinstance(expression, aggregates.Aggregate) and len(expression.source_expressions) > 1:
            raise utils.NotSupportedError(
                "SQLite doesn't support DISTINCT on aggregate functions "
                "accepting multiple arguments."
            ) 
Example 17
Project: openhgsenti   Author: drexly   File: operations.py    Apache License 2.0 6 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                    if isinstance(output_field, bad_fields):
                        raise NotImplementedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        )
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass 
Example 18
Project: Hood   Author: Monroe100   File: operations.py    MIT License 6 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                    if isinstance(output_field, bad_fields):
                        raise NotImplementedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        )
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass 
Example 19
Project: VirtualGym   Author: LuBrian   File: operations.py    MIT License 6 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                    if isinstance(output_field, bad_fields):
                        raise NotImplementedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        )
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass 
Example 20
Project: Uber-django-   Author: zecollokaris   File: operations.py    MIT License 6 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass
                else:
                    if isinstance(output_field, bad_fields):
                        raise NotImplementedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        ) 
Example 21
Project: aspiring_youth   Author: sunx2   File: operations.py    MIT License 6 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass
                else:
                    if isinstance(output_field, bad_fields):
                        raise utils.NotSupportedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        )
        if isinstance(expression, aggregates.Aggregate) and len(expression.source_expressions) > 1:
            raise utils.NotSupportedError(
                "SQLite doesn't support DISTINCT on aggregate functions "
                "accepting multiple arguments."
            ) 
Example 22
Project: Karmo-Onsite-Judge   Author: chunky2808   File: operations.py    MIT License 6 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                    if isinstance(output_field, bad_fields):
                        raise NotImplementedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        )
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass 
Example 23
Project: python2017   Author: bpgc-cte   File: operations.py    MIT License 6 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                    if isinstance(output_field, bad_fields):
                        raise NotImplementedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        )
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass 
Example 24
Project: kasir   Author: iColdPlayer   File: operations.py    MIT License 6 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass
                else:
                    if isinstance(output_field, bad_fields):
                        raise utils.NotSupportedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        )
        if isinstance(expression, aggregates.Aggregate) and len(expression.source_expressions) > 1:
            raise utils.NotSupportedError(
                "SQLite doesn't support DISTINCT on aggregate functions "
                "accepting multiple arguments."
            ) 
Example 25
Project: jieduizuoye   Author: dyssl   File: operations.py    MIT License 6 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass
                else:
                    if isinstance(output_field, bad_fields):
                        raise utils.NotSupportedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        )
        if isinstance(expression, aggregates.Aggregate) and len(expression.source_expressions) > 1:
            raise utils.NotSupportedError(
                "SQLite doesn't support DISTINCT on aggregate functions "
                "accepting multiple arguments."
            ) 
Example 26
Project: Real-World-Projects-in-Python-3.x   Author: PacktPublishing   File: operations.py    MIT License 6 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass
                else:
                    if isinstance(output_field, bad_fields):
                        raise utils.NotSupportedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        )
        if isinstance(expression, aggregates.Aggregate) and len(expression.source_expressions) > 1:
            raise utils.NotSupportedError(
                "SQLite doesn't support DISTINCT on aggregate functions "
                "accepting multiple arguments."
            ) 
Example 27
Project: scouting-app   Author: ArcticWarriors   File: homepage.py    MIT License 6 votes vote down vote up
def _get_competition_metrics(self, competition):

        num_to_display = 5

        metrics_names = []
        metrics_names.append(('scored_uber_tube', "Scored Uber Tube"))
        metrics_names.append(('high_tubes_hung', "High Tubes"))
        metrics_names.append(('mid_tubes_hung', "Mid Tubes"))
        metrics_names.append(('low_tubes_hung', "Low Tubes"))

        output = []

        for metric, full_name in metrics_names:
            result = ScoreResult.objects.filter(competition=competition).values('team__teamNumber').annotate(the_result=Avg(metric)).order_by('-the_result')[0:num_to_display]

            this_result = [(x['team__teamNumber'], "%.2f" % x['the_result']) for x in result]
            print this_result
            output.append((full_name, this_result))

        return output 
Example 28
Project: scouting-app   Author: ArcticWarriors   File: models2011.py    MIT License 6 votes vote down vote up
def get_team_metrics(team, all_fields=ScoreResult.get_fields()):

    kargs = {}
    field_order = []
    for key in all_fields:
        sr_field = all_fields[key]
        field_order.append(sr_field.display_name)
        if sr_field.metric_type == "Average":
            kargs[sr_field.display_name] = Avg(key)
        elif sr_field.metric_type == "Sum":
            kargs[sr_field.display_name] = Sum(key)
        else:
            print("field %s is not metrics-able" % key)

    results = team.scoreresult_set.aggregate(**kargs)
    output = []
    for key in all_fields:
        sr_field = all_fields[key]
        if sr_field.display_name in results:
            output.append((sr_field.display_name, results[sr_field.display_name]))

    return output 
Example 29
Project: scouting-app   Author: ArcticWarriors   File: homepage.py    MIT License 6 votes vote down vote up
def get_competition_metrics(self, competition):

        num_to_display = 5

        metrics_names = []
        metrics_names.append(('hanging_points', "Hanging Points"))
        metrics_names.append(('pyramid_goals', "Pyramid Goals"))
        metrics_names.append(('high_goals', "High Goals"))
        metrics_names.append(('mid_goals', "Mid Goals"))
        metrics_names.append(('low_goals', "Low Goals"))

        output = []

        for metric, full_name in metrics_names:
            result = ScoreResult.objects.filter(competition=competition).values('team__teamNumber').annotate(the_result=Avg(metric)).order_by('-the_result')[0:num_to_display]

            this_result = [(x['team__teamNumber'], "%.2f" % x['the_result']) for x in result]
            print this_result
            output.append((full_name, this_result))

        return output 
Example 30
Project: scouting-app   Author: ArcticWarriors   File: models2013.py    MIT License 6 votes vote down vote up
def get_team_metrics(team, all_fields=ScoreResult.get_fields()):

    kargs = {}
    field_order = []

    for key in all_fields:
        sr_field = all_fields[key]
        field_order.append(sr_field.display_name)
        if sr_field.metric_type == "Average":
            kargs[sr_field.display_name] = Avg(key)
        elif sr_field.metric_type == "Sum":
            kargs[sr_field.display_name] = Sum(key)
        else:
            print("field %s is not metrics-able" % key)

    results = team.scoreresult_set.aggregate(**kargs)
    output = []
    for key in all_fields:
        sr_field = all_fields[key]
        if sr_field.display_name in results:
            output.append((sr_field.display_name, results[sr_field.display_name]))

    return output 
Example 31
Project: scouting-app   Author: ArcticWarriors   File: homepage.py    MIT License 6 votes vote down vote up
def _get_competition_metrics(self, competition):

        num_to_display = 5

        metrics_names = []
        metrics_names.append(('high_score_successful', "High Goals"))
        metrics_names.append(('auto_score_high', "Auton High Goals"))
        metrics_names.append(('low_score_successful', "Low Goals"))
        metrics_names.append(('auto_score_low', "Auton Low Goals"))

        output = []

        for metric, full_name in metrics_names:
            result = ScoreResult.objects.filter(competition=competition).values('team__teamNumber').annotate(the_result=Avg(metric)).order_by('-the_result')[0:num_to_display]

            this_result = [(x['team__teamNumber'], "%.2f" % x['the_result']) for x in result]
            output.append((full_name, this_result))

        return output 
Example 32
Project: open-cabinet   Author: CivicTechTO   File: operations.py    MIT License 6 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                    if isinstance(output_field, bad_fields):
                        raise NotImplementedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        )
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass 
Example 33
Project: hood   Author: rehemafaith   File: operations.py    MIT License 6 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                    if isinstance(output_field, bad_fields):
                        raise NotImplementedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        )
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass 
Example 34
Project: DjangoCrud   Author: TanvirArjel   File: operations.py    MIT License 6 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass
                else:
                    if isinstance(output_field, bad_fields):
                        raise utils.NotSupportedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        ) 
Example 35
Project: voteswap   Author: sbuss   File: operations.py    MIT License 6 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                    if isinstance(output_field, bad_fields):
                        raise NotImplementedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        )
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass 
Example 36
Project: chattR   Author: patrickstocklin   File: operations.py    GNU General Public License v2.0 5 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            try:
                output_field = expression.input_field.output_field
                if isinstance(output_field, bad_fields):
                    raise NotImplementedError(
                        'You cannot use Sum, Avg, StdDev and Variance aggregations '
                        'on date/time fields in sqlite3 '
                        'since date/time is saved as text.')
            except FieldError:
                # not every sub-expression has an output_field which is fine to
                # ignore
                pass 
Example 37
Project: djfirebirdsql   Author: nakagami   File: operations.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def check_expression_support(self, expression):
        from django.db.models.aggregates import Avg
        from django.db.models.expressions import Value
        from django.db.models.functions import (
            Greatest, Least, Length, Chr, LTrim, RTrim, Ord
        )

        if isinstance(expression, Avg):
            expression.template = '%(function)s(CAST(%(expressions)s as double precision))'
        elif isinstance(expression, Greatest):
            expression.function = 'MAXVALUE'
        elif isinstance(expression, Least):
            expression.function = 'MINVALUe'
        elif isinstance(expression, Length):
            expression.function = 'CHARACTER_LENGTH'
        elif isinstance(expression, Chr):
            expression.function = 'ASCII_CHAR'
        elif isinstance(expression, LTrim):
            expression.template = 'TRIM(LEADING FROM %(expressions)s)'
        elif isinstance(expression, RTrim):
            expression.template = 'TRIM(TRAILING FROM %(expressions)s)'
        elif isinstance(expression, Ord):
            expression.function = 'ASCII_VAL'
        elif isinstance(expression, Degrees):
            expression.template='(Cast(%%(expressions)s AS DOUBLE PRECISION) * 180 / %s)' % math.pi
        elif isinstance(expression, (MD5, SHA1, SHA224, SHA256, SHA384, SHA512)):
            expression.template='LOWER(HEX_ENCODE(Hash(%(expressions)s using %(function)s)))'
        elif isinstance(expression, Value):
            if isinstance(expression.value, datetime.datetime):
                expression.value = str(expression.value)[:24] 
Example 38
Project: GTDWeb   Author: lanbing510   File: operations.py    GNU General Public License v2.0 5 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            try:
                output_field = expression.input_field.output_field
                if isinstance(output_field, bad_fields):
                    raise NotImplementedError(
                        'You cannot use Sum, Avg, StdDev and Variance aggregations '
                        'on date/time fields in sqlite3 '
                        'since date/time is saved as text.')
            except FieldError:
                # not every sub-expression has an output_field which is fine to
                # ignore
                pass 
Example 39
Project: Fun5G   Author: OpenWinCon   File: operations.py    Apache License 2.0 5 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            try:
                output_field = expression.input_field.output_field
                if isinstance(output_field, bad_fields):
                    raise NotImplementedError(
                        'You cannot use Sum, Avg, StdDev and Variance aggregations '
                        'on date/time fields in sqlite3 '
                        'since date/time is saved as text.')
            except FieldError:
                # not every sub-expression has an output_field which is fine to
                # ignore
                pass 
Example 40
Project: Vigtech-Services   Author: VigTech   File: operations.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            try:
                output_field = expression.input_field.output_field
                if isinstance(output_field, bad_fields):
                    raise NotImplementedError(
                        'You cannot use Sum, Avg, StdDev and Variance aggregations '
                        'on date/time fields in sqlite3 '
                        'since date/time is saved as text.')
            except FieldError:
                # not every sub-expression has an output_field which is fine to
                # ignore
                pass 
Example 41
Project: DroidPot   Author: WhySoGeeky   File: operations.py    MIT License 5 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            try:
                output_field = expression.input_field.output_field
                if isinstance(output_field, bad_fields):
                    raise NotImplementedError(
                        'You cannot use Sum, Avg, StdDev and Variance aggregations '
                        'on date/time fields in sqlite3 '
                        'since date/time is saved as text.')
            except FieldError:
                # not every sub-expression has an output_field which is fine to
                # ignore
                pass 
Example 42
Project: mudong_blog   Author: mudong1991   File: operations.py    GNU General Public License v2.0 5 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            try:
                output_field = expression.input_field.output_field
                if isinstance(output_field, bad_fields):
                    raise NotImplementedError(
                        'You cannot use Sum, Avg, StdDev and Variance aggregations '
                        'on date/time fields in sqlite3 '
                        'since date/time is saved as text.')
            except FieldError:
                # not every sub-expression has an output_field which is fine to
                # ignore
                pass 
Example 43
Project: django-google-adwords   Author: alexhayes   File: models.py    MIT License 5 votes vote down vote up
def average_ctr_for_period(self, start, finish):
            return self.within_period(start, finish).aggregate(Avg('ctr')) 
Example 44
Project: django-google-adwords   Author: alexhayes   File: models.py    MIT License 5 votes vote down vote up
def daily_average_ctr_for_period(self, start, finish, order_by='day'):
            return self.within_period(start, finish).order_by(order_by).values('day').annotate(ctr=Avg('ctr')) 
Example 45
Project: django-google-adwords   Author: alexhayes   File: models.py    MIT License 5 votes vote down vote up
def average_cpc_for_period(self, start, finish):
            return self.within_period(start, finish).aggregate(Avg('avg_cpc')) 
Example 46
Project: django-google-adwords   Author: alexhayes   File: models.py    MIT License 5 votes vote down vote up
def daily_average_cpc_for_period(self, start, finish, order_by='day'):
            return self.within_period(start, finish).order_by(order_by).values('day').annotate(cpc=Avg('avg_cpc')) 
Example 47
Project: django-google-adwords   Author: alexhayes   File: models.py    MIT License 5 votes vote down vote up
def average_click_conversion_rate_for_period(self, start, finish):
            return self.within_period(start, finish).aggregate(Avg('click_conversion_rate')) 
Example 48
Project: django-google-adwords   Author: alexhayes   File: models.py    MIT License 5 votes vote down vote up
def average_cost_conv_for_period(self, start, finish):
            return self.within_period(start, finish).aggregate(Avg('cost_conv')) 
Example 49
Project: django-google-adwords   Author: alexhayes   File: models.py    MIT License 5 votes vote down vote up
def daily_average_cost_conv_for_period(self, start, finish, order_by='day'):
            return self.within_period(start, finish).order_by(order_by).values('day').annotate(cost_conv=Avg('cost_conv')) 
Example 50
Project: django-google-adwords   Author: alexhayes   File: models.py    MIT License 5 votes vote down vote up
def average_search_lost_impression_share_budget(self, start, finish):
            return self.within_period(start, finish).aggregate(Avg('search_lost_is_budget')) 
Example 51
Project: django-google-adwords   Author: alexhayes   File: models.py    MIT License 5 votes vote down vote up
def device_average_click_conversion_rate_for_period(self, start, finish):
            return self.within_period(start, finish).values('device').annotate(click_conversion_rate=Avg('click_conversion_rate')) 
Example 52
Project: django-google-adwords   Author: alexhayes   File: models.py    MIT License 5 votes vote down vote up
def top_by_clicks(self, start, finish):
            return self.filter(metrics__day__gte=start, metrics__day__lte=finish) \
                .annotate(clicks=Sum('metrics__clicks'),
                          impressions=Sum('metrics__impressions'),
                          ctr=Avg('metrics__ctr'),
                          cost=Sum('metrics__cost'),
                          avg_position=Avg('metrics__avg_position')) \
                .order_by('-clicks') 
Example 53
Project: django-google-adwords   Author: alexhayes   File: models.py    MIT License 5 votes vote down vote up
def top_by_clicks(self, start, finish):
            return self.filter(metrics__day__gte=start, metrics__day__lte=finish) \
                       .annotate(clicks=Sum('metrics__clicks'),
                                 impressions=Sum('metrics__impressions'),
                                 ctr=Avg('metrics__ctr'),
                                 cost=Sum('metrics__cost'),
                                 avg_position=Avg('metrics__avg_position')) \
                       .order_by('-clicks') 
Example 54
Project: django-google-adwords   Author: alexhayes   File: models.py    MIT License 5 votes vote down vote up
def top_by_conversion_rate(self, start, finish):
            return self.filter(metrics__day__gte=start, metrics__day__lte=finish) \
                       .annotate(conversions=Sum('metrics__conversions'),
                                 conv_rate=Avg('metrics__conv_rate'),
                                 cost_conv=Avg('metrics__cost_conv'),
                                 impressions=Sum('metrics__impressions'),
                                 clicks=Sum('metrics__clicks'),
                                 cost=Sum('metrics__cost'),
                                 ctr=Avg('metrics__ctr'),
                                 avg_cpc=Avg('metrics__avg_cpc')) \
                       .order_by('-conversions') 
Example 55
Project: workspace_2016   Author: nwiizo   File: operations.py    MIT License 5 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            try:
                output_field = expression.input_field.output_field
                if isinstance(output_field, bad_fields):
                    raise NotImplementedError(
                        'You cannot use Sum, Avg, StdDev and Variance aggregations '
                        'on date/time fields in sqlite3 '
                        'since date/time is saved as text.')
            except FieldError:
                # not every sub-expression has an output_field which is fine to
                # ignore
                pass 
Example 56
Project: ga_statistics   Author: wolfskaempf   File: operations.py    MIT License 5 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            try:
                output_field = expression.input_field.output_field
                if isinstance(output_field, bad_fields):
                    raise NotImplementedError(
                        'You cannot use Sum, Avg, StdDev and Variance aggregations '
                        'on date/time fields in sqlite3 '
                        'since date/time is saved as text.')
            except FieldError:
                # not every sub-expression has an output_field which is fine to
                # ignore
                pass 
Example 57
Project: scouting-app   Author: ArcticWarriors   File: models2016.py    MIT License 5 votes vote down vote up
def get_advanced_team_metrics(team, all_fields=ScoreResult.get_fields()):

    kargs = {}
    field_order = []
    for key in all_fields:
        sr_field = all_fields[key]
        field_order.append(sr_field.display_name)
        if sr_field.metric_type == "Average":
            kargs[sr_field.display_name] = Avg(key)
        elif sr_field.metric_type == "Sum":
            kargs[sr_field.display_name] = Sum(key)
        else:
            print("field %s is not metrics-able" % key)

    results = team.scoreresult_set.aggregate(**kargs)
    output = []
    for key in all_fields:
        sr_field = all_fields[key]
        if sr_field.display_name in results:
            print type(results[sr_field.display_name])
            result = results[sr_field.display_name]
            if type(result) == float:
                result = "%.2f" % result
            output.append((sr_field.display_name, result))

    return output 
Example 58
Project: scouting-app   Author: ArcticWarriors   File: pick_list.py    MIT License 5 votes vote down vote up
def get_context_data(self, **kwargs):
        context = super(PickListView2017, self).get_context_data(**kwargs)

        all_teams = []
        competition = Competition.objects.get(code=kwargs['regional_code'])
        for team_competes_in in TeamCompetesIn.objects.filter(competition=competition):
            all_teams.append(team_competes_in.team)

        all_teams = sorted(all_teams, key=operator.attrgetter('teamNumber'))

        context['original_overall_list'] = PickList.objects.filter(competition=competition, grouping="Overall").order_by('rank_in_group')
        context['original_fuel_list'] = PickList.objects.filter(competition=competition, grouping="Fuel").order_by('rank_in_group')
        context['original_gear_list'] = PickList.objects.filter(competition=competition, grouping="Gear").order_by('rank_in_group')
        context['original_defense_list'] = PickList.objects.filter(competition=competition, grouping="Defense").order_by('rank_in_group')
        context['original_dnp_list'] = PickList.objects.filter(competition=competition, grouping="Do Not Pick").order_by('rank_in_group')
        context['all_teams'] = all_teams

        top_teams = {}

        averages = ScoreResult.objects.values("team_id").annotate(fuel=Avg("auto_fuel_high_score") + Avg("tele_fuel_high_score") / 3.0 + Avg("auto_fuel_low_score") / 3.0 + Avg("tele_fuel_low_score") / 9.0,
                                                                  gears=Avg("auto_gears") + Avg("tele_gears"),
                                                                  rope=Avg(Case(When(rope=True, then=1), When(rope=False, then=0)))
                                                                  ).order_by()

        gear_weight = 15
        category_size_to_add = 5

        sorted_overall = [Team.objects.get(id=x["team_id"]).teamNumber for x in sorted(averages, key=lambda x: x["fuel"] + x["gears"] * gear_weight + x["rope"], reverse=True)]

        top_fuel = [Team.objects.get(id=x["team_id"]).teamNumber for x in sorted(averages, key=lambda x: x["fuel"], reverse=True)[0:category_size_to_add]]
        top_gear = [Team.objects.get(id=x["team_id"]).teamNumber for x in sorted(averages, key=lambda x: x["gears"], reverse=True)[0:category_size_to_add]]
        top_teams["fuel"] = top_fuel
        top_teams["gear"] = top_gear
        top_teams["overall"] = sorted_overall[:24]
        top_teams["do_not_pick"] = sorted_overall[-category_size_to_add:]
        top_teams["defense"] = sorted_overall[-category_size_to_add:]

        context["top_teams"] = top_teams

        return context 
Example 59
Project: scouting-app   Author: ArcticWarriors   File: predict_match.py    MIT License 5 votes vote down vote up
def __get_team_average_for_match_prediction(team, competition):
    
    output = {}
    output["team_number"] = team.teamNumber

    score_results = team.scoreresult_set.filter(competition=competition)
    if len(score_results) == 0:
        return output

    sr_results = score_results.aggregate(
        auto_fuel_high=Avg("auto_fuel_high_score"),
        auto_gears=Avg("auto_gears"),
        tele_fuel_high=Avg("tele_fuel_high_score"),
        tele_gears=Avg("tele_gears"),
        baseline=Avg(Case(When(auto_baseline=True, then=1), When(auto_baseline=False, then=0))),
        rope=Avg(Case(When(rope=True, then=1), When(rope=False, then=0))))
    output.update(sr_results)

    fuel_total = output['auto_fuel_high'] + \
                 output['tele_fuel_high'] / 3.0 

    output["fuel_total"] = fuel_total
    output["gear_total"] = output['auto_gears'] + output['tele_gears']
    output["total_score"] = fuel_total + output['baseline'] * 5 + output['rope'] * 50

    return output 
Example 60
Project: scouting-app   Author: ArcticWarriors   File: get_team_metrics.py    MIT License 5 votes vote down vote up
def get_team_metrics(team, regional_code):
    metrics = team.scoreresult_set.filter(competition__code=regional_code).aggregate(
                                             Avg("auto_fuel_high_score"),
                                             Avg("auto_gears"),

                                             Avg("tele_fuel_high_score"),
                                             Avg("tele_gears"),

                                             Sum("foul"),
                                             Sum("tech_foul"),
                                             Sum("yellow_card"),
                                             Sum("red_card"),

                                             rope__avg=Avg(Case(When(rope=True, then=1), When(rope=False, then=0))),
                                             baseline__avg=Avg(Case(When(auto_baseline=True, then=1), When(auto_baseline=False, then=0))),
                                             )

    # Format all of the numbers.  If we haven't scouted the team, None will be returned.  Turn that into NA
    for key in metrics:
        if metrics[key] == None:
            metrics[key] = "NA"
        elif "__avg" in key:
            metrics[key] = "{:10.2f}".format(metrics[key])

    if metrics['tele_fuel_high_score__avg'] != "NA":

        metrics['auto_fuel_high_misses__avg'] = float(metrics['auto_fuel_high_shots__avg']) - float(metrics['auto_fuel_high_score__avg'])

        metrics['tele_fuel_high_misses__avg'] = float(metrics['tele_fuel_high_shots__avg']) - float(metrics['tele_fuel_high_score__avg'])
    else:
        metrics['auto_fuel_high_misses__avg'] = "NA"

        metrics['tele_fuel_high_misses__avg'] = "NA"

    return metrics 
Example 61
Project: django-wechat-api   Author: crazy-canux   File: operations.py    GNU General Public License v3.0 5 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            try:
                output_field = expression.input_field.output_field
                if isinstance(output_field, bad_fields):
                    raise NotImplementedError(
                        'You cannot use Sum, Avg, StdDev and Variance aggregations '
                        'on date/time fields in sqlite3 '
                        'since date/time is saved as text.')
            except FieldError:
                # not every sub-expression has an output_field which is fine to
                # ignore
                pass 
Example 62
Project: MulticsSH   Author: MulticsYin   File: operations.py    Apache License 2.0 5 votes vote down vote up
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            try:
                output_field = expression.input_field.output_field
                if isinstance(output_field, bad_fields):
                    raise NotImplementedError(
                        'You cannot use Sum, Avg, StdDev and Variance aggregations '
                        'on date/time fields in sqlite3 '
                        'since date/time is saved as text.')
            except FieldError:
                # not every sub-expression has an output_field which is fine to
                # ignore
                pass