Beispiel #1
0
        public void CovariancePlonk(TextBox t, Coeff x, Coeff y)
        {
            Double d        = cev.covar(x, y);
            bool   modified = (Format.ToDbl(t.Text, ref d));

            if (modified)
            {
                cev.setcovar(x, y, d); imd.modified = true;
            }                                                            // a,b,c,d - 0,1,2,3
            t.Text = cev.covar(x, y).ToString("E6");
        }
Beispiel #2
0
 public SplashPas(string pName, float fNearRange, Coeff roExNearDamage, float fFarRange, Coeff roExFarDamage, UnitEventTrigger dwTriggerMask = UnitEventTrigger.kTriggerOnAttackTargetTrigger, ForceEffective dwEffectiveTypeFlags = ForceEffective.kEnemy)
     : base(pName, 0)
 {
     m_fNearRange         = fNearRange;
     m_oExNearDamage      = roExNearDamage;
     m_fFarRange          = fFarRange;
     m_oExFarDamage       = roExFarDamage;
     m_dwTriggerMask      = dwTriggerMask;
     m_effectiveTypeFlags = dwEffectiveTypeFlags;
     SetTriggerFlags(UnitEventTrigger.kTriggerOnAttackTargetTrigger);
 }
Beispiel #3
0
 public static string GetEmptyCoeffs()
 {
     Coeff[][] res = new Coeff[8][];
     for (int i = 0; i < 8; i++)
     {
         res[i] = new Coeff[15];
         for (int j = 0; j < 15; j++)
         {
             res[i][j] = new Coeff {
                 HitCoeff = 1m, MissCoeff = 1m
             };
         }
     }
     return(res.ToJson());
 }
Beispiel #4
0
        public string GetCoeff(Coeff coeff, int channel)
        {
            lock (syncRoot)
            {
                string coeffName = coeff.ToString();
                try
                {
                    DUTCoeffControlByPN.CoeffInfo coeffInfo = dataTable_DUTCoeffControlByPN.GetOneInfoFromTable(coeffName, channel);

                    EnterEngMode(coeffInfo.Page);
                    string value = EEPROM_SNOEC.ReadCoef(DUT_USB_Port, 0xA0, coeffInfo.StartAddress, coeffInfo.Format);

                    //Log.SaveLogToTxt("Get " + coeffName + " is " + value);
                    return(value);
                }
                catch
                {
                    //Log.SaveLogToTxt("Failed to get value of " + coeffName);
                    return(Algorithm.MyNaN.ToString());
                }
            }
        }
Beispiel #5
0
        public override bool SetCoeff(Coeff coeff, int channel, string value)
        {
            lock (syncRoot)
            {
                try
                {
                    string coeffName = coeff.ToString();
                    DUTCoeffControlByPN.CoeffInfo coeffInfo = dataTable_DUTCoeffControlByPN.GetOneInfoFromTable(coeffName, channel);

                    EnterEngMode(coeffInfo.Page);
                    bool result = EEPROM.SetCoef(TestPlanParaByPN.DUT_USB_Port, 0xA0, coeffInfo.StartAddress, value, coeffInfo.Format);

                    Log.SaveLogToTxt("Set " + coeffName + " to " + value);
                    return(result);
                }
                catch (Exception ex)
                {
                    Log.SaveLogToTxt(ex.ToString());
                    return(false);
                }
            }
        }
Beispiel #6
0
 public Value(float value)
 {
     x     = value;
     coeff = new Coeff(1, 0);
 }
