all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Emacs as old-school batch number cruncher
@ 2014-11-20  4:16 Emanuel Berg
  0 siblings, 0 replies; only message in thread
From: Emanuel Berg @ 2014-11-20  4:16 UTC (permalink / raw
  To: help-gnu-emacs

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-11-20  4:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-20  4:16 Emacs as old-school batch number cruncher Emanuel Berg

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.