Example #1
0
        private static bool DoTestsMatchFilterRequest(string[] testTags, KeyValuePair<string, string>[] filterTags)
        {
            //If no tags were requested, then then it is a match
            if (!filterTags.Any())
            {
                return true;
            }

            var includeTags = filterTags.Where(t => t.Value.Equals("true", StringComparison.OrdinalIgnoreCase))
                                        .Select(t => t.Key)
                                        .ToArray();
            var excludeTags = filterTags.Where(t => t.Value.Equals("false", StringComparison.OrdinalIgnoreCase))
                                        .Select(t => t.Key)
                                        .ToArray();

            return !excludeTags.Intersect(testTags, StringComparer.OrdinalIgnoreCase).Any()  &&
                   includeTags.Intersect(testTags, StringComparer.OrdinalIgnoreCase).Count() == includeTags.Count();
        }
        private static IEnumerable<Interval> GenerateIntervals(DateTime start, KeyValuePair<DateTime, float>[] staffingPercentages)
        {
            if (!staffingPercentages.Any())
                throw new ApplicationException("Staffing percentages required");

            var lastEnd = start;
            foreach (var workforcePercentage in staffingPercentages)
            {
                var interval = new Interval()
                    {
                        Start = lastEnd,
                        End = workforcePercentage.Key,
                        StaffingPercentage = workforcePercentage.Value
                    };
                lastEnd = interval.End;
                yield return interval;
            }
        }
Example #3
0
        // Taken from https://stackoverflow.com/questions/1132494/string-escape-into-xml
        public static string XmlEscape(string escaped)
        {
            var replacements = new KeyValuePair<string, string>[]
            {
            new KeyValuePair<string,string>("&", "&amp;"),
            new KeyValuePair<string,string>("\"", "&quot;"),
            new KeyValuePair<string,string>("'", "&apos;"),
            new KeyValuePair<string,string>("<", "&lt;"),
            new KeyValuePair<string,string>(">", "&gt;"),
            };

            foreach (var pair in replacements)
                foreach (var index in escaped.IndexesOf(pair.Key, 0).Reverse())
                    if (!replacements.Any(other => string.Compare(other.Value, 0, escaped, index, other.Value.Length, StringComparison.Ordinal) == 0))
                    {
                        escaped = escaped.Substring(0, index) + pair.Value + escaped.Substring(index + 1, escaped.Length - index - 1);
                    }
            return escaped;
        }
Example #4
0
        /// <summary>
        /// Serializes the navigator popular rooms news.
        /// </summary>
        /// <param name="reply">The reply.</param>
        /// <param name="rooms">The rooms.</param>
        /// <param name="category">The category.</param>
        /// <param name="direct">if set to <c>true</c> [direct].</param>
        public void SerializeNavigatorPopularRoomsNews(ref ServerMessage reply, KeyValuePair<RoomData, uint>[] rooms,
                                                       int category, bool direct)
        {
            if (rooms == null || !rooms.Any())
            {
                reply.AppendInteger(0);
                return;
            }

            List<RoomData> roomsCategory = new List<RoomData>();
            foreach (KeyValuePair<RoomData, uint> pair in rooms.Where(pair => pair.Key.Category.Equals(category)))
            {
                roomsCategory.Add(pair.Key);
                if (roomsCategory.Count == (direct ? 40 : 8)) break;
            }
            reply.AppendInteger(roomsCategory.Count);
            foreach (RoomData data in roomsCategory) data.Serialize(reply, false);
        }
        private static string BuilCommandCall(string fullName, VariableParameter[] givenParameters, KeyValuePair<string, string>[] defaultedValues)
        {
            var result = new StringBuilder();

            result.Append(fullName);

            foreach (var parameter in givenParameters)
            {
                result.Append(" ");
                result.Append(parameter.Name);
                result.Append("=\"");
                result.Append(parameter.Value);
                result.Append("\"");
            }

            if (defaultedValues.Any())
            {
                result.Append("(with defaults:");

                foreach (var pair in defaultedValues)
                {
                    result.Append(" ");
                    result.Append(pair.Key);
                    result.Append("=\"");
                    result.Append(pair.Value);
                    result.Append("\"");
                }

                result.Append(")");
            }

            return result.ToString();
        }
Example #6
0
        public void CopyTo_IndexZero_ValuesCopied()
        {
            Trie<string, char, int> trie = new Trie<string, char, int>();

            trie.Add("key1", 5);
            trie.Add("key2", 6);

            KeyValuePair<string, int>[] vals = new KeyValuePair<string, int>[4];
            trie.CopyTo(vals, 0);

            Assert.IsTrue(vals.Any(k => k.Key == "key1" && k.Value == 5));
            Assert.IsTrue(vals.Any(k => k.Key == "key2" && k.Value == 6));

            Assert.AreEqual(0, vals[2].Value);
            Assert.AreEqual(0, vals[3].Value);
        }
        /// <summary>
        /// Realiza todas las realizaciones de una evidencia estocastica
        /// </summary>
        /// <param name="evidence"></param>
        /// <param name="realization"></param>
        /// <param name="pos"></param>
        /// <returns></returns>
        static IEnumerable<Tuple<KeyValuePair<BayesianNode, int>[],double>> EvidenceRealization(Evidence evidence, KeyValuePair<BayesianNode, int>[] realization, int pos,double probability=1.0)
        {
            if (pos == realization.Length)
            {
                if(realization.Any(x=>x.Value>=0))
                yield return new Tuple<KeyValuePair<BayesianNode, int>[], double>(realization,probability);
                
                yield break;
            }
            //en cada paso recursivo se escoge un nodo para su seleccion de estado
            //por cada probabilidad de estar en un estado de el nodo en la posicion pos
            bool outofevidence = true;
            for (int i = 0; i < evidence.EvidenceValues[pos].Length; i++)
            {
                
                if (evidence.EvidenceValues[pos][i] > 0)
                {
                    realization[pos] = new KeyValuePair<BayesianNode, int>(realization[pos].Key, i);
                    outofevidence = false;
                    var p = probability*evidence.EvidenceValues[pos][i];
                    foreach (var item in EvidenceRealization(evidence, realization, pos + 1,p))
                        yield return item;
                }
                
            }
            //si no esta en la evidencia entonces relization[pos]=bayesiannode,-1
            if(outofevidence)
                foreach (var item in EvidenceRealization(evidence, realization, pos + 1,probability))
                    yield return item;

        }