0.4.1
This commit is contained in:
parent
fae85de8ca
commit
f99496c497
4 changed files with 32 additions and 9 deletions
13
CHANGELOG.md
13
CHANGELOG.md
|
@ -1,6 +1,19 @@
|
||||||
# iCalendar Timeseries Server Changelog
|
# iCalendar Timeseries Server Changelog
|
||||||
|
|
||||||
|
|
||||||
|
<!-- BEGIN RELEASE v0.4.1 -->
|
||||||
|
## Version 0.4.1
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
|
||||||
|
<!-- BEGIN CHANGES 0.4.1 -->
|
||||||
|
- Fix todo sorting by due date.
|
||||||
|
- Update README regarding `todo` time series.
|
||||||
|
<!-- END CHANGES 0.4.1 -->
|
||||||
|
|
||||||
|
<!-- END RELEASE v0.4.1 -->
|
||||||
|
|
||||||
|
|
||||||
<!-- BEGIN RELEASE v0.4.0 -->
|
<!-- BEGIN RELEASE v0.4.0 -->
|
||||||
## Version 0.4.0
|
## Version 0.4.0
|
||||||
|
|
||||||
|
|
|
@ -168,6 +168,12 @@ In addition, PromQL label filters can be used.
|
||||||
event{calendar="public",foo=~".*"}
|
event{calendar="public",foo=~".*"}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Alongside with events, todos are exported in a second time series:
|
||||||
|
|
||||||
|
```
|
||||||
|
todo{status!="COMPLETED"}
|
||||||
|
```
|
||||||
|
|
||||||
## Why Prometheus API
|
## Why Prometheus API
|
||||||
|
|
||||||
- It's JSON. A JSON generator is builtin in Python, so no further dependency.
|
- It's JSON. A JSON generator is builtin in Python, so no further dependency.
|
||||||
|
|
|
@ -38,9 +38,8 @@ def prometheus_api():
|
||||||
elif q.name == 'todo':
|
elif q.name == 'todo':
|
||||||
events.extend(get_calendar_todos(name))
|
events.extend(get_calendar_todos(name))
|
||||||
events = list(filter(q, events))
|
events = list(filter(q, events))
|
||||||
[print(e.name, e.due, e.priority) for e in events]
|
|
||||||
# Sort by due date and priority
|
# Sort by due date and priority
|
||||||
events.sort(key=lambda e: (e.due, e.priority))
|
events.sort(key=lambda e: (e.due is None, e.due, e.priority))
|
||||||
response = {
|
response = {
|
||||||
'status': 'success',
|
'status': 'success',
|
||||||
'data': {
|
'data': {
|
||||||
|
|
|
@ -2,7 +2,7 @@ from typing import Any, Dict, List
|
||||||
|
|
||||||
import icalendar
|
import icalendar
|
||||||
import jinja2
|
import jinja2
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, date, timedelta
|
||||||
|
|
||||||
from icalendar_timeseries_server.config import get_config, get_jenv
|
from icalendar_timeseries_server.config import get_config, get_jenv
|
||||||
from icalendar_timeseries_server.query import Metric
|
from icalendar_timeseries_server.query import Metric
|
||||||
|
@ -18,7 +18,6 @@ _ATTRIBUTES: List[str] = [
|
||||||
'status',
|
'status',
|
||||||
'summary',
|
'summary',
|
||||||
'url',
|
'url',
|
||||||
'due',
|
|
||||||
'attach'
|
'attach'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -28,6 +27,15 @@ class Todo(Metric):
|
||||||
def __init__(self, cname: str, todo: icalendar.cal.Todo, start: datetime, end: datetime):
|
def __init__(self, cname: str, todo: icalendar.cal.Todo, start: datetime, end: datetime):
|
||||||
self.calendar: str = cname
|
self.calendar: str = cname
|
||||||
self.start = start
|
self.start = start
|
||||||
|
due = todo.get('due', None)
|
||||||
|
if due:
|
||||||
|
if isinstance(due.dt, datetime):
|
||||||
|
self.due = due.dt
|
||||||
|
elif isinstance(due.dt, date):
|
||||||
|
self.due = datetime.combine(due.dt, datetime.min.time())
|
||||||
|
self.due = self.due.replace(tzinfo=get_config().tz)
|
||||||
|
else:
|
||||||
|
self.due = None
|
||||||
# self.attributes: Dict[str, str] = dict()
|
# self.attributes: Dict[str, str] = dict()
|
||||||
attributes: Dict[str, str] = dict()
|
attributes: Dict[str, str] = dict()
|
||||||
tmp: Dict[str, Any] = {
|
tmp: Dict[str, Any] = {
|
||||||
|
@ -35,6 +43,8 @@ class Todo(Metric):
|
||||||
'start': start,
|
'start': start,
|
||||||
'end': end
|
'end': end
|
||||||
}
|
}
|
||||||
|
if self.due:
|
||||||
|
tmp['due'] = str(self.due)
|
||||||
for attr in _ATTRIBUTES:
|
for attr in _ATTRIBUTES:
|
||||||
tmp[attr] = todo.get(attr, '')
|
tmp[attr] = todo.get(attr, '')
|
||||||
substitution_keys = set(_ATTRIBUTES)
|
substitution_keys = set(_ATTRIBUTES)
|
||||||
|
@ -49,11 +59,6 @@ class Todo(Metric):
|
||||||
newvalue: str = jtemplate.render(**tmp)
|
newvalue: str = jtemplate.render(**tmp)
|
||||||
attributes[newkey] = newvalue
|
attributes[newkey] = newvalue
|
||||||
self.uid: str = f'{cname}-{start.strftime("%Y%m%dT%H%M%S%Z")}'
|
self.uid: str = f'{cname}-{start.strftime("%Y%m%dT%H%M%S%Z")}'
|
||||||
due = todo.get('due', None)
|
|
||||||
if due:
|
|
||||||
self.due = due.dt
|
|
||||||
else:
|
|
||||||
self.due = datetime.now(get_config().tz) + timedelta(days=36500)
|
|
||||||
self.priority = todo.get('priority', '0')
|
self.priority = todo.get('priority', '0')
|
||||||
super().__init__('todo', attributes)
|
super().__init__('todo', attributes)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue