public static string ReturnFormattedPersonInfo(UserQueryResult UQR, List <Tuple <string, string> > AllADGroupsList, bool TitleNotDescription = true)
        {
            if (AllADGroupsList.Count != UQR.ReturnAccessVector().Count)
            {
                throw new ArgumentOutOfRangeException();
            }
            string Outstring = UQR.AccountName;

            while (Outstring.Length < 80)
            {
                Outstring = Outstring + " ";
            }
            if (TitleNotDescription)
            {
                Outstring = Outstring + UQR.Title;
            }
            else
            {
                Outstring = Outstring + UQR.Description;
            }
            Outstring = $"{Outstring}\r\n{UQR.DistinguishedName}\r\n------------------------------------------------------------------------------------------------------------------------\r\n\r\n";
            Vector AccVect = UQR.ReturnAccessVector();

            for (int i = 0; i < AccVect.Count; i++)
            {
                if (AccVect[i] > 0)
                {
                    string TempString = AllADGroupsList[i].Item1;
                    while (TempString.Length < 80)
                    {
                        TempString = TempString + " ";
                    }
                    TempString = TempString + AllADGroupsList[i].Item2;
                    Outstring  = Outstring + TempString + "\r\n";
                }
            }
            Outstring = Outstring + "\r\n";
            return(Outstring);
        }
Example #2
0
 public UserKNNResult(UserQueryResult UQR) : base(UQR.Title, UQR.Description, UQR.Name, UQR.AccountName, UQR.DistinguishedName, UQR.ReturnAccessVector())
 {
 }
