private Dictionary<DateTime, decimal> Process(DateTime fromDate)
        {
            /*
             * Unfortunately because EMA's rely on previous ema processed data and the first EMA is aways the SMA
             * we always have to process the entire data set every time so it remains consistent for partial updates
             */

            var orderedClosingPrices = this.closingPrices.OrderBy(p => p.Key);
            var startingEmaValue = Math.Round(orderedClosingPrices.Take(this.timePeriod).Average(e => e.Value), 2);
            var startingEmaDate = orderedClosingPrices.Skip(timePeriod - 1).First().Key;

            var multiplier = (decimal)2 / (decimal)(this.timePeriod + 1);
            var ema = new Dictionary<DateTime, decimal> { { startingEmaDate, startingEmaValue } };

            var closingPricesToWorkWith = this.closingPrices.Where(e => e.Key > startingEmaDate).OrderBy(e => e.Key);

            foreach (var closingPrice in closingPricesToWorkWith)
            {
                var yesterdayEma = ema.LastOrDefault();
                ema.Add(closingPrice.Key, Math.Round(((closingPrice.Value - yesterdayEma.Value) * multiplier + yesterdayEma.Value), 2));
            }

            return ema.Where(d => d.Key >= fromDate).ToDictionary(d => d.Key, d => d.Value);
        }
        /// <summary>
        /// average Data By Week
        /// </summary>
        /// <param name="conductivityData">conductivity Data</param>
        /// <param name="sourceNumber">source Number</param>
        private void AverageDataByWeek(Dictionary<DateTime, Tuple<int, int>> conductivityData, int sourceNumber)
        {
            try
            {
                DateTime firstDate = new DateTime();
                if (conductivityData != null && conductivityData.Count > 0)
                {
                    firstDate = conductivityData.FirstOrDefault().Key;
                }
                DateTime lastDate = new DateTime();
                if (conductivityData != null && conductivityData.Count > 0)
                {
                    lastDate = conductivityData.LastOrDefault().Key;
                }
                int weeks = Convert.ToInt32(((lastDate - firstDate).TotalDays / 7) + 1);

                DateTime previousDate = new DateTime();
                if (conductivityData != null && conductivityData.Count > 0)
                {
                    previousDate = conductivityData.FirstOrDefault().Key;
                }
                int nextWeek = 0;
                if (conductivityData != null && conductivityData.Count > 0)
                {
                    nextWeek = WeekNumberCalculator(conductivityData.LastOrDefault().Key.AddDays(7));
                }
                List<int>[] groupedWeekCondData = new List<int>[weeks];

                int i = 0;
                foreach (var entry in conductivityData)
                {
                    int currentWeek = WeekNumberCalculator(entry.Key);
                    int average;
                    if (currentWeek != nextWeek && !this.dataForWeekToAverage.ContainsKey(entry.Key))
                    {
                        this.dataForWeekToAverage.Add(entry.Key, entry.Value);
                    }
                    else
                    {
                        List<int> valuesForWeek = new List<int>();
                        foreach (var condVal in this.dataForWeekToAverage.Values)
                        {
                            valuesForWeek.Add(condVal.Item2);
                        }

                        if (this.dataForWeekToAverage.Count == 0)
                        {
                            valuesForWeek.Add(entry.Value.Item2);
                        }

                        groupedWeekCondData[i] = valuesForWeek;
                        average = Convert.ToInt32(valuesForWeek.Average());
                        Tuple<int, int, List<int>> weekCondVal = new Tuple<int, int, List<int>>(currentWeek, average, groupedWeekCondData[i]);
                        if (!this.weeklyAverageCondDataSource1.ContainsKey(entry.Key))
                        {
                            if (sourceNumber == 1)
                            {
                                this.weeklyAverageCondDataSource1.Add(entry.Key, weekCondVal);
                            }
                            else
                            {
                                this.weeklyAverageCondDataSource2.Add(entry.Key, weekCondVal);
                            }
                        }
                        nextWeek = WeekNumberCalculator(entry.Key.AddDays(7));
                        this.dataForWeekToAverage.Clear();
                        i++;
                    }
                    previousDate = entry.Key;
                }
            }
            catch
            {
                throw;
            }
        }
        private bool loadAndCheckArguments(string[] args)
        {
            print_about();
            if (args == null || args.Length == 0)
            {
                print_help();
                return false;
            }

            // Parsing Arguments
            file_with_list = null;
            dest_dir = null;
            flags = new Dictionary<string, object>();
            string[] empty_flags = new string[] { "i", "interface" };

            foreach (var arg in args)
            {
                var last = flags.LastOrDefault();
                if (flags.Count > 0 && last.Value == null && !empty_flags.Any(x => x == last.Key))
                {
                    flags[last.Key] = arg;
                    continue;
                }

                // Flag
                if (arg.StartsWith("-"))
                {
                    flags[arg.Substring(1).ToLower()] = null;
                }
                else
                {
                    if (file_with_list == null) file_with_list = arg;
                    else if (dest_dir == null) dest_dir = arg;
                }
            }

            //Process flags
            for (var i = 0; i < flags.Count; i++)
            {
                var flag = flags.ElementAt(i);
                switch (flag.Key)
                {
                    case "threads":
                    case "t":
                        int c;
                        flags["threads"] = int.TryParse(flag.Value.ToString(), out c) ? c : -1;
                        break;
                    case "interface":
                    case "i":
                        //without value
                        flags["interface"] = null;
                        break;
                }
            }

            //Interface call
            if (flags.ContainsKey("interface"))
            {
                var result = ParamsForm.OpenDialog();

                if (result != null)
                {
                    file_with_list = null;
                    file_list = result.Links.Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
                    dest_dir = result.DestinationFolder;
                    flags["threads"] = result.ThreadCount;
                }
                else if (file_with_list == null)
                {
                    print_help();
                    return false;
                }
            }

            //Check file list and load links
            if (file_list == null && !File.Exists(file_with_list))
            {
                print_text(string.Format("Error: File \"{0}\" doesn't exists.", file_with_list));
                return false;
            }
            else if (file_list == null)
            {
                file_list = File.ReadAllLines(file_with_list).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
            }

            //Output parameter
            try
            {
                if (!Directory.Exists(dest_dir)) Directory.CreateDirectory(dest_dir);
            }
            catch
            {
                dest_dir = ".";
            }
            dest_dir = Path.GetFullPath(dest_dir);

            return true;
        }
