package com.fs.watch.calculation;

import com.fs.watch.service.WatchRriDataService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RriPreprocessor {
    private final WatchRriDataService watchRriDataService;

    private static final Logger log = LoggerFactory.getLogger(RriPreprocessor.class);

    public RriPreprocessor(WatchRriDataService watchRriDataService) {
        this.watchRriDataService = watchRriDataService;
    }

//    public void DataPrepare(byte[] payload,String deviceId) {
//        HisDataOuterClass.HisNotification hisNotify = null;
//        try {
//            hisNotify = HisDataOuterClass.HisNotification.parseFrom(payload);
//        } catch (InvalidProtocolBufferException ex) {
//            ex.printStackTrace();
//            return;
//        }
//        if(hisNotify.hasHisData()){
//            HisDataOuterClass.HisData hisData = hisNotify.getHisData();
//            if(hisData.hasRri()){
//                HisRriData.HisDataRRI rriData = hisData.getRri();
//                /*
//                    not like ecg, rri is not one time measure, but
//                    continuous value, you can calculate af result
//                    of random time range, combine all rri value of
//                    the time range for calculation
//                 */
//                List<Integer> rawDataList = rriData.getRawDataList();
//                List<Short> actualDataList = new ArrayList<>();
//                for(int i=0;i<rawDataList.size();i++){
//                    short fval = (short)((rawDataList.get(i) >> 16) & 0x0000ffff);
//                    short sval = (short)(rawDataList.get(i) & 0x0000ffff);
//                    actualDataList.add(fval);
//                    actualDataList.add(sval);
//                }
//                log.info(String.format("rri count:%d",actualDataList.size()));
//                String data_time = MyDateTimeUtils.convert2DateTimeString(rriData.getTimeStamp().getDateTime().getSeconds());
//                WatchRriData watchRriData = new WatchRriData();
//                watchRriData.setDeviceId(deviceId);
//                watchRriData.setJsonDataVal(actualDataList.toString());
//                watchRriData.setCount(rawDataList.size());
//                watchRriData.setCreateTime(DateUtils.parseDate(data_time));
//                watchRriDataService.insert(watchRriData);
//            }
//        }
//    }
}
