public override void ReadData(ESPReader reader, long dataEnd)
        {
            while (reader.BaseStream.Position < dataEnd)
            {
                string subTag = reader.PeekTag();

                switch (subTag)
                {
                case "EDID":
                    if (EditorID == null)
                    {
                        EditorID = new SimpleSubrecord <String>();
                    }

                    EditorID.ReadBinary(reader);
                    break;

                case "DATA":
                    if (Data == null)
                    {
                        Data = new ThresholdData();
                    }

                    Data.ReadBinary(reader);
                    break;

                default:
                    throw new Exception();
                }
            }
        }
    public static void LoadData()
    {
        g_DataDic = new Dictionary <PEAbnormalType, AbnormalData>();
        SqliteDataReader reader = LocalDatabase.Instance.ReadFullTable("AbnormalType");

        while (reader.Read())
        {
            AbnormalData data = new AbnormalData();
            data.type          = (PEAbnormalType)PETools.Db.GetInt(reader, "AbnormalId");
            data.name          = PELocalization.GetString(PETools.Db.GetInt(reader, "TranslationNameId"));
            data.iconName      = PETools.Db.GetString(reader, "Icon");
            data.description   = PELocalization.GetString(PETools.Db.GetInt(reader, "TranslationDescribeId"));
            data.target        = PETools.Db.GetInt(reader, "AbnormalTarget");
            data.deathRemove   = PETools.Db.GetBool(reader, "IsDeathRemove");
            data.updateByModel = PETools.Db.GetBool(reader, "UpdateByModel");

            data.trigger_TimeInterval = PETools.Db.GetFloat(reader, "Trigger_Time");
            data.trigger_BuffAdd      = PETools.Db.GetIntArray(reader, "Trigger_BuffAdd");
            data.trigger_ItemGet      = PETools.Db.GetIntArray(reader, "Trigger_ItemGet");
            data.trigger_Damage       = PETools.Db.GetBool(reader, "Trigger_Damage");
            data.trigger_InWater      = PETools.Db.GetBool(reader, "Trigger_IntoWater");

            data.hit_MutexAbnormal = GetAbnormalType(reader, "Hit_MutexAbnormal");
            data.hit_PreAbnormal   = GetAbnormalType(reader, "Hit_PreAbnormal");
            data.hit_BuffID        = PETools.Db.GetIntArray(reader, "Hit_BuffList");
            data.hit_Attr          = HitAttr.GetHitAttrArray(reader, "Hit_Attr");
            data.hit_Damage        = HitAttr.GetHitAttr(reader, "Hit_Damage");
            data.hit_TimeInterval  = PETools.Db.GetFloat(reader, "Hit_Time");
            data.hit_AreaTime      = PETools.Db.GetFloatArray(reader, "Hit_AreaTime");
            data.hit_RainTime      = PETools.Db.GetFloat(reader, "Hit_RainTime");
            data.hit_HitRate       = PETools.Db.GetFloat(reader, "Hit_Rate");

            data.eff_BuffAddList    = PETools.Db.GetIntArray(reader, "Eff_BuffAdd");
            data.eff_Anim           = reader.GetString(reader.GetOrdinal("Eff_Anim"));
            data.eff_Camera         = EffCamera.GetEffCamera(reader, "Eff_Camera");
            data.eff_AbnormalRemove = GetAbnormalType(reader, "Eff_RemoveAbnormal");
            data.eff_Particles      = PETools.Db.GetIntArray(reader, "Eff_Particle");
            data.eff_SkinColor      = PETools.Db.GetColor(reader, "Eff_SkinColor");
            data.eff_BodyWeight     = ThresholdData.GetThresholdDatas(reader, "Eff_BodyWeight");

            data.rt_Immediate    = PETools.Db.GetBool(reader, "RT_Imm");
            data.rt_TimeInterval = PETools.Db.GetFloat(reader, "RT_Time");
            data.rt_BuffRemove   = PETools.Db.GetIntArray(reader, "RT_BuffRemove");
            data.rt_EffectEnd    = PETools.Db.GetBool(reader, "RT_EffEnd");
            data.rt_OutsideWater = PETools.Db.GetBool(reader, "RT_OutWater");

            data.rh_BuffList = PETools.Db.GetIntArray(reader, "RH_BuffRemove");
            data.rh_Attr     = HitAttr.GetHitAttrArray(reader, "RH_Attr");

            data.re_BuffRemove  = PETools.Db.GetIntArray(reader, "RE_BuffRemove");
            data.re_BuffAdd     = PETools.Db.GetIntArray(reader, "RE_BuffAdd");
            data.re_AbnormalAdd = GetAbnormalType(reader, "RE_AbnormalAdd");
            data.re_Anim        = reader.GetString(reader.GetOrdinal("RE_Anim"));
            data.re_Camera      = EffCamera.GetEffCamera(reader, "RE_Camera");
            data.re_Particles   = PETools.Db.GetIntArray(reader, "RE_Particle");

            g_DataDic.Add(data.type, data);
        }
    }
        static ThresholdData GetThresholdData(string str)
        {
            float[] readValues = PETools.Db.ReadFloatArray(str);
            if (null == readValues)
            {
                return(null);
            }
            ThresholdData ret = new ThresholdData();

            ret.type      = Mathf.RoundToInt(readValues[0]);
            ret.threshold = readValues[1];
            return(ret);
        }
        public static ThresholdData[] GetThresholdDatas(SqliteDataReader reader, string fieldName)
        {
            string str = reader.GetString(reader.GetOrdinal(fieldName));

            if (string.IsNullOrEmpty(str) || str == "0")
            {
                return(null);
            }
            string[]        subStr = str.Split(';');
            ThresholdData[] ret    = new ThresholdData[subStr.Length];
            for (int i = 0; i < subStr.Length; ++i)
            {
                ret[i] = GetThresholdData(subStr[i]);
            }
            return(ret);
        }
