Merge lp:~rohanm/gtimelog/custom-date-range-report into lp:~gtimelog-dev/gtimelog/trunk

Proposed by Rohan Mitchell
Status: Merged
Merged at revision: 255
Proposed branch: lp:~rohanm/gtimelog/custom-date-range-report
Merge into: lp:~gtimelog-dev/gtimelog/trunk
Diff against target: 170 lines (+114/-1)
4 files modified
NEWS.txt (+1/-1)
src/gtimelog/gtimelog.ui (+11/-0)
src/gtimelog/main.py (+34/-0)
src/gtimelog/test_gtimelog.py (+68/-0)
To merge this branch: bzr merge lp:~rohanm/gtimelog/custom-date-range-report
Reviewer Review Type Date Requested Status
Marius Gedminas Approve
Review via email: mp+162547@code.launchpad.net

Description of the change

Added a custom date range report so that you can generate a report between any two dates.
This feature can be reached at Report -> Report for a Custom Date Range.
This branch includes tests for the new report.

To post a comment you must log in.
Revision history for this message
Marius Gedminas (mgedmin) wrote :

Looks good, thanks!

I'd like to play with Glade and create a single dialog for selecting both the start and end dates in one go, instead of dealing with two distinct unlabeled popup dialogs asking for same thing. Or maybe you'd care to do that? ;-)

review: Approve
Revision history for this message
Rohan Mitchell (rohanm) wrote :

I'll see if I can find some time to hack on it, perhaps Monday :)

> Looks good, thanks!
>
> I'd like to play with Glade and create a single dialog for selecting both the
> start and end dates in one go, instead of dealing with two distinct unlabeled
> popup dialogs asking for same thing. Or maybe you'd care to do that? ;-)

Revision history for this message
Marius Gedminas (mgedmin) wrote :

