circulate/debugging.py
author Puneeth Chaganti <punchagan@gmail.com>
Thu, 09 Dec 2010 18:39:26 +0530
branchscipyin2010
changeset 441 9d9e4026238f
parent 436 7c9e949851e2
permissions -rw-r--r--
Changed session-2 - now uses loadtxt.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
436
7c9e949851e2 EHN: Add trival debugging.py example.
Christopher Burns <chris.d.burns@gmail.com>
parents:
diff changeset
     1
7c9e949851e2 EHN: Add trival debugging.py example.
Christopher Burns <chris.d.burns@gmail.com>
parents:
diff changeset
     2
def foo(science):
7c9e949851e2 EHN: Add trival debugging.py example.
Christopher Burns <chris.d.burns@gmail.com>
parents:
diff changeset
     3
    for record in open('sslc1.txt'):
7c9e949851e2 EHN: Add trival debugging.py example.
Christopher Burns <chris.d.burns@gmail.com>
parents:
diff changeset
     4
        fields = record.split(';')
7c9e949851e2 EHN: Add trival debugging.py example.
Christopher Burns <chris.d.burns@gmail.com>
parents:
diff changeset
     5
        region_code = fields[0].strip()
7c9e949851e2 EHN: Add trival debugging.py example.
Christopher Burns <chris.d.burns@gmail.com>
parents:
diff changeset
     6
7c9e949851e2 EHN: Add trival debugging.py example.
Christopher Burns <chris.d.burns@gmail.com>
parents:
diff changeset
     7
        score_str = fields[6].strip()
7c9e949851e2 EHN: Add trival debugging.py example.
Christopher Burns <chris.d.burns@gmail.com>
parents:
diff changeset
     8
        score = int(score_str) if score_str != 'AA' \
7c9e949851e2 EHN: Add trival debugging.py example.
Christopher Burns <chris.d.burns@gmail.com>
parents:
diff changeset
     9
                               else 0
7c9e949851e2 EHN: Add trival debugging.py example.
Christopher Burns <chris.d.burns@gmail.com>
parents:
diff changeset
    10
7c9e949851e2 EHN: Add trival debugging.py example.
Christopher Burns <chris.d.burns@gmail.com>
parents:
diff changeset
    11
        if score > 90:
7c9e949851e2 EHN: Add trival debugging.py example.
Christopher Burns <chris.d.burns@gmail.com>
parents:
diff changeset
    12
            science[region_code] += 1
7c9e949851e2 EHN: Add trival debugging.py example.
Christopher Burns <chris.d.burns@gmail.com>
parents:
diff changeset
    13
7c9e949851e2 EHN: Add trival debugging.py example.
Christopher Burns <chris.d.burns@gmail.com>
parents:
diff changeset
    14
def bar():
7c9e949851e2 EHN: Add trival debugging.py example.
Christopher Burns <chris.d.burns@gmail.com>
parents:
diff changeset
    15
    science = {}
7c9e949851e2 EHN: Add trival debugging.py example.
Christopher Burns <chris.d.burns@gmail.com>
parents:
diff changeset
    16
    science = foo(science)
7c9e949851e2 EHN: Add trival debugging.py example.
Christopher Burns <chris.d.burns@gmail.com>
parents:
diff changeset
    17
    pie(science.values(), labels=science.keys())
7c9e949851e2 EHN: Add trival debugging.py example.
Christopher Burns <chris.d.burns@gmail.com>
parents:
diff changeset
    18
    savefig('science.png')
7c9e949851e2 EHN: Add trival debugging.py example.
Christopher Burns <chris.d.burns@gmail.com>
parents:
diff changeset
    19
7c9e949851e2 EHN: Add trival debugging.py example.
Christopher Burns <chris.d.burns@gmail.com>
parents:
diff changeset
    20
if __name__ == '__main__':
7c9e949851e2 EHN: Add trival debugging.py example.
Christopher Burns <chris.d.burns@gmail.com>
parents:
diff changeset
    21
    bar()
7c9e949851e2 EHN: Add trival debugging.py example.
Christopher Burns <chris.d.burns@gmail.com>
parents:
diff changeset
    22