import pygal
import numpy as np
import pandas as pd

"""
Explanation: ANALYSIS OF PRISM ADAPTATION AND ACOUSTIC CUES

Open a document in a text editor to answer some questions, then proceed with this notebook.
First import the relevant packages
End of explanation
"""


# Experimental subjects
Names = ['Paloma','Corey','Emma','Maizy','Jane','Michael','Megan']
# Number of throws
Throws=range(20)

"""
Explanation: Then let's define useful variables
End of explanation
"""


# No prism glasses and no acoustic cues
Control=np.empty([7,20]);
Control[0,0:]=[3,2,2,2,1,1,3,2,1,1,1,0,1,1,2,0,0,1,2,0];
Control[1,0:]=[1,0,2,1,2,0,1,1,0,2,1,1,3,1,0,1,1,0,1,0];
Control[2,0:]=[3,1,1,0,3,2,2,2,0,1,1,1,3,1,1,3,1,1,1,1];
Control[3,0:]=['NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN'];
Control[4,0:]=['NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN'];
Control[5,0:]=[1,1,2,1,1,1,1,2,1,1,2,1,1,2,1,1,3,1,2,1];
Control[6,0:]=[3,2,2,2,1,2,2,1,2,1,1,3,2,2,1,2,2,2,2,2];

# Prism glasses and no acoustic cues
Prism=np.empty([7,20]);
Prism[0,0:]=['NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN'];
Prism[1,0:]=[3,2,2,2,1,2,1,2,1,1,2,1,1,1,1,2,2,1,1,1];
Prism[2,0:]=[4,3,2,3,2,4,4,4,4,3,4,2,2,4,2,2,3,2,2,0];
Prism[3,0:]=[2,3,2,2,2,2,1,1,2,2,2,2,1,1,2,2,2,1,1,1];
Prism[4,0:]=['NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN'];
Prism[5,0:]=[2,3,1,2,3,2,2,2,2,1,1,1,1,1,1,2,1,1,2,2];
Prism[6,0:]=[2,4,2,4,1,3,2,3,1,2,1,1,3,2,3,1,3,3,1,3];

Music=np.empty([7,20]);
Music[0,0:]=[3,2,2,4,1,2,2,2,1,2,1,2,0,3,2,2,0,0,1,3];
Music[1,0:]=[1,2,2,2,1,1,2,2,2,1,2,1,3,0,1,1,2,0,1,1];
Music[2,0:]=[4,4,2,2,1,1,3,3,4,2,2,3,2,0,1,2,1,1,1,2];
Music[3,0:]=[3,1,2,1,2,0,2,2,1,3,1,2,2,1,2,2,2,2,2,1];
Music[4,0:]=[4,4,1,4,4,2,1,2,2,2,3,2,4,2,2,2,1,2,1,1];
Music[5,0:]=[4,3,3,1,1,2,2,1,3,2,1,1,3,2,1,1,3,2,2,1];
Music[6,0:]=['NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN'];

Blind=np.empty([7,20]);
Blind[0,0:]=[3,3,3,2,3,3,1,3,3,3,3,3,3,3,3,4,3,2,1,2];
Blind[1,0:]=[4,4,4,4,4,4,4,4,4,4,3,4,4,4,4,4,4,4,4,4];
Blind[2,0:]=[3,4,4,4,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4];
Blind[3,0:]=[2,3,2,1,3,2,2,2,1,0,3,3,3,1,2,2,3,4,3,1];
Blind[4,0:]=[1,1,0,1,2,1,2,2,1,1,2,2,1,3,1,1,2,2,2,3];
Blind[5,0:]=[3,2,2,3,1,1,2,2,1,1,3,2,2,1,2,2,2,2,3,3];
Blind[6,0:]=['NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN','NaN'];

"""
Explanation: For the data below, each row corresponds to a set of 20 throws by one experimental subject.
The numbers correspond to the ring where the sandbag landed.
'NaN' stands for 'not a number' because the data is missing (does somebody have it?).
Load the data by running each of the cells
End of explanation
"""


# Control graph
fig1 = pygal.XY(show_y_guides=False, dots_size=5, stroke_style={'width': 3})
fig1.title = 'Control (no prism, no acoustic cues)'
fig1.x_title = 'Throw number'
fig1.y_title = 'Ring number'
fig1.y_labels=[0,1,2,3,4];
fig1.add(Names[0], list(zip(Throws,Control[0,0:])))
fig1.add(Names[1], list(zip(Throws,Control[1,0:])))
fig1.add(Names[2], list(zip(Throws,Control[2,0:])))
fig1.add(Names[3], list(zip(Throws,Control[3,0:])))
fig1.add(Names[4], list(zip(Throws,Control[4,0:])))
fig1.add(Names[5], list(zip(Throws,Control[5,0:])))
fig1.add(Names[6], list(zip(Throws,Control[6,0:])))
fig1.add('Mean', list(zip(Throws,np.nanmean(Control, axis=0))))
fig1.render_to_file('Control.svg')

"""
Explanation: Plot the control data first. Here is an example for the controls.
End of explanation
"""


# Prism graph


# Music + prism graph


# Blind graph


"""
Explanation: Remember to open a new tab on the browser and to load the .svg file pygal just saved
The line 'fig1.add('Mean', list(zip(Throws,np.nanmean(Control, axis=0))))' is calculating the mean (or average) of the 'Control' variable while omitting any NaN from the calculation
Now copy the commands for 'Control data' in a new cell and create new graphs for each of our conditions. Remember to change the name of the svg file (otherwise Control.svg will be overwritten).
End of explanation
"""


# Average graph


"""
Explanation: Question 1: What preliminary conclusions/interpretations of our data can you make for each group (i.e., what does each graph tell you)?
Make a new graph that only contains the averages (or means) for each experimental condition.
End of explanation
"""


