Exemplo n.º 1
0
        //returns tuple of start and end timestamps for best frame range to splice from existing mp4
        private Tuple <long, long> ProcessAllFrames()
        {
            var coreframeslength = _fps * 2;                            //core sample of frames will be two seconds of video might in future vary depending on user settings
            var computelimit     = _framelist.Count - coreframeslength; //this will keep walking average calcs only happening within range

            try
            {
                if (_framelist != null)
                {
                    for (var i = 0; i < _framelist.Count; i++)
                    {
                        var currenttimestamp = _framelist.Keys[i];

                        if (i < computelimit) //makes sense to compute because we will can use it
                        {
                            var coreframesrange = _framelist.ToList().GetRange(i, coreframeslength);

                            var listofscores = new SortedList <long, double>();
                            foreach (var kvp in coreframesrange)
                            {
                                listofscores.Add(kvp.Key, kvp.Value.Size() != 0 ? GetImageUsability(Utils.GetSparseFace(kvp.Value)) : -1); //return -1 for usabilty if no face exists
                            }

                            var avg = listofscores.Average(x => x.Value);

                            var sumOfSquaresOfDifferences = listofscores.ToList().Select(val => (val.Value - avg) * (val.Value - avg)).Sum();

                            var stdev = Math.Sqrt(sumOfSquaresOfDifferences / coreframesrange.Count);

                            Coreframesavg.Add(currenttimestamp, avg - stdev); //avg - std dev should give those with best avg score and lowest deviation
                        }
                        else //can't use computations past this point so just need timestamps
                        {
                            Coreframesavg.Add(currenttimestamp, 0); //avg - std dev should give those with best avg score and lowest deviation
                        }

                        //Log.Info(TAG, "moving average index" + i);
                    }
                }

                var bestframegroupkey = Coreframesavg.Aggregate((l, r) => l.Value > r.Value ? l : r).Key; //gets key of max value (avg-stdev) from dictionary

                bestTSRange = new Tuple <long, long>(bestframegroupkey, Coreframesavg.Keys[Coreframesavg.IndexOfKey(bestframegroupkey) + GetFrameTotal()]);

                return(bestTSRange);
            }
            catch (Exception e)
            {
                Log.Error(TAG, "Frames Processing messed up", e);
                throw;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// SWIFT-формат
        /// </summary>
        public string ToSwift()
        {
            // Проверка сообщения:
            string message;

            if (!Check(out message))
            {
                throw new FormatException(message);
            }

            string result =
                Fields.Aggregate(string.Empty,
                                 (current, field) => current + (field.Value.ToSwift() + Environment.NewLine)) + "-}";

            return(result);
        }
Exemplo n.º 3
0
        public ItemBase GetDrop()
        {
            var random = Random.Range(0, Max());

            ItemBase output = null;

            Table
            .Aggregate(0f, (prev, curr) => {
                if (prev < random && random < curr.Key)
                {
                    output = curr.Value;
                }

                return(curr.Key);
            });

            return((ItemBase)output?.Clone());
        }
        //Executes various different heightmap forming functions at random
        public static Heightmap Arbitrary(SortedList<double, Action> functions, int iterations = 10000, Func<int, bool> StepCallback = null)
        {
            //Want to make sure that they're sorted in descending order and normalized.
            double total = functions.Aggregate<KeyValuePair<double, Action>, double>(0, (current, next) => current + next.Key);
            var actionsSorted = (from kvp in functions select new {Key = kvp.Key/total,
                                                                  Value = kvp.Value}).OrderBy((x)=>x.Key);

            List<int> actionsDone = new List<int>(functions.Count);
            for (int i = 0; i < functions.Count; i++)
            {
                actionsDone.Add(0);
            }

            for (int i = 0; i < iterations; i++)
            {
                //try to "roll under" the key value; we perform the first action whose key + cumulative value is higher than this value.
                double randomValue = rand.NextDouble();
                double cumulativeValue = 0;

                for(int j = 0; j < actionsSorted.Count(); j++)
                {
                    var kvp = actionsSorted.ElementAt(j);
                    cumulativeValue += kvp.Key;
                    if (randomValue < cumulativeValue)
                    {
                        actionsDone[j]++;
                        kvp.Value();
                        break;
                    }
                }

                if (StepCallback != null)
                {
                    bool Continue = StepCallback(i);
                    if (!Continue)
                        break;
                }
            }

            return Map;
        }
 public string GetExtraData()
 {
     return(_responseData.Aggregate("", (current, item) => current + (item.Key + " = " + item.Value)));
 }
Exemplo n.º 6
0
        public static void SaveResultTask2(SortedList <int, Triangle> list, string filename)
        {
            var info = list.Aggregate(String.Empty, (current, elem) => current + string.Concat($"Perimeter: {elem.Key}", ", ", elem.Value, "\n"));

            File.AppendAllText(filename, $"{info}\n");
        }