Move get_date_counts into DateCountExporter; misc changes

This commit is contained in:
karimpwnz 2021-01-05 00:08:38 +02:00
parent bff9bb1997
commit 5219600aa0
2 changed files with 7 additions and 15 deletions

View file

@ -2,13 +2,13 @@
# encoding: utf-8 # encoding: utf-8
# Copyright (C) 2012-2021 jrnl contributors # Copyright (C) 2012-2021 jrnl contributors
# License: https://www.gnu.org/licenses/gpl-3.0.html # License: https://www.gnu.org/licenses/gpl-3.0.html
from collections import Counter
from .text_exporter import TextExporter from .text_exporter import TextExporter
from .util import get_date_counts
class DatecountExporter(TextExporter): class DatecountExporter(TextExporter):
"""This Exporter can lists the tags for entries and journals, exported as a plain text file.""" """This Exporter lists dates and their respective counts, for heatingmapping etc."""
names = ["datecount"] names = ["datecount"]
extension = "datecount" extension = "datecount"
@ -20,6 +20,10 @@ class DatecountExporter(TextExporter):
@classmethod @classmethod
def export_journal(cls, journal): def export_journal(cls, journal):
"""Returns dates and their frequencies for an entire journal.""" """Returns dates and their frequencies for an entire journal."""
date_counts = get_date_counts(journal) date_counts = Counter()
for entry in journal.entries:
# entry.date.date() gets date without time
date = str(entry.date.date())
date_counts[date] += 1
result = "\n".join(f"{date}, {count}" for date, count in date_counts.items()) result = "\n".join(f"{date}, {count}" for date, count in date_counts.items())
return result return result

View file

@ -3,18 +3,6 @@
# Copyright (C) 2012-2021 jrnl contributors # Copyright (C) 2012-2021 jrnl contributors
# License: https://www.gnu.org/licenses/gpl-3.0.html # License: https://www.gnu.org/licenses/gpl-3.0.html
from collections import Counter
def get_date_counts(journal):
"""Returns a collections.Counter object containing date counts"""
date_counts = Counter()
for entry in journal.entries:
# entry.date.date() gets date without time
date = str(entry.date.date())
date_counts[date] += 1
return date_counts
def get_tags_count(journal): def get_tags_count(journal):
"""Returns a set of tuples (count, tag) for all tags present in the journal.""" """Returns a set of tuples (count, tag) for all tags present in the journal."""