mirror of
https://codeberg.org/langfingaz/bbb-status
synced 2024-12-23 00:36:05 +01:00
refactor: timedelta - filter recent BbbStatus objects
This commit is contained in:
parent
1e5b44f2c9
commit
d240d4e82f
@ -2,7 +2,8 @@ from functools import total_ordering
|
||||
from typing import List
|
||||
from pathlib import Path
|
||||
from xml.etree import ElementTree
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
import logging
|
||||
|
||||
from langfingaz import loadData
|
||||
@ -142,8 +143,9 @@ def parseMeetingsData(dataStr: str) -> List[Meeting]:
|
||||
return [Meeting(xml_meeting) for xml_meeting in xml_meetings.iter('meeting')]
|
||||
|
||||
|
||||
def readBbbStatiFromDir(dataDir: Path = fileUtil.getDataDir()) -> List[BbbStatus]:
|
||||
def readBbbStatiFromDir(dataDir: Path = fileUtil.getDataDir(), delta: timedelta = None) -> List[BbbStatus]:
|
||||
"""
|
||||
:arg delta: (optional) Only return BbbStatus objects in the time-range now-delta and now. Example: timedelta(days=28)
|
||||
:return: List of BbbStatus objects, sorted by date
|
||||
"""
|
||||
|
||||
@ -155,9 +157,21 @@ def readBbbStatiFromDir(dataDir: Path = fileUtil.getDataDir()) -> List[BbbStatus
|
||||
dataStr, t = loadData.loadData(file)
|
||||
meetings: List[Meeting] = parseMeetingsData(dataStr)
|
||||
bbbStati.append(BbbStatus(meetings, t))
|
||||
|
||||
if (len(bbbStati) < 1):
|
||||
print("No bbbStatus objects were found in data directory: " + str(dataDir))
|
||||
return []
|
||||
|
||||
# sort by date
|
||||
return sorted(bbbStati, key=BbbStatus.getKey)
|
||||
bbbStati = sorted(bbbStati, key=BbbStatus.getKey)
|
||||
|
||||
if delta is not None and len(bbbStati) > 1:
|
||||
# filter: take only bbbStatus objects of the last month (4 weeks)
|
||||
#
|
||||
# start: datetime = bbbStati[0].pointOfTime
|
||||
# end: datetime = bbbStati[-1].pointOfTime
|
||||
# delta: timedelta = end-start
|
||||
end: datetime = bbbStati[-1].pointOfTime
|
||||
monthBeforeEnd: datetime = end - delta
|
||||
bbbStati = [bbbStatus for bbbStatus in bbbStati if bbbStatus.pointOfTime >= monthBeforeEnd]
|
||||
|
||||
return bbbStati
|
||||
|
@ -22,19 +22,10 @@ def plotMeetings(dataDir: Path = fileUtil.getDataDir()):
|
||||
plot BBB meetings of the last month
|
||||
"""
|
||||
|
||||
bbbStati: List[BbbStatus] = parseMeetings.readBbbStatiFromDir(dataDir)
|
||||
bbbStati: List[BbbStatus] = parseMeetings.readBbbStatiFromDir(dataDir=dataDir, delta=timedelta(days=28))
|
||||
if len(bbbStati) < 1:
|
||||
return
|
||||
|
||||
# filter: take only bbbStatus objects of the last month (4 weeks)
|
||||
#
|
||||
# start: datetime = bbbStati[0].pointOfTime
|
||||
# end: datetime = bbbStati[-1].pointOfTime
|
||||
# delta: timedelta = end-start
|
||||
end: datetime = bbbStati[-1].pointOfTime
|
||||
monthBeforeEnd: datetime = end - timedelta(days=28)
|
||||
bbbStati = [bbbStatus for bbbStatus in bbbStati if bbbStatus.pointOfTime >= monthBeforeEnd]
|
||||
|
||||
image: Path = doPlotMeetings(bbbStati)
|
||||
print("saved image at " + str(image))
|
||||
|
||||
|
@ -27,7 +27,7 @@ def getModerators(dataDir: Path = fileUtil.getDataDir()) -> Dict[parseMeetings.U
|
||||
:return: Dict[User, count-how-often-as-moderator] sorted by User.fullName
|
||||
"""
|
||||
|
||||
bbbStati: List[BbbStatus] = parseMeetings.readBbbStatiFromDir(dataDir)
|
||||
bbbStati: List[BbbStatus] = parseMeetings.readBbbStatiFromDir(dataDir=dataDir, delta=timedelta(days=28))
|
||||
if len(bbbStati) < 1:
|
||||
return {}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user