+ (setq continue nil)))))
+ numberofrounds))
+
+(defun arbitools-calculate-points ()
+ "Automatically calculate the points of each player"
+ (interactive)
+ (save-excursion
+ (let ( (numberofrounds (arbitools-number-of-rounds))
+ (pointsstring "")
+ (points 0.0)
+ (pointstosum 0.0)
+ (roundcount 1))
+ (goto-char (point-min))
+ (while (re-search-forward "^001" nil t)
+ (setq points 0.0)
+ (setq roundcount 1)
+ (while (<= roundcount numberofrounds)
+ (beginning-of-line)
+ (forward-char (+ 98 (* (- roundcount 1) 10))) ;; go to where the result is for each round
+ (setq pointsstring (thing-at-point 'symbol))
+ (cond ((string= (thing-at-point 'symbol) "1") (setq pointstosum 1.0))
+ ((string= (thing-at-point 'symbol) "+") (setq pointstosum 1.0))
+ ((string= (thing-at-point 'symbol) "=") (setq pointstosum 0.5))
+ ((string= (thing-at-point 'symbol) "0") (setq pointstosum 0.0))
+ ((string= (thing-at-point 'symbol) "-") (setq pointstosum 0.0))
+ ((string= (thing-at-point 'symbol) nil) (setq pointstosum 0.0)))
+ (setq points (+ points pointstosum))
+ (setq roundcount (+ roundcount 1)))
+ (beginning-of-line)
+ (forward-char 84)
+ (forward-char -3)
+ (delete-char 3)
+ (insert-char ?\s (- 3 (length (format "%s" points))))
+ (insert (format "%s" points))))))
+
+(defun arbitools-calculate-standings ()
+ "Write the standings in the Standings buffer"
+ (interactive)
+ (arbitools-calculate-points) ;; make sure the points of each player are correct
+ (save-excursion
+ (with-current-buffer "Standings"
+ (erase-buffer))
+ (let ((datachunk ""))
+ (goto-char (point-min))
+ (while (re-search-forward "^001" nil t)
+ (let* ((linestring (thing-at-point 'line)))
+ (beginning-of-line)
+ (forward-char 89) ;; get the POS field
+ (setq datachunk (thing-at-point 'word))
+ (with-current-buffer "Standings"
+ (insert (format "%s" datachunk))
+ (insert-char ?\s (- 3 (length datachunk)))
+ (insert " "))
+ (setq datachunk (substring-no-properties (thing-at-point 'line) 14 47)) ;; get name
+ (with-current-buffer "Standings"
+ (insert (format "%s " datachunk))
+ (insert-char ?\s (- 33 (length datachunk))))
+ (beginning-of-line)
+ (forward-char 68)
+ (setq datachunk (thing-at-point 'word)) ;; get idfide
+ (with-current-buffer "Standings"
+ (insert (format "%s " datachunk))
+ (insert-char ?\s (- 10 (length datachunk))))
+ (setq datachunk (substring-no-properties (thing-at-point 'line) 80 84)) ;; get points
+ (with-current-buffer "Standings"
+ (insert (format "%s " datachunk))
+ (insert-char ?\s (- 4 (length datachunk))))
+ (with-current-buffer "Standings"
+ (insert "\n")
+ (sort-columns 1 49 (- (point-max) 1))))))
+ (let ((newpos 0)
+ (idfide ""))
+ (goto-char (point-min))
+ (while (re-search-forward "^001" nil t)
+ (beginning-of-line)
+ (forward-char 68)
+ (setq idfide (thing-at-point 'word))
+ (with-current-buffer "Standings"
+ (goto-char (point-min))
+ (search-forward idfide nil t)
+ (setq newpos (line-number-at-pos))) ;; the POS is in the beginning of the line in Standings
+ (with-current-buffer "Arbitools-output"
+ (insert (format "%s" newpos))
+ (insert "\n"))
+ (beginning-of-line)
+ (forward-char 89) ;; go to POS field
+ (forward-char -3)
+ (delete-char 3)
+ (insert-char ?\s (- 3 (length (format "%s" newpos))))
+ (insert (format "%s" newpos))))))