示例#1
0
 public Team(IGrouping <int, Player> grouping)
 {
     CurrentBet = grouping.Aggregate(0, (teamBetAmount, player) => teamBetAmount + player.CurrentBet);
     CoinsLeft  = grouping.Aggregate(0, (coinsTotal, player) => coinsTotal + player.Coins);
     Players    = grouping.Select(p => p);
     TeamId     = grouping.Key;
 }
示例#2
0
        private IEnumerable <PolygonData> projectileSpriteData(IGrouping <Vector2D, ProjectileInfo> hex)
        {
            var hexTransform    = Matrix4.CreateTranslation(hexX(hex.Key), hexY(hex.Key), 0);
            var shownProjectile = hex.Aggregate((a, b) => a.Count > b.Count ? a : b);
            var unitSprite      = GalaxyTextures.Get.Sprite(shownProjectile.ImagePath);

            yield return(new PolygonData(
                             ProjectileZ,
                             new SpriteData(Matrix4.CreateScale(ProjectileScale, ProjectileScale, 1) * hexTransform, unitSprite.Id, shownProjectile.Owner.Color, null),
                             SpriteHelpers.UnitRect(unitSprite).ToList()
                             ));

            var formatter = new ThousandsFormatter();

            foreach (var layer in TextRenderUtil.Get.BufferText(formatter.Format(shownProjectile.Count), -1, 0, ProjectileZ, 1 / Layers))
            {
                //TODO(v0.9) text as sprite data? should be SDF
                yield return(new PolygonData(
                                 layer.Key,
                                 new SpriteData(
                                     Matrix4.CreateScale(0.2f, 0.2f, 1) * Matrix4.CreateTranslation(0.5f, -0.5f * ProjectileScale, 0) * hexTransform,
                                     TextRenderUtil.Get.TextureId,
                                     Color.Gray,
                                     null
                                     ),
                                 layer.Value.ToList()
                                 ));
            }
        }
        private static MetaField AggregateFieldInstances(IGrouping <int, MetaField> field_instances)
        {
            if (g_field_type_aggregation_threshold < 1.0)
            {
                long instances_num = 0;
                Dictionary <FieldType, long> cnt_dict  = new Dictionary <FieldType, long>();
                Dictionary <FieldType, bool> list_dict = new Dictionary <FieldType, bool>();
                foreach (var instance in field_instances)
                {
                    ++instances_num;
                    if (cnt_dict.ContainsKey(instance.fieldType))
                    {
                        ++cnt_dict[instance.fieldType];
                        list_dict[instance.fieldType] = list_dict[instance.fieldType] || instance.isList;
                    }
                    else
                    {
                        cnt_dict[instance.fieldType]  = 1;
                        list_dict[instance.fieldType] = instance.isList;
                    }
                }

                if (instances_num == 0)
                {
                    throw new ArgumentException("No instances for a field", "field_instances");
                }

                long      dominating_num  = cnt_dict.Max(_ => _.Value);
                FieldType dominating_type = cnt_dict.First(_ => _.Value == dominating_num).Key;
                bool      dominating_list = list_dict[dominating_type];

                double dominating_type_ratio = dominating_num / (double)instances_num;
                if (dominating_type_ratio >= g_field_type_aggregation_threshold)
                {
                    var dominating_field = new MetaField
                    {
                        fieldId   = field_instances.Key,
                        fieldType = dominating_type,
                        isList    = dominating_list,
                        typeId    = field_instances.First().typeId
                    };

                    Log.WriteLine("Found dominating type {0} for Type {1}: Field {2} ({3:P1}).", dominating_type, dominating_field.typeId, dominating_field.fieldId, dominating_type_ratio);

                    return(dominating_field);
                }
            }

            return(field_instances.Aggregate(field_instances.First(), (f, current) =>
            {
                f.isList = f.isList || current.isList;
                f.fieldType = UpdateFieldType(f.fieldType, current.fieldType);
                return f;
            }));
        }
示例#4
0
        public static float RootMeanSquare(this IGrouping <float, SampleData> source)
        {
            if (source.Count() < 2)
            {
                throw new System.InvalidOperationException("Source must have at least 2 elements");
            }

            double s = source.Aggregate(0.0, (x, d) => x += Mathf.Pow((float)d.interSampleAngle, 2));

            return(Mathf.Sqrt((float)(s / source.Count())));
        }
示例#5
0
        private void UpdateNonAckedCounts(IGrouping <PeerId, MatcherEntry> entry)
        {
            var nonAcked = entry.Aggregate(0, (s, e) => s + (e.IsAck ? -1 : 1));
            var peerKey  = GetPeerKey(entry.Key);

            using (var iterator = _db.NewIterator(_peersColumnFamily))//, new ReadOptions().SetTotalOrderSeek(true)))
            {
                // TODO: figure out why Seek() returns true for a different key
                var alreadyExists   = iterator.Seek(peerKey).Valid() && CompareStart(iterator.Key(), peerKey, peerKey.Length);
                var currentNonAcked = alreadyExists ? BitConverter.ToInt32(iterator.Value(), 0) : 0;

                var value = currentNonAcked + nonAcked;
                _db.Put(peerKey, BitConverter.GetBytes(value), _peersColumnFamily);
            }
        }
