Example #1
0
        public override void Run(IGUI guiHandler)
        {
            guiHandler.PrintList(MockList, "Starting list");
            guiHandler.WriteMessage();

            #region Extensions example
            guiHandler.PrintList(MockList.ToRevertedStrings(), "Reverted elements list");
            guiHandler.WriteMessage();
            guiHandler.PrintList(MockList.ToLengthList(), "Elements length list");
            guiHandler.WriteMessage();
            guiHandler.PrintList(MockList.LessThanLength(3), "Elements shorter than 3");
            guiHandler.WriteMessage();
            guiHandler.PrintList(MockList.StartWithLetter('a'), "Elements beginning with a");
            guiHandler.WriteMessage();
            guiHandler.PrintList(MockList.IsConvertibleInInt(), "Elements convertible in int");
            guiHandler.WriteMessage();
            #endregion Extensions example

            #region Interface example
            guiHandler.WriteMessage("WITH INTERFACE");
            guiHandler.PrintList(MockList.Filter(new ShortStringFilter(3)), "Elements shorter than 3");
            guiHandler.WriteMessage();
            guiHandler.PrintList(MockList.Filter(new StartWithFilter('a')), "Elements beginning with a");
            guiHandler.WriteMessage();
            guiHandler.PrintList(MockList.Filter(new StringConvertibleToInt_Filter()), "Elements convertible in int");
            guiHandler.WriteMessage();

            guiHandler.PrintList(MockList.Project(new LenghtFromString_Projection()), "Elements length list");
            guiHandler.WriteMessage();
            guiHandler.PrintList(MockList.Project(new InvertedString_Projection()), "Reverted elements list");
            guiHandler.WriteMessage();
            #endregion Interface example

            #region Delegate example
            guiHandler.WriteMessage("WITH DELEGATES");
            guiHandler.PrintList(MockList.FilterBy(x => x != null && x.Length < 3), "Elements shorter than 3");
            guiHandler.WriteMessage();
            guiHandler.PrintList(MockList.FilterBy(x => x != null && (x.StartsWith("A") || x.StartsWith("a"))), "Elements beginning with a");
            guiHandler.WriteMessage();
            guiHandler.PrintList(MockList.FilterBy(x => x != null && int.TryParse(x, out int _)), "Elements convertible in int");
            guiHandler.WriteMessage();

            //guiHandler.PrintList(MockList.Project(new LenghtFromString_Projection()), "Elements length list");
            //guiHandler.WriteMessage();
            //guiHandler.PrintList(MockList.Project(new InvertedString_Projection()), "Reverted elements list");
            //guiHandler.WriteMessage();
            #endregion Delegate example

            guiHandler.AskForExit();
        }
Example #2
0
        public void Project_WhenFlatWithImpedenceMatch_ExpectAllAttributesMapped()
        {
            // arrange
            var sources =
                new List <Source>
            {
                new Source {
                    FirstName = @"first1", LastName = @"last1", Id = 1
                },
                new Source {
                    FirstName = @"first2", LastName = @"last2", Id = 2
                }
            }.AsQueryable();

            // act
            for (int index = 0; index < 100; index++)
            {
                var stopwatch    = Stopwatch.StartNew();
                var destinations = sources.Project().To <Destination>();
                stopwatch.Stop();

                // assert
                Assert.NotNull(destinations);
                Assert.True(destinations.Count() == 2);
                Assert.True(string.Compare(sources.FirstOrDefault().FirstName, destinations.FirstOrDefault().FirstName, StringComparison.CurrentCultureIgnoreCase) == 0);
                Assert.True(string.Compare(sources.FirstOrDefault().LastName, destinations.FirstOrDefault().LastName, StringComparison.CurrentCultureIgnoreCase) == 0);
                Assert.True(sources.FirstOrDefault().Id == destinations.FirstOrDefault().Id);

                this.WriteTimeElaped(stopwatch.ElapsedMilliseconds);
            }
        }