Example #3
0
 public UserClusteringResult(UserQueryResult UQR, string ClusterID, int ClusterIndex) : base(UQR.Title, UQR.Description, UQR.Name, UQR.AccountName, UQR.DistinguishedName, UQR.ReturnAccessVector())
 {
     clusterID    = ClusterID;
     clusterIndex = ClusterIndex;
 }
        private void nearestNeighboursButton_Click(object sender, EventArgs e)
        {
            nNDataGridView.AutoGenerateColumns = true;
            bool KSpecified = true;
            int  K;
            List <iKNNResult>          AllResults = new List <iKNNResult>();
            ConcurrentBag <iKNNResult> ResultBag  = new ConcurrentBag <iKNNResult>();

            try { K = Convert.ToInt32(kTextBox.Text); }
            catch
            {
                KSpecified    = false;
                kTextBox.Text = "All";
                Application.DoEvents();
                K = -1;
            }
            if (thisFormResultType == typeof(UserQueryResult))
            {
                UserQueryResult      UQR     = (UserQueryResult)thisFormResult;
                List <UserKNNResult> UKRList = new List <UserKNNResult>();
                Parallel.ForEach <UserQueryResult>(parentReference.UserQueryResults, CurrentUQR => {
                    if (CurrentUQR.AccountName != UQR.AccountName)
                    {
                        UserKNNResult UKR      = new UserKNNResult(CurrentUQR);
                        double CurrentDistance = HelperFunctions.GetEuclideanDistance(UQR.ReturnAccessVector(), CurrentUQR.ReturnAccessVector());
                        UKR.AssignKNNDistanceFromX(CurrentDistance);
                        ResultBag.Add(UKR);
                    }
                });
                UKRList         = ResultBag.Cast <UserKNNResult>().ToList <UserKNNResult>();
                AllResults      = UKRList.OrderBy(o => o.Distance).ToList().Cast <iKNNResult>().ToList();
                thisQueryReport = new UserKNNReport(AllResults.Cast <UserKNNResult>().ToList(), Ordering.Ascending);
            }
            else if (thisFormResultType == typeof(GroupingQueryResult))
            {
                GroupingQueryResult      GQR     = (GroupingQueryResult)thisFormResult;
                List <GroupingKNNResult> GKRList = new List <GroupingKNNResult>();
                Parallel.ForEach <GroupingQueryResult>(parentReference.GroupingQueryResults, CurrentGQR => {
                    if (CurrentGQR.GroupingName != GQR.GroupingName)
                    {
                        GroupingKNNResult GKR = new GroupingKNNResult(CurrentGQR);
                        double CurrentDistance;
                        if (parentReference.ClusterByRelativeCount)
                        {
                            CurrentDistance = HelperFunctions.GetEuclideanDistance(GQR.ReturnAccessVector(), CurrentGQR.ReturnAccessVector());
                        }
                        else
                        {
                            CurrentDistance = HelperFunctions.GetEuclideanDistance(GQR.ReturnTF_IDFVector(), CurrentGQR.ReturnTF_IDFVector());
                        }
                        GKR.AssignKNNDistanceFromX(CurrentDistance);
                        ResultBag.Add(GKR);
                    }
                });
                GKRList         = ResultBag.Cast <GroupingKNNResult>().ToList();
                AllResults      = GKRList.OrderBy(o => o.Distance).ToList().Cast <iKNNResult>().ToList();
                thisQueryReport = new GroupingKNNReport(AllResults.Cast <GroupingKNNResult>().ToList(), Ordering.Ascending);
            }
            else
            {
            }

            if (KSpecified && K <= AllResults.Count)
            {
                List <iKNNResult> Outlist = new List <iKNNResult>();
                for (int i = 0; i < K; i++)
                {
                    Outlist.Add(AllResults[i]);
                }
                //AllKNNResults = Outlist;
                if (thisFormResultType == typeof(UserQueryResult))
                {
                    thisQueryReport = new UserKNNReport(Outlist.Cast <UserKNNResult>().ToList(), Ordering.Ascending);
                }
                else if (thisFormResultType == typeof(GroupingQueryResult))
                {
                    thisQueryReport = new GroupingKNNReport(Outlist.Cast <GroupingKNNResult>().ToList(), Ordering.Ascending);
                }
                else
                {
                }
            }
            else
            {
                AllKNNResults = AllResults;
            }
            if (thisFormResultType == typeof(UserQueryResult))
            {
                UserKNNReport ReportPointer = (UserKNNReport)thisQueryReport;
                thisBindingSource.DataSource = ReportPointer.QRList;
                //thisBindingSource.DataSource = (UserKNNReport)thisQueryReport..Cast<UserKNNResult>().ToList();
                nNDataGridView.DataSource = thisBindingSource;
            }
            else if (thisFormResultType == typeof(GroupingQueryResult))
            {
                GroupingKNNReport ReportPointer = (GroupingKNNReport)thisQueryReport;
                thisBindingSource.DataSource = ReportPointer.QRList;

                nNDataGridView.DataSource = thisBindingSource;
            }
            else
            {
            }
        }
        public ClusteringOutput(List <QueryResult> QRList, RBAC RBACRef)
        {
            thisFormResultType = QRList[0].GetType();
            parentReference    = RBACRef;
            ConcurrentBag <Tuple <string, DenseVector> > InputList = new ConcurrentBag <Tuple <string, DenseVector> >();

            if (QRList[0].GetType() == typeof(UserQueryResult))
            {
                Parallel.ForEach <QueryResult>(QRList, QR =>
                {
                    UserQueryResult UQR = (UserQueryResult)QR;
                    Tuple <string, DenseVector> TupleIn = new Tuple <string, DenseVector>(UQR.AccountName, (DenseVector)UQR.ReturnAccessVector());
                    InputList.Add(TupleIn);
                });
            }
            else if (QRList[0].GetType() == typeof(GroupingQueryResult))
            {
                Parallel.ForEach <QueryResult>(QRList, QR =>
                {
                    GroupingQueryResult GQR = (GroupingQueryResult)QR;
                    DenseVector VectorA;
                    if (parentReference.ClusterByRelativeCount)
                    {
                        VectorA = (DenseVector)GQR.ReturnAccessVector();
                    }
                    else
                    {
                        VectorA = (DenseVector)GQR.ReturnTF_IDFVector();
                    }
                    Tuple <string, DenseVector> TupleIn = new Tuple <string, DenseVector>(GQR.GroupingName, VectorA);
                    InputList.Add(TupleIn);
                });
            }
            else
            {
            }
            //add options on algo configtab on main form later
            if (parentReference.ClusteringAlgoType == typeof(HACAlgo))
            {
                thisAlgo = new HACAlgo(InputList.OrderBy(o => o.Item1).ToList(), parentReference.PreferredDistanceStyle, parentReference.HACStoppingMetric, parentReference.PreferredStoppingStyle);
            }
            else
            {
                thisAlgo = new KMeansPlusPlus(InputList.OrderBy(o => o.Item1).ToList(), parentReference.KMeansValue, parentReference.PreferredKMeansStoppingStyle, parentReference.KMeansMaxIter);
            }
            parentReference.statusLabelChanger($"Initialising {thisAlgo.GetType().ToString().Split('.')[1]}, please be patient");
            thisAlgo.InitialiseClusters();

            while (!thisAlgo.Stopped)
            {
                thisAlgo.IterateOnce();
                if (!thisAlgo.Stopped)
                {
                    parentReference.statusLabelChanger($"Running {thisAlgo.GetType().ToString().Split('.')[1]}, iteration {thisAlgo.Iterator}");
                }
            }
            //set all centroids as means in case mapping of clusters is required further
            //down the line:

            if (QRList[0].ReturnAccessVector().Count > 500)
            {
                thisAlgo.SetCentroidsAsMeansHighDimensionality();
            }
            else
            {
                thisAlgo.SetCentroidsAsMeans();
            }
            parentReference.statusLabelChanger("Creating Data View");

            ConcurrentBag <QueryResult> ResultsBag = new ConcurrentBag <QueryResult>();

            if (thisFormResultType == typeof(UserQueryResult))
            {
                foreach (Cluster Clust in thisAlgo.Clusters)
                {
                    Parallel.ForEach <Tuple <string, DenseVector> >(Clust.MemberList, Member => {
                        UserQueryResult Target = (UserQueryResult)(from UQR in QRList.Cast <UserQueryResult>() where UQR.AccountName == Member.Item1 select UQR).ToList()[0];
                        ResultsBag.Add(new UserClusteringResult(Target, Clust.ClusterID, Clust.ListPosition));
                    });
                }
                clusteringResultList = ResultsBag.Cast <UserClusteringResult>().OrderBy(o => o.ClusterIndex).ToList <QueryResult>();
            }
            else if (thisFormResultType == typeof(GroupingQueryResult))
            {
                foreach (Cluster Clust in thisAlgo.Clusters)
                {
                    Parallel.ForEach <Tuple <string, DenseVector> >(Clust.MemberList, Member => {
                        GroupingQueryResult Target = (GroupingQueryResult)(from GQR in QRList.Cast <GroupingQueryResult>().ToList() where GQR.GroupingName == Member.Item1 select GQR).ToList <GroupingQueryResult>()[0];
                        ResultsBag.Add(new GroupingClusteringResult(Target, Clust.ClusterID, Clust.ListPosition));
                    });
                }
                clusteringResultList = ResultsBag.Cast <GroupingClusteringResult>().OrderBy(o => o.ClusterIndex).ToList <QueryResult>();
            }
            else
            {
            }
            parentReference.statusLabelChanger("Idle");

            InitializeComponent();
            this.Text = $"Clustering Results from {thisAlgo.Iterator} Iterations, using {thisAlgo.GetType().ToString().Split('.')[1]}, {thisAlgo.Clusters.Count} Clusters";


            thisBindingSource = new BindingSource();
            if (thisFormResultType == typeof(UserQueryResult))
            {
                //needs a bit of casting to allow datagridview to access type-specific public properties
                thisQR = new UserClusteringReport(clusteringResultList.Cast <UserClusteringResult>().ToList(), Ordering.Ascending);
                UserClusteringReport ReportReference = (UserClusteringReport)thisQR;
                thisBindingSource.DataSource    = ReportReference.QRList;
                clustersDataGridView.DataSource = thisBindingSource;
            }
            else
            {
                thisQR = new GroupingClusteringReport(clusteringResultList.Cast <GroupingClusteringResult>().ToList(), Ordering.Ascending);
                GroupingClusteringReport ReportReference = (GroupingClusteringReport)thisQR;
                thisBindingSource.DataSource    = ReportReference.QRList;
                clustersDataGridView.DataSource = thisBindingSource;
            }
        }