loglan_db.model_db.base_event   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 87
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A BaseEvent.deprecated_words() 0 8 1
A BaseEvent.latest() 0 6 1
A BaseEvent.appeared_words() 0 8 1
1
# -*- coding: utf-8 -*-
2
# pylint: disable=C0303
3
4 1
"""
5
This module contains a basic Event Model
6
"""
7 1
from __future__ import annotations
8 1
from loglan_db import db
9 1
from loglan_db.model_db import t_name_events
10 1
from loglan_db.model_init import InitBase, DBBase
11
12 1
__pdoc__ = {
13
    'BaseEvent.created': False, 'BaseEvent.updated': False,
14
}
15
16
17 1
class BaseEvent(db.Model, InitBase, DBBase):
18
    """Base Event's DB Model
19
20
    Describes a table structure for storing information about lexical events.
21
22
    <details><summary>Show Examples</summary><p>
23
    ```python
24
    {'suffix': 'INIT', 'definition': 'The initial vocabulary before updates.',
25
     'date': datetime.date(1975, 1, 1), 'annotation': 'Initial', 'name': 'Start', 'id': 1}
26
27
    {'suffix': 'RDC', 'definition': 'parsed all the words in the dictionary,
28
    identified ones that the parser did not recognize as words',
29
    'date': datetime.date(2016, 1, 15), 'annotation': 'Randall Cleanup',
30
    'name': 'Randall Dictionary Cleanup', 'id': 5}
31
    ```
32
    </p></details>
33
    """
34 1
    __tablename__ = t_name_events
35
36 1
    id = db.Column(db.Integer, primary_key=True)
37
    """*Event's internal ID number*  
38
        **int** : primary_key=True"""
39 1
    date = db.Column(db.Date, nullable=False, unique=False)
40
    """*Event's starting day*  
41
        **dateime.date** : nullable=False, unique=False"""
42 1
    name = db.Column(db.String(64), nullable=False, unique=False)
43
    """*Event's short name*  
44
        **str** : max_length=64, nullable=False, unique=False"""
45 1
    definition = db.Column(db.Text, nullable=False, unique=False)
46
    """*Event's definition*  
47
        **str** : nullable=False, unique=False"""
48 1
    annotation = db.Column(db.String(16), nullable=False, unique=False)
49
    """*Event's annotation (displayed in old format dictionary HTML file)*  
50
        **str** : max_length=16, nullable=False, unique=False"""
51 1
    suffix = db.Column(db.String(16), nullable=False, unique=False)
52
    """*Event's suffix (used to create filename when exporting HTML file)*  
53
        **str** : max_length=16, nullable=False, unique=False"""
54
55 1
    _deprecated_words = db.relationship(
56
        "BaseWord", back_populates="_event_end",
57
        foreign_keys="BaseWord.event_end_id")
58
59 1
    _appeared_words = db.relationship(
60
        "BaseWord", back_populates="_event_start",
61
        foreign_keys="BaseWord.event_start_id")
62
63 1
    @property
64
    def deprecated_words(self):
65
        """
66
        *Relationship query for getting a list of words deprecated during this event*
67
68
        **query** : Optional[List[BaseWord]]"""
69
70 1
        return self._deprecated_words
71
72 1
    @property
73
    def appeared_words(self):
74
        """
75
        *Relationship query for getting a list of words appeared during this event*
76
77
        **query** : Optional[List[BaseWord]]"""
78
79 1
        return self._appeared_words
80
81 1
    @classmethod
82
    def latest(cls) -> BaseEvent:
83
        """
84
        Gets the latest (current) `BaseEvent` from DB
85
        """
86
        return cls.query.order_by(-cls.id).first()
87