Beispiel #1
0
        public static void ExecutesScreenShotActionOnAgent(Agent agent, Act act)
        {
            NewPayLoad        PL       = new NewPayLoad("ScreenshotAction");
            List <NewPayLoad> PLParams = new List <NewPayLoad>();

            NewPayLoad AIVPL = new NewPayLoad("AIV", "WindowsToCapture", act.WindowsToCapture.ToString());

            PLParams.Add(AIVPL);
            PL.AddListPayLoad(PLParams);
            // Get the action payload

            PL.ClosePackage();
            // Send the payload to the service
            NewPayLoad RC = agent.GingerNodeProxy.RunAction(PL);

            if (RC.Name == "ScreenShots")
            {
                List <NewPayLoad> FieldsandParams = RC.GetListPayLoad();

                foreach (NewPayLoad Np in FieldsandParams)
                {
                    string Name = Np.GetValueString();

                    //string base64string = Np.GetValueString();
                    act.AddScreenShot(Name);
                }
            }
            else
            {
                // The RC is not OK when we faced some unexpected exception
                //TODO:
                string Err = RC.GetValueString();
                act.Error += Err;
            }
        }
Beispiel #2
0
        /// <summary>
        /// This lists the price changing method.
        /// </summary>
        /// <param name="shopLogic">Logic for Orders repository and SkiEqupments repository.</param>
        public static void ChangePrice(ShopLogic shopLogic)
        {
            int  id    = IntParse(Enter.ToString());
            bool valid = false;

            try
            {
                shopLogic?.GetSkiEquipmentsById(id);
                valid = true;
            }
            catch (ArgumentException)
            {
                Console.WriteLine(Other.ToString());
            }

            if (valid)
            {
                Console.WriteLine(Selected.ToString());

                Console.WriteLine(shopLogic?.GetSkiEquipmentsById(id).ToString());
                const string Np = "Enter new price here: ";

                int price = IntParse(Np.ToString());

                shopLogic?.ChangePrice(id, price);

                Console.WriteLine(Saved.ToString());
            }

            Console.ReadLine();
        }
Beispiel #3
0
        private NewPayLoad StartDriver(NewPayLoad pl)
        {
            try
            {
                List <NewPayLoad> FieldsandParams = pl.GetListPayLoad();

                Dictionary <string, string> InputParams = new Dictionary <string, string>();
                foreach (NewPayLoad Np in FieldsandParams)
                {
                    string Name = Np.GetValueString();

                    string Value = Np.GetValueString();
                    if (!InputParams.ContainsKey(Name))
                    {
                        InputParams.Add(Name, Value);
                    }
                }


                ConfigureServiceParams(mService, InputParams);
                Console.WriteLine("Payload - Start Session");
                ((IServiceSession)mService).StartSession();
                NewPayLoad PLRC = new NewPayLoad("OK");
                PLRC.ClosePackage();
                return(PLRC);
            }
            catch (Exception ex)
            {
                return(NewPayLoad.Error(ex.Message));
            }
        }
Beispiel #4
0
        public string Create([Bind(Exclude = "Id")] Np Model)
        {
            ApplicationDbContext db = new ApplicationDbContext();
            string msg;

            try
            {
                if (ModelState.IsValid)
                {
                    db.Nps.Add(Model);

                    db.SaveChanges();
                    msg = "Сохранено успешно";
                }
                else
                {
                    msg = "Данные не прошли проверку ввода";
                }
            }
            catch (Exception ex)
            {
                msg = "Произошла ошибка:" + ex.Message;
            }
            return(msg);
        }
Beispiel #5
0
        public static void ConvertPyPlot()
        {
            var x = Np.ARange(0, 5, 0.1);
            var y = Np.Sin(x);

            PyPlot.Plot(x, y);
        }
Beispiel #6
0
        public string Delete(int Id)
        {
            ApplicationDbContext db = new ApplicationDbContext();
            Np nps = db.Nps.Find(Id);

            db.Nps.Remove(nps);
            db.SaveChanges();
            return("Удалено успешно");
        }
 // Update is called once per frame
 void Update()
 {
     if (!SetScore && Np)
     {
         Np.SetNum(optionManager.GetScore(number));
         result.SetRankToStageSelect(optionManager.GetScore(number), number);
         SetScore = true;
     }
 }
