package jtznyj.engineer.service.winform.data;

public class RealDataField {

    public String get_unit() {
        return _unit;
    }

    public void set_unit(String _unit) {
        this._unit = _unit;
    }

    public enum MeterDataCalMethod {
        MeterLagDepth,
        MeterDepth,
        Avg,
        Max,
        Min,
        TotalCount,
        Last
    }

    public static String[] MeterDataCalMethodNames = new String[]
            {
                    "平均值",
                    "最大值",
                    "最小值",
                    "非零值最多",
                    "最后一个值",
                    "整米实测井深",
                    "整米迟到井深"
            };

    private String _field;

    private float _minValue;

    private float _maxValue;

    //小写字段
    private String _realField;

    private String _displayName;

    private String _unit;

    private MeterDataCalMethod _meterDataCalMethod;

    private double _meterTempValue;

    private double _lagMeterTempValue;

    public double get_lagMeterTempValue() {
        return _lagMeterTempValue;
    }

    public void set_lagMeterTempValue(double _lagMeterTempValue) {
        this._lagMeterTempValue = _lagMeterTempValue;
    }

    public double get_lastValue() {
        return _lastValue;
    }

    public void set_lastValue(double _lastValue) {
        this._lastValue = _lastValue;
    }

    public double getMeterTempValue() {
        return _meterTempValue;
    }

    public void setMeterTempValue(double meterTempValue) {
        _meterTempValue = meterTempValue;
    }

    private double _lastValue;

    public int _meterCount;

    public int _lagMeterCount;

    private int _totalCountCount;

    public String get_field() {
        return _field;
    }

    public void set_field(String _field) {
        this._field = _field;
    }

    public float get_minValue() {
        return _minValue;
    }

    public void set_minValue(float _minValue) {
        this._minValue = _minValue;
    }

    public float get_maxValue() {
        return _maxValue;
    }

    public void set_maxValue(float _maxValue) {
        this._maxValue = _maxValue;
    }

    public String get_realField() {
        return _realField;
    }

    public void set_realField(String _realField) {
        this._realField = _realField;
    }

    public String get_displayName() {
        return _displayName;
    }

    public void set_displayName(String _displayName) {
        this._displayName = _displayName;
    }

    public MeterDataCalMethod get_meterDataCalMethod() {
        return _meterDataCalMethod;
    }

    public void set_meterDataCalMethod(MeterDataCalMethod _meterDataCalMethod) {
        this._meterDataCalMethod = _meterDataCalMethod;
    }

    private int _lagTotalCountCount;

    public float K;

    public float Plus;

    public int DecimalPlace;

    public int WitsNO;

    public boolean SendWits;

    public String get_text() {
        return String.format("%s(%s)", this._displayName, this._field);
    }

    public String StandardName;

    public static MeterDataCalMethod StringToMeterDataCalMethod(String name) {
        MeterDataCalMethod result;
        if (name == "平均值") {
            result = MeterDataCalMethod.Avg;
        } else if (name == "最大值") {
            result = MeterDataCalMethod.Max;
        } else if (name == "最小值") {
            result = MeterDataCalMethod.Min;
        } else if (name == "非零值最多") {
            result = MeterDataCalMethod.TotalCount;
        } else if (name == "最后一个值") {
            result = MeterDataCalMethod.Last;
        } else if (name == "整米实测井深") {
            result = MeterDataCalMethod.MeterDepth;
        } else if (name == "整米迟到井深") {
            result = MeterDataCalMethod.MeterLagDepth;
        } else {
            result = MeterDataCalMethod.Last;
        }
        return result;
    }

    public static String MeterDataCalMethodToString(MeterDataCalMethod method) {
        String result;
        switch (method) {
            case MeterLagDepth:
                result = "整米迟到井深";
                break;
            case MeterDepth:
                result = "整米实测井深";
                break;
            case Avg:
                result = "平均值";
                break;
            case Max:
                result = "最大值";
                break;
            case Min:
                result = "最小值";
                break;
            case TotalCount:
                result = "非零值最多";
                break;
            case Last:
                result = "最后一个值";
                break;
            default:
                result = "最后一个值";
                break;
        }
        return result;
    }

    public RealDataField(String field, String realFieldName,String unit, float min, float max, float k) {
        this(field, realFieldName,unit, min, max);
        this.K = k;
        this.Plus = 0f;
        this.WitsNO = 0;
        this.DecimalPlace = 4;
        this.SendWits = true;
        this._realField = realFieldName;
        this._displayName = field;
    }

