todonotifier.summary_generators

This module provides the base summary generator that can be inherited to define a new summary generator. It also provides three default summary generators.

  1"""This module provides the base summary generator that can be inherited to define a new
  2summary generator. It also provides three default summary generators.
  3"""
  4
  5import logging
  6from abc import ABC, abstractmethod
  7from datetime import datetime
  8from typing import Dict, List, TypeVar
  9
 10from todonotifier.constants import DEFAULT_SUMMARY_GENERATORS_ENUM, UNKNOWN_USER_NAME
 11from todonotifier.models import TODO
 12
 13T = TypeVar("T")
 14
 15# logging configuration
 16logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(process)d - %(name)s - %(levelname)s - %(message)s")
 17logger = logging.getLogger(__name__)
 18
 19TABLE_CLOSE_TAG = """
 20            </table>
 21            """
 22
 23
 24class BaseSummaryGenerator(ABC):
 25    def __init__(self, name: str, container: T, html: str = "") -> None:
 26        """Initializer for `BaseSummaryGenerator`
 27
 28        Args:
 29            name (str): Name of the respective Summary Generator
 30            container (T): A container in which `generate_summary` would add info of the current todo object, It could be a list or dict or sth else
 31            html (str, optional): A placeholder for html report contained in `container`. defaults to ""
 32        """
 33        self._name = name
 34        self._container = container
 35        self._html = html
 36
 37    @property
 38    def name(self) -> str:
 39        """Getter for `name`
 40
 41        Returns:
 42            str: Name of the respective summary generator
 43        """
 44        return self._name
 45
 46    @property
 47    def container(self) -> str:
 48        """Getter for `container`
 49
 50        Returns:
 51            str: container of the respective summary generator
 52        """
 53        return self._container
 54
 55    @property
 56    def html(self) -> str:
 57        """Getter for `html`
 58
 59        Returns:
 60            str: html of the respective summary generator
 61        """
 62        return self._html
 63
 64    @abstractmethod
 65    def generate_summary(self, all_todos_objs: Dict[str, List[TODO]]) -> None:
 66        """Abstract function to generate_summary summary
 67
 68        Args:
 69            all_todos_objs (Dict[str, List[TODO]]):  Key-value pair where key is relative path of file parsed and value is list of todo objects in that file
 70        """
 71        pass
 72
 73    @abstractmethod
 74    def generate_html(self) -> None:
 75        """Generates the html representation of the respective summary to be sent as notifications to users"""
 76        pass
 77
 78
 79class ByModuleSummaryGenerator(BaseSummaryGenerator):
 80    def __init__(self, name: str = DEFAULT_SUMMARY_GENERATORS_ENUM.TODO_BY_MODULE, container: Dict[str, List[List[str]]] = None) -> None:
 81        """Initializer for `ByModuleSummaryGenerator`
 82
 83        Args:
 84            name (str, optional): Name of the respective Summary Generator. Defaults to DEFAULT_SUMMARY_GENERATORS_ENUM.TODO_BY_MODULE.
 85            container (Dict[str, List[List[str]], optional): A container in which `generate_summary` would add info of the current todo object. Defaults to {}.
 86        """
 87        super().__init__(name=name, container=container or {})
 88
 89    def generate_summary(self, all_todos_objs: Dict[str, List[TODO]]) -> None:
 90        """Generates summary for each module
 91
 92        Args:
 93            all_todos_objs (Dict[str, List[TODO]]):  Key-value pair where key is relative path of file parsed and value is list of todo objects in that file
 94        """
 95        logger.info(f"Generating summary: {self.name}")
 96
 97        for module in all_todos_objs:
 98            logger.info(f"Generating summary: {self.name} for module: {module}")
 99            for todo_obj in all_todos_objs[module]:
