forked from okfde/2030-watch.de
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscore.el
57 lines (50 loc) · 1.73 KB
/
score.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
;;;; Scoring functions for 2030-watch.de in Emacs Lisp
;; 7.3. Share of energy from renewables.json
(defun score-value-fn (value)
(cond ((> value 40.5) 1)
((and (<= value 40.5) (> value 30.5)) 2)
((and (<= value 30.5) (> value 20.5)) 3)
((and (<= value 20.5) (> value 10.5)) 4)
((<= value 10.5) 5)))
;; Open Government Partnership membership.json
(defun score-value-fn (value)
(cond ((= value 1) 1)
((= value 2) 2)
((= value 3) 3)
((= value 5) 5)
(t 6)))
;; EarlySchoolLeavers.json
(defun score-value-fn (value)
(cond ((< value 4) 1)
((< value 8) 2)
((< value 12) 3)
((< value 16) 4)
(t 5)))
;; Consumption -OECD Municipal waste per capita 2013
(defun score-value-fn (value)
(cond ((< value 0) 6)
((< value 300) 1)
((< value 400) 2)
((< value 500) 3)
((< value 600) 4)
((>= value 600) 5)))
;; Economy - EPI Agricultural Subsidies 2011
(defun score-value-fn (value)
(cond ((< value 0) 1)
((< value 0.1) 2)
((< value 0.2) 3)
((< value 0.3) 4)
((and (>= value 0.3)
(<= value 1)) 5)
(t 6)))
(defun score-value ()
"Iterates through a preformatted 2030-watch json file
and computes scores from values using score-value-fn."
(interactive)
(let* ((value-start (re-search-forward "value\":[[:space:]]*"))
(value-end (re-search-forward "[[:digit:]]+\\.?[[:digit:]]*"))
(value (string-to-number (buffer-substring value-start value-end)))
(score-start (re-search-forward "score\":[[:space:]]*"))
(score-end (re-search-forward "$")))
(delete-region score-start score-end)
(insert (number-to-string (score-value-fn value)))))