circulate/sslc_allreg.py
author Santosh G. Vattam <vattam.santosh@gmail.com>
Tue, 02 Mar 2010 10:55:49 +0530
changeset 374 0ba81871dae5
parent 359 cb17c87b090e
child 385 c70118cdde66
permissions -rw-r--r--
Branches merged.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
358
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     1
scores = [[], [], [], [], []]
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     2
ninety_percents = [{}, {}, {}, {}, {}]
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     3
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     4
for record in open('sslc1.txt'):
359
cb17c87b090e Fixed errors found during REC workshop.
Puneeth Chaganti <punchagan@fossee.in>
parents: 358
diff changeset
     5
#    record = record.strip()
358
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     6
    fields = record.split(';')
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     7
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     8
    region_code = fields[0].strip()
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     9
   
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    10
    for i, field in enumerate(fields[3:8]):
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    11
        if region_code not in ninety_percents[i]:
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    12
            ninety_percents[i][region_code] = 0
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    13
        score_str = field.strip()
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    14
        score = 0 if score_str == 'AA' else int(score_str)
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    15
        scores[i].append(score)
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    16
        if score > 90:
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    17
            ninety_percents[i][region_code] += 1
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    18
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    19
subj_total = []
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    20
for subject in ninety_percents:
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    21
    subj_total.append(sum(subject.values()))
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    22
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    23
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    24
figure(1)
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    25
pie(ninety_percents[3].values(), labels=ninety_percents[3].keys())
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    26
title('Students scoring 90% and above in science by region')
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    27
savefig('science.png')
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    28
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    29
figure(2)
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    30
pie(subj_total, labels=['English', 'Hindi', 'Maths', 'Science', 'Social'])
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    31
title('Students scoring more than 90% by subject(All regions combined).')
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    32
savefig('all_regions.png')
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    33
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    34
# List method
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    35
print "Mean: ", mean(scores[2])
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    36
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    37
print "Median: ", median(scores[2])
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    38
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    39
print "Standard Deviation: ", std(scores[2])
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    40
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    41
# Array method
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    42
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    43
#math_scores = array(scores[2])
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    44
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    45
#print "Mean: ", mean(math_scores)
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    46
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    47
#print "Median: ", median(math_scores)
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    48
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    49
#print "Standard Deviation: ", std(math_scores)
162e3e453920 Added files to be circulated during workshops.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    50