emacs-wiki-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[emacs-wiki-discuss] Patch to planner-timeclock-summary: Added exclusion


From: Chris Parsons
Subject: [emacs-wiki-discuss] Patch to planner-timeclock-summary: Added exclusion regexp to filter
Date: Thu, 23 Dec 2004 12:19:52 +0000
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3 (windows-nt)

Hi planners,

I've got another patch for planner-timeclock-summary: this time we add a
regexp to specifically exclude from the summary. (Came about as I was
trying to find a way of excluding certain plan-pages just by one regexp
- wasn't easy).

There are no interactive functions for this as of yet.

Entry-point (my timesheet for the month):

(planner-timeclock-summary-show-range "2004.12.01" "2004.12.31" 
                                      "ClientA\\|ClientB\\|ClientC" 
"Personal\\|NotBillable")

All the function signatures are backwards-compatible.

Sacha, do you think this'll be ok to go in? Not too much bloat, and it's
very useful.

Chris


cd c:/Program Files/emacs-21.3/site-lisp/planner/
diff -u "c:/Program 
Files/emacs-21.3/site-lisp/planner/planner-timeclock-summary.el.orig" 
"c:/Program Files/emacs-21.3/site-lisp/planner/planner-timeclock-summary.el"
--- c:/Program 
Files/emacs-21.3/site-lisp/planner/planner-timeclock-summary.el.orig     
2004-12-23 11:46:42.775168900 +0000
+++ c:/Program Files/emacs-21.3/site-lisp/planner/planner-timeclock-summary.el  
2004-12-23 12:04:38.115432400 +0000
@@ -182,11 +182,14 @@
        (setq task-name task-fullname)))
     (list project-name task-name task-length)))
 
