From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric Schulte" Subject: Re: org-plot and timestamps Date: Tue, 28 Oct 2008 09:23:53 -0700 Message-ID: <87iqrb88qd.fsf@mitre.org> References: <87prlm83pl.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KvHLL-0006oc-Uh for emacs-orgmode@gnu.org; Wed, 29 Oct 2008 16:08:39 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KvHLJ-0006oQ-Ht for emacs-orgmode@gnu.org; Wed, 29 Oct 2008 16:08:38 -0400 Received: from [199.232.76.173] (port=32901 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KvHLJ-0006oN-8u for emacs-orgmode@gnu.org; Wed, 29 Oct 2008 16:08:37 -0400 Received: from smtp-bedford.mitre.org ([129.83.20.191]:36039) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KvHLI-0007tI-QE for emacs-orgmode@gnu.org; Wed, 29 Oct 2008 16:08:37 -0400 Received: from smtp-bedford.mitre.org (localhost.localdomain [127.0.0.1]) by smtp-bedford.mitre.org (8.13.1/8.13.1) with ESMTP id m9TK8Y0F002336 for ; Wed, 29 Oct 2008 16:08:34 -0400 Received: from linus.mitre.org (linus.mitre.org [129.83.10.1]) by smtp-bedford.mitre.org (8.13.1/8.13.1) with ESMTP id m9TK8YSx002330 for ; Wed, 29 Oct 2008 16:08:34 -0400 Received: from eschulte-work (linus.mitre.org [129.83.10.1]) by linus.mitre.org (8.12.11/8.12.10) with ESMTP id m9TK8KET009643 for ; Wed, 29 Oct 2008 16:08:34 -0400 (EDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org > On 27 Oct 2008, Charles Sebold wrote: > >> How's this for a first pass? Not a git user before I started with >> org-mode so any pointers on how to generate these would be >> appreciated. > Hi Charles, The patch looks great, I vote we drop it 'as is' into org-plot.el. The only enhancement that comes to mind would be to expose the `time-ind' variable as a plot option. Allowing users to specify different time formats, but really if they're that sophisticated in their use of gnuplot, then they can do that on their own through the `set:' option. Thanks for the addition! -- Eric > > How embarrassing. This is the patch I meant to send: > > Changes in origin/HEAD > Modified lisp/org-plot.el > diff --git a/lisp/org-plot.el b/lisp/org-plot.el > index db67257..d0d62f6 100644 > --- a/lisp/org-plot.el > +++ b/lisp/org-plot.el > @@ -101,10 +101,16 @@ will be added. Returns the resulting property list." > (org-plot/add-options-to-plist params (match-string 1 line)) > params))) > > +(defun org-plot-quote-timestamp-field (s) > + "Convert field S from timestamp to Unix time and export to gnuplot." > + (format-time-string "%Y-%m-%d-%H:%M:%S" (org-time-string-to-time s))) > + > (defun org-plot-quote-tsv-field (s) > "Quote field S for export to gnuplot." > (if (string-match org-table-number-regexp s) s > - (concat "\"" (mapconcat 'identity (split-string s "\"") "\"\"") "\""))) > + (if (string-match org-ts-regexp3 s) > + (org-plot-quote-timestamp-field s) > + (concat "\"" (mapconcat 'identity (split-string s "\"") "\"\"") "\"")))) > > (defun org-plot/gnuplot-to-data (table data-file params) > "Export TABLE to DATA-FILE in a format readable by gnuplot. > @@ -180,6 +186,7 @@ NUM-COLS controls the number of columns plotted in a 2-d plot." > (title (plist-get params :title)) > (file (plist-get params :file)) > (ind (plist-get params :ind)) > + (time-ind (plist-get params :timeind)) > (text-ind (plist-get params :textind)) > (deps (if (plist-member params :deps) (plist-get params :deps))) > (col-labels (plist-get params :labels)) > @@ -217,6 +224,9 @@ NUM-COLS controls the number of columns plotted in a 2-d plot." > (mapconcat (lambda (pair) > (format "\"%s\" %d" (cdr pair) (car pair))) > y-labels ", ")))) > + (when time-ind ;; timestamp index > + (add-to-script "set xdata time") > + (add-to-script "set timefmt \"%Y-%m-%d-%H:%M:%S\"")) > (case type ;; plot command > ('2d (dotimes (col num-cols) > (unless (and (equal type '2d) > @@ -284,16 +294,24 @@ line directly before or after the table." > ('grid (let ((y-labels (org-plot/gnuplot-to-grid-data > table data-file params))) > (when y-labels (plist-put params :ylabels y-labels))))) > - ;; check for text ind column > + ;; check for timestamp ind column > (let ((ind (- (plist-get params :ind) 1))) > - (when (and (>= ind 0) (equal '2d (plist-get params :plot-type))) > - (if (> (length > - (delq 0 (mapcar > + (when (and (>= ind 0) (equal '2d (plist-get params :plot-type))) > + (if (= (length > + (delq 0 (mapcar > (lambda (el) > - (if (string-match org-table-number-regexp el) > + (if (string-match org-ts-regexp3 el) > 0 1)) > (mapcar (lambda (row) (nth ind row)) table)))) 0) > - (plist-put params :textind t)))) > + (plist-put params :timeind t) > + ;; check for text ind column > + (if (> (length > + (delq 0 (mapcar > + (lambda (el) > + (if (string-match org-table-number-regexp el) > + 0 1)) > + (mapcar (lambda (row) (nth ind row)) table)))) 0) > + (plist-put params :textind t))))) > ;; write script > (with-temp-buffer > (if (plist-get params :script) ;; user script > @@ -307,7 +325,8 @@ line directly before or after the table." > (gnuplot-mode) > (gnuplot-send-buffer-to-gnuplot)) > ;; cleanup > - (bury-buffer (get-buffer "*gnuplot*"))(delete-file data-file)))) > + (bury-buffer (get-buffer "*gnuplot*")) > + (delete-file data-file)))) > > (provide 'org-plot)