Beispiel #8
0
        private NewPayLoad TakeScreenot(NewPayLoad ActionPayload)
        {
            if (mService is IScreenShotService ScreenshotService)
            {
                Dictionary <string, string> InputParams     = new Dictionary <string, string>();
                List <NewPayLoad>           FieldsandParams = ActionPayload.GetListPayLoad();


                foreach (NewPayLoad Np in FieldsandParams)
                {
                    string Name = Np.GetValueString();

                    string Value = Np.GetValueString();
                    if (!InputParams.ContainsKey(Name))
                    {
                        InputParams.Add(Name, Value);
                    }
                }
                NewPayLoad ResponsePL       = new NewPayLoad("ScreenShots");
                string     WindowsToCapture = InputParams["WindowsToCapture"];

                List <NewPayLoad> ScreenShots = new List <NewPayLoad>();

                switch (WindowsToCapture)
                {
                case "OnlyActiveWindow":
                    ScreenShots.Add(BitmapToPayload(ScreenshotService.GetActiveScreenImage()));

                    break;

                case "AllAvailableWindows":


                    foreach (Bitmap bmp in ScreenshotService.GetAllScreensImages())
                    {
                        ScreenShots.Add(BitmapToPayload(bmp));
                    }
                    break;

                default:
                    return(NewPayLoad.Error("Service is not supporting IScreenShotService cannot delegate to take screen shot"));
                }



                Bitmap img = ScreenshotService.GetActiveScreenImage();


                ResponsePL.AddListPayLoad(ScreenShots);
                ResponsePL.ClosePackage();
                return(ResponsePL);
            }

            NewPayLoad err2 = NewPayLoad.Error("Service is not supporting IScreenShotService cannot delegate to take screen shot");

            return(err2);
        }
Beispiel #9
0
        public static void ConvertArange()
        {
            var int1 = Np.ARange(5);
            var int2 = Np.ARange(5, 10);
            var int3 = Np.ARange(5, 10, 3);

            var double1 = Np.ARange(5.1);
            var double2 = Np.ARange(5.1, 10);
            var double3 = Np.ARange(5.1, 10, 3);
        }
Beispiel #10
0
        /// <summary>
        /// Compute sample weights such that the class distribution of y becomes
        /// balanced.
        /// </summary>
        /// <param name="?"></param>
        private static double[] BalanceWeights(int[] y)
        {
            var encoder = new LabelEncoder <int>();

            y = encoder.FitTransform(y);
            var bins = Np.BinCount(y);


            var weights = bins.ElementsAt(y).Select(v => 1.0 / v * bins.Min()).ToArray();

            return(weights);
        }
        /// <summary>
        ///     Returns true if Profitability instances are equal
        /// </summary>
        /// <param name="other">Instance of Profitability to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Profitability other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Roe == other.Roe ||
                     Roe != null &&
                     Roe.Equals(other.Roe)
                     ) &&
                 (
                     Npm == other.Npm ||
                     Npm != null &&
                     Npm.Equals(other.Npm)
                 ) &&
                 (
                     Gpm == other.Gpm ||
                     Gpm != null &&
                     Gpm.Equals(other.Gpm)
                 ) &&
                 (
                     Np == other.Np ||
                     Np != null &&
                     Np.Equals(other.Np)
                 ) &&
                 (
                     Eps == other.Eps ||
                     Eps != null &&
                     Eps.Equals(other.Eps)
                 ) &&
                 (
                     Mbr == other.Mbr ||
                     Mbr != null &&
                     Mbr.Equals(other.Mbr)
                 ) &&
                 (
                     Ts == other.Ts ||
                     Ts != null &&
                     Ts.Equals(other.Ts)
                 ) &&
                 (
                     Cs == other.Cs ||
                     Cs != null &&
                     Cs.Equals(other.Cs)
                 ));
        }
Beispiel #12
0
        public void NdArrayDemo()
        {
            var a = new[]
            {
                new[] { 1, 2, 3 },
                new[] { 4, 5, 6 }
            };
            NdArray2DInt      array2 = Np.Array2(a); // regular
            NdArray1D <int[]> array1 = Np.Array1(a); // not regular

            var tmp_sin = Np.Sin(array2);
            // var t1_sin = Np.Sin(array1);
        }
 /// <summary>
 ///     Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked            // Overflow is fine, just wrap
     {
         int hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (Roe != null)
         {
             hashCode = hashCode * 59 + Roe.GetHashCode();
         }
         if (Npm != null)
         {
             hashCode = hashCode * 59 + Npm.GetHashCode();
         }
         if (Gpm != null)
         {
             hashCode = hashCode * 59 + Gpm.GetHashCode();
         }
         if (Np != null)
         {
             hashCode = hashCode * 59 + Np.GetHashCode();
         }
         if (Eps != null)
         {
             hashCode = hashCode * 59 + Eps.GetHashCode();
         }
         if (Mbr != null)
         {
             hashCode = hashCode * 59 + Mbr.GetHashCode();
         }
         if (Ts != null)
         {
             hashCode = hashCode * 59 + Ts.GetHashCode();
         }
         if (Cs != null)
         {
             hashCode = hashCode * 59 + Cs.GetHashCode();
         }
         return(hashCode);
     }
 }
Beispiel #14
0
        public string Edit(Np Model)
        {
            ApplicationDbContext db = new ApplicationDbContext();
            string msg;

            try
            {
                if (ModelState.IsValid)
                {
                    db.Entry(Model).State = EntityState.Modified;
                    db.SaveChanges();
                    msg = "Сохранено успешно";
                }
                else
                {
                    msg = "Данные не прошли проверку ввода";
                }
            }
            catch (Exception ex)
            {
                msg = "Произошла ошибка:" + ex.Message;
            }
            return(msg);
        }