Beispiel #7
0
    public void SetUnit(Unit unit)
    {
        if (m_unit.Unit == unit)
        {
            return;
        }
        m_unit.Set(unit);
        Unit u = m_unit;

        if (u == null)
        {
            Hide();
            return;
        }

        string path = string.Format("{0}/portrait_sel", u.Model);

        m_portrait.sprite = Resources.Load <Sprite>(path);
        m_name.text       = u.Name;

        // level
        m_levelValue = u.level.Level;
        m_level.text = string.Format("Lv {0}", m_levelValue);

        // hp
        m_hpValue    = (int)u.Hp;
        m_maxHpValue = (int)u.MaxHp;
        m_hp.text    = string.Format("{0}/{1}", m_hpValue, m_maxHpValue);

        // attack
        switch (u.AttackSkill.AttackType)
        {
        default:
            m_attackType.sprite = m_SpriteAttackPhysical;
            break;

        case AttackValue.Type.kMagical:
            m_attackType.sprite = m_SpriteAttackMagical;
            break;
        }
        float baseValue   = u.AttackSkill.AttackValueBase;
        float halfRange   = u.AttackSkill.AttackValueRandomRange * 0.5f;
        int   from        = (int)(baseValue * (1.0f - halfRange));
        int   to          = (int)(baseValue * (1.0f + halfRange));
        Coeff coeff       = u.AttackSkill.AttackValueCoeff;
        int   appendValue = (int)(u.AttackSkill.AttackValue - baseValue);

        if (appendValue > 0)
        {
            m_attackValue.text = string.Format("{0} - {1} <color=lime>+{2}</color>", from, to, appendValue);
        }
        else if (appendValue < 0)
        {
            m_attackValue.text = string.Format("{0} - {1} <color=red>{2}</color>", from, to, appendValue);
        }
        else
        {
            m_attackValue.text = string.Format("{0} - {1}", from, to);
        }

        // armor
        switch (u.ArmorType)
        {
        default:
            m_armorType.sprite = m_SpriteArmorHeavy;
            break;

        case ArmorValue.Type.kCrystal:
            m_armorType.sprite = m_SpriteArmorCrystal;
            break;
        }
        baseValue   = u.ArmorValueBase;
        appendValue = (int)(u.ArmorValue - baseValue);
        if (appendValue > 0)
        {
            m_armorValue.text = string.Format("{0} <color=lime>+{1}</color>", (int)baseValue, appendValue);
        }
        else if (appendValue < 0)
        {
            m_armorValue.text = string.Format("{0} <color=red>{1}</color>", (int)baseValue, appendValue);
        }
        else
        {
            m_armorValue.text = string.Format("{0}", (int)baseValue);
        }
    }
Beispiel #8
0
 public Polynom(params double [] Coeff)
 {
     Coefficients = new double[Coeff.Length];
     Coeff.CopyTo(Coefficients, 0);
 }
Beispiel #9
0
 public void CovariancePlonk(TextBox t, Coeff x, Coeff y)
 {
     Double d = cev.covar(x, y);
     bool modified = (Format.ToDbl(t.Text, ref d));
     if (modified) { cev.setcovar(x, y, d); imd.modified = true; }// a,b,c,d - 0,1,2,3
     t.Text = cev.covar(x, y).ToString("E6");
 }
        public override string ToString()
        {
            if (Type == 1)
            {
                return(Part.ToString());
            }

            List <string> polys = new List <string>();

            if (Type == 2)
            {
                foreach (Polynomial poly in Polynomials)
                {
                    polys.Add(poly.ToString());
                }
                string str = "(" + string.Join("+", polys) + ")";
                if (Power != 1)
                {
                    str = str + "^" + Power;
                }
                if (Coeff == -1)
                {
                    str = "-" + str;
                }
                else if (Coeff != 1)
                {
                    str = Coeff + "" + str;
                }

                return(str.Replace("+-", " - "));
            }
            else
            {
                List <string> polysDown = new List <string>();
                if (Coeff != 1 && Coeff != -1)
                {
                    polys.Add(Coeff.ToString());
                }
                foreach (Polynomial poly in Polynomials)
                {
                    if (poly.Power > 0)
                    {
                        polys.Add(poly.ToString());
                    }
                    else if (poly.Power < 0)
                    {
                        polysDown.Add((poly ^ -1).ToString());
                    }
                }
                string str;

                if (polys.Count > 0)
                {
                    if (Coeff != -1)
                    {
                        if (polys.Count == 1 && polys[0].StartsWith("(") && polys[0].EndsWith(")"))
                        {
                            str = polys[0].Substring(1, polys[0].Length - 2);
                        }
                        else
                        {
                            str = string.Join("", polys);
                        }
                    }
                    else
                    {
                        str = '-' + string.Join("", polys);
                    }
                }
                else
                {
                    str = Coeff.ToString();
                }


                if (polysDown.Count == 1 && polysDown[0].StartsWith("(") && polysDown[0].EndsWith(")"))
                {
                    polysDown[0] = polysDown[0].Substring(1, polysDown[0].Length - 2);
                }

                if (polysDown.Count > 0)
                {
                    str = @"\frac{" + str + "}{" + string.Join("", polysDown) + "}";
                }

                if (Power != 1)
                {
                    str = "(" + str + ")^" + Power;
                }

                return(str);
            }
        }