Example #3
0
        public void Project_WhenFlatWithNoMatch_ExpectAllNotMapped()
        {
            // arrange
            var sources =
                new List <NoMatch>
            {
                new NoMatch
                {
                    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxxx = 123,
                    YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYxx  = "fff"
                },
                new NoMatch
                {
                    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxxx = 456,
                    YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYxx  = "erre"
                }
            }.AsQueryable();

            // act
            var stopwatch    = Stopwatch.StartNew();
            var destinations = sources.Project().To <TestObjectScenarios.FlatImpedenceMismath.Destination>();

            stopwatch.Stop();

            // assert
            Assert.NotNull(destinations);
            Assert.True(destinations.Count() == 2);
            Assert.Null(destinations.FirstOrDefault().FirstNameQQQ);
            Assert.Null(destinations.FirstOrDefault().LastName);
            Assert.True(destinations.FirstOrDefault().IdQQQ == 0);
            this.WriteTimeElaped(stopwatch.ElapsedMilliseconds);
        }
        public void EnumerablesAreMappedToArrays()
        {
            var movies =
                new List <Movie>()
            {
                new Movie()
                {
                    Actors = new Actor[] { new Actor()
                                           {
                                               Name = "Actor 1"
                                           }, new Actor()
                                           {
                                               Name = "Actor 2"
                                           } }
                },
                new Movie()
                {
                    Actors = new Actor[] { new Actor()
                                           {
                                               Name = "Actor 3"
                                           }, new Actor()
                                           {
                                               Name = "Actor 4"
                                           } }
                }
            }.AsQueryable();

            var mapped = movies.Project().To <MovieDto>();

            mapped.ElementAt(0).Actors.Length.ShouldEqual(2);
            mapped.ElementAt(1).Actors[1].Name.ShouldEqual("Actor 4");
        }
        public void EnumerablesAreMappedToArrays()
        {
            var movies = 
                new List<Movie>() {
                new Movie() { Actors = new Actor[] { new Actor() { Name = "Actor 1" }, new Actor() { Name = "Actor 2" } } },
                new Movie() { Actors = new Actor[] { new Actor() { Name = "Actor 3" }, new Actor() { Name = "Actor 4" } } }
                }.AsQueryable();

            var mapped = movies.Project().To<MovieDto>();

            mapped.ElementAt(0).Actors.Length.ShouldEqual(2);
            mapped.ElementAt(1).Actors[1].Name.ShouldEqual("Actor 4");
        }
Example #6
0
        public void FlattenFatherSonsCountDtoOk()
        {
            //SETUP
            Mapper.Register <FatherSons, FlattenFatherSonsCountDto>().Flatten();
            Mapper.Compile(CompilationTypes.Source);

            //ATTEMPT
            var single = FatherSons.CreateOne();
            var queryData = new List <FatherSons> {
                single
            }.AsQueryable();
            var dto = queryData.Project <FatherSons, FlattenFatherSonsCountDto>().Single();

            //VERIFY
            Assert.AreEqual("Father", dto.MyString);
            Assert.AreEqual(5, dto.SonsCount);
        }
        public static void Main(string[] args)
        {
            List<int> number = new List<int>()
            {
                3,
                4,
                5,
                6,
                1,
                7
            };
            var orderNumber = number.OrderEnumerable(n => n);
            Console.WriteLine(string.Join(".", orderNumber));
            var filterList = number.Filter(n => n % 2 != 0);
            var res = number.WhereNot(n => n < 5);
            ;

            Console.WriteLine(string.Join(" ", filterList));
            Console.WriteLine(string.Join(" ", res) + "new");

            Student misho = new Student("Aisho", 10, 5);
            Student gosho = new Student("Gosho", 20, 6);
            Student minka = new Student("Binka", 40, 4);
            Student koko = new Student("Coko", 30, 2);

            List<Student> studentCollection = new List<Student>();
            studentCollection.Add(misho);
            studentCollection.Add(gosho);
            studentCollection.Add(minka);
            studentCollection.Add(koko);
            var orderListOfStudentByName = studentCollection.OrderEnumerable(st => st.Name);

            Console.WriteLine(string.Join("\n", orderListOfStudentByName));

            var age = studentCollection.Project(st => st.Age);
            var stres = studentCollection.WhereNot(st => st.Name.StartsWith("K"));

            foreach (var s in stres)
            {
                Console.WriteLine(s.Name);
            }

            Console.WriteLine(string.Join(" ", age));
        }
        private bool IsIdentifier(Member member)
        {
            if (member.Name == "Id")
            {
                return(true);
            }

            if (member.Name.IndexOf("id", StringComparison.OrdinalIgnoreCase) == -1)
            {
                return(false);
            }

            var declaringTypeName = member.DeclaringType.Name;

            if (member.Name == declaringTypeName + "Id")
            {
                return(true);
            }

            var potentialIds = new List <string> {
                "Identifier", declaringTypeName + "Identifier"
            };

            AddPotentialTypeIdsIfApplicable(potentialIds, declaringTypeName, "Dto");
            AddPotentialTypeIdsIfApplicable(potentialIds, declaringTypeName, "ViewModel");

            if (potentialIds.Contains(member.Name))
            {
                return(true);
            }

            if (_customNameMatchers.None())
            {
                return(false);
            }

            potentialIds.InsertRange(0, new[] { "Id", "Identifier" });

            return(_customNameMatchers
                   .Project(customNameMatcher => customNameMatcher.Match(member.Name))
                   .Any(memberNameMatch =>
                        memberNameMatch.Success &&
                        potentialIds.Contains(GetMemberName(memberNameMatch))));
        }
