]> git.donarmstrong.com Git - neurodebian.git/commitdiff
NF: parsing out those ratings questions
authorYaroslav Halchenko <debian@onerussian.com>
Mon, 16 May 2011 17:44:42 +0000 (13:44 -0400)
committerYaroslav Halchenko <debian@onerussian.com>
Mon, 16 May 2011 17:44:45 +0000 (13:44 -0400)
survey/Makefile
survey/makestats

index e817fc8ed400aacc1765ccd58b90db052107c2b7..b532301d9c7d3e82732b5fdc19bc1eaaa22e7100 100644 (file)
@@ -18,7 +18,7 @@ results_snippet.html: results.html
                | tail -n$$(echo "$$(wc -l < results.html) - $$(grep -n '<body>' \
                < results.html | cut -d ':' -f 1,1) - 2" | bc ) > $@
 
-statfigures: oslist.txt swlist.txt datamodlist.txt employer-dd-list.txt position-dd-list.txt
+statfigures: oslist.txt swlist.txt datamodlist.txt employer-dd-list.txt position-dd-list.txt ratingslist.txt
 # create "lockfile'
        @touch $@
        @[ "$$(cat nsubmissions.stamp 2>/dev/null || echo)" != "$$(ls -1 data |wc -l)" ] \
@@ -49,6 +49,15 @@ datamodlist.txt: survey.rst
        @sed -n -e '/bg_$*/,/\/tr/p' survey.rst \
        | sed -ne '/option/s,.*value="\([^"]*\)" *label=\("[^"]*"\)>.*,\1: \2,gp' >| $@
 
+ratingslist.txt: survey.rst
+       @echo "I: Extracting fields for ratings into $@"
+       @grep -B 6 -e 'radio.*_r.*value="3"' survey.rst \
+       | grep -v -e '^\.\. raw' -e '^[ -]*$$' -e '<td' \
+       | sed -e 's,.*name="\([^"]*\)" value.*,|\1#,g' \
+       | tr '\n' ' ' \
+       | sed -e 's,#,#\n,g' \
+       | sed -e 's,\(.*\)|\(.*\)#,\2: "\1",g' >| $@
+
 upload: index.html results.html results_snippet.html jquery.form.js survey.css surveycollector.cgi
        rsync -rvzlhp --delete  \
         --exclude='*.txt' --exclude=data --exclude='*.cgi' --exclude=figures \
index 69e689cad14822883dbbae26e14283ef2d6eb5ed..7f500d692773156983d7f8fa83fa640a30a59f7f 100755 (executable)
@@ -91,7 +91,13 @@ def load_list2dict(name):
     d = {}
     lfile = open(name)
     for line in lfile:
+        if line.strip() == "":
+            continue
         kv = line.split(':')
+        if kv[0] in d:
+            raise RuntimeError(
+                "Got a line %s with a duplicate key %s whenever value for it "
+                "is known already to be %r" % (line, kv[0], d[kv[0]]))
         d[kv[0]] = kv[1].strip().strip('"')
     return d
 
@@ -103,6 +109,7 @@ class DB(dict):
     sw_dict = load_list2dict('swlist.txt')
     position_dict = load_list2dict('position-dd-list.txt')
     employer_dict = load_list2dict('employer-dd-list.txt')
+    ratings_dict = load_list2dict('ratingslist.txt')
 
     def __init__(self, srcdir):
         # eats the whole directory