100                user_name = todo_obj.user.user_name
101
102                if todo_obj.module not in self._container:
103                    self._container[todo_obj.module] = [
104                        [
105                            user_name,
106                            todo_obj.msg,
107                            todo_obj.position.line_no,
108                            str(todo_obj.completion_date),
109                        ]
110                    ]
111                else:
112                    self._container[todo_obj.module].append(
113                        [
114                            user_name,
115                            todo_obj.msg,
116                            todo_obj.position.line_no,
117                            str(todo_obj.completion_date),
118                        ]
119                    )
120
121        logger.info(f"Summary generated: {self.container}")
122
123    def generate_html(self) -> None:
124        """Generates the html representation showing module wise summary of todo items"""
125        logger.info(f"Generating html for: {self.name}")
126
127        tables = ""
128        for module in self._container:
129            table = """
130            <table>
131                <caption>Module wise summary</caption>
132            <tr>
133                <th>User Name</th>
134                <th>Message</th>
135                <th>Line No.</th>
136                <th>Completion Date</th>
137            </tr>
138            """
139
140            for todo_item in self._container[module]:
141                table += f"""
142                <tr>
143                    <td>{todo_item[0]}</td>
144                    <td>{todo_item[1]}</td>
145                    <td>{todo_item[2]}</td>
146                    <td>{todo_item[3]}</td>
147                </tr>
148                """
149            table += TABLE_CLOSE_TAG
150
151            tables += f"""
152            <h3>TODOs for module {module}</h3>
153            <p>
154                {table}
155            </p><br>
156            """
157
158        logger.info(f"HTML generated: {tables}")
159        self._html = tables
160
161
162class ExpiredTodosByUserSummaryGenerator(BaseSummaryGenerator):
163    def __init__(self, name: str = DEFAULT_SUMMARY_GENERATORS_ENUM.EXPIRED_TODO_BY_USER, container: Dict[str, List[List[str]]] = None) -> None:
164        """Initializer for `ByModuleSummaryGenerator`
165
166        Args:
167            name (str, optional): Name of the respective Summary Generator. Defaults to DEFAULT_SUMMARY_GENERATORS_ENUM.EXPIRED_TODO_BY_USER.
168            container (Dict[str, List[List[str]], optional): A container in which `generate_summary` would add info of the current todo object. Defaults to {}.
169        """
170        super().__init__(name=name, container=container or {})
171
172    def generate_summary(self, all_todos_objs: Dict[str, List[TODO]]) -> None:
173        """Generates summary for all expired todo items by user
174
175        Args:
176            all_todos_objs (Dict[str, List[TODO]]):  Key-value pair where key is relative path of file parsed and value is list of todo objects in that file
177            expired_todos_by_user_list (dict): Dictionary with user_name as key and corresponding expired todo items as value
178        """
179        logger.info(f"Generating summary: {self.name}")
180
181        curr_date = datetime.today().date()
182
183        for module in all_todos_objs:
184            logger.info(f"Generating summary: {self.name} for module: {module}")
185            for todo_obj in all_todos_objs[module]:
186                user_name = todo_obj.user.user_name
187
188                if curr_date > todo_obj.completion_date:
189                    if user_name not in self._container:
190                        self._container[user_name] = [
191                            [
192                                todo_obj.msg,
193                                todo_obj.module,
194                                todo_obj.position.line_no,
195                                str(todo_obj.completion_date),
196                            ]
197                        ]
198                    else:
199                        self._container[user_name].append(
200                            [
201                                todo_obj.msg,
202                                todo_obj.module,
203                                todo_obj.position.line_no,
204                                str(todo_obj.completion_date),
205                            ]
206                        )
207
208        logger.info(f"Summary generated: {self.container}")
209
210    def generate_html(self) -> None:
211        """Generates the html representation of the user-wise summary of expired todo items for all users"""
212        logger.info(f"Generating html for: {self.name}")
213
214        tables = ""
215        for user_name in self._container:
216            table = """
217            <table>
218                <caption>User wise summary of expired todo item</caption>
219            <tr>
220                <th>Message</th>
221                <th>Module</th>
222                <th>Line No.</th>
223                <th>Completion Date</th>
224            </tr>
225            """
226
227            for todo_item in self._container[user_name]:
228                table += f"""
229                    <tr>
230                        <td>{todo_item[0]}</td>
231                        <td>{todo_item[1]}</td>
232                        <td>{todo_item[2]}</td>
233                        <td>{todo_item[3]}</td>
234                    </tr>
235                    """
236            table += TABLE_CLOSE_TAG
237
238            tables += f"""
239            <h3>Expired TODOs for {user_name}</h3>
240            <p>
241                {table}
242            </p><br>
243            """
244
245        logger.info(f"HTML generated: {tables}")
246        self._html = tables
247
248
249class UpcomingWeekTodosByUserSummaryGenerator(BaseSummaryGenerator):
250    def __init__(self, name: str = DEFAULT_SUMMARY_GENERATORS_ENUM.UPCOMING_TODO_BY_USER, container: Dict[str, List[List[str]]] = None) -> None:
251        """Initializer for `ByModuleSummaryGenerator`
252
253        Args:
254            name (str, optional): Name of the respective Summary Generator. Defaults to DEFAULT_SUMMARY_GENERATORS_ENUM.UPCOMING_TODO_BY_USER
255            container (Dict[str, List[List[str]]], optional): A container in which `generate_summary` would add info of the current todo object. Defaults to {}
256        """
257        super().__init__(name=name, container=container or {})
258
259    def generate_summary(self, all_todos_objs: Dict[str, List[TODO]]) -> None:
260        """Generates summary for all upcoming todo items by user
261
262        Args:
263            all_todos_objs (Dict[str, List[TODO]]):  Key-value pair where key is relative path of file parsed and value is list of todo objects in that file
264        """
265        logger.info(f"Generating summary: {self.name}")
266
267        curr_date = datetime.today().date()
268
269        for module in all_todos_objs:
270            logger.info(f"Generating summary: {self.name} for module: {module}")
271            for todo_obj in all_todos_objs[module]:
272                user_name = todo_obj.user.user_name if todo_obj.user.user_name else UNKNOWN_USER_NAME
273
274                if curr_date <= todo_obj.completion_date and (todo_obj.completion_date - curr_date).days <= 7:
275                    if user_name not in self._container:
276                        self._container[user_name] = [
277                            [
278                                todo_obj.msg,
279                                todo_obj.module,
280                                todo_obj.position.line_no,
281                                str(todo_obj.completion_date),
282                            ]
283                        ]
284                    else:
285                        self._container[user_name].append(
286                            [
287                                todo_obj.msg,
288                                todo_obj.module,
289                                todo_obj.position.line_no,
290                                str(todo_obj.completion_date),
291                            ]
292                        )
293
294        logger.info(f"Summary generated: {self.container}")
295
296    def generate_html(self) -> None:
297        """Generates the html representation of the user-wise summary of the upcoming (within a week) todo items for all users"""
298        logger.info(f"Generating html for: {self.name}")
299
300        tables = ""
301        for user_name in self._container:
302            table = """
303            <table>
304                <caption>User wise summary of upcoming todo items</caption>
305            <tr>
306                <th>Message</th>
307                <th>Module</th>
308                <th>Line No.</th>
309                <th>Completion Date</th>
310            </tr>
311            """
312
313            for todo_item in self._container.get(user_name):
314                table += f"""
315                    <tr>
316                        <td>{todo_item[0]}</td>
317                        <td>{todo_item[1]}</td>
318                        <td>{todo_item[2]}</td>
319                        <td>{todo_item[3]}</td>
320                    </tr>
321                    """
322            table += TABLE_CLOSE_TAG
323
324            tables += f"""
325            <h3>Upcoming TODOs for {user_name}</h3>
326            <p>
327                {table}
328            </p><br>
329            """
330
331        logger.info(f"HTML generated: {tables}")
332        self._html = tables
logger = <Logger todonotifier.summary_generators (INFO)>
TABLE_CLOSE_TAG = '\n </table>\n '
class BaseSummaryGenerator(abc.ABC):
25class BaseSummaryGenerator(ABC):
26    def __init__(self, name: str, container: T, html: str = "") -> None:
27        """Initializer for `BaseSummaryGenerator`
28
29        Args:
30            name (str): Name of the respective Summary Generator
31            container (T): A container in which `generate_summary` would add info of the current todo object, It could be a list or dict or sth else
32            html (str, optional): A placeholder for html report contained in `container`. defaults to ""
33        """
34        self._name = name
35        self._container = container
36        self._html = html
37
38    @property
39    def name(self) -> str:
40        """Getter for `name`
41
42        Returns:
43            str: Name of the respective summary generator
44        """
45        return self._name
46
47    @property
48    def container(self) -> str:
49        """Getter for `container`
50
51        Returns:
52            str: container of the respective summary generator
53        """
54        return self._container
55
56    @property
57    def html(self) -> str:
58        """Getter for `html`
59
60        Returns:
61            str: html of the respective summary generator
62        """
63        return self._html
64
65    @abstractmethod
66    def generate_summary(self, all_todos_objs: Dict[str, List[TODO]]) -> None:
67        """Abstract function to generate_summary summary
68
69        Args:
70            all_todos_objs (Dict[str, List[TODO]]):  Key-value pair where key is relative path of file parsed and value is list of todo objects in that file
71        """
72        pass
73
74    @abstractmethod
75    def generate_html(self) -> None:
76        """Generates the html representation of the respective summary to be sent as notifications to users"""
77        pass

