[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Emacs as old-school batch number cruncher
From: |
Emanuel Berg |
Subject: |
Emacs as old-school batch number cruncher |
Date: |
Thu, 20 Nov 2014 05:16:44 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) |
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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Emacs as old-school batch number cruncher,
Emanuel Berg <=