user tree with points and profile in C #

9

I have a list of users who each have a sponsor (sponsor is also a user). Each user has points and is of one type. I want to know which branch of the tree has the highest number of points, and for each branch know how many equal types I have. Suppose I have the tree:

Theresultwouldbe:ForthenumberofPointsofeachbranch:

and for the number of equal types:

Whatisthebestwaytoachievethis?Icreatedafunctionthatrunsthroughthewholetreeandinanarrayputsthepointsandinanotherarrayplacesthetypes.Anyway,itisgivingerror.I'vebeenrunningaroundbutI'minneedofhelp.ThefunctionIcreatedis:

////FUNÇÃOTreeBranchPathint[]TotalPontosRamo=newint[1];int[,]FolhaInfoPontos=newint[6,6];int[,]FolhaInfoPatamar=newint[6,6];intCountRamos=1;intCountFilhos=0;privatevoidTreeBranchPath(intidusr,intusrpnts,intusrpata,intramo,intfilho,boolFirstInteract){FolhaInfoPontos[ramo,filho]=usrpnts;FolhaInfoPatamar[ramo,filho]=usrpata;if(FirstInteract){ramo=ramo+1;}/*Inicio-Verificasetemdescendentes-afilhados*/Session["ConfDados"] = Session["ConfDados"] + "Verifica se o User " + idusr + " tem descendentes<br>";
        var AfilhadosList = (from af in db.NRV_USERS
                                where af.idpatrocinador == idusr
                                select af).ToList();

        if (AfilhadosList.Count() != 0)
        {


            foreach (var descid in AfilhadosList)
            {

                CountFilhos = CountFilhos + 1;

                /* Inicio - Quantos Pontos o User tem */
                var UserPoints = (from pnt in db.NRV_USERPONTOS
                                    where pnt.iduser == descid.id_user && pnt.usrpntact == true
                                    select pnt).FirstOrDefault();

                int TotalUserPoints = UserPoints.pontosgrupo + UserPoints.pontosproprios;

                Session["ConfDados"] = Session["ConfDados"] + "O User " + descid.id_user + " tem  " + TotalUserPoints + " pontos (" + UserPoints.pontosgrupo + " + " + UserPoints.pontosproprios + ")<br>";
                /* Fim - Quantos Pontos o User tem */


                /* Inicio - Em que Patamar o User está */
                var AuxUserPatamar = (from cp in db.NRV_USERPATAMAR
                                      where cp.iduser == descid.id_user
                                      select cp.idpatamax).FirstOrDefault();
                Session["ConfDados"] = Session["ConfDados"] + "O User " + descid.id_user + " está no Patamar Maximo " + AuxUserPatamar + "<br>";
                /* Fim - Em que Patamar o User está */


                //FolhaInfoPontos = ResizeArray(FolhaInfoPontos, ramo + 1, numfilho + 1);
                //FolhaInfoPatamar = ResizeArray(FolhaInfoPatamar, ramo + 1, numfilho + 1);

                TreeBranchPath(descid.id_user, TotalUserPoints, AuxUserPatamar, ramo, CountFilhos, false);

               // TotalPontosRamo[ramo] = TotalPontosRamo[ramo] + TotalUserPoints;


                ramo = ramo + 1;

            }

        }
        else
        {
            //ramo = ramo + 1;
            CountRamos = CountRamos + 1;
            CountFilhos = 0;
            Session["ConfDados"] = Session["ConfDados"] + "O User " + idusr + " do Ramo " + ramo + " não descendentes<br><br>";
        }



    }

Can someone help me?

    
asked by anonymous 01.06.2015 / 23:39

2 answers

1

Create a class that has the following properties:

class DadosRamo {
  LinkedList<Filho> PontosDoRamo;
  int TotalDePontos = 0;
  Dictionary<Filho, int> contagemPorTipoDeFilho;
}
  • PontosDoRamo : As you walk through the list, you must store the points in that linked list.
  • TotalDePontos : Add the points of each child here, in the end you will have the total.
  • ContagemPorTipoDeFilho : Add the child to the dictionary, if it is already there, add 1 to the count.

At the end you should have a List<DadosRamo> with information from all your branches.

    
11.09.2015 / 15:58
-2

The question seems pertinent and I do not know to what extent I will be able to give an adequate answer, but if I had to address a problem of this nature, I would rather use an architecture like MongoDB, perhaps combined with Ruby on Rails >     

12.09.2015 / 23:20