mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 04:58:32 +02:00
Move get_date_counts into DateCountExporter; misc changes
This commit is contained in:
parent
bff9bb1997
commit
5219600aa0
2 changed files with 7 additions and 15 deletions
|
@ -2,13 +2,13 @@
|
|||
# encoding: utf-8
|
||||
# Copyright (C) 2012-2021 jrnl contributors
|
||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
from collections import Counter
|
||||
|
||||
from .text_exporter import TextExporter
|
||||
from .util import get_date_counts
|
||||
|
||||
|
||||
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"]
|
||||
extension = "datecount"
|
||||
|
@ -20,6 +20,10 @@ class DatecountExporter(TextExporter):
|
|||
@classmethod
|
||||
def export_journal(cls, 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())
|
||||
return result
|
||||
|
|
|
@ -3,18 +3,6 @@
|
|||
# Copyright (C) 2012-2021 jrnl contributors
|
||||
# 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):
|
||||
"""Returns a set of tuples (count, tag) for all tags present in the journal."""
|
||||
|
|
Loading…
Add table
Reference in a new issue