%% for cnqx cultures

fid_prefix = 'turbo361';
[evt_times evt_txt] = get_events(fid_prefix);
load([fid_prefix '/' fid_prefix '_asdr_BIfilt.mat']);
z = 2; %index of when cnqx (or vehicle) is added
y = 1; %label_number in structure

fid_prefix = 'milton359';
[evt_times evt_txt] = get_events(fid_prefix);
load([fid_prefix '/' fid_prefix '_asdr_BIfilt.mat']);
z = 3; %index of when cnqx (or vehicle) is added
y = 2; %label_number in structure

fid_prefix = 'nacho364';
[evt_times evt_txt] = get_events(fid_prefix);
load([fid_prefix '/' fid_prefix '_asdr_BIfilt.mat']);
z = 2; %index of when cnqx (or vehicle) is added
y = 3; %label_number in structure

fid_prefix = 'orion360';
[evt_times evt_txt] = get_events(fid_prefix);
load([fid_prefix '/' fid_prefix '_asdr_BIfilt.mat']);
z = 1; %index of when cnqx (or vehicle) is added
y = 4; %label_number in structure

fid_prefix = 'quetzalcoatl364';
[evt_times evt_txt] = get_events(fid_prefix);
load([fid_prefix '/' fid_prefix '_asdr_BIfilt.mat']);
z = 1; %index of when cnqx (or vehicle) is added
y = 5; %label_number in structure

fid_prefix = 'sebastian364';
[evt_times evt_txt] = get_events(fid_prefix);
load([fid_prefix '/' fid_prefix '_asdr_BIfilt.mat']);
z = 1; %index of when cnqx (or vehicle) is added
y = 6; %label_number in structure

fid_prefix = 'unicorn359';
[evt_times evt_txt] = get_events(fid_prefix);
load([fid_prefix '/' fid_prefix '_asdr_BIfilt.mat']);
z = 2; %index of when cnqx (or vehicle) is added
y = 7; %label_number in structure

fid_prefix = 'yoda363';
[evt_times evt_txt] = get_events(fid_prefix);
load([fid_prefix '/' fid_prefix '_asdr_BIfilt.mat']);
z = 1; %index of when cnqx (or vehicle) is added
y = 8; %label_number in structure


%% stuff
t = asdr_times-evt_times(z);
label_cnqx{y} = fid_prefix;

meanASDR.cnqx(y,1) = mean(asdr_1sec(t>=-12*3600 & t<0));
meanASDR.cnqx(y,2) = mean(asdr_1sec(t>=0 & t<12*3600));
meanASDR.cnqx(y,3) = mean(asdr_1sec(t>=0*3600 & t<24*3600));
meanASDR.cnqx(y,4) = mean(asdr_1sec(t>=24*3600 & t<48*3600));

medianASDR.cnqx(y,1) = median(asdr_1sec(t>=-12*3600 & t<0));
medianASDR.cnqx(y,2) = median(asdr_1sec(t>=0 & t<12*3600));
medianASDR.cnqx(y,3) = median(asdr_1sec(t>=0*3600 & t<24*3600));
medianASDR.cnqx(y,4) = median(asdr_1sec(t>=24*3600 & t<48*3600));

asdr_sort = sort(asdr_1sec(t>=-12*3600 & t<0));
f15 = sum(asdr_sort(round(0.85*length(asdr_sort)):length(asdr_sort)))/sum(asdr_sort);
BIfilt.cnqx(y,1) = (f15-0.15/0.85);

asdr_sort = sort(asdr_1sec(t>=0 & t<12*3600));
f15 = sum(asdr_sort(round(0.85*length(asdr_sort)):length(asdr_sort)))/sum(asdr_sort);
BIfilt.cnqx(y,2) = (f15-0.15/0.85);

asdr_sort = sort(asdr_1sec(t>=0*3600 & t<24*3600));
f15 = sum(asdr_sort(round(0.85*length(asdr_sort)):length(asdr_sort)))/sum(asdr_sort);
BIfilt.cnqx(y,3) = (f15-0.15/0.85);

asdr_sort = sort(asdr_1sec(t>=24*3600 & t<48*3600));
f15 = sum(asdr_sort(round(0.85*length(asdr_sort)):length(asdr_sort)))/sum(asdr_sort);
BIfilt.cnqx(y,4) = (f15-0.15/0.85);