Beispiel #15
0
        public void TestMinSamplesLeaf()
        {
            foreach (var name in CLF_TREES)
            {
                var est = CreateClassifier <double>(name, min_samples_leaf: 5, random: new Random(0));
                est.Fit(X, y);
                var @out        = est.Tree.apply(X.ToDenseMatrix());
                var node_counts = Np.BinCount(@out.Select(v => (int)v).ToArray());
                var leaf_count  = node_counts.Where(v => v != 0).ToList(); // drop inner nodes
                Assert.IsTrue(leaf_count.Min() > 4,
                              "Failed with {0}".Frmt(name));
            }

            foreach (var name in RegTrees)
            {
                var est = CreateRegressor(name, min_samples_leaf: 5, random: new Random(0));
                est.Fit(X, y);
                var @out       = est.Tree.apply(X.ToDenseMatrix());
                var nodeCounts = Np.BinCount(@out.Select(v => (int)v).ToArray());
                var leafCount  = nodeCounts.Where(v => v != 0).ToList(); // drop inner nodes
                Assert.IsTrue(leafCount.Min() > 4,
                              "Failed with {0}".Frmt(name));
            }
        }
Beispiel #16
0
 public static void CreateNumpyArrays()
 {
     var list = new[] { 1, 2, 3 };
     var tmp  = Np.Array1(new[] { 1.0, 2, 3 });
     var tmp2 = Np.Array1(new[] { 1.0, 2, 3 }, order: NumpyArrayOrder.C);
 }
Beispiel #17
0
 // Use this for initialization
 void Start()
 {
     m_root = this.transform.parent.GetComponent <Np>();
 }
Beispiel #18
0
 // Start is called before the first frame update
 void Start()
 {
     rootObj = transform.root.GetComponent <Np>();
     PV      = rootObj.PV;
 }
        public void T01()
        {
            var a = Np.Array1(new [] { 2, 4, 6 });

            Assert.Equal(4.0, a.Mean());
        }
Beispiel #20
0
        public void TestSampleWeight()
        {
            // Test that zero-weighted samples are not taken into account
            var X = Enumerable.Range(0, 100).ToColumnMatrix();
            var y = Enumerable.Repeat(1, 100).ToArray();

            Array.Clear(y, 0, 50);

            var sampleWeight = Enumerable.Repeat(1, 100).ToVector();

            sampleWeight.SetSubVector(0, 50, Enumerable.Repeat(0, 50).ToVector());

            var clf = new DecisionTreeClassifier <int>(random: new Random(0));

            clf.Fit(X, y, sampleWeight: sampleWeight);
            AssertExt.ArrayEqual(clf.Predict(X), Enumerable.Repeat(1, 100).ToArray());

            // Test that low weighted samples are not taken into account at low depth
            X = Enumerable.Range(0, 200).ToColumnMatrix();
            y = new int[200];
            Array.Copy(Enumerable.Repeat(1, 50).ToArray(), 0, y, 50, 50);
            Array.Copy(Enumerable.Repeat(2, 100).ToArray(), 0, y, 100, 100);
            X.SetSubMatrix(100, 100, 0, 1, Enumerable.Repeat(200, 100).ToColumnMatrix());

            sampleWeight = Enumerable.Repeat(1, 200).ToVector();

            sampleWeight.SetSubVector(100, 100, Enumerable.Repeat(0.51, 100).ToVector());
            // Samples of class '2' are still weightier
            clf = new DecisionTreeClassifier <int>(maxDepth: 1, random: new Random(0));
            clf.Fit(X, y, sampleWeight: sampleWeight);
            Assert.AreEqual(149.5, clf.Tree.Threshold[0]);

            sampleWeight.SetSubVector(100, 100, Enumerable.Repeat(0.50, 100).ToVector());
            // Samples of class '2' are no longer weightier
            clf = new DecisionTreeClassifier <int>(maxDepth: 1, random: new Random(0));
            clf.Fit(X, y, sampleWeight: sampleWeight);
            Assert.AreEqual(49.5, clf.Tree.Threshold[0]); // Threshold should have moved


            // Test that sample weighting is the same as having duplicates
            X = iris.Data;
            y = iris.Target;

            var random     = new Random(0);
            var duplicates = new int[200];

            for (int i = 0; i < duplicates.Length; i++)
            {
                duplicates[i] = random.Next(X.RowCount);
            }

            clf = new DecisionTreeClassifier <int>(random: new Random(1));
            clf.Fit(X.RowsAt(duplicates), y.ElementsAt(duplicates));


            sampleWeight = Np.BinCount(duplicates, minLength: X.RowCount).ToVector();
            var clf2 = new DecisionTreeClassifier <int>(random: new Random(1));

            clf2.Fit(X, y, sampleWeight: sampleWeight);


            var @internal = clf.Tree.ChildrenLeft.Indices(v => v != Tree._TREE_LEAF);

            AssertExt.AlmostEqual(clf.Tree.Threshold.ElementsAt(@internal),
                                  clf2.Tree.Threshold.ElementsAt(@internal));
        }