package com.gyee.generation.util.statisticcs;

import com.gyee.common.contant.Contant;
import com.gyee.common.model.PointData;
import com.gyee.common.model.StringUtils;
import com.gyee.generation.model.auto.ProBasicEquipment;
import com.gyee.generation.model.vo.StatusItemVo;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

public class WindSpeedStatistics extends StatusStatistics {

    public WindSpeedStatistics(Map<String, ProBasicEquipment> windTurbines, Date date) {
        super(windTurbines, date);
    }

    @Override
    public void addPointValue(String windTurbineId, double value) {
        ProBasicEquipment wt = windTurbines.get(windTurbineId);


        if (dic.containsKey(wt.getWindpowerstationId()) && dic.get(wt.getWindpowerstationId()).containsKey(Contant.SSFS)) {

            Map<String, StatusItemVo> tempmap = dic.get(wt.getWindpowerstationId());
            Double tempvalue = tempmap.get(Contant.SSFS).getEdnaValue();
            tempvalue++;
            tempmap.get(Contant.SSFS).setEdnaValue(tempvalue);
            Double tempcount = tempmap.get(Contant.SSFS).getCount();
            tempcount++;
            tempmap.get(Contant.SSFS).setCount(tempcount);

        }
        if (dic.containsKey(wt.getLineId()) && dic.get(wt.getLineId()).containsKey(Contant.SSFS)) {

            Map<String, StatusItemVo> tempmap = dic.get(wt.getLineId());
            Double tempvalue = tempmap.get(Contant.SSFS).getEdnaValue();
            tempvalue++;
            tempmap.get(Contant.SSFS).setEdnaValue(tempvalue);
            Double tempcount = tempmap.get(Contant.SSFS).getCount();
            tempcount++;
            tempmap.get(Contant.SSFS).setCount(tempcount);

        }
        if (dic.containsKey(wt.getProjectId()) && dic.get(wt.getProjectId()).containsKey(Contant.SSFS)) {

            Map<String, StatusItemVo> tempmap = dic.get(wt.getProjectId());
            Double tempvalue = tempmap.get(Contant.SSFS).getEdnaValue();
            tempvalue++;
            tempmap.get(Contant.SSFS).setEdnaValue(tempvalue);
            Double tempcount = tempmap.get(Contant.SSFS).getCount();
            tempcount++;
            tempmap.get(Contant.SSFS).setCount(tempcount);

        }
        if (dic.containsKey("0") && dic.get("0").containsKey(Contant.SSFS)) {

            Map<String, StatusItemVo> tempmap = dic.get("0");
            Double tempvalue = tempmap.get(Contant.SSFS).getEdnaValue();
            tempvalue++;
            tempmap.get(Contant.SSFS).setEdnaValue(tempvalue);
            Double tempcount = tempmap.get(Contant.SSFS).getCount();
            tempcount++;
            tempmap.get(Contant.SSFS).setCount(tempcount);

        }
        if (wt.getWindpowerstationId().indexOf("FDC") >= 0) {
            if (dic.containsKey("-1") && dic.get("-1").containsKey(Contant.SSFS)) {

                Map<String, StatusItemVo> tempmap = dic.get("-1");
                Double tempvalue = tempmap.get(Contant.SSFS).getEdnaValue();
                tempvalue++;
                tempmap.get(Contant.SSFS).setEdnaValue(tempvalue);
                Double tempcount = tempmap.get(Contant.SSFS).getCount();
                tempcount++;
                tempmap.get(Contant.SSFS).setCount(tempcount);
            }
        } else {
            if (dic.containsKey("-2") && dic.get("-2").containsKey(Contant.SSFS)) {

                Map<String, StatusItemVo> tempmap = dic.get("-2");
                Double tempvalue = tempmap.get(Contant.SSFS).getEdnaValue();
                tempvalue++;
                tempmap.get(Contant.SSFS).setEdnaValue(tempvalue);
                Double tempcount = tempmap.get(Contant.SSFS).getCount();
                tempcount++;
                tempmap.get(Contant.SSFS).setCount(tempcount);
            }
        }

    }

    @Override
    public List<PointData> getRealParameter() {
        java.util.List<PointData> retValue = new ArrayList<PointData>();
        for (String mkey : dic.keySet()) {
            for (String skey : dic.get(mkey).keySet()) {
                StatusItemVo item = dic.get(mkey).get(skey);

                if (item.getCount() != 0) {
                    PointData p = new PointData();

                    p.setPointValueInDouble(StringUtils.round(item.getEdnaValue() / item.getCount(), 2));
                    p.setEdnaId(item.getEdnaPoint());
                    p.setPointTime(date.getTime() / 1000);
                    retValue.add(p);
                }
            }
        }
        return retValue;
    }
}
