public static CandidateComparerCollection <T> Concat(CandidateComparerCollection <T> first, CandidateComparerCollection <T> second)
        {
            if (first.CandidateCount != second.CandidateCount)
            {
                throw new ArgumentException("Candidate Counts must be equal.");
            }

            return(new CandidateComparerCollection <T>(first.CandidateCount, CountedList <T> .Concat(first.Comparers, second.Comparers)));
        }
Exemplo n.º 2
0
        public static CountedList <T> ToCountedList <T>(this IEnumerable <T> source)
        {
            var list = new CountedList <T>();

            foreach (var item in source)
            {
                list.Add(item, 1);
            }

            return(list);
        }
        public CandidateComparerCollection <T> Append(T value)
        {
            if (CandidateCount != value.CandidateCount)
            {
                throw new ArgumentException("Candidate Counts must be equal.");
            }

            var second = new CountedList <T>();

            second.Add(value);
            return(new CandidateComparerCollection <T>(CandidateCount, CountedList <T> .Concat(Comparers, second)));
        }
Exemplo n.º 4
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());

            CountedList <string> newList = word_cloud.Program.getStringCountedList();

            foreach (var i in newList)
            {
                new FloatingLabel(i.Value, i.Counter);
            }
        }
Exemplo n.º 5
0
        public static Polling FromBallots <TBallot>(CountedList <CandidateComparerCollection <TBallot> > polls, Func <CandidateComparerCollection <TBallot>, List <List <int> > > getRanking)
            where TBallot : CandidateComparer
        {
            var pollFactor     = 1d / polls.Sum(_ => 1);
            int candidateCount = 0;

            double[, ] placeChanceByCandidate = null;

            foreach (var(poll, count) in polls)
            {
                if (placeChanceByCandidate == null)
                {
                    candidateCount         = poll.CandidateCount;
                    placeChanceByCandidate = new double[candidateCount, candidateCount];
                }

                var result     = getRanking(poll);
                var placeStart = 0;

                foreach (var tier in result)
                {
                    var teirFactor = count * pollFactor / tier.Count;

                    foreach (var candidate in tier)
                    {
                        foreach (var place in Enumerable.Range(placeStart, tier.Count))
                        {
                            placeChanceByCandidate[place, candidate] += teirFactor;
                        }
                    }

                    placeStart += tier.Count;
                }
            }

            return(new Polling(candidateCount, placeChanceByCandidate));
        }
Exemplo n.º 6
0
        public CountedList <Product> Search(string name, DateTime sellingStartDate, string keywords, int page, int pagesize)

        {
            var products = new List <Product>();

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string query = "select p.productid, p.name, p.productnumber, p.sellstartdate, pd.description " +
                               "from production.product p " +
                               "left join production.productmodel pm on p.productmodelid = pm.productmodelid " +
                               "left join production.productmodelproductdescriptionculture pmpdc on pm.productmodelid = pmpdc.productmodelid " +
                               "left join production.productdescription pd on pmpdc.productdescriptionid = pd.productdescriptionid " +
                               "where p.sellstartdate > @StartDate " +
                               "and p.name like @Name " +
                               "and pd.description like @Description " +
                               "order by p.sellstartdate " +
                               "offset @Skip rows fetch next @Take rows only; " +
                               "Select Count(*) " +
                               "from production.product p " +
                               "left join production.productmodel pm on p.productmodelid = pm.productmodelid " +
                               "left join production.productmodelproductdescriptionculture pmpdc on pm.productmodelid = pmpdc.productmodelid " +
                               "left join production.productdescription pd on pmpdc.productdescriptionid = pd.productdescriptionid " +
                               "where p.sellstartdate > @StartDate " +
                               "and p.name like @Name " +
                               "and pd.description like @Description";

                int skip = (page - 1) * pagesize;

                var command = new SqlCommand(query, connection);
                command.Parameters.AddWithValue("@Name", "%" + name + "%");
                command.Parameters.AddWithValue("@Description", "%" + keywords + "%");
                command.Parameters.AddWithValue("@Skip", skip);
                command.Parameters.AddWithValue("@Take", pagesize);

                SqlParameter startDate = new SqlParameter("@StartDate", SqlDbType.DateTime);
                startDate.Value = sellingStartDate;
                command.Parameters.Add(startDate);

                int totalCount = 0;
                try
                {
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        var product = ReadProduct(reader);
                        products.Add(product);
                    }
                    reader.NextResult();

                    while (reader.Read())
                    {
                        totalCount = (int)reader[0];
                    }
                }
                catch (Exception ex)
                {
                }

                var result = new CountedList <Product>
                {
                    TotalCount = totalCount,
                    Items      = products
                };

                return(result);
            }
        }
Exemplo n.º 7
0
 public void TestInitialize()
 {
     _countedList = new CountedList(DefaultCount * 4);
 }
 public CandidateComparerCollection(int candidateCount, CountedList <T> comparers)
 {
     CandidateCount = candidateCount;
     Comparers      = comparers;
 }