    public RealDataField(String field, String realFieldName,String unit, float min, float max) {
        this._field = field.toLowerCase();
        this._minValue = min;
        this._maxValue = max;
        this._realField = realFieldName;
        this._unit = unit;
        this.K = 1f;
        this.Plus = 0f;
        this.DecimalPlace = 4;
        this._displayName = field;
        this.StandardName = realFieldName.toLowerCase();
        this.WitsNO = 0;
        this.SendWits = true;
        this._meterDataCalMethod = MeterDataCalMethod.Last;
        this._meterTempValue = 0.0;
        this._meterCount = 0;
        this._lagMeterCount = 0;
        this._totalCountCount = 0;
        this._lagTotalCountCount = 0;
    }

    public RealDataField(RealDataField f) {
        this._field = f.get_field();
        this._minValue = f.get_minValue();
        this._maxValue = f.get_maxValue();
        this._realField = f.get_realField();
        this._realField = f.get_realField().toLowerCase();
        this._unit = f._unit;
        this.K = f.K;
        this.Plus = f.Plus;
        this._displayName = f.get_displayName();
        this.StandardName = f.StandardName;
        this.DecimalPlace = f.DecimalPlace;
        this.StandardName = f.StandardName;
        this._meterDataCalMethod = f._meterDataCalMethod;
        this._meterTempValue = f._meterTempValue;
        this._meterCount = f._meterCount;
        this._lagMeterCount = f._lagMeterCount;
        this._totalCountCount = f._totalCountCount;
        this._lagTotalCountCount = f._lagTotalCountCount;
        this.WitsNO = f.WitsNO;
        this.SendWits = true;
    }


    public RealDataField Clone() {
        return new RealDataField(this);
    }

    public int Init(double p, int haveValueCount) {
        this._meterCount = 1;
        haveValueCount = 0;
        MeterDataCalMethod meterDataCalMethod = this._meterDataCalMethod;
        if (meterDataCalMethod != MeterDataCalMethod.MeterDepth) {
            if (meterDataCalMethod != MeterDataCalMethod.TotalCount) {
                this._meterTempValue = p;
            } else if (p > 0.0) {
                haveValueCount = 1;
            }
        } else {
            this._meterTempValue = Math.ceil(p);
        }

        return haveValueCount;
    }

    public int SetValue(double p, int haveValueCount) {
        switch (this._meterDataCalMethod) {
            case MeterDepth:
                break;
            case Avg:
                this._meterCount++;
                this._meterTempValue += p;
                break;
            case Max:
                this._meterTempValue = Math.max(this._meterTempValue, p);
                break;
            case Min:
                this._meterTempValue = Math.min(this._meterTempValue, p);
                break;
            case TotalCount:
                if (p > 0.0) {
                    haveValueCount++;
                }
                break;
            default:
                this._meterTempValue = p;
                break;
        }
        return haveValueCount;
    }

    public int SetLagValue(double p, int haveValueCount) {
        switch (this._meterDataCalMethod) {
            case MeterLagDepth:
                return haveValueCount;
            case Avg:
                this._lagMeterCount++;
                this._lagMeterTempValue += p;
                return haveValueCount;
            case Max:
                this._lagMeterTempValue = Math.max(this._lagMeterTempValue, p);
                return haveValueCount;
            case Min:
                this._lagMeterTempValue = Math.min(this._lagMeterTempValue, p);
                return haveValueCount;
            case TotalCount:
                if (p > 0.0) {
                    haveValueCount++;
                }
                return haveValueCount;
        }
        this._lagMeterTempValue = p;
        return haveValueCount;
    }

    public int InitLag(double p, int haveValueCount) {
        this._lagMeterCount = 1;
        haveValueCount = 0;
        MeterDataCalMethod meterDataCalMethod = this._meterDataCalMethod;
        if (meterDataCalMethod != MeterDataCalMethod.MeterLagDepth) {
            if (meterDataCalMethod != MeterDataCalMethod.TotalCount) {
                this._lagMeterTempValue = p;
            } else if (p > 0.0) {
                haveValueCount = 1;
            }
        } else {
            this._lagMeterTempValue = Math.ceil(p);
        }
        return haveValueCount;
    }
}
