<commit_before>package hrv.band.aurora.Control;

import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction;

import java.util.Date;
import java.util.Arrays;
import hrv.band.aurora.Fourier.IFourierTransformation;
import hrv.band.aurora.Interpolation.IInterpolation;
import hrv.band.aurora.RRInterval.Interval;

/**
 * Created by Julian on 11.06.2016.
 */
public class Calculation {

    IFourierTransformation fourierTransf;
    IInterpolation interpolation;

    public Calculation(IFourierTransformation fTrans, IInterpolation interpol)
    {
        fourierTransf = fTrans;
        interpolation = interpol;
    }

    public HRVParameters Calculate(Interval rrinterval)
    {
        double[] unfiltered_y = rrinterval.GetRRInterval();
        double[] y= filter(unfiltered_y);
        double[] x = new double[y.length];

        for(int i = 1; i < y.length; i++)
        {
            x[i] = x[i-1] + y[i];
        }

        PolynomialSplineFunction interpolFunction = interpolation.calculate(x,y);
        int numInterpolVals = 4096;
        double[] xInterpolated = new double[numInterpolVals];
        double[] yInterpolated = new double[numInterpolVals];

        double lastTimeVal = x[x.length - 1];
        double stepSize = lastTimeVal / numInterpolVals;

        for(int i = 0; i < numInterpolVals; i++)
        {
            xInterpolated[i] = stepSize * i;
            yInterpolated[i] = interpolFunction.value(xInterpolated[i]);
        }

        double[] complexPart = new double[numInterpolVals];
        double[] realPart = new double[numInterpolVals];
        for(int i = 0; i < numInterpolVals; i++)
            realPart[i] = yInterpolated[i];

        fourierTransf.calculate(realPart, complexPart);

        double[] betrag = new double[xInterpolated.length];
        for(int i = 0; i < xInterpolated.length; i++)
        {
            betrag[i] = realPart[i] * realPart[i] + complexPart[i] * complexPart[i];
        }

        double maxAbtastFrequenz = 0.5 * (1 / stepSize);
        double frequencySteps = maxAbtastFrequenz / (numInterpolVals - 1);
        double[] frequencies = new double[numInterpolVals];

        for(int i = 0; i < numInterpolVals; i++)
        {
            frequencies[i] = (frequencySteps) * i;
        }

        return createHRVParameter(y, frequencies, betrag);
    }

    private HRVParameters createHRVParameter(double[] y, double[] frequencies, double[] betrag) {
        double sdnn = SDNN(y);
        double sdsd = SDSD(y);
        double sd1 = SD1(sdnn);
        double sd2 = SD2(sdnn,sdsd);
        double lf = LfPow(frequencies, betrag, frequencies[1]);
        double hf = HfPow(frequencies, betrag, frequencies[1]);<commit_msg>Update Calculation.java<commit_after>package hrv.band.aurora.Control;

import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction;

import java.util.Date;
import java.util.Arrays;
import hrv.band.aurora.Fourier.IFourierTransformation;
import hrv.band.aurora.Interpolation.IInterpolation;
import hrv.band.aurora.RRInterval.Interval;

/**
 * Created by Julian on 11.06.2016.
 */
public class Calculation {

    IFourierTransformation fourierTransf;
    IInterpolation interpolation;

    public Calculation(IFourierTransformation fTrans, IInterpolation interpol)
    {
        fourierTransf = fTrans;
        interpolation = interpol;
    }

    public HRVParameters Calculate(Interval rrinterval)
    {
        double[] unfiltered_y = rrinterval.GetRRInterval();
        double[] y= filter(unfiltered_y);
        double[] x = new double[y.length];

        for(int i = 1; i < y.length; i++)
        {
            x[i] = x[i-1] + y[i];
        }

        PolynomialSplineFunction interpolFunction = interpolation.calculate(x,y);
        int numInterpolVals = 4096;
        double[] xInterpolated = new double[numInterpolVals];
        double[] yInterpolated = new double[numInterpolVals];

        double lastTimeVal = x[x.length - 1];
        double stepSize = lastTimeVal / numInterpolVals;

        for(int i = 0; i < numInterpolVals; i++)
        {
            xInterpolated[i] = stepSize * i;
            yInterpolated[i] = interpolFunction.value(xInterpolated[i]);
        }

        double[] complexPart = new double[numInterpolVals];
        double[] realPart = new double[numInterpolVals];
        for(int i = 0; i < numInterpolVals; i++)
            realPart[i] = yInterpolated[i];

        fourierTransf.calculate(realPart, complexPart);

        double[] betrag = new double[xInterpolated.length];
        for(int i = 0; i < xInterpolated.length; i++)
        {
            betrag[i] = realPart[i] * realPart[i] + complexPart[i] * complexPart[i];
        }

        double maxAbtastFrequenz = 0.5 * (1 / stepSize);
        double frequencySteps = maxAbtastFrequenz / (numInterpolVals - 1);
        double[] frequencies = new double[numInterpolVals];

        for(int i = 0; i < numInterpolVals; i++)
        {
            frequencies[i] = (frequencySteps) * i;
        }

        return createHRVParameter(y, frequencies, betrag);
    }

    private HRVParameters createHRVParameter(double[] y, double[] frequencies, double[] betrag) {
        double sdnn = SDNN(y);
        double sdsd = SDSD(y);
        double sd1 = SD1(sdnn);
        double sd2 = SD2(sdnn,sdsd);
        double lfpow1 = LfPow(frequencies, betrag, frequencies[1]);
        double hfpow1 = HfPow(frequencies, betrag, frequencies[1]);
        double lf=lfpow1/(lfpow1+hfpow1);
        double hf=hfpow1/(lfpow1+hfpow1);
{'fraction_non_alphanumeric': 0.1119753979739508, 'fraction_numerical': 0.012301013024602027, 'mean_word_length': 2.753564154786151, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6437306', 'n_tokens_mistral': 1842, 'n_tokens_neox': 1752, 'n_words': 366}