Example #4
0
        public Result SearchK2(int N, double delta)
        {
            Dictionary<int, double> K2_dic = new Dictionary<int, double>();
            K2_dic.Add(100, 1.0);
            K2_dic.Add(200, 1.03);
            K2_dic.Add(300, 1.06);
            K2_dic.Add(500, 1.09);
            K2_dic.Add(700, 1.14);
            K2_dic.Add(900, 1.20);
            K2_dic.Add(1000, 1.32);
            K2_dic.Add(2000, 1.49);
            K2_dic.Add(3000, 1.55);
            K2_dic.Add(4000, 1.65);
            K2_dic.Add(5000, 1.77);
            K2_dic.Add(10000, 1.90);
            K2_dic.Add(20000, 2.03);
            K2_dic.Add(30000, 2.16);
            K2_dic.Add(40000, 2.35);
            K2_dic.Add(50000, 2.90);
            K2_dic.Add(60000, 3.0);
            K2_dic.Add(80000, 3.0);
            K2_dic.Add(100000, 3.0);

            Result result = new Result();

            var maximum = K2_dic.FirstOrDefault(x => x.Key > N);

            if (maximum.Key == 0)
            {
                Result max = new Result();
                max.key = 100000;
                max.value = 3;

                //return max;
            }

            var minimum = K2_dic.LastOrDefault(x => x.Key < N);

            Result bottom = new Result();
            bottom.key = minimum.Key;
            bottom.value = minimum.Value;

            Result upper = new Result();
            upper.key = maximum.Key;
            upper.value = maximum.Value;

            result.key = ((upper.key + bottom.key) / 2.0);
            result.value = ((upper.value + bottom.value) / 2.0);

            while (Math.Abs(N - result.key) > delta)
            {
                if (N < result.key)
                {
                    upper = result;
                }
                else
                {
                    bottom = result;
                }

                result.key = ((upper.key + bottom.key) / 2.0);
                result.value = ((upper.value + bottom.value) / 2.0);
            }

            return result;
        }
Example #5
0
        public static Obj_AI_Minion NearestWard(IEnumerable<Obj_AI_Minion> Wards)
        {
            if (!Wards.Any()) return null;

               Dictionary<Obj_AI_Minion, float> Distances = new Dictionary<Obj_AI_Minion, float>();
               Vector3 Mousepos = Game.CursorPos;

               int i = new int();
               i = 0;

               foreach (Obj_AI_Minion Ward in Wards)
               {
               if (i != 0 && Geometry.Distance(Ward.ServerPosition, Mousepos) <= Distances.LastOrDefault().Value)//If the new ward is at a shorter distance.
               {
                   Distances.Remove(Distances.LastOrDefault().Key);//Remove the last ward.
                   Distances.Add(Ward, Geometry.Distance(Ward.ServerPosition, Mousepos));//Here, we add the new ward to the dictionary.
               }
               else if (i != 0 && Geometry.Distance(Ward.ServerPosition, Mousepos) >= Distances.LastOrDefault().Value)//If the new ward is at a greater distance. we don't do nothing.
               {

               }
               else//First ward found in the loop.
               {
                   Distances.Add(Ward, Geometry.Distance(Ward.ServerPosition, Mousepos));//As a first ward, we simply add it.
               }

               i += 1;
               }

               if (Distances.LastOrDefault().Key.IsValid) return Distances.LastOrDefault().Key;
               else return null;
        }