Esempio n. 5
0
        //Generat the values based on contract database
        private void Generator(object arg)
        {
            RTDataGenerator me            = (RTDataGenerator)arg;
            Random          randGenerator = new Random();

            while (shouldContinue)
            {
                foreach (DeviceData currDevice in devicesData)
                {
                    DeviceData theChosenDevice = currDevice;

                    if (thresholdForDeviceType.ContainsKey(theChosenDevice.type))
                    {
                        ContractData currContract = thresholdForDeviceType[theChosenDevice.type];

                        foreach (KeyValuePair <int, float> thresholdWithContractValue in currContract.listThresholdIds)
                        {
                            int           thresholdId    = thresholdWithContractValue.Key;
                            ThresholdData theChosenRange = thresholds[thresholdId];
                            //device_id
                            insertSimulatedMeasurementCmd.Parameters[0].Value = theChosenDevice.id;
                            //threshold_id
                            insertSimulatedMeasurementCmd.Parameters[1].Value = thresholdId;
                            //value
                            insertSimulatedMeasurementCmd.Parameters[2].Value =
                                GetValueForDeviceThresholdPair(theChosenDevice, thresholdId, currContract, (irregularPeak % 67) == 0);
                            //timestamp
                            insertSimulatedMeasurementCmd.Parameters[3].Value = DateTime.Now;

                            //Here for debugging - need to know the generate values are correct
                            Debug.WriteLine("device: " + theChosenDevice.id + " threshold_id: " + thresholdId + " value: " + insertSimulatedMeasurementCmd.Parameters[2].Value + " time: " + insertSimulatedMeasurementCmd.Parameters[3].Value);

                            //ExecuteNonQuery - use when insert data to database
                            insertSimulatedMeasurementCmd.ExecuteNonQuery();

                            //Incrase the irregularPeak to insert diff values after some time
                            ++irregularPeak;
                        }
                    }
                }
                //Generate values each time based on the interval
                System.Threading.Thread.Sleep(interval);
            }
        }
        public override void ReadDataXML(XElement ele, ElderScrollsPlugin master)
        {
            XElement subEle;

            if (ele.TryPathTo("EditorID", false, out subEle))
            {
                if (EditorID == null)
                {
                    EditorID = new SimpleSubrecord <String>();
                }

                EditorID.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("Data", false, out subEle))
            {
                if (Data == null)
                {
                    Data = new ThresholdData();
                }

                Data.ReadXML(subEle, master);
            }
        }
