In [13]:
import csv
import os
import pandas as pd
from pyUtil import flattenList as flat
import re

In [3]:
def get_out(directory):
    tot_dir_list = os.listdir(directory)
    return [f for f in tot_dir_list if '.xlsx' in f]

In [4]:
directory = os.getcwd()

In [38]:
out_file_list = get_out(directory)
#sort the list
out_file_list = sorted(out_file_list, key = lambda x: int(re.search('[0-9]+', x).group(0)))

In [39]:
def get_data(out_file_list):
    result_list = []
    for num, f in enumerate(out_file_list):
        df = pd.read_excel(f, 'Sheet2')
        result_list.append(zip(df.index, df.reactor))
    return result_list

In [40]:
result_list = get_data(out_file_list)

In [41]:
df = pd.DataFrame(zip(*flat.flatten(result_list)))
df = df.T
df.columns = ['Ratio', 'Reactor']
grouped = df.groupby('Ratio')
for ratio, data in grouped:
    counter_VVER = 0
    counter_RBMK = 0
    for result in data.Reactor:
        if result == 'RBMK':
            counter_RBMK += 1
        elif result == 'VVER':
            counter_VVER += 1
    print '%s error: %.2f%%' % (ratio, (100-((counter_RBMK + counter_VVER)/float(len(result_list)))*100))
    print 'Error matches: RBMK: %d  VVER: %d' % (counter_RBMK, counter_VVER)


pu238/pu239 error: 83.33%
Error matches: RBMK: 4  VVER: 6
pu241/pu239 error: 90.00%
Error matches: RBMK: 6  VVER: 0
pu242/pu239 error: 80.00%
Error matches: RBMK: 1  VVER: 11

Check matching for reactor and enrichment


In [60]:
#get results with reactor, ration and enrichment

def get_data_enrich(out_file_list):
    result_list = []
    for num, f in enumerate(out_file_list):
        df = pd.read_excel(f, 'Sheet2')
        result_list.append(zip(df.index, df.reactor, df.enrichment))
    return result_list

result_list_enrich = get_data_enrich(out_file_list)

df_enrich = pd.DataFrame(zip(*flat.flatten(result_list_enrich)))
df_enrich = df_enrich.T
df_enrich.columns = ['Ratio', 'Reactor', 'Enrichment']

In [69]:
# get the real enrichment data to compare against

df_real = pd.read_excel('../../All_Data.xlsx', 'Sheet1')
df_real = df_real[df_real.Reactor == 'BWR']

In [79]:
#match real enichment with guessed enrichment
results_enrich = []

for ix, row in df_enrich.iterrows():
    if row.Reactor == 'BWR':
        if list(df_real.Enrichment)[ix/3] == row.Enrichment:
            results_enrich.append(row)

#put in dataframe
df_result_enrich = pd.DataFrame(results_enrich)

In [86]:
for ratio, data in df_result_enrich.groupby('Ratio'):
    print len(data)
    print '%s correct: %.2f%%' % (ratio, (((len(data))/float(len(df_real)))*100))


29
pu238/pu239 correct: 48.33%
12
pu241/pu239 correct: 20.00%
7
pu242/pu239 correct: 11.67%

In [105]:
#match real enichment with guessed enrichment
results_enrich_dif = []

for ix, row in df_enrich.iterrows():
    results_enrich_dif.append(list(df_real.Enrichment)[ix/3] - row.Enrichment)

#put in dataframe
df_enrich['Enrich_dif'] = results_enrich_dif
#df_result_enrich_dif = pd.DataFrame(results_enrich_dif, columns=['Ratio'])

for ratio, data in df_enrich.groupby('Ratio'):
    count = 0
    for ix, row in data.iterrows():
        if row.Reactor == 'BWR':
            if abs(row.Enrich_dif) <= 1:
                count+=1

    print count
    print '%s: Percent within 1%% enrichment: %.2f%%' % (ratio, (count/float(len(data)))*100)


46
pu238/pu239: Percent within 1% enrichment: 76.67%
50
pu241/pu239: Percent within 1% enrichment: 83.33%
39
pu242/pu239: Percent within 1% enrichment: 65.00%

In [ ]: