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            <tr>
132                <th>User Name</th>
133                <th>Message</th>
134                <th>Line No.</th>
135                <th>Completion Date</th>
136            </tr>
137            """
138
139            for todo_item in self._container[module]:
140                table += f"""
141                <tr>
142                    <td>{todo_item[0]}</td>
143                    <td>{todo_item[1]}</td>
144                    <td>{todo_item[2]}</td>
145                    <td>{todo_item[3]}</td>
146                </tr>
147                """
148            table += TABLE_CLOSE_TAG
149
150            tables += f"""
151            <h3>TODOs for module {module}</h3>
152            <p>
153                {table}
154            </p><br>
155            """
156
157        logger.info(f"HTML generated: {tables}")
158        self._html = tables
159
160
161class ExpiredTodosByUserSummaryGenerator(BaseSummaryGenerator):
162    def __init__(self, name: str = DEFAULT_SUMMARY_GENERATORS_ENUM.EXPIRED_TODO_BY_USER, container: Dict[str, List[List[str]]] = None) -> None:
163        """Initializer for `ByModuleSummaryGenerator`
164
165        Args:
166            name (str, optional): Name of the respective Summary Generator. Defaults to DEFAULT_SUMMARY_GENERATORS_ENUM.EXPIRED_TODO_BY_USER.
167            container (Dict[str, List[List[str]], optional): A container in which `generate_summary` would add info of the current todo object. Defaults to {}.
168        """
169        super().__init__(name=name, container=container or {})
170
171    def generate_summary(self, all_todos_objs: Dict[str, List[TODO]]) -> None:
172        """Generates summary for all expired todo items by user
173
174        Args:
175            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
176            expired_todos_by_user_list (dict): Dictionary with user_name as key and corresponding expired todo items as value
177        """
178        logger.info(f"Generating summary: {self.name}")
179
180        curr_date = datetime.today().date()
181
182        for module in all_todos_objs:
183            logger.info(f"Generating summary: {self.name} for module: {module}")
184            for todo_obj in all_todos_objs[module]:
185                user_name = todo_obj.user.user_name
186
187                if curr_date > todo_obj.completion_date:
188                    if user_name not in self._container:
189                        self._container[user_name] = [
190                            [
191                                todo_obj.msg,
192                                todo_obj.module,
193                                todo_obj.position.line_no,
194                                str(todo_obj.completion_date),
195                            ]
196                        ]
197                    else:
198                        self._container[user_name].append(
199                            [
200                                todo_obj.msg,
201                                todo_obj.module,
202                                todo_obj.position.line_no,
203                                str(todo_obj.completion_date),
204                            ]
205                        )
206
207        logger.info(f"Summary generated: {self.container}")
208
209    def generate_html(self) -> None:
210        """Generates the html representation of the user-wise summary of expired todo items for all users"""
211        logger.info(f"Generating html for: {self.name}")
212
213        tables = ""
214        for user_name in self._container:
215            table = """
216            <table>
217            <tr>
218                <th>Message</th>
219                <th>Module</th>
220                <th>Line No.</th>
221                <th>Completion Date</th>
222            </tr>
223            """
224
225            for todo_item in self._container[user_name]:
226                table += f"""
227                    <tr>
228                        <td>{todo_item[0]}</td>
229                        <td>{todo_item[1]}</td>
230                        <td>{todo_item[2]}</td>
231                        <td>{todo_item[3]}</td>
232                    </tr>
233                    """
234            table += TABLE_CLOSE_TAG
235
236            tables += f"""
237            <h3>Expired TODOs for {user_name}</h3>
238            <p>
239                {table}
240            </p><br>
241            """
242
243        logger.info(f"HTML generated: {tables}")
244        self._html = tables
245
246
247class UpcomingWeekTodosByUserSummaryGenerator(BaseSummaryGenerator):
248    def __init__(self, name: str = DEFAULT_SUMMARY_GENERATORS_ENUM.UPCOMING_TODO_BY_USER, container: Dict[str, List[List[str]]] = None) -> None:
249        """Initializer for `ByModuleSummaryGenerator`
250
251        Args:
252            name (str, optional): Name of the respective Summary Generator. Defaults to DEFAULT_SUMMARY_GENERATORS_ENUM.UPCOMING_TODO_BY_USER
253            container (Dict[str, List[List[str]]], optional): A container in which `generate_summary` would add info of the current todo object. Defaults to {}
254        """
255        super().__init__(name=name, container=container or {})
256
257    def generate_summary(self, all_todos_objs: Dict[str, List[TODO]]) -> None:
258        """Generates summary for all upcoming todo items by user
259
260        Args:
261            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
262        """
263        logger.info(f"Generating summary: {self.name}")
264
265        curr_date = datetime.today().date()
266
267        for module in all_todos_objs:
268            logger.info(f"Generating summary: {self.name} for module: {module}")
269            for todo_obj in all_todos_objs[module]:
270                user_name = todo_obj.user.user_name if todo_obj.user.user_name else UNKNOWN_USER_NAME
271
272                if curr_date <= todo_obj.completion_date and (todo_obj.completion_date - curr_date).days <= 7:
273                    if user_name not in self._container:
274                        self._container[user_name] = [
275                            [
276                                todo_obj.msg,
277                                todo_obj.module,
278                                todo_obj.position.line_no,
279                                str(todo_obj.completion_date),
280                            ]
281                        ]
282                    else:
283                        self._container[user_name].append(
284                            [
285                                todo_obj.msg,
286                                todo_obj.module,
287                                todo_obj.position.line_no,
288                                str(todo_obj.completion_date),
289                            ]
290                        )
291
292        logger.info(f"Summary generated: {self.container}")
293
294    def generate_html(self) -> None:
295        """Generates the html representation of the user-wise summary of the upcoming (within a week) todo items for all users"""
296        logger.info(f"Generating html for: {self.name}")
297
298        tables = ""
299        for user_name in self._container:
300            table = """
301            <table>
302            <tr>
303                <th>Message</th>
304                <th>Module</th>
305                <th>Line No.</th>
306                <th>Completion Date</th>
307            </tr>
308            """
309
310            for todo_item in self._container.get(user_name):
311                table += f"""
312                    <tr>
313                        <td>{todo_item[0]}</td>
314                        <td>{todo_item[1]}</td>
315                        <td>{todo_item[2]}</td>
316                        <td>{todo_item[3]}</td>
317                    </tr>
318                    """
319            table += TABLE_CLOSE_TAG
320
321            tables += f"""
322            <h3>Upcoming TODOs for {user_name}</h3>
323            <p>
324                {table}
325            </p><br>
326            """
327
328        logger.info(f"HTML generated: {tables}")
329        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

Getter for name

Returns:

str: Name of the respective summary generator

container: str

Getter for container

Returns:

str: container of the respective summary generator

html: str

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            <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

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            <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

Generates the html representation showing module wise summary of todo items

class ExpiredTodosByUserSummaryGenerator(BaseSummaryGenerator):
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            <tr>
219                <th>Message</th>
220                <th>Module</th>
221                <th>Line No.</th>
222                <th>Completion Date</th>
223            </tr>
224            """
225
226            for todo_item in self._container[user_name]:
227                table += f"""
228                    <tr>
229                        <td>{todo_item[0]}</td>
230                        <td>{todo_item[1]}</td>
231                        <td>{todo_item[2]}</td>
232                        <td>{todo_item[3]}</td>
233                    </tr>
234                    """
235            table += TABLE_CLOSE_TAG
236
237            tables += f"""
238            <h3>Expired TODOs for {user_name}</h3>
239            <p>
240                {table}
241            </p><br>
242            """
243
244        logger.info(f"HTML generated: {tables}")
245        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)
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 {})

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:
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}")

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:
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            <tr>
219                <th>Message</th>
220                <th>Module</th>
221                <th>Line No.</th>
222                <th>Completion Date</th>
223            </tr>
224            """
225
226            for todo_item in self._container[user_name]:
227                table += f"""
228                    <tr>
229                        <td>{todo_item[0]}</td>
230                        <td>{todo_item[1]}</td>
231                        <td>{todo_item[2]}</td>
232                        <td>{todo_item[3]}</td>
233                    </tr>
234                    """
235            table += TABLE_CLOSE_TAG
236
237            tables += f"""
238            <h3>Expired TODOs for {user_name}</h3>
239            <p>
240                {table}
241            </p><br>
242            """
243
244        logger.info(f"HTML generated: {tables}")
245        self._html = tables

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

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

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