Helper class that provides a standard way to create an ABC using inheritance.

BaseSummaryGenerator(name: str, container: ~T, html: str = '')
26    def __init__(self, name: str, container: T, html: str = "") -> None:
27        """Initializer for `BaseSummaryGenerator`
28
29        Args:
30            name (str): Name of the respective Summary Generator
31            container (T): A container in which `generate_summary` would add info of the current todo object, It could be a list or dict or sth else
32            html (str, optional): A placeholder for html report contained in `container`. defaults to ""
33        """
34        self._name = name
35        self._container = container
36        self._html = html

Initializer for BaseSummaryGenerator

Arguments:
  • name (str): Name of the respective Summary Generator
  • container (T): A container in which generate_summary would add info of the current todo object, It could be a list or dict or sth else
  • html (str, optional): A placeholder for html report contained in container. defaults to ""
name: str
38    @property
39    def name(self) -> str:
40        """Getter for `name`
41
42        Returns:
43            str: Name of the respective summary generator
44        """
45        return self._name

Getter for name

Returns:

str: Name of the respective summary generator

container: str
47    @property
48    def container(self) -> str:
49        """Getter for `container`
50
51        Returns:
52            str: container of the respective summary generator
53        """
54        return self._container

Getter for container

Returns:

str: container of the respective summary generator

