%% QDC Actual Day DB
%  Actual day QDC to DB
%%

function qday_db(start_dt);
% ----------------------------------------------------
% The function calculates QDC for 30-days dataset
% and upload QDC to "Actual Day" date in DB
% INPUT
% start_dt vector of start data [YYYY, MM, DD] 
%
% ----------------------------------------------------

% filed end date of 30-days period
ds = datenum(start_dt);
[y, m, d] = datevec(ds+30);
end_dt = [y,m,d,23,59,00];

% Read DB
%   Read components
    var_x = dbget ( start_dt,end_dt,'x');
    var_y = dbget ( start_dt,end_dt,'y');
%   Read SS for the components
    ss_x = dbget ( start_dt,end_dt,'ss_x');
    ss_y = dbget ( start_dt,end_dt,'ss_y');
% Calculate COMP-SS
    by_x = var_x - ss_x;
    by_y = var_y - ss_y;

% Calculate QDC for every component

[qday_x, ActDay_x]= q_day(by_x);
[qday_y, ActDay_y]= q_day(by_y);

if ~isnan(ActDay_x)
    % Calculate date for the Actual Day;
    [y, m, d] = datevec(ds+ActDay_x);
    act_dt_x = [y, m, d];
     % Write QDC for Atcual Day to DB
     dbset ( [act_dt_x,0,0,0],[act_dt_x,23,59,0],'qdc_x',qday_x); 
end;
if ~isnan(ActDay_y)
    [y, m, d] = datevec(ds+ActDay_y);
    act_dt_y = [y, m, d];
     % Write QDC for Atcual Day to DB
     dbset ( [act_dt_y,0,0,0],[act_dt_y,23,59,0],'qdc_y',qday_y); 
end;    
  