Beispiel #11
0
            internal static CoefRequestResult Parse(string result)
            {
                // Culture info for decimal value conversion.
                System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-us");

                // return value
                CoefRequestResult retval = new CoefRequestResult();


                List <CoefBlock> blockList = new List <CoefBlock>();

                // Invalid json format
                if (result.Length < 2 || !result.StartsWith("[") || !result.EndsWith("]"))
                {
                    throw new FormatException("Invalid format");
                }
                string objectstring = result.Substring(1, result.Length - 2);

                string[] blocks = objectstring.Split('[');
                foreach (var block in blocks)
                {
                    CoefBlock    newBlock      = new CoefBlock();
                    List <Coeff> coefBlockList = new List <Coeff>();
                    if (block.Length < 1)
                    {
                        continue;
                    }
                    string[] coefs = block.Split('{');
                    //Console.WriteLine(coefs);
                    foreach (var coef in coefs)
                    {
                        if (coef.Length < 1)
                        {
                            continue;
                        }

                        string coefstring = "";
                        if (coef.EndsWith("},") || coef.EndsWith("}]"))
                        {
                            coefstring = coef.Substring(0, coef.Length - 2);
                        }
                        else if (coef.EndsWith("}],"))
                        {
                            coefstring = coef.Substring(0, coef.Length - 3);
                        }
                        else
                        {
                            throw new FormatException("invalid Format");
                        }

                        string[] coefValues = coefstring.Split(',');
                        Coeff    newItem    = new Coeff();
                        foreach (var item in coefValues)
                        {
                            string[] valuePair = item.Split(':');

                            if (valuePair[0] == "\"hitCoeff\"")
                            {
                                newItem.HitCoeff = decimal.Parse(valuePair[1], ci);
                                //Console.WriteLine("HitCoeff:\n\t{0}\n\t{1:F16}", valuePair[1], newItem.HitCoeff);
                            }
                            else if (valuePair[0] == "\"missCoeff\"")
                            {
                                newItem.MissCoeff = decimal.Parse(valuePair[1], ci);
                                //Console.WriteLine("MissCoeff :\n\t{0}\n\t{1:F16}", valuePair[1], newItem.MissCoeff);
                            }
                        }
                        coefBlockList.Add(newItem);
                    }
                    newBlock.Coeffs = coefBlockList.ToArray();
                    retval.CoefBlocks.Add(newBlock);
                }

                return(retval);
            }
Beispiel #12
0
 public virtual string GetCoeff(Coeff coeff, int channel)
 {
     return(Algorithm.MyNaN.ToString());
 }