html: str
56    @property
57    def html(self) -> str:
58        """Getter for `html`
59
60        Returns:
61            str: html of the respective summary generator
62        """
63        return self._html

Getter for html

Returns:

str: html of the respective summary generator

@abstractmethod
def generate_summary(self, all_todos_objs: Dict[str, List[todonotifier.models.TODO]]) -> None:
65    @abstractmethod
66    def generate_summary(self, all_todos_objs: Dict[str, List[TODO]]) -> None:
67        """Abstract function to generate_summary summary
68
69        Args:
70            all_todos_objs (Dict[str, List[TODO]]):  Key-value pair where key is relative path of file parsed and value is list of todo objects in that file
71        """
72        pass

Abstract function to generate_summary summary

Arguments:
  • all_todos_objs (Dict[str, List[TODO]]): Key-value pair where key is relative path of file parsed and value is list of todo objects in that file
@abstractmethod
def generate_html(self) -> None:
74    @abstractmethod
75    def generate_html(self) -> None:
76        """Generates the html representation of the respective summary to be sent as notifications to users"""
77        pass

Generates the html representation of the respective summary to be sent as notifications to users

class ByModuleSummaryGenerator(BaseSummaryGenerator):
 80class ByModuleSummaryGenerator(BaseSummaryGenerator):
 81    def __init__(self, name: str = DEFAULT_SUMMARY_GENERATORS_ENUM.TODO_BY_MODULE, container: Dict[str, List[List[str]]] = None) -> None:
 82        """Initializer for `ByModuleSummaryGenerator`
 83
 84        Args:
 85            name (str, optional): Name of the respective Summary Generator. Defaults to DEFAULT_SUMMARY_GENERATORS_ENUM.TODO_BY_MODULE.
 86            container (Dict[str, List[List[str]], optional): A container in which `generate_summary` would add info of the current todo object. Defaults to {}.
 87        """
 88        super().__init__(name=name, container=container or {})
 89
 90    def generate_summary(self, all_todos_objs: Dict[str, List[TODO]]) -> None:
 91        """Generates summary for each module
 92
 93        Args:
 94            all_todos_objs (Dict[str, List[TODO]]):  Key-value pair where key is relative path of file parsed and value is list of todo objects in that file
 95        """
 96        logger.info(f"Generating summary: {self.name}")
 97
 98        for module in all_todos_objs:
 99            logger.info(f"Generating summary: {self.name} for module: {module}")
100            for todo_obj in all_todos_objs[module]:
101                user_name = todo_obj.user.user_name
102
103                if todo_obj.module not in self._container:
104                    self._container[todo_obj.module] = [
105                        [
106                            user_name,
107                            todo_obj.msg,
108                            todo_obj.position.line_no,
109                            str(todo_obj.completion_date),
110                        ]
111                    ]
112                else:
113                    self._container[todo_obj.module].append(
114                        [
115                            user_name,
116                            todo_obj.msg,
117                            todo_obj.position.line_no,
118                            str(todo_obj.completion_date),
119                        ]
120                    )
121
122        logger.info(f"Summary generated: {self.container}")
123
124    def generate_html(self) -> None:
125        """Generates the html representation showing module wise summary of todo items"""
126        logger.info(f"Generating html for: {self.name}")
127
128        tables = ""
129        for module in self._container:
130            table = """
131            <table>
132                <caption>Module wise summary</caption>
133            <tr>
134                <th>User Name</th>
135                <th>Message</th>
136                <th>Line No.</th>
137                <th>Completion Date</th>
138            </tr>
139            """
140
141            for todo_item in self._container[module]:
142                table += f"""
143                <tr>
144                    <td>{todo_item[0]}</td>
145                    <td>{todo_item[1]}</td>
146                    <td>{todo_item[2]}</td>
147                    <td>{todo_item[3]}</td>
148                </tr>
149                """
150            table += TABLE_CLOSE_TAG
151
152            tables += f"""
153            <h3>TODOs for module {module}</h3>
154            <p>
155                {table}
156            </p><br>
157            """
158
159        logger.info(f"HTML generated: {tables}")
160        self._html = tables