No need any more, I found some time to play with Glade today.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'NEWS.txt'
--- NEWS.txt 2013-02-10 19:56:21 +0000
+++ NEWS.txt 2013-05-06 00:11:25 +0000
@@ -1,6 +1,6 @@
10.8.2 (unreleased)10.8.2 (unreleased)
2==================2==================
33* New custom date range report
44
50.8.1 (2013-02-10)50.8.1 (2013-02-10)
6==================6==================
77
=== modified file 'src/gtimelog/gtimelog.ui'
--- src/gtimelog/gtimelog.ui 2012-08-23 05:20:13 +0000
+++ src/gtimelog/gtimelog.ui 2013-05-06 00:11:25 +0000
@@ -425,6 +425,17 @@
425 </object>425 </object>
426 </child>426 </child>
427 <child>427 <child>
428 <object class="GtkImageMenuItem" id="custom_range_report">
429 <property name="label">Report for a Custom Date Range...</property>
430 <property name="visible">True</property>
431 <property name="can_focus">False</property>
432 <property name="use_action_appearance">False</property>
433 <property name="use_underline">True</property>
434 <property name="use_stock">True</property>
435 <signal name="activate" handler="on_custom_range_report_activate" swapped="no"/>
436 </object>
437 </child>
438 <child>
428 <object class="GtkSeparatorMenuItem" id="separator1">439 <object class="GtkSeparatorMenuItem" id="separator1">
429 <property name="visible">True</property>440 <property name="visible">True</property>
430 <property name="can_focus">False</property>441 <property name="can_focus">False</property>
431442
=== modified file 'src/gtimelog/main.py'
--- src/gtimelog/main.py 2013-02-07 08:33:21 +0000
+++ src/gtimelog/main.py 2013-05-06 00:11:25 +0000
@@ -738,6 +738,17 @@
738 period_name='month',738 period_name='month',
739 estimated_column=estimated_column)739 estimated_column=estimated_column)
740740
741 def custom_range_report_categorized(self, output, email, who,
742 estimated_column=False):
743 """Format a custom range report with entries displayed under categories."""
744 min = self.window.min_timestamp.strftime('%Y-%m-%d')
745 max = self.window.max_timestamp - datetime.timedelta(1)
746 max = max.strftime('%Y-%m-%d')
747 subject = u'Custom date range report for %s (%s - %s)' % (who, min, max)
748 return self._categorizing_report(output, email, who, subject,
749 period_name='custom range',
750 estimated_column=estimated_column)
751
741 def daily_report(self, output, email, who):752 def daily_report(self, output, email, who):
742 """Format a daily report.753 """Format a daily report.
743754
@@ -884,6 +895,12 @@
884 first_of_next_month, self.virtual_midnight)895 first_of_next_month, self.virtual_midnight)
885 return self.window_for(min, max)896 return self.window_for(min, max)
886897
898 def window_for_date_range(self, min, max):
899 min = datetime.datetime.combine(min, self.virtual_midnight)
900 max = datetime.datetime.combine(max, self.virtual_midnight)
901 max = max + datetime.timedelta(1)
902 return self.window_for(min, max)
903
887 def whole_history(self):904 def whole_history(self):
888 """Return a TimeWindow for the whole history."""905 """Return a TimeWindow for the whole history."""
889 # XXX I don't like this solution. Better make the min/max filtering906 # XXX I don't like this solution. Better make the min/max filtering
@@ -1967,6 +1984,23 @@
1967 report = reports.monthly_report_plain1984 report = reports.monthly_report_plain
1968 self.mail(report)1985 self.mail(report)
19691986
1987 def range_window(self, min, max):
1988 if not min:
1989 min = self.timelog.day
1990 if not max:
1991 max = self.timelog.day
1992 if max < min:
1993 max = min
1994 return self.timelog.window_for_date_range(min, max)
1995
1996 def on_custom_range_report_activate(self, widget):
1997 """File -> Report for a Custom Date Range"""
1998 min = self.choose_date()
1999 max = self.choose_date()
2000 if min and max:
2001 reports = Reports(self.range_window(min, max))
2002 self.mail(reports.custom_range_report_categorized)
2003
1970 def on_open_complete_spreadsheet_activate(self, widget):2004 def on_open_complete_spreadsheet_activate(self, widget):
1971 """Report -> Complete Report in Spreadsheet"""2005 """Report -> Complete Report in Spreadsheet"""
1972 tempfn = tempfile.mktemp(suffix='gtimelog.csv') # XXX unsafe!2006 tempfn = tempfile.mktemp(suffix='gtimelog.csv') # XXX unsafe!
19732007
=== modified file 'src/gtimelog/test_gtimelog.py'
--- src/gtimelog/test_gtimelog.py 2013-02-06 09:26:32 +0000
+++ src/gtimelog/test_gtimelog.py 2013-05-06 00:11:25 +0000
@@ -587,6 +587,74 @@
587587
588 """588 """
589589
590def doctest_Reports_custom_range_report_categorized():
591 r"""Tests for Reports.custom_range_report_categorized
592
593 >>> import sys
594
595 >>> from datetime import datetime, time
596 >>> from tempfile import NamedTemporaryFile
597 >>> from gtimelog.main import TimeWindow, Reports
598
599 >>> vm = time(2, 0)
600 >>> min = datetime(2010, 1, 25)
601 >>> max = datetime(2010, 2, 1)
602 >>> fh = NamedTemporaryFile()
603
604 >>> window = TimeWindow(fh.name, min, max, vm)
605 >>> reports = Reports(window)
606 >>> reports.custom_range_report_categorized(sys.stdout, 'foo@bar.com',
607 ... 'Bob Jones')
608 To: foo@bar.com
609 Subject: Custom date range report for Bob Jones (2010-01-25 - 2010-01-31)
610 <BLANKLINE>
611 No work done this custom range.
612
613 >>> _ = [fh.write(s + '\n') for s in [
614 ... '2010-01-20 09:00: arrived',
615 ... '2010-01-20 09:30: asdf',
616 ... '2010-01-20 10:00: Bar: Foo',
617 ... ''
618 ... '2010-01-30 09:00: arrived',
619 ... '2010-01-30 09:23: Bing: stuff',
620 ... '2010-01-30 12:54: Bong: other stuff',
621 ... '2010-01-30 13:32: lunch **',
622 ... '2010-01-30 23:46: misc',
623 ... '']]
624 >>> fh.flush()
625
626 >>> window = TimeWindow(fh.name, min, max, vm)
627 >>> reports = Reports(window)
628 >>> reports.custom_range_report_categorized(sys.stdout, 'foo@bar.com',
629 ... 'Bob Jones')
630 To: foo@bar.com
631 Subject: Custom date range report for Bob Jones (2010-01-25 - 2010-01-31)
632 <BLANKLINE>
633 time
634 Bing:
635 Stuff 0:23
636 ----------------------------------------------------------------------
637 0:23
638 <BLANKLINE>
639 Bong:
640 Other stuff 3:31
641 ----------------------------------------------------------------------
642 3:31
643 <BLANKLINE>
644 No category:
645 Misc 10:14
646 ----------------------------------------------------------------------
647 10:14
648 <BLANKLINE>
649 Total work done this custom range: 14:08
650 <BLANKLINE>
651 Categories by time spent:
652 No category 10:14
653 Bong 3:31
654 Bing 0:23
655
656 """
657
590def doctest_Settings_get_config_dir():658def doctest_Settings_get_config_dir():
591 """Test for Settings.get_config_dir659 """Test for Settings.get_config_dir
592660

Subscribers

People subscribed via source and target branches