#III. Store data into Pandas

cu12_data = {'id': pd.Series(cu12_id), 'tool': pd.Series(cu12_tool), 'weight': pd.Series(cu12_weight)} 
cu12_df = pd.DataFrame(cu12_data) #store data into panda dataframe

meco_data = {'id': pd.Series(meco_id), 'weight': pd.Series(meco_weight)}
meco_df = pd.DataFrame(meco_data)

rejected = cu1_rejected + cu2_rejected + meco_rejected #total number of rejected grids

#####################################################################################
#IV. Retrieve data From Pandas to be used in Bokeh

cu1_ids = list(cu12_df[cu12_df['tool'] == 1].id)
cu1_weights = list(cu12_df[cu12_df['tool'] == 1].weight)
cu1_stats = statfunctions.stats(cu1_weights)

cu2_ids = list(cu12_df[cu12_df['tool'] == 2].id)
cu2_weights = list(cu12_df[cu12_df['tool'] == 2].weight)
cu2_stats = statfunctions.stats(cu2_weights)

m_ids = list(meco_df.id)
m_weights = list(meco_df.weight)
m_stats = statfunctions.stats(m_weights)

c_thickness_stats = statfunctions.liststats(meco_c_thickness)
l_thickness_stats = statfunctions.liststats(meco_l_thickness)
r_thickness_stats = statfunctions.liststats(meco_r_thickness)

######################################################################################
#V. Start Bokeh Plotting
######################################################################################
#III. Start Bokeh Plotting
######################################################################################
file_folder = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) + '\\html_archive\\' #Finds the absolute file path of the 

if first == last:
	output_file(first + '.html', title=first)
else:
	output_file(file_folder + first + ' to ' + last + '.html', title=first + ' to ' + last)

cl = 2 #control limit multiplier

#FOR ALL OF THE FOLLOWING GRAPHS, functions were created in graph_functions.py to avoid writing the code multiple times 
######################################################################################
#Cu1 Plot
cu1_stats = statfunctions.stats(cu1_weight, cl)
p1 = graph_functions.create_histogram(cu1_stats['avg'], cu1_stats['std'], cu1_weight, 50, 1.2, 1.6, cu1_accepted, t1_failure_pos)

######################################################################################
#Cu2 Plot
cu2_stats = statfunctions.stats(cu2_weight, cl)
p2 = graph_functions.create_histogram(cu2_stats['avg'], cu2_stats['std'], cu2_weight, 50, .2, .55, cu2_accepted, t2_failure_pos)

######################################################################################
#Meco GridThicknesses
######################################################################################
#p3 = graph_functions.thickness_uniformity(statfunctions.liststats(meco_c_thickness, cl)['avg'], statfunctions.liststats(meco_l_thickness, cl)['avg'], statfunctions.liststats(meco_r_thickness, cl)['avg'], cu1_measured, cu1_accepted, meco_c_thickness, cl)[0]

c_thickness_stats = statfunctions.liststats(meco_c_thickness, cl)
l_thickness_stats = statfunctions.liststats(meco_l_thickness, cl)
r_thickness_stats = statfunctions.liststats(meco_r_thickness, cl)