示例#6
0
        static string ConcatPrice(
            IGrouping <string, ListViewItem> cl,
            int column_index)
        {
            // PrintOrderForm.RemoveChangedChar()
            string strList = ListViewUtil.GetItemText(cl.Aggregate((current, next) =>
            {
                string s1 = ListViewUtil.GetItemText(current, column_index);
                string s2 = ListViewUtil.GetItemText(next, column_index);
                var r     = new ListViewItem();
                ListViewUtil.ChangeItemText(r, column_index, s1 + "," + s2);
                return(r);
            }), column_index);

            return(PriceUtil.TotalPrice(StringUtil.SplitList(strList)));
        }
示例#7
0
        static string ConcatLinePrice(
            IGrouping <string, PrintOrderForm.LineInfo> cl,
            string strFieldName)
        {
            // PrintOrderForm.RemoveChangedChar()
            string strList = (string)GetPropertyValue(cl.Aggregate((current, next) =>
            {
                // TODO:单价应该乘以套数。或者还有期数也要乘上
                string s1 = (string)GetPropertyValue(current, strFieldName);
                string s2 = (string)GetPropertyValue(next, strFieldName);
                var r     = new PrintOrderForm.LineInfo();
                SetPropertyValue(r, strFieldName, s1 + "," + s2);
                return(r);
            }), strFieldName);

            return(PriceUtil.TotalPrice(StringUtil.SplitList(strList)));
        }
示例#8
0
        private static string GetPlace(IList <IGrouping <int, IGrouping <string, Forecast> > > orderedUsers, int place,
                                       string endSymbol)
        {
            if (place > orderedUsers.Count)
            {
                return(string.Empty);
            }

            IGrouping <int, IGrouping <string, Forecast> > bestInTour = orderedUsers.ElementAt(place - 1);
            string aggregate = bestInTour
                               .Aggregate("<b>" + place + "-е место</b> в туре ",
                                          (current, q) => current + LjUserTag(q.First().Ljuser.Name) + ", ");

            aggregate = $"{aggregate.Trim(' ', ',')}: {bestInTour.Key} {ScoreText(bestInTour.Key)}{endSymbol}<br/>";

            return(aggregate);
        }
        public static List <Card> GetHistory(Account account)
        {
            List <Card> lstHistory = Cache.LoadCollection(account, DisenchantedString);

            List <IGrouping <string, Card> > lstGroupedById = lstHistory.GroupBy(c => c.Id).ToList();

            lstHistory.Clear();

            for (int i = 0; i < lstGroupedById.Count; i++)
            {
                List <IGrouping <bool, Card> > lstGroupedByPremium = lstGroupedById[i].GroupBy(c => c.Premium).ToList();

                for (int j = 0; j < lstGroupedByPremium.Count; j++)
                {
                    IGrouping <bool, Card> grouping = lstGroupedByPremium[j];

                    lstHistory.Add(grouping.Aggregate((a, b) => new Card(a.Id, a.Count + b.Count, a.Premium)));
                }
            }

            return(lstHistory);
        }
示例#10
0
		private IEnumerable<PolygonData> projectileSpriteData(IGrouping<Vector2D, ProjectileInfo> hex)
		{
			var hexTransform = Matrix4.CreateTranslation(hexX(hex.Key), hexY(hex.Key), 0);
			var shownProjectile = hex.Aggregate((a, b) => a.Count > b.Count ? a : b);
			var unitSprite = GalaxyTextures.Get.Sprite(shownProjectile.ImagePath);

			yield return new PolygonData(
				ProjectileZ,
				new SpriteData(Matrix4.CreateScale(ProjectileScale, ProjectileScale, 1) * hexTransform, unitSprite.Id, shownProjectile.Owner.Color, null, true),
				SpriteHelpers.UnitRect(unitSprite).ToList()
			);

			yield return new PolygonData(
				ProjectileZ,
				new SpriteData(
					Matrix4.CreateScale(0.2f, 0.2f, 1) * Matrix4.CreateTranslation(0.5f, -0.5f * ProjectileScale, 0) * hexTransform,
					TextRenderUtil.Get.TextureId,
					Color.Gray, 
					null, true
				),
				TextRenderUtil.Get.BufferRaster(new ThousandsFormatter().Format(shownProjectile.Count), -1, Matrix4.Identity).ToList()
			);
		}
 public TestResults Max(IGrouping <string, TestResults> group)
 {
     return(group.Aggregate(group.First(), (maxPerson, next) => maxPerson.Score < next.Score ? next : maxPerson));
 }
示例#12
0
 private static MethodInfo SignatureWithTheMostDerivedDeclaringType(IGrouping <Signature, MethodInfo> group)
 {
     return(group.Aggregate(
                (a, b) => a.DeclaringType.IsAssignableFrom(b.DeclaringType) ? b : a));
 }
示例#13
0
 private ImmutableList <double> CalculateCenter(IGrouping <ImmutableList <double>, ImmutableList <double> > points)
 => points
 .Aggregate(new double[RowLength], (acc, item) => acc.Zip(item, (a, b) => a + b).ToArray())
 .Select(items => items / points.Count())
 .ToImmutableList();