%% for ctrl cultures

fid_prefix = 'turbo364';
[evt_times evt_txt] = get_events(fid_prefix);
load([fid_prefix '/' fid_prefix '_asdr_BIfilt.mat']);
z = 2; %index of when cnqx (or vehicle) is added
y = 1; %label_number in structure

fid_prefix = 'milton360';
[evt_times evt_txt] = get_events(fid_prefix);
load([fid_prefix '/' fid_prefix '_asdr_BIfilt.mat']);
z = 3; %index of when cnqx (or vehicle) is added
y = 2; %label_number in structure

fid_prefix = 'nacho361';
[evt_times evt_txt] = get_events(fid_prefix);
load([fid_prefix '/' fid_prefix '_asdr_BIfilt.mat']);
z = 2; %index of when cnqx (or vehicle) is added
y = 3; %label_number in structure

fid_prefix = 'orion363';
[evt_times evt_txt] = get_events(fid_prefix);
load([fid_prefix '/' fid_prefix '_asdr_BIfilt.mat']);
z = 1; %index of when cnqx (or vehicle) is added
y = 4; %label_number in structure

fid_prefix = 'quetzalcoatl361';
[evt_times evt_txt] = get_events(fid_prefix);
load([fid_prefix '/' fid_prefix '_asdr_BIfilt.mat']);
z = 1; %index of when cnqx (or vehicle) is added
y = 5; %label_number in structure

fid_prefix = 'sebastian361';
[evt_times evt_txt] = get_events('sebastian364');
load([fid_prefix '/' fid_prefix '_asdr_BIfilt.mat']);
z = 1; %index of when cnqx (or vehicle) is added
y = 6; %label_number in structure

fid_prefix = 'unicorn364';
[evt_times evt_txt] = get_events('unicorn359');
load([fid_prefix '/' fid_prefix '_asdr_BIfilt.mat']);
z = 2; %index of when cnqx (or vehicle) is added
y = 7; %label_number in structure

fid_prefix = 'yoda359';
[evt_times evt_txt] = get_events(fid_prefix);
load([fid_prefix '/' fid_prefix '_asdr_BIfilt.mat']);
z = 1; %index of when cnqx (or vehicle) is added
y = 8; %label_number in structure


%% stuff
t = asdr_times-evt_times(z);
label.ctrl{y} = fid_prefix;

meanASDR.ctrl(y,1) = mean(asdr_1sec(t>=-12*3600 & t<0));
meanASDR.ctrl(y,2) = mean(asdr_1sec(t>=0 & t<12*3600));
meanASDR.ctrl(y,3) = mean(asdr_1sec(t>=0*3600 & t<24*3600));
meanASDR.ctrl(y,4) = mean(asdr_1sec(t>=24*3600 & t<48*3600));

medianASDR.ctrl(y,1) = median(asdr_1sec(t>=-12*3600 & t<0));
medianASDR.ctrl(y,2) = median(asdr_1sec(t>=0 & t<12*3600));
medianASDR.ctrl(y,3) = median(asdr_1sec(t>=0*3600 & t<24*3600));
medianASDR.ctrl(y,4) = median(asdr_1sec(t>=24*3600 & t<48*3600));

asdr_sort = sort(asdr_1sec(t>=-12*3600 & t<0));
f15 = sum(asdr_sort(round(0.85*length(asdr_sort)):length(asdr_sort)))/sum(asdr_sort);
BIfilt.ctrl(y,1) = (f15-0.15/0.85);

asdr_sort = sort(asdr_1sec(t>=0 & t<12*3600));
f15 = sum(asdr_sort(round(0.85*length(asdr_sort)):length(asdr_sort)))/sum(asdr_sort);
BIfilt.ctrl(y,2) = (f15-0.15/0.85);

asdr_sort = sort(asdr_1sec(t>=0*3600 & t<24*3600));
f15 = sum(asdr_sort(round(0.85*length(asdr_sort)):length(asdr_sort)))/sum(asdr_sort);
BIfilt.ctrl(y,3) = (f15-0.15/0.85);

asdr_sort = sort(asdr_1sec(t>=24*3600 & t<48*3600));
f15 = sum(asdr_sort(round(0.85*length(asdr_sort)):length(asdr_sort)))/sum(asdr_sort);
BIfilt.ctrl(y,4) = (f15-0.15/0.85);