Example #9
0
        private bool IsIdentifier(Member member)
        {
            if (member.Name == "Id")
            {
                return(true);
            }

            if (member.Name.IndexOf("id", StringComparison.OrdinalIgnoreCase) == -1)
            {
                return(false);
            }

            var declaringTypeName = member.DeclaringType.Name;

            if (member.Name == declaringTypeName + "Id")
            {
                return(true);
            }

            var potentialIds = new List <string> {
                "Identifier", declaringTypeName + "Identifier"
            };

            AddPotentialTypeIdsIfApplicable(potentialIds, declaringTypeName, "Dto");
            AddPotentialTypeIdsIfApplicable(potentialIds, declaringTypeName, "ViewModel");

            if (potentialIds.Contains(member.Name))
            {
                return(true);
            }

            if (_customNameMatchers.NoneOrNull())
            {
                return(false);
            }

            potentialIds.InsertRange(0, _defaultIdMemberNames);

            return(_customNameMatchers
                   .Project(member, (m, customNameMatcher) => customNameMatcher.GetMemberName(m))
                   .WhereNotNull()
                   .Any(potentialIds.Contains));
        }
Example #10
0
        public void FlattenCircularReferenceDtoOk()
        {
            //SETUP
            Mapper.Reset();
            Mapper.Register <FlattenCircularReference, FlattenCircularReferenceDto>().Flatten();
            Mapper.Compile(CompilationTypes.Source);

            //ATTEMPT
            var single = FlattenCircularReference.CreateOne();
            var queryData = new List <FlattenCircularReference> {
                single
            }.AsQueryable();
            var dto = queryData.Project <FlattenCircularReference, FlattenCircularReferenceDto>().Single();

            //VERIFY
            Assert.AreEqual("Outer", dto.MyString);
            Assert.AreEqual("Son", dto.SonMyString);
            Assert.AreEqual("Inner", dto.CircularRefMyString);
        }
Example #11
0
        public void FlattenLinqCollectionMethodsDtoOk()
        {
            //SETUP
            Mapper.Register <FatherSons, FlattenLinqCollectionMethodsDto>().Flatten();
            Mapper.Compile(CompilationTypes.Source);

            //ATTEMPT
            var single = FatherSons.CreateOne();
            var queryData = new List <FatherSons> {
                single
            }.AsQueryable();
            var dto = queryData.Project <FatherSons, FlattenLinqCollectionMethodsDto>().Single();

            //VERIFY
            Assert.AreEqual(true, dto.SonsAny);
            Assert.AreEqual(5, dto.SonsCount);
            Assert.AreEqual(5, dto.SonsLongCount);
            Assert.AreEqual("Son", dto.SonsFirstOrDefault.MyString);
        }
