diff --git a/src/langfingaz/parseMeetings.py b/src/langfingaz/parseMeetings.py index eede3a6..8557273 100644 --- a/src/langfingaz/parseMeetings.py +++ b/src/langfingaz/parseMeetings.py @@ -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 diff --git a/src/langfingaz/plotMeetings.py b/src/langfingaz/plotMeetings.py index 1154802..d06e0f6 100644 --- a/src/langfingaz/plotMeetings.py +++ b/src/langfingaz/plotMeetings.py @@ -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)) diff --git a/src/langfingaz/recentModerators.py b/src/langfingaz/recentModerators.py index 0b04283..925e5cb 100644 --- a/src/langfingaz/recentModerators.py +++ b/src/langfingaz/recentModerators.py @@ -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 {}