Passed
Pull Request — master (#30)
by
unknown
03:59
created

validation.models   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 37
dl 0
loc 62
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A ValidationResult.__str__() 0 2 1
A ValidationSummary.get_issues_count() 0 2 1
A ValidationSummary.get_unknown_count() 0 2 1
A ValidationSummary.get_all_count() 0 2 1
1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
"""
4
Created on Mon Jan 28 11:09:02 2019
5
6
@author: Paolo Cozzi <[email protected]>
7
"""
8
9
from django.db import models
10
from django.contrib.postgres.fields import ArrayField
11
12
from image_app.models import Name
13
14
15
class ValidationResult(models.Model):
16
    name = models.OneToOneField(
17
        Name,
18
        on_delete=models.CASCADE)
19
20
    status = models.CharField(
21
            max_length=255,
22
            blank=False,
23
            null=True)
24
25
    messages = ArrayField(
26
        models.TextField(max_length=255, blank=True),
27
        default=list
28
    )
29
30
    def __str__(self):
31
        return "%s:%s" % (self.name, self.status)
32
33
34
class ValidationSummary(models.Model):
35
    submission = models.ForeignKey('image_app.Submission',
36
                                   on_delete=models.CASCADE)
37
38
    all_count = models.PositiveIntegerField(default=0)
39
    validation_known_count = models.PositiveIntegerField(default=0)
40
    issues_count = models.PositiveIntegerField(default=0)
41
    pass_count = models.PositiveIntegerField(default=0)
42
    warning_count = models.PositiveIntegerField(default=0)
43
    error_count = models.PositiveIntegerField(default=0)
44
    json_count = models.PositiveIntegerField(default=0)
45
    type = models.CharField(max_length=6, blank=True, null=True)
46
    messages = ArrayField(
47
        models.TextField(max_length=255, blank=True),
48
        default=list
49
    )
50
51
    # Returns number of all samples or animals in submission
52
    def get_all_count(self):
53
        return self.all_count
54
55
    # Returns number of samples or animals with unknown validation
56
    def get_unknown_count(self):
57
        return self.all_count - self.validation_known_count
58
59
    # Returns number of samples or animals with issues in validation
60
    def get_issues_count(self):
61
        return self.issues_count
62