Beispiel #13
0
 public virtual bool SetCoeff(Coeff coeff, int channel, string value)
 {
     return(false);
 }
        /// <summary>
        /// Activity heavy lifting.
        /// </summary>
        /// <param name="context"></param>
        protected override void DoWork(CodeActivityContext context)
        {
            // Activity inputs
            int patId1 = PatId.Get(context);
            EntityList <PrescriptionSite> rxSite = RxSite.Get(context);
            string regionName = RegionName.Get(context);
            double doseCoeff  = DoseCoeff.Expression != null?DoseCoeff.Get(context) : 1.000;

            ImpacPersistenceManager pm = PersistenceManager.Expression != null
                                             ? PersistenceManager.Get(context)
                                             : PM;


            // Activity output
            DoseSiteCreated.Set(context, false); // Initialize the Activity output to False

            // Make sure rxSite is not supplied as a null (e.g. Nothing)
            if (rxSite == null)
            {
                return;
            }

            // Make sure none of the given Sites is Null
            if (rxSite.Count == 0)
            {
                return;
            }

            for (int i = 0; i < rxSite.Count; i++)
            {
                if (rxSite[i] == null)
                {
                    return;
                }
            }

            // Only continue if doseCoeff given is within valid range
            if ((doseCoeff < 0.0) || (doseCoeff > 9.9990))
            {
                return;
            }

            // Name for the Region cannot be empty or null
            if (string.IsNullOrEmpty(regionName))
            {
                return;
            }

            // Trim regionName to max allowed chars
            const int maxSiteNameLength = 20;

            if (regionName.Length > maxSiteNameLength)
            {
                regionName = regionName.Substring(0, maxSiteNameLength);
            }

            // First check if supplied siteName exists already in the database
            var query = new ImpacRdbQuery(typeof(Region));

            query.AddClause(Region.Pat_ID1EntityColumn, EntityQueryOp.EQ, patId1);
            query.AddClause(Region.Region_NameEntityColumn, EntityQueryOp.EQ, regionName);
            EntityList <Region> queryRegion = pm.GetEntities <Region>(query);

            if (queryRegion.Count > 0)
            {
                return;
            }

            // Check if any of the tip revision or historic Rx sites are already using the name
            var rxSitesQuery = new ImpacRdbQuery(typeof(PrescriptionSite));

            rxSitesQuery.AddClause(PrescriptionSiteDataRow.Pat_ID1EntityColumn, EntityQueryOp.EQ, patId1);
            rxSitesQuery.AddClause(PrescriptionSiteDataRow.SiteNameEntityColumn, EntityQueryOp.EQ, regionName);
            if (pm.GetEntities <PrescriptionSite>(rxSitesQuery).Count > 0)
            {
                return;
            }

            // Create an entry in the Region table (new REG_ID will be used later)
            Region region = Region.Create(pm);

            region.Pat_ID1     = patId1;
            region.Region_Name = regionName;
            try
            {
                pm.SaveChanges();
            }
            catch
            {
                return;
            }

            // Go through each Rx Site given and collect the treatment field properties
            var txField = new EntityList <Field>();

            foreach (var t in rxSite)
            {
                query = new ImpacRdbQuery(typeof(PrescriptionSite));
                query.AddClause(PrescriptionSite.Pat_ID1EntityColumn, EntityQueryOp.EQ, patId1);
                query.AddClause(PrescriptionSite.SIT_IDEntityColumn, EntityQueryOp.EQ, t.SIT_ID);
                query.AddClause(PrescriptionSite.VersionEntityColumn, EntityQueryOp.EQ, 0);
                EntityList <PrescriptionSite> site = pm.GetEntities <PrescriptionSite>(query);

                if (site.Count == 1)
                {
                    query = new ImpacRdbQuery(typeof(Field));
                    query.AddClause(Field.SIT_Set_IDEntityColumn, EntityQueryOp.EQ, site[0].SIT_SET_ID);
                    query.AddClause(Field.VersionEntityColumn, EntityQueryOp.EQ, 0);
                    txField.AddRange(pm.GetEntities <Field>(query));
                }
            }

            // Now add for each field an entry in the Coeff table with a link to the Region entry earlier
            int fieldsInserted = 0;

            try
            {
                foreach (var t in txField)
                {
                    Coeff coeff = Coeff.Create(pm);
                    coeff.Pat_ID1                   = patId1;
                    coeff.FLD_SET_ID                = t.FLD_SET_ID;
                    coeff.REG_ID                    = region.REG_ID;
                    coeff.Reg_Coeff                 = doseCoeff;
                    coeff.IsFromDataImport          = false;
                    coeff.IsModifiedAfterDataImport = false;
                    pm.SaveChanges();
                    fieldsInserted++;
                }
            }
            finally
            {
                DoseSiteCreated.Set(context, fieldsInserted == txField.Count);
            }
        }