all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Parsing records in lisp?
@ 2003-05-13  9:09 Henrik Jönsson
  2003-05-13 10:48 ` Oliver Scholz
  0 siblings, 1 reply; 2+ messages in thread
From: Henrik Jönsson @ 2003-05-13  9:09 UTC (permalink / raw)


Hi!

I have a file to record what I have I worked on every day. I use this
list when I do my time reporting each week.

The file looks like this:

Week: 19
#Date           Hours   Project Comment
2003-05-08	2	FVCI	Meeting with Prover about the quotation
2003-05-08	2	FVCI	Reviewing Test Spec and Req Spec
2003-05-09	2	SCM	Misc
	
Week: 20
2003-05-12	2	FVCI	Misc
2003-05-13	6	SCM	Support Phoenix
2003-05-13	2	FVCI	Test Spec SST

Currently I have a small perl script that reads this file and
generates a more suitable report that I can use when entering the
hours into our time reporting system.

The output is like this:

###############################
Week: 19
	FVCI:	4
	SCM:	6
Totals: 10

###############################
Week: 20
	FVCI:	4
	SCM:	1
Totals: 5

However, I would like to create this report in lisp. I have tried
some, but lisp is not yet my favourite language. Can anyone help me
with this? Give me some snippets to be able to continue.

Thanks!

Regards
Henrik

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Parsing records in lisp?
  2003-05-13  9:09 Parsing records in lisp? Henrik Jönsson
@ 2003-05-13 10:48 ` Oliver Scholz
  0 siblings, 0 replies; 2+ messages in thread
From: Oliver Scholz @ 2003-05-13 10:48 UTC (permalink / raw)


henrik.jonsson@se.transport.bombardier.com (Henrik Jönsson) writes:

> Hi!
>
> I have a file to record what I have I worked on every day. I use this
> list when I do my time reporting each week.
>
> The file looks like this:
>
> Week: 19
> #Date           Hours   Project Comment
> 2003-05-08	2	FVCI	Meeting with Prover about the quotation
> 2003-05-08	2	FVCI	Reviewing Test Spec and Req Spec
[...]

> However, I would like to create this report in lisp. I have tried
> some, but lisp is not yet my favourite language. Can anyone help me
> with this? Give me some snippets to be able to continue.

I think the most straightforward way for you is to read the stuff
into lists using regular expressions, `re-search-forward',
`looking-at' and `match-string':

[Everything below is completely untested, of course.]

(defconst my-regexp
  (concat 
   "\\([[:digit:]]\\{4\\}-[01][[:digit:]]-[0-3][[:digit:]]\\)"
   "\\s-+\\([[:digit:]]\\)"
   "\\s-+\\([[:alnum:]]+\\)"
   "\\s-+\\(.*\\)"))

(defun my-read-stuff ()

 [...]

(let ((file-list nil))
  (while (re-search-forward "^Week: \\([[:digit:]]+\\)" nil t)
    (let ((week (match-string 1))
	  (week-list nil))
      (while (not (looking-at my-regexp))
	(forward-line 1))
      (while (looking-at my-regexp)
	(push (list (match-string 1)  ; date
		    (match-string 2)  ; hours
		    (match-string 3)  ; project
		    (match-string 4)) ; comment
	      week-list)
	(forward-line 1))
      (push (cons week week-list) file-list)))

 [...]

 file-list)
  

And write it out again using `insert' (and maybe `format'):

(defconst my-separator (make-string 15 ?#))

(defun my-write-stuff ()
  (interactive)

  [...]

  (with-current-buffer [...]
    (let ((contents (my-read-stuff)))

      [...]

      (dolist (week contents)
	(insert my-separator "\n")
	(insert (format "Week: %s" (car week)))
	(let ((time-accounts (my-calculate-projects-time
			      (cdr week))))
	  ;; `my-calculate-projects-time' (or whatever name you
	  ;; choose) should return a list of projects of the form:
	  ;; (ACCOUNT ACCOUNT*)
	  ;; Where account is a cons cell: (PROJECT . TIME).
	  ;; Use `cons' to build cons cells. Use `string-to-number' to
	  ;; get the numbers from the strings.
	  (dolist (entry time-accounts)
	    (insert (format "Project %s: %s"
			    (car entry) (cdr entry))))))

      [...])

HTH

    Oliver
-- 
24 Floréal an 211 de la Révolution
Liberté, Egalité, Fraternité!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-05-13 10:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-05-13  9:09 Parsing records in lisp? Henrik Jönsson
2003-05-13 10:48 ` Oliver Scholz

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.