public void DecideIncludeReasonsDecideOptions()
        {
            var flagKey = "invalid_key";
            var user    = Optimizely.CreateUserContext(UserID);

            user.SetAttribute("browser_type", "chrome");

            var decision = user.Decide(flagKey);

            Assert.True(decision.Reasons.Length == 1);
            Assert.AreEqual(decision.Reasons[0], DecisionMessage.Reason(DecisionMessage.FLAG_KEY_INVALID, flagKey));

            var decideOptions = new OptimizelyDecideOption[] { OptimizelyDecideOption.INCLUDE_REASONS };

            decision = user.Decide(flagKey, decideOptions);
            Assert.True(decision.Reasons.Length == 1);
            Assert.AreEqual(decision.Reasons[0], DecisionMessage.Reason(DecisionMessage.FLAG_KEY_INVALID, flagKey));

            flagKey  = "multi_variate_feature";
            decision = user.Decide(flagKey);
            Assert.True(decision.Reasons.Length == 0);

            Assert.AreEqual(decision.VariationKey, "Gred");
            Assert.False(decision.Enabled);
            Assert.AreEqual(decision.RuleKey, "test_experiment_multivariate");
            Assert.AreEqual(decision.FlagKey, flagKey);
            Assert.AreNotEqual(decision.UserContext, user);
            Assert.IsTrue(TestData.CompareObjects(decision.UserContext, user));
            Assert.True(decision.Reasons.IsNullOrEmpty());

            decision = user.Decide(flagKey, decideOptions);
            Assert.True(decision.Reasons.Length > 0);
            Assert.AreEqual("User [testUserID] is in variation [Gred] of experiment [test_experiment_multivariate].", decision.Reasons[1]);
            Assert.AreEqual("The user \"testUserID\" is bucketed into experiment \"test_experiment_multivariate\" of feature \"multi_variate_feature\".", decision.Reasons[2]);
        }
Exemplo n.º 2
0
    public void SendDecisionText(DecisionMessage msg)
    {
        lastMsg = msg;
        playersVoted = 0;

        NetworkServer.SendToAll(MyMsgTypes.Decision, msg);

        StartCoroutine(Voting());
    }
        public void TestNewDecisionReasonWithoutIncludeReasons()
        {
            var decisionReasons = new DecisionReasons();

            decisionReasons.AddError(DecisionMessage.Reason(DecisionMessage.FLAG_KEY_INVALID, "invalid_key"));

            Assert.AreEqual(decisionReasons.ToReport()[0], "No flag was found for key \"invalid_key\".");
            decisionReasons.AddError(DecisionMessage.Reason(DecisionMessage.VARIABLE_VALUE_INVALID, "invalid_key"));
            Assert.AreEqual(decisionReasons.ToReport()[1], "Variable value for key \"invalid_key\" is invalid or wrong type.");
            decisionReasons.AddInfo("Some info message.");
            Assert.AreEqual(decisionReasons.ToReport().Count, 2);
        }
        public void TestNewDecisionReasonWithIncludeReasons()
        {
            var decisionReasons = new DecisionReasons();
            var decideOptions   = new OptimizelyDecideOption[] { OptimizelyDecideOption.INCLUDE_REASONS };

            decisionReasons.AddError(DecisionMessage.Reason(DecisionMessage.FLAG_KEY_INVALID, "invalid_key"));

            Assert.AreEqual(decisionReasons.ToReport(decideOptions.Contains(OptimizelyDecideOption.INCLUDE_REASONS))[0], "No flag was found for key \"invalid_key\".");
            decisionReasons.AddError(DecisionMessage.Reason(DecisionMessage.VARIABLE_VALUE_INVALID, "invalid_key"));
            Assert.AreEqual(decisionReasons.ToReport(decideOptions.Contains(OptimizelyDecideOption.INCLUDE_REASONS))[1], "Variable value for key \"invalid_key\" is invalid or wrong type.");
            decisionReasons.AddInfo("Some info message.");
            Assert.AreEqual(decisionReasons.ToReport(decideOptions.Contains(OptimizelyDecideOption.INCLUDE_REASONS))[2], "Some info message.");
        }
        public void DecideInvalidFlagKey()
        {
            var flagKey = "invalid_feature";

            var user = Optimizely.CreateUserContext(UserID);

            user.SetAttribute("browser_type", "chrome");

            var decisionExpected = OptimizelyDecision.NewErrorDecision(
                flagKey,
                user,
                DecisionMessage.Reason(DecisionMessage.FLAG_KEY_INVALID, flagKey),
                ErrorHandlerMock.Object,
                LoggerMock.Object);
            var decision = user.Decide(flagKey);

            Assert.IsTrue(TestData.CompareObjects(decision, decisionExpected));
        }
