Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1"""LICENSE 

2Copyright 2019 Hermann Krumrey <hermann@krumreyh.com> 

3 

4This file is part of otaku-info-bot. 

5 

6otaku-info-bot is free software: you can redistribute it and/or modify 

7it under the terms of the GNU General Public License as published by 

8the Free Software Foundation, either version 3 of the License, or 

9(at your option) any later version. 

10 

11otaku-info-bot is distributed in the hope that it will be useful, 

12but WITHOUT ANY WARRANTY; without even the implied warranty of 

13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

14GNU General Public License for more details. 

15 

16You should have received a copy of the GNU General Public License 

17along with otaku-info-bot. If not, see <http://www.gnu.org/licenses/>. 

18LICENSE""" 

19 

20from kudubot.db import Base 

21from sqlalchemy import Column, Integer, ForeignKey 

22from sqlalchemy.orm import relationship 

23 

24 

25class Notification(Base): 

26 """ 

27 Models a generic Notification 

28 """ 

29 

30 __tablename__ = "notifications" 

31 """ 

32 The name of the database table 

33 """ 

34 

35 id = Column(Integer, primary_key=True, autoincrement=True) 

36 """ 

37 The ID of the notification 

38 """ 

39 

40 address_id = Column(Integer, ForeignKey("addressbook.id")) 

41 """ 

42 The ID of the associated address 

43 """ 

44 

45 address = relationship("Address") 

46 """ 

47 The associated address 

48 """ 

49 

50 entry_id = Column(Integer, ForeignKey("anilist_entries.id")) 

51 """ 

52 The ID of the associated anilist entry 

53 """ 

54 

55 entry = relationship("AnilistEntry") 

56 """ 

57 The associated anilist entry 

58 """ 

59 

60 user_progress = Column(Integer, default=0, nullable=False) 

61 """ 

62 The user's current progress 

63 """ 

64 

65 last_update = Column(Integer, default=0, nullable=False) 

66 """ 

67 The last notification update 

68 """ 

69 

70 user_score = Column(Integer, default=0, nullable=False) 

71 """ 

72 Score that the user gave the entry 

73 """ 

74 

75 @property 

76 def diff(self) -> int: 

77 """ 

78 The difference between the last update and the current entry value 

79 :return: The difference 

80 """ 

81 return self.entry.latest - self.last_update 

82 

83 @property 

84 def user_diff(self) -> bool: 

85 """ 

86 :return: The difference between the user's progress and the latest 

87 entry value 

88 """ 

89 return self.entry.latest - self.user_progress 

90 

91 def __str__(self) -> str: 

92 return "({})[{}]: {} (diff:{} [{}/{}])".format( 

93 self.id, 

94 self.address.address, 

95 self.entry.name, 

96 self.diff, 

97 self.last_update, 

98 self.entry.latest 

99 )