Helper class that provides a standard way to create an ABC using inheritance.

ByModuleSummaryGenerator( name: str = 'Module-wise Summary', container: Dict[str, List[List[str]]] = None)
81    def __init__(self, name: str = DEFAULT_SUMMARY_GENERATORS_ENUM.TODO_BY_MODULE, container: Dict[str, List[List[str]]] = None) -> None:
82        """Initializer for `ByModuleSummaryGenerator`
83
84        Args:
85            name (str, optional): Name of the respective Summary Generator. Defaults to DEFAULT_SUMMARY_GENERATORS_ENUM.TODO_BY_MODULE.
86            container (Dict[str, List[List[str]], optional): A container in which `generate_summary` would add info of the current todo object. Defaults to {}.
87        """
88        super().__init__(name=name, container=container or {})

Initializer for ByModuleSummaryGenerator

Arguments:
  • name (str, optional): Name of the respective Summary Generator. Defaults to DEFAULT_SUMMARY_GENERATORS_ENUM.TODO_BY_MODULE.
  • container (Dict[str, List[List[str]], optional): A container in which generate_summary would add info of the current todo object. Defaults to {}.
def generate_summary(self, all_todos_objs: Dict[str, List[todonotifier.models.TODO]]) -> None:
 90    def generate_summary(self, all_todos_objs: Dict[str, List[TODO]]) -> None:
 91        """Generates summary for each module
 92
 93        Args:
 94            all_todos_objs (Dict[str, List[TODO]]):  Key-value pair where key is relative path of file parsed and value is list of todo objects in that file
 95        """
 96        logger.info(f"Generating summary: {self.name}")
 97
 98        for module in all_todos_objs:
 99            logger.info(f"Generating summary: {self.name} for module: {module}")
100            for todo_obj in all_todos_objs[module]:
101                user_name = todo_obj.user.user_name
102
103                if todo_obj.module not in self._container:
104                    self._container[todo_obj.module] = [
105                        [
106                            user_name,
107                            todo_obj.msg,
108                            todo_obj.position.line_no,
109                            str(todo_obj.completion_date),
110                        ]
111                    ]
112                else:
113                    self._container[todo_obj.module].append(
114                        [
115                            user_name,
116                            todo_obj.msg,
117                            todo_obj.position.line_no,
118                            str(todo_obj.completion_date),
119                        ]
120                    )
121
122        logger.info(f"Summary generated: {self.container}")

Generates summary for each module

Arguments:
  • all_todos_objs (Dict[str, List[TODO]]): Key-value pair where key is relative path of file parsed and value is list of todo objects in that file
def generate_html(self) -> None:
124    def generate_html(self) -> None:
125        """Generates the html representation showing module wise summary of todo items"""
126        logger.info(f"Generating html for: {self.name}")
127
128        tables = ""
129        for module in self._container:
130            table = """
131            <table>
132                <caption>Module wise summary</caption>
133            <tr>
134                <th>User Name</th>
135                <th>Message</th>
136                <th>Line No.</th>
137                <th>Completion Date</th>
138            </tr>
139            """
140
141            for todo_item in self._container[module]:
142                table += f"""
143                <tr>
144                    <td>{todo_item[0]}</td>
145                    <td>{todo_item[1]}</td>
146                    <td>{todo_item[2]}</td>
147                    <td>{todo_item[3]}</td>
148                </tr>
149                """
150            table += TABLE_CLOSE_TAG
151
152            tables += f"""
153            <h3>TODOs for module {module}</h3>
154            <p>
155                {table}
156            </p><br>
157            """
158
159        logger.info(f"HTML generated: {tables}")
160        self._html = tables

Generates the html representation showing module wise summary of todo items

class ExpiredTodosByUserSummaryGenerator(BaseSummaryGenerator):
163class ExpiredTodosByUserSummaryGenerator(BaseSummaryGenerator):
164    def __init__(self, name: str = DEFAULT_SUMMARY_GENERATORS_ENUM.EXPIRED_TODO_BY_USER, container: Dict[str, List[List[str]]] = None) -> None:
165        """Initializer for `ByModuleSummaryGenerator`
166
167        Args:
168            name (str, optional): Name of the respective Summary Generator. Defaults to DEFAULT_SUMMARY_GENERATORS_ENUM.EXPIRED_TODO_BY_USER.
169            container (Dict[str, List[List[str]], optional): A container in which `generate_summary` would add info of the current todo object. Defaults to {}.
170        """
171        super().__init__(name=name, container=container or {})
172
173    def generate_summary(self, all_todos_objs: Dict[str, List[TODO]]) -> None:
174        """Generates summary for all expired todo items by user
175
176        Args:
177            all_todos_objs (Dict[str, List[TODO]]):  Key-value pair where key is relative path of file parsed and value is list of todo objects in that file
178            expired_todos_by_user_list (dict): Dictionary with user_name as key and corresponding expired todo items as value
179        """
180        logger.info(f"Generating summary: {self.name}")
181
182        curr_date = datetime.today().date()
183
184        for module in all_todos_objs:
185            logger.info(f"Generating summary: {self.name} for module: {module}")
186            for todo_obj in all_todos_objs[module]:
187                user_name = todo_obj.user.user_name
188
189                if curr_date > todo_obj.completion_date:
190                    if user_name not in self._container:
191                        self._container[user_name] = [
192                            [
193                                todo_obj.msg,
194                                todo_obj.module,
195                                todo_obj.position.line_no,
196                                str(todo_obj.completion_date),
197                            ]
198                        ]
199                    else:
200                        self._container[user_name].append(
201                            [
202                                todo_obj.msg,
203                                todo_obj.module,
204                                todo_obj.position.line_no,
205                                str(todo_obj.completion_date),
206                            ]
207                        )
208
209        logger.info(f"Summary generated: {self.container}")
210
211    def generate_html(self) -> None:
212        """Generates the html representation of the user-wise summary of expired todo items for all users"""
213        logger.info(f"Generating html for: {self.name}")
214
215        tables = ""
216        for user_name in self._container:
217            table = """
218            <table>
219                <caption>User wise summary of expired todo item</caption>
220            <tr>
221                <th>Message</th>
222                <th>Module</th>
223                <th>Line No.</th>
224                <th>Completion Date</th>
225            </tr>
226            """
227
228            for todo_item in self._container[user_name]:
229                table += f"""
230                    <tr>
231                        <td>{todo_item[0]}</td>
232                        <td>{todo_item[1]}</td>
233                        <td>{todo_item[2]}</td>
234                        <td>{todo_item[3]}</td>
235                    </tr>
236                    """
237            table += TABLE_CLOSE_TAG
238
239            tables += f"""
240            <h3>Expired TODOs for {user_name}</h3>
241            <p>
242                {table}
243            </p><br>
244            """
245
246        logger.info(f"HTML generated: {tables}")
247        self._html = tables

Helper class that provides a standard way to create an ABC using inheritance.

ExpiredTodosByUserSummaryGenerator( name: str = 'Expired TODO Items', container: Dict[str, List[List[str]]] = None)
164    def __init__(self, name: str = DEFAULT_SUMMARY_GENERATORS_ENUM.EXPIRED_TODO_BY_USER, container: Dict[str, List[List[str]]] = None) -> None:
165        """Initializer for `ByModuleSummaryGenerator`
166
167        Args:
168            name (str, optional): Name of the respective Summary Generator. Defaults to DEFAULT_SUMMARY_GENERATORS_ENUM.EXPIRED_TODO_BY_USER.
169            container (Dict[str, List[List[str]], optional): A container in which `generate_summary` would add info of the current todo object. Defaults to {}.
170        """
171        super().__init__(name=name, container=container or {})

Initializer for ByModuleSummaryGenerator

Arguments:
  • name (str, optional): Name of the respective Summary Generator. Defaults to DEFAULT_SUMMARY_GENERATORS_ENUM.EXPIRED_TODO_BY_USER.
  • container (Dict[str, List[List[str]], optional): A container in which generate_summary would add info of the current todo object. Defaults to {}.
def generate_summary(self, all_todos_objs: Dict[str, List[todonotifier.models.TODO]]) -> None:
173    def generate_summary(self, all_todos_objs: Dict[str, List[TODO]]) -> None:
174        """Generates summary for all expired todo items by user
175
176        Args:
177            all_todos_objs (Dict[str, List[TODO]]):  Key-value pair where key is relative path of file parsed and value is list of todo objects in that file
178            expired_todos_by_user_list (dict): Dictionary with user_name as key and corresponding expired todo items as value
179        """
180        logger.info(f"Generating summary: {self.name}")
181
182        curr_date = datetime.today().date()
183
184        for module in all_todos_objs:
185            logger.info(f"Generating summary: {self.name} for module: {module}")
186            for todo_obj in all_todos_objs[module]:
187                user_name = todo_obj.user.user_name
188
189                if curr_date > todo_obj.completion_date:
190                    if user_name not in self._container:
191                        self._container[user_name] = [
192                            [
193                                todo_obj.msg,
194                                todo_obj.module,
195                                todo_obj.position.line_no,
196                                str(todo_obj.completion_date),
197                            ]
198                        ]
199                    else:
200                        self._container[user_name].append(
201                            [
202                                todo_obj.msg,
203                                todo_obj.module,
204                                todo_obj.position.line_no,
205                                str(todo_obj.completion_date),
206                            ]
207                        )
208
209        logger.info(f"Summary generated: {self.container}")

Generates summary for all expired todo items by user

Arguments:
  • all_todos_objs (Dict[str, List[TODO]]): Key-value pair where key is relative path of file parsed and value is list of todo objects in that file
  • expired_todos_by_user_list (dict): Dictionary with user_name as key and corresponding expired todo items as value
def generate_html(self) -> None:
211    def generate_html(self) -> None:
212        """Generates the html representation of the user-wise summary of expired todo items for all users"""
213        logger.info(f"Generating html for: {self.name}")
214
215        tables = ""
216        for user_name in self._container:
217            table = """
218            <table>
219                <caption>User wise summary of expired todo item</caption>
220            <tr>
221                <th>Message</th>
222                <th>Module</th>
223                <th>Line No.</th>
224                <th>Completion Date</th>
225            </tr>
226            """
227
228            for todo_item in self._container[user_name]:
229                table += f"""
230                    <tr>
231                        <td>{todo_item[0]}</td>
232                        <td>{todo_item[1]}</td>
233                        <td>{todo_item[2]}</td>
234                        <td>{todo_item[3]}</td>
235                    </tr>
236                    """
237            table += TABLE_CLOSE_TAG
238
239            tables += f"""
240            <h3>Expired TODOs for {user_name}</h3>
241            <p>
242                {table}
243            </p><br>
244            """
245
246        logger.info(f"HTML generated: {tables}")
247        self._html = tables

Generates the html representation of the user-wise summary of expired todo items for all users

class UpcomingWeekTodosByUserSummaryGenerator(BaseSummaryGenerator):
250class UpcomingWeekTodosByUserSummaryGenerator(BaseSummaryGenerator):
251    def __init__(self, name: str = DEFAULT_SUMMARY_GENERATORS_ENUM.UPCOMING_TODO_BY_USER, container: Dict[str, List[List[str]]] = None) -> None:
252        """Initializer for `ByModuleSummaryGenerator`
253
254        Args:
255            name (str, optional): Name of the respective Summary Generator. Defaults to DEFAULT_SUMMARY_GENERATORS_ENUM.UPCOMING_TODO_BY_USER
256            container (Dict[str, List[List[str]]], optional): A container in which `generate_summary` would add info of the current todo object. Defaults to {}
257        """
258        super().__init__(name=name, container=container or {})
259
260    def generate_summary(self, all_todos_objs: Dict[str, List[TODO]]) -> None:
261        """Generates summary for all upcoming todo items by user
262
263        Args:
264            all_todos_objs (Dict[str, List[TODO]]):  Key-value pair where key is relative path of file parsed and value is list of todo objects in that file
265        """
266        logger.info(f"Generating summary: {self.name}")
267
268        curr_date = datetime.today().date()
269
270        for module in all_todos_objs:
271            logger.info(f"Generating summary: {self.name} for module: {module}")
272            for todo_obj in all_todos_objs[module]:
273                user_name = todo_obj.user.user_name if todo_obj.user.user_name else UNKNOWN_USER_NAME
274
275                if curr_date <= todo_obj.completion_date and (todo_obj.completion_date - curr_date).days <= 7:
276                    if user_name not in self._container:
277                        self._container[user_name] = [
278                            [
279                                todo_obj.msg,
280                                todo_obj.module,
281                                todo_obj.position.line_no,
282                                str(todo_obj.completion_date),
283                            ]
284                        ]
285                    else:
286                        self._container[user_name].append(
287                            [
288                                todo_obj.msg,
289                                todo_obj.module,
290                                todo_obj.position.line_no,
291                                str(todo_obj.completion_date),
292                            ]
293                        )
294
295        logger.info(f"Summary generated: {self.container}")
296
297    def generate_html(self) -> None:
298        """Generates the html representation of the user-wise summary of the upcoming (within a week) todo items for all users"""
299        logger.info(f"Generating html for: {self.name}")
300
301        tables = ""
302        for user_name in self._container:
303            table = """
304            <table>
305                <caption>User wise summary of upcoming todo items</caption>
306            <tr>
307                <th>Message</th>
308                <th>Module</th>
309                <th>Line No.</th>
310                <th>Completion Date</th>
311            </tr>
312            """
313
314            for todo_item in self._container.get(user_name):
315                table += f"""
316                    <tr>
317                        <td>{todo_item[0]}</td>
318                        <td>{todo_item[1]}</td>
319                        <td>{todo_item[2]}</td>
320                        <td>{todo_item[3]}</td>
321                    </tr>
322                    """
323            table += TABLE_CLOSE_TAG
324
325            tables += f"""
326            <h3>Upcoming TODOs for {user_name}</h3>
327            <p>
328                {table}
329            </p><br>
330            """
331
332        logger.info(f"HTML generated: {tables}")
333        self._html = tables

Helper class that provides a standard way to create an ABC using inheritance.

UpcomingWeekTodosByUserSummaryGenerator( name: str = 'Upcoming Week TODO Items', container: Dict[str, List[List[str]]] = None)
251    def __init__(self, name: str = DEFAULT_SUMMARY_GENERATORS_ENUM.UPCOMING_TODO_BY_USER, container: Dict[str, List[List[str]]] = None) -> None:
252        """Initializer for `ByModuleSummaryGenerator`
253
254        Args:
255            name (str, optional): Name of the respective Summary Generator. Defaults to DEFAULT_SUMMARY_GENERATORS_ENUM.UPCOMING_TODO_BY_USER
256            container (Dict[str, List[List[str]]], optional): A container in which `generate_summary` would add info of the current todo object. Defaults to {}
257        """
258        super().__init__(name=name, container=container or {})

Initializer for ByModuleSummaryGenerator

Arguments:
  • name (str, optional): Name of the respective Summary Generator. Defaults to DEFAULT_SUMMARY_GENERATORS_ENUM.UPCOMING_TODO_BY_USER
  • container (Dict[str, List[List[str]]], optional): A container in which generate_summary would add info of the current todo object. Defaults to {}
def generate_summary(self, all_todos_objs: Dict[str, List[todonotifier.models.TODO]]) -> None:
260    def generate_summary(self, all_todos_objs: Dict[str, List[TODO]]) -> None:
261        """Generates summary for all upcoming todo items by user
262
263        Args:
264            all_todos_objs (Dict[str, List[TODO]]):  Key-value pair where key is relative path of file parsed and value is list of todo objects in that file
265        """
266        logger.info(f"Generating summary: {self.name}")
267
268        curr_date = datetime.today().date()
269
270        for module in all_todos_objs:
271            logger.info(f"Generating summary: {self.name} for module: {module}")
272            for todo_obj in all_todos_objs[module]:
273                user_name = todo_obj.user.user_name if todo_obj.user.user_name else UNKNOWN_USER_NAME
274
275                if curr_date <= todo_obj.completion_date and (todo_obj.completion_date - curr_date).days <= 7:
276                    if user_name not in self._container:
277                        self._container[user_name] = [
278                            [
279                                todo_obj.msg,
280                                todo_obj.module,
281                                todo_obj.position.line_no,
282                                str(todo_obj.completion_date),
283                            ]
284                        ]
285                    else:
286                        self._container[user_name].append(
287                            [
288                                todo_obj.msg,
289                                todo_obj.module,
290                                todo_obj.position.line_no,
291                                str(todo_obj.completion_date),
292                            ]
293                        )
294
295        logger.info(f"Summary generated: {self.container}")

Generates summary for all upcoming todo items by user

Arguments:
  • all_todos_objs (Dict[str, List[TODO]]): Key-value pair where key is relative path of file parsed and value is list of todo objects in that file
def generate_html(self) -> None:
297    def generate_html(self) -> None:
298        """Generates the html representation of the user-wise summary of the upcoming (within a week) todo items for all users"""
299        logger.info(f"Generating html for: {self.name}")
300
301        tables = ""
302        for user_name in self._container:
303            table = """
304            <table>
305                <caption>User wise summary of upcoming todo items</caption>
306            <tr>
307                <th>Message</th>
308                <th>Module</th>
309                <th>Line No.</th>
310                <th>Completion Date</th>
311            </tr>
312            """
313
314            for todo_item in self._container.get(user_name):
315                table += f"""
316                    <tr>
317                        <td>{todo_item[0]}</td>
318                        <td>{todo_item[1]}</td>
319                        <td>{todo_item[2]}</td>
320                        <td>{todo_item[3]}</td>
321                    </tr>
322                    """
323            table += TABLE_CLOSE_TAG
324
325            tables += f"""
326            <h3>Upcoming TODOs for {user_name}</h3>
327            <p>
328                {table}
329            </p><br>
330            """
331
332        logger.info(f"HTML generated: {tables}")
333        self._html = tables

Generates the html representation of the user-wise summary of the upcoming (within a week) todo items for all users