Exemplo n.º 6
0
        public ExpertiseModel Get(int id, int expertiseId)
        {
            ExpertiseModel expertise = db.t_Expertise.Where(w => w.ExpertiseId == expertiseId).Select(s => new ExpertiseModel()
            {
                ExpertiseId            = s.ExpertiseId, Staff = s.Staff, Reason = s.Reason,
                Conclusion             = s.Conclusion, NumberExp = s.NumberExp, DateExp = s.DateExp,
                RequestId              = s.RequestId,
                Staff2                 = s.Staff2,
                IsServiceableEquipment = s.IsServiceableEquipment,
                IsWarrantyRepair       = s.IsWarrantyRepair,
                IsOrganizationRepair   = s.IsOrganizationRepair,
                IsPartsSupply          = s.IsPartsSupply,
                IsServiceable          = s.IsServiceable,
                IsForWriteoff          = s.IsForWriteoff
            }).FirstOrDefault();

            if (expertise == null)
            {
                expertise = new ExpertiseModel();
                //expertise.ExpertiseId = id;
                StringBuilder        nameOfMalfunctions = new StringBuilder();
                t_Equipment          equipment          = db.t_Equipment.Find(id);
                IEnumerable <string> malfunctions       = equipment.t_Malfunction.Select(s => s.Name).ToList();
                //nameOfMalfunctions.Append("Выявлены неисправности следующих деталей:\n");
                foreach (string Name in malfunctions)
                {
                    nameOfMalfunctions.Append(Name + "\n");
                }
                expertise.Reason = nameOfMalfunctions.ToString();
                DecisionMessage decisionMessage = new DecisionMessage(id);
                expertise.Conclusion = decisionMessage.Text;
                expertise.NumberExp  =
                    db.t_Message.Select(s => s.LastNumber + 1).FirstOrDefault();
                expertise.DateExp = DateTimeOffset.Now;

                // insert Position and FIO of staff
                var user = _userManager.FindByName(_userName);
                if (user != null)
                {
                    expertise.Staff = user.Position + " " + user.FIO;
                }
            }

            /*else
             * {
             *  expertise.NumberExp =
             *  db.t_Message.Select(s => s.LastNumber).FirstOrDefault();
             *  expertise.DateExp = DateTime.Today;
             * }*/

            if (expertise != null && String.IsNullOrWhiteSpace(expertise.Conclusion))
            {
                DecisionMessage decisionMessage = new DecisionMessage(id);
                expertise.Conclusion = decisionMessage.Text;
            }

            if (expertise != null && String.IsNullOrWhiteSpace(expertise.Reason))
            {
                StringBuilder        nameOfMalfunctions = new StringBuilder();
                t_Equipment          equipment          = db.t_Equipment.Find(id);
                IEnumerable <string> malfunctions       = equipment.t_Malfunction.Select(s => s.Name).ToList();
                //nameOfMalfunctions.Append("Выявлены неисправности следующих деталей:\n");
                foreach (string Name in malfunctions)
                {
                    nameOfMalfunctions.Append(Name + "\n");
                }
                expertise.Reason = nameOfMalfunctions.ToString();
            }

            // Изменить ИД пользователя на другого в t_UserExpertise
            if (expertise != null && String.IsNullOrWhiteSpace(expertise.Staff))
            {
                /* var user = db.t_User.SingleOrDefault(w => w.UserName == _userName);
                 * if (user != null)
                 * {
                 *  expertise.Staff = user.Position + " " + user.FIO;
                 *
                 *  var expertiseUser = db.t_Expertise.Find(expertiseId).t_User.FirstOrDefault();
                 *
                 *  if (expertiseUser != null)
                 *  {
                 *      db.t_Expertise.Find(expertiseId).t_User.Remove(expertiseUser);
                 *      db.SaveChanges();
                 *      db.t_Expertise.Find(expertiseId).t_User.Add(user);
                 *      db.SaveChanges();
                 *  }
                 * }*/
                var user = _userManager.FindByName(_userName);

                ExpertiseUser expertiseUser = new ExpertiseUser();
                if (expertiseUser.ReplaceUserForExpertise(expertiseId, user.UserID))
                {
                    expertise.Staff = user.Position + " " + user.FIO;
                }
            }



            return(expertise);
        }
Exemplo n.º 7
0
    public static void TriggerDecision(int decisionId)
    {
        _instance._pendingDecision = decisionId;
        newButtons = new List<Button>();

        for (int i = 0; i < 4; i++)
        {
            _instance.ButtonPanel.GetComponent<ButtonPanel>().votes[i] = 0;
        }

        if(decisionId == 1)
        {
            _instance.ButtonPanel.GetComponent<ButtonPanel>().zero_3.gameObject.SetActive(false);
        }

        if(decisionId == 3)
        {
            _instance.ButtonPanel.GetComponent<ButtonPanel>().zero_3.gameObject.SetActive(true);
        }

        if (_instance.gameObject.activeInHierarchy)
        {
            return;
        }
        if (DecisionDisplayed != null)
        {
            DecisionDisplayed();
        }

        var decision = _instance.Decisions[decisionId];
        Debug.Log(decision.Description);
        Debug.Log(_instance.DescriptionText.name);
        _instance.DescriptionText.text = decision.Description;
        _instance.DecisionSprite.sprite = decision.sprite;
        for (int i = 0; i < decision.Options.Length; i++)
        {
            var option = decision.Options[i];
            var newButton = Instantiate(_instance.ButtonPrefab);
            newButton.GetComponent<DecisionButton>().Init(option, i);
            newButton.transform.SetParent(_instance.ButtonPanel);
            newButton.GetComponent<Button>().interactable = false;
            newButtons.Add(newButton.GetComponent<Button>());
            _instance.activeButtons.Add(newButton);
            _instance.gameObject.SetActive(true);
        }

        DecisionMessage decisionMessage = new DecisionMessage();

        int length = _instance.Decisions[decisionId].Options.Length + 1;
        decisionMessage.Decisions = new string[length];
        decisionMessage.Decisions[0] = _instance.Decisions[decisionId].Description;
        for (int i = 1; i < length; i++)
        {
            decisionMessage.Decisions[i] = _instance.Decisions[decisionId].Options[i - 1];
        }
        Server.Instance.SendDecisionText(decisionMessage);
    }