[damned-lies] Avoid null values in global statistics query
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Avoid null values in global statistics query
- Date: Fri, 19 Mar 2021 07:37:57 +0000 (UTC)
commit 1cfe71200178b00eff9ca39ed3d89010ed35eca2
Author: Claude Paroz <claude 2xlibre net>
Date: Fri Mar 19 08:28:19 2021 +0100
Avoid null values in global statistics query
stats/models.py | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
---
diff --git a/stats/models.py b/stats/models.py
index fb27f1f4..bdcde8c1 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -21,6 +21,7 @@ from django.utils.functional import cached_property
from django.utils.translation import ngettext, gettext as _, gettext_noop
from django.utils import dateformat
from django.db import models
+from django.db.models.functions import Coalesce
from common.fields import DictionaryField, JSONField
from common.utils import is_site_admin, run_shell_command
@@ -1097,9 +1098,12 @@ class Release(models.Model):
query = Statistics.objects.filter(language__isnull=False, branch__releases=self
).exclude(domain__in=self.excluded_domains
).values('domain__dtype', 'language'
- ).annotate(trans=models.Sum('full_po__translated'), fuzzy=models.Sum('full_po__fuzzy'),
- trans_p=models.Sum('part_po__translated'), fuzzy_p=models.Sum('part_po__fuzzy'),
- locale=models.Min('language__locale'), lang_name=models.Min('language__name')
+ ).annotate(
+ trans=Coalesce(models.Sum('full_po__translated'), models.Value(0)),
+ fuzzy=Coalesce(models.Sum('full_po__fuzzy'), models.Value(0)),
+ trans_p=Coalesce(models.Sum('part_po__translated'), models.Value(0)),
+ fuzzy_p=Coalesce(models.Sum('part_po__fuzzy'), models.Value(0)),
+ locale=models.Min('language__locale'), lang_name=models.Min('language__name')
).order_by('domain__dtype', 'trans')
stats = {}
total_docstrings, total_uistrings = self.total_strings()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]