Example #12
0
        static void RunRandomisedPca(List <Model> data)
        {
            MLContext ct             = new MLContext();
            var       dataProjection = data.Project().Take(50);

            IDataView trainingData = ct.Data.LoadFromEnumerable <FeatureModel>(dataProjection);

            var rpcaProjection = ct.Transforms.Concatenate("Features", "GeneOneScore", "GeneTwoScore")
                                 .Append(ct.Transforms.NormalizeMeanVariance("NormalisedFeatures", "Features"))
                                 .Append(ct.AnomalyDetection.Trainers.RandomizedPca(featureColumnName: "NormalisedFeatures", rank: 2));

            var fitOfTrainingData = rpcaProjection.Fit(trainingData);

            var transformOfTrainingData = fitOfTrainingData.Transform(trainingData);

            // gene one is constrained to be within .8 and .9, and gene two between .1 and .5
            var anomaly = new List <FeatureModel> {
                new FeatureModel {
                    GeneOneScore = (float)100000, GeneTwoScore = (float)25000
                }
            };

            var iDataViewOfAnomaly = ct.Data.LoadFromEnumerable <FeatureModel>(anomaly);
            var transformOfAnomaly = fitOfTrainingData.Transform(iDataViewOfAnomaly);

            var trainingDataResults = ct.Data.CreateEnumerable <ResultDisplay>(transformOfTrainingData, reuseRowObject: false).ToList();
            var anomalousDataResult = ct.Data.CreateEnumerable <ResultDisplay>(transformOfAnomaly, reuseRowObject: false).ToList();

            Console.WriteLine("Results from transforming first 20 training data: Predicted, score, PCA co-ordinates");
            foreach (var r in trainingDataResults.Take(20))
            {
                Console.WriteLine(r.PredictedLabel + ", " + r.Score + ", " + r.NormalisedFeatures[0] + ", " + r.NormalisedFeatures[1]);
            }

            // Claims this has a similar score to the other data, despite completely different co-ordinates.
            Console.WriteLine("Results from transforming the \"anomaly\": Predicted, score, PCA co-ordinates");
            foreach (var r in anomalousDataResult)
            {
                Console.WriteLine(r.PredictedLabel + ", " + r.Score + ", " + r.NormalisedFeatures[0] + ", " + r.NormalisedFeatures[1]);
            }
        }
Example #13
0
        public static void AddOrReplaceThenSort <T>(this List <T> cloneableItems, T newItem)
            where T : IPotentialAutoCreatedItem, IComparable <T>
        {
            if (cloneableItems.None())
            {
                cloneableItems.Add(newItem);
                return;
            }

            var replacedItem = cloneableItems
                               .Project((item, index) => new { Item = item, Index = index, IsClone = item.WasAutoCreated })
                               .Filter(d => d.IsClone)
                               .FirstOrDefault(d => newItem.IsReplacementFor(d.Item));

            if (replacedItem != null)
            {
                cloneableItems.RemoveAt(replacedItem.Index);
                cloneableItems.Insert(replacedItem.Index, newItem);
                return;
            }

            cloneableItems.AddThenSort(newItem);
        }
Example #14
0
        public void Project_WhenLevelLevel0Match_ExpectLevel0MatchOnly()
        {
            // arrange
            var source = new List <TestObjectScenarios.nLevelImpedenceMatch.Source>
            {
                new TestObjectScenarios.nLevelImpedenceMatch.Source
                {
                    Id
                        =
                            1,
                    Name
                        =
                            @"item1_level0",
                    SourceLevel1s
                        =
                            new List
                            <
                                SourceLevel1
                            >
                        {
                        new SourceLevel1
                        {
                            Level1_Id
                                =
                                    1,
                            Level1_Name
                                =
                                    @"item1_level1",
                            SourceLevel2Objects
                                =
                                    new List
                                    <
                                        SourceLevel2
                                    >
                                {
                                new SourceLevel2
                                {
                                    Level2_Id
                                        =
                                            1,
                                    Level2_Name
                                        =
                                            @"item1_level2"
                                }
                                }
                        }
                        }
                },
                new TestObjectScenarios.nLevelImpedenceMatch.Source
                {
                    Id
                        =
                            2,
                    Name
                        =
                            @"item2_level0",
                    SourceLevel1s
                        =
                            new List
                            <
                                SourceLevel1
                            >
                        {
                        new SourceLevel1
                        {
                            Level1_Id
                                =
                                    2,
                            Level1_Name
                                =
                                    @"item2_level1",
                            SourceLevel2Objects
                                =
                                    new List
                                    <
                                        SourceLevel2
                                    >
                                {
                                new SourceLevel2
                                {
                                    Level2_Id
                                        =
                                            2,
                                    Level2_Name
                                        =
                                            @"item2_level2"
                                }
                                }
                        }
                        }
                }
            }.AsQueryable();

            for (int i = 0; i < 100; i++)
            {
                // act
                var stopwatch    = Stopwatch.StartNew();
                var destinations = source.Project().To <TestObjectScenarios.nLevelImpedenceMatch.Destination>();
                stopwatch.Stop();

                // assert
                Assert.NotNull(destinations);
                Assert.True(destinations.Count() == 2);
                Assert.Null(destinations.FirstOrDefault().SourceLevel1s);
                Assert.True(string.Compare(@"item1_level0", destinations.FirstOrDefault().Name, StringComparison.CurrentCultureIgnoreCase) == 0);
                Assert.True(destinations.FirstOrDefault().Id == 1);
                this.WriteTimeElaped(stopwatch.ElapsedMilliseconds);
            }
        }