Esempio n. 7
0
        //Create the values for device - Taking in considoration the contract values
        private object GetValueForDeviceThresholdPair(DeviceData deviceData, int thresholdId, ContractData contractData, bool generageIrregularData)
        {
            // Get the contract value of thresholdId.
            KeyValuePair <int, float> currContractValue = contractData.listThresholdIds.Find(x => x.Key == thresholdId);
            ThresholdData             thresholdData     = thresholds[thresholdId];

            float nextValue = 0;

            if (generageIrregularData)
            {
                if (!thresholdData.isAbove)
                {
                    nextValue = (float)randGenerator.Next((int)Math.Ceiling(currContractValue.Value), thresholdData.maxVal);
                }
                else
                {
                    nextValue = (float)randGenerator.Next(thresholdData.minVal, (int)Math.Floor(currContractValue.Value));
                }
            }
            else
            {
                pastMeasurements.Parameters["@device_id"].Value    = deviceData.id;
                pastMeasurements.Parameters["@threshold_id"].Value = thresholdId;
                pastMeasurements.Parameters["@timestamp"].Value    = DateTime.Now.Subtract(new TimeSpan(0, 0, (int)(((float)interval) / (1000) * 5)));



                double lastMeasurementsAverageValue = 0;
                if (!Double.TryParse(pastMeasurements.ExecuteScalar().ToString(), out lastMeasurementsAverageValue))
                {
                    if (thresholdData.isAbove)
                    {
                        nextValue = currContractValue.Value * 1.2f;
                    }
                    else
                    {
                        nextValue = currContractValue.Value * 0.8f;
                    }
                }
                else
                {
                    float min = (float)(lastMeasurementsAverageValue * 0.85);
                    float max = (float)(lastMeasurementsAverageValue * 1.15);

                    if (thresholdData.isAbove)
                    {
                        if (min < currContractValue.Value ||
                            max < currContractValue.Value)
                        {
                            max = thresholdData.maxVal;
                            min = currContractValue.Value;
                        }
                    }
                    else
                    {
                        if (max > currContractValue.Value ||
                            min > currContractValue.Value)
                        {
                            max = currContractValue.Value;
                            min = thresholdData.minVal;
                        }
                    }


                    if (min < thresholdData.minVal)
                    {
                        min = thresholdData.minVal * 1.1f;
                    }


                    if (max > thresholdData.maxVal)
                    {
                        max = thresholdData.maxVal * 0.9f;
                    }


                    nextValue = (float)(randGenerator.NextDouble() * (max - min) + min);
                }
            }

            return(Math.Round(nextValue, 2));
        }
 public SleepDeprivationStage(SimpleSubrecord <String> EditorID, ThresholdData Data)
 {
     this.EditorID = EditorID;
     this.Data     = Data;
 }
 public SleepDeprivationStage()
 {
     EditorID = new SimpleSubrecord <String>("EDID");
     Data     = new ThresholdData("DATA");
 }
Esempio n. 10
0
 public DehydrationStage(SimpleSubrecord <String> EditorID, ThresholdData Data)
 {
     this.EditorID = EditorID;
     this.Data     = Data;
 }
Esempio n. 11
0
 public HungerStage(SimpleSubrecord <String> EditorID, ThresholdData Data)
 {
     this.EditorID = EditorID;
     this.Data     = Data;
 }
Esempio n. 12
0
 public HungerStage()
 {
     EditorID = new SimpleSubrecord <String>("EDID");
     Data     = new ThresholdData("DATA");
 }