From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Emanuel Berg Newsgroups: gmane.emacs.help Subject: Emacs as old-school batch number cruncher Date: Thu, 20 Nov 2014 05:16:44 +0100 Organization: Aioe.org NNTP Server Message-ID: <87egsycxqr.fsf@debian.uxu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1416457238 30651 80.91.229.3 (20 Nov 2014 04:20:38 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 20 Nov 2014 04:20:38 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Nov 20 05:20:33 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XrJEP-0005qh-3c for geh-help-gnu-emacs@m.gmane.org; Thu, 20 Nov 2014 05:20:33 +0100 Original-Received: from localhost ([::1]:33494 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XrJEO-0004YI-KZ for geh-help-gnu-emacs@m.gmane.org; Wed, 19 Nov 2014 23:20:32 -0500 Original-Path: usenet.stanford.edu!news.kjsl.com!feeder.erje.net!eu.feeder.erje.net!news.albasani.net!news.mixmin.net!aioe.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 104 Original-NNTP-Posting-Host: feB02bRejf23rfBm51Mt7Q.user.speranza.aioe.org Original-X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) X-Notice: Filtered by postfilter v. 0.8.2 Cancel-Lock: sha1:qNEHuTTJSElbecVeLvglQf2FFzw= Mail-Copies-To: never Original-Xref: usenet.stanford.edu gnu.emacs.help:208790 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:101070 Archived-At: 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