#!/usr/bin/env python

import methods
import numpy as np

def FeatureExtractSingle(record):
    order_stat_num = 10
    sample_len = 8192

    ECG = methods.ReadRecordMat(record)
    temp_wc= methods.MedianTemplateECGsWCs(ECG)
    wc = methods.WaveDecomp(ECG,dec_lvl=7)
    wc = methods.WaveDenoise(wc,sample_len/2, constant=3)
    wc = methods.RemoveNested(wc)
    HR = methods.HeartRate(ECG)
    order_HR = methods.OrderStat(HR,order_stat_num)
    PreHR = methods.PreHeartRate(HR)
    order_PreHR = methods.OrderStat(PreHR, order_stat_num)
    if len(PreHR) > 1:
        PrePreHR = methods.PreHeartRate(PreHR)
        order_PrePreHR = methods.OrderStat(PrePreHR, order_stat_num)
    else: # len(PreHR) == 1
        order_PrePreHR = [0] * order_stat_num
    feature_set = methods.RemoveNested([wc, temp_wc, order_HR, order_PreHR, order_PrePreHR])
    return np.asarray([feature_set])