Example #6
0
        //-------------------------------------------------------NearestWard-------------------------------------------
        public static Obj_AI_Minion NearestWard()
        {
            if (!ObjectManager.Get<Obj_AI_Minion>().Where(ward => ward.IsAlly && ward.Name.ToLower().Contains("ward") && Geometry.Distance(ward.ServerPosition, Game.CursorPos) < 1900 && Geometry.Distance(Player.ServerPosition, ward.ServerPosition) <= Program.W.Range).Any()) return null;

               Dictionary<Obj_AI_Minion, float> Distances = new Dictionary<Obj_AI_Minion, float>();
               Vector3 Mousepos = Game.CursorPos;

               int i = new int();
               i = 0;

               foreach (Obj_AI_Minion Ward in ObjectManager.Get<Obj_AI_Minion>().Where(ward => ward.IsAlly && ward.Name.ToLower().Contains("ward") && Geometry.Distance(ward.ServerPosition, Game.CursorPos) < 1900 && Geometry.Distance(Player.ServerPosition, ward.ServerPosition) <= Program.W.Range))
               {
               if (i != 0 && Geometry.Distance(Ward.ServerPosition, Mousepos) <= Distances.LastOrDefault().Value)//If the new ward is at a shorter distance.
               {
                   Distances.Remove(Distances.LastOrDefault().Key);//Remove the last ward.
                   Distances.Add(Ward, Geometry.Distance(Ward.ServerPosition, Mousepos));//Here, we add the new ward to the dictionary.
               }
               else if (i != 0 && Geometry.Distance(Ward.ServerPosition, Mousepos) >= Distances.LastOrDefault().Value)//If the new ward is at a greater distance. we don't do nothing.
               {

               }
               else//First ward found in the loop.
               {
                   Distances.Add(Ward, Geometry.Distance(Ward.ServerPosition, Mousepos));//As a first ward, we simply add it.
               }

               i += 1;
               }

               if (Distances.LastOrDefault().Key.IsValid) return Distances.LastOrDefault().Key;
               else return null;
        }
Example #7
0
        public static IList<ApTimeLine> GetPlayerApTimeline(Player p, string patch, int matchId, int teamId)
        {
            try
            {
                IList<ApTimeLine> timelines = new List<ApTimeLine>();
                var orderedTime = p.ItemTimeLine.OrderBy(a => a.TimeStamp).ToList();
                IDictionary<int, double> apPerMin = new Dictionary<int, double>();
                var items = new List<Item>();
                var groups = orderedTime.GroupBy(a => (int)Math.Truncate((double)a.TimeStamp / 60000));

                var runesAp = p.Runes.Sum(r => r.Ap);
                var runesApPerLv = p.Runes.Sum(r => r.ApPerLevel);
                var runesMr = p.Runes.Sum(r => r.MagicResist);
                var runesMrPerLv = p.Runes.Sum(r => r.MagicResistPerLevel);
                foreach (var group in groups)
                {
                    try
                    {
                        var t = new ApTimeLine();
                        t.Minute = group.Key;
                        var lv = p.TimeLine[t.Minute].Level;
                        t.PlayerId = p.ParticipantId;
                        t.MatchId = matchId;
                        t.TeamId = teamId;

                        foreach (var itemTimeline in group)
                        {
                            Item item;
                            if (patch.StartsWith("5.11"))
                                item = ItemsCache.GetItemV511(itemTimeline.ItemId);
                            else
                                item = ItemsCache.GetItemV514(itemTimeline.ItemId);

                            double itemAp = 0;
                            if (itemTimeline.EventType == "ITEM_PURCHASED")
                            {
                                items.Add(item);
                            }
                            else
                            {
                                items.Remove(item);
                            }

                            double totalAp = items.Sum(i => ItemStats.GetTotalAP(i,t.Minute,p.SelectedChampion)) + runesAp + runesApPerLv * lv;
                            if (items.Any(i => i.Name == "Rabadon's Deathcap"))
                            {
                                if (patch.StartsWith("5.11"))
                                    totalAp = totalAp * 1.30;
                                else
                                    totalAp = totalAp * 1.35;
                            }

                            if (apPerMin.ContainsKey(t.Minute))
                            {
                                apPerMin[t.Minute] = totalAp;
                            }
                            else
                            {
                                apPerMin.Add(new KeyValuePair<int, double>(t.Minute, totalAp));
                            }

                        }
                        t.Items = items.ToList();

                        t.CurrentGold = p.TimeLine[t.Minute].CurrentGold;
                        t.GoldSpent = items.Sum(i => i.GoldCost);

                        t.TotalMr = items.Sum(i => i.ItemStats.MR) + p.SelectedChampion.Stat.MagicResist + p.SelectedChampion.Stat.MagicResistPerLv * lv + runesMr + runesMrPerLv * lv; ;
                        t.TotalAp = apPerMin.LastOrDefault().Value;
                        timelines.Add(t);
                    }
                    catch {
                        throw;
                    }
                }
                return timelines;
            }
            catch {
                throw;
            }
        }