From: Emanuel Berg <embe8573@student.uu.se>
To: help-gnu-emacs@gnu.org
Subject: Emacs as old-school batch number cruncher
Date: Thu, 20 Nov 2014 05:16:44 +0100 [thread overview]
Message-ID: <87egsycxqr.fsf@debian.uxu> (raw)
I have written a simple-but-cool program [1] that
works on a text file of digits (one for each line) and
then outputs some offsets and properties that you are
familiar with (just read :)).
Questions: 1. What other such Emacs-tools are around?
2. How can I make the program better?
(Code last, or follow the URL for the
file.)
Here is how it works:
For these clock ticks (in nanoseconds):
85033108461718
85033109544537
85033110621490
85033111714366
85033112794112
85033113871903
85033114934049
85033116009605
85033117089909
85033118169656
85033119256945
85033120336411
...
The output is:
readings: 543
mean: 1076366.000000
variance: 14127140.000000
standard deviation: 3758.608785
min: 1062145
max: 1096507
1082818
1076952
1092875
1079745
1077790
1062145
1075555
1080303
1079746
1087288
1079465
1072762
...
Code:
;;; -*- lexical-binding: t -*-
(require 'cl-macs)
(defun get-variance (mean)
(save-excursion
(goto-char 1)
(let ((sum 0) (offsets 0))
(cl-loop
(let ((offset (thing-at-point 'number)))
(if offset
(progn
(cl-incf offsets)
(setq sum (+ sum (expt (- offset mean) 2)))
(forward-line 1) )
(cl-return) )))
(/ sum offsets) )))
(defun tick-stats (desired-tick)
(interactive "n desired tick: ")
(save-excursion
(goto-char 1)
(let ((sum 0) (offsets 0) (max nil) (min nil) )
(cl-loop
(let((t0 (thing-at-point 'number)))
(forward-line 1)
(let((t1 (thing-at-point 'number)))
(save-current-buffer
(set-buffer (get-buffer-create "offsets.log"))
(if t1
(let((offset (- t1 t0 desired-tick)))
(cl-incf offsets)
(setq sum (+ sum offset))
(if (or (not max) (> offset max)) (setq max offset))
(if (or (not min) (> min offset)) (setq min offset))
(insert (format "%d\n" offset)) )
(progn
(goto-char 1)
(insert
(let*((mean (/ sum offsets))
(variance (get-variance mean)) )
(format
"readings: %d\nmean: %f\nvariance: %f\nstandard deviation: %f\nmin: %d\nmax: %d\n\n"
offsets mean variance (sqrt variance) min max)))
(save-buffer)
(cl-return) )))))))))
[1] http://user.it.uu.se/~embe8573/tick/
--
underground experts united
reply other threads:[~2014-11-20 4:16 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87egsycxqr.fsf@debian.uxu \
--to=embe8573@student.uu.se \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.