close all
clear all


hourly_data_file = '../HourlyResults/HourlyAverages.mat'

decoded_data_path = '../DecodedResults/';


load(hourly_data_file);

idx = 1356:4416; %   find((HourlyData.baseFileDateNum > 739383) & (HourlyData.baseFileDateNum < 739511) & (HourlyData.PC_Power > 0));


figure
plot(HourlyData.baseFileDateNum(idx),HourlyData.PC_Power(idx));
datetick('x')
ylabel('Hourly Mean Power (W)');

PC_Time = [];
PC_RPM =[];
PC_BattCurr = [];
PC_LoadCurr = [];
PC_Voltage = [];
PC_Status = [];
PC_WindingCurrent = [];
PC_TargVolt = [];
PC_TargCurr = [];

j = 0;
for i = idx %idx(1):idx(20)
  j = j+1;
  data = load([decoded_data_path HourlyData.baseFilename{i} '_raw.mat']);

  PC_Time = [PC_Time ; data.PC_Time];
  PC_RPM = [PC_RPM ; data.PC_RPM];
  PC_WindingCurrent = [PC_WindingCurrent ; data.PC_WindingCurrent];
  PC_BattCurr = [PC_BattCurr; data.PC_BattCurr];
  PC_LoadCurr = [PC_LoadCurr; data.PC_LoadCurr];
  PC_TargVolt = [PC_TargVolt ; data.PC_TargVolt];
  PC_TargCurr = [PC_TargCurr ; data.PC_TargCurr];

  PC_Voltage = [PC_Voltage; data.PC_Voltage];
  PC_Status = [PC_Status; data.PC_Status];
  disp(['Loaded ' num2str(j) ' of ' num2str(length(idx))]);
  if(mod(j,100) == 0)
    save(['PowerData_ ' num2str(j)],'PC_Time','PC_RPM','PC_WindingCurrent','PC_BattCurr','PC_TargVolt','PC_TargCurr','PC_LoadCurr','PC_Voltage','PC_Status');
    PC_Time = [];
    PC_RPM =[];
    PC_BattCurr = [];
    PC_LoadCurr = [];
    PC_Voltage = [];
    PC_Status = [];
    PC_WindingCurrent = [];
    PC_TargVolt = [];
    PC_TargCurr = [];
  end
end
    save(['PowerData_ ' num2str(j)],'PC_Time','PC_RPM','PC_WindingCurrent','PC_BattCurr','PC_TargVolt','PC_TargCurr','PC_LoadCurr','PC_Voltage','PC_Status');

% 
% figure
% plot(PC_RPM);
% 
% figure
% hist(PC_RPM);
% 
% Kv = 
% Rw = 
% 
% 