-(defun planner-timeclock-summary-day-range-entry (start-date end-date 
&optional filter-regexp)
+(defun planner-timeclock-summary-day-range-entry (start-date end-date 
&optional filter-regexp filter-exclude-regexp)
   "Return the data between START-DATE and END-DATE (inclusive)
-START-DATE and END-DATE should be strings of the form YYYY/MM/DD.
-If FILTER-REGEXP is non-nil, only plan pages matching that regexp
-will be included. Use the format specified in timeclock.el."
+START-DATE and END-DATE should be strings of the form YYYY/MM/DD. Use
+the format specified in timeclock.el.  If FILTER-REGEXP is non-nil,
+only plan pages matching that regexp will be included. If
+FILTER-EXCLUDE-REGEXP is non-nil any plan pages matching that regexp
+will be included.
+"
   (let ((day-list (timeclock-day-alist))
         entry-list)
     (while day-list
@@ -194,12 +197,16 @@
         (when (or (not start-date)
                   (planner-timeclock-within-date-range start-date end-date 
(car theday)))
           (setq entry-list (append (cddr theday) entry-list)))))
-    (when (and filter-regexp (not (string= filter-regexp "")))
+    (when (or (and filter-regexp (not (string= filter-regexp "")))
+                                                       (and 
filter-exclude-regexp (not (string= filter-exclude-regexp ""))))
       (setq entry-list
             (delq nil
                   (mapcar
                    (lambda (item)
-                     (if (string-match filter-regexp (nth 2 item))
+                     (if (and (or (not filter-regexp) 
+                                                                               
                                                        (string-match 
filter-regexp (nth 2 item)))
+                                                                               
                                        (or (not filter-exclude-regexp)
+                                                                               
                                                        (not (string-match 
filter-exclude-regexp (nth 2 item)))))
                          item))
                    entry-list))))
     (setq entry-list
@@ -307,13 +314,15 @@
    (planner-timeclock-summary-one-day-alist date)))
 
 (defun planner-timeclock-summary-make-summary-string-range
-  (start-date end-date total &optional filter-regexp)
+  (start-date end-date total &optional filter-regexp filter-exclude-regexp)
   "Use `planner-timeclock-summary-summary-string' from START-DATE to END-DATE.
 Dates are in format YYYY/MM/DD. TOTAL is the total time clocked
 today, in seconds. If FILTER-REGEXP is non-nil, only plan pages
-matching that regexp will be included."
+matching that regexp will be included. If FILTER-EXCLUDE-REGEXP 
+is non-nil, plan pages *not* matching this regexp also will be
+included."
   (let ((target-string planner-timeclock-summary-summary-string)
-       (data (planner-timeclock-summary-day-range-entry start-date end-date 
filter-regexp))
+       (data (planner-timeclock-summary-day-range-entry start-date end-date 
filter-regexp filter-exclude-regexp))
        begin end last span2 span)
     (setq begin (timeclock-day-begin data))
     (setq last (timeclock-day-end data))
@@ -355,15 +364,17 @@
 today, in seconds."
   (planner-timeclock-summary-make-summary-string-range date date total))
 
-(defun planner-timeclock-summary-calculate-ratio-day (start-date &optional 
end-date filter-regexp)
-  "Calculate time ratio for START-DATE to END-DATE.
-If FILTER-REGEXP is non-nil, only projects matching that regexp will be 
included."
+(defun planner-timeclock-summary-calculate-ratio-day (start-date &optional 
end-date filter-regexp filter-exclude-regexp)
+  "Calculate time ratio for START-DATE to END-DATE.  If FILTER-REGEXP
+is non-nil, only projects matching that regexp will be included. If
+FILTER-EXCLUDE-REGEXP is non-nil, plan pages *not* matching this
+regexp also will be included."
   (when (not end-date)
     (setq end-date start-date))
   (let (target-data)
     (setq target-data (planner-timeclock-summary-extract-data
                        (cdr (planner-timeclock-summary-day-range-entry
-                             start-date end-date filter-regexp))))
+                             start-date end-date filter-regexp 
filter-exclude-regexp))))
     (let ((total (car target-data))
           (projects (cdr target-data)))
       (while projects
@@ -380,16 +391,17 @@
 ;;;_+ Presentation
 
 (defun planner-timeclock-summary-make-text-table-day
-  (start-date &optional end-date filter-regexp hide-summary)
+  (start-date &optional end-date filter-regexp hide-summary 
filter-exclude-regexp)
   "Make the summary table for START-DATE to END-DATE using plain text.
-If FILTER-REGEXP is non-nil, only plan pages matching that regexp
-will be included. If START-DATE is nil, then it will ignore the
-date information and return data for everything.
+If FILTER-REGEXP is non-nil, only plan pages matching that regexp will
+be included. If FILTER-EXCLUDE-REGEXP is non-nil, plan pages *not*
+matching this regexp also will be included. If START-DATE is nil, then
+it will ignore the date information and return data for everything.
 If HIDE-SUMMARY is non-nil, do not include the summary."
   (unless end-date (setq end-date start-date))
   (let (source-list)
     (setq source-list (planner-timeclock-summary-calculate-ratio-day
-                       start-date end-date filter-regexp))
+                       start-date end-date filter-regexp 
filter-exclude-regexp))
     (let ((projects (cdr source-list))
           (total (car source-list)))
       (if total
@@ -440,7 +452,7 @@
             (goto-char (point-max))
             (unless hide-summary
               (insert (planner-timeclock-summary-make-summary-string-range
-                       start-date end-date total filter-regexp)))
+                       start-date end-date total filter-regexp 
filter-exclude-regexp)))
             (buffer-string))
         ""))))
 
@@ -504,11 +516,13 @@
     (planner-read-date "End")))
   (planner-timeclock-summary-show-range start-date end-date filter-regexp))
 
-(defun planner-timeclock-summary-show-range (start-date end-date &optional 
filter-regexp)
+(defun planner-timeclock-summary-show-range (start-date end-date &optional 
filter-regexp filter-exclude-regexp)
   "Show a timeclock report for the date range START-DATE to END-DATE.
-FILTER-REGEXP is an optional parameter which runs each entry
-through a regexp to ensure it matches before using the data.
-Dates are strings in the form YYYY.MM.DD."
+FILTER-REGEXP is an optional parameter which runs each entry through a
+regexp to ensure it matches before using the data.
+FILTER-EXCLUDE-REGEXP is an optional parameter which excludes any
+entry it matches before using the data. Dates are strings in the form
+YYYY.MM.DD."
   (interactive (list (planner-read-date "Start") (planner-read-date "End")))
   (switch-to-buffer (get-buffer-create planner-timeclock-summary-buffer))
   (erase-buffer)
@@ -521,7 +535,7 @@
            (planner-timeclock-summary-make-text-table-day
             (replace-in-string start-date "\\." "/" t)
              (replace-in-string end-date "\\." "/" t)
-             filter-regexp))
+             filter-regexp nil filter-exclude-regexp))
     (planner-mode))
   (goto-char (point-min)))
 

Diff finished at Thu Dec 23 12:09:00

-- 
Chris Parsons
address@hidden





reply via email to

[Prev in Thread] Current Thread [Next in Thread]