/// <summary>
        /// Metoda zwracająca listę okresów notowań połączonych, jeżeli mają ten sam kierunek trendu. Metoda ta rozpoczyna wyznaczanie od parametru periodsEndDate i zmierza ku przeszłości.
        /// </summary>
        /// <param name="DesiredNumberOfPeriods">Oczekiwana liczba okresów.</param>
        /// <param name="periodsEndDate">Ostatnia data okresów.</param>
        /// <param name="periodsStartDate">Data będąca granicą wyznaczania kolejnych okresów.</param>
        /// <param name="daysInterval">Liczba określająca długość okresu w dniach.</param>
        /// <returns>Lista okresów notowań połaczonych, jeżeli mają ten sam kierunek trendu.</returns>
        public List<ExchangePeriod> GetExchangePeriodsMergedByMovementDirectoryFromEndDate(int DesiredNumberOfPeriods, DateTime periodsEndDate, DateTime periodsStartDate, int daysInterval)
        {
            DateTime iterationDate = periodsEndDate.Date;
            string dataPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\data\\";
            List<ExchangePeriod> periodList = new List<ExchangePeriod>();
            while (iterationDate >= periodsStartDate)
            {
                DateTime periodStart;
                if (iterationDate.AddDays(-daysInterval) > periodsStartDate)
                {
                    periodStart = iterationDate.AddDays(-daysInterval);
                }
                else
                {
                    periodStart = periodsStartDate.Date;
                }

                ExchangePeriod period = GetExchangePeriod(periodStart, iterationDate);
                if (period != null)
                {

                    period.PublicTrading -= GetExchangeDay(period.PeriodStart).PublicTrading;
                    if (periodList.Count != 0)
                    {
                        periodList.First().OpenRate = period.CloseRate;

                        //If percentage changes have the same sign.
                        if ((periodList.First().PercentageChange * period.PercentageChange) > 0 || periodList.First().PeriodStart == periodList.First().PeriodEnd)
                        {
                            periodList.First().PublicTrading += period.PublicTrading;
                            if (period.PeriodEnd != periodList.First().PeriodStart)
                            {
                                periodList.First().PublicTrading += GetExchangeDay(periodList.First().PeriodStart).PublicTrading;
                            }

                            periodList.First().PeriodStart = period.PeriodStart;
                            if ((periodList.Count > 1) && ((periodList[0].PercentageChange * periodList[1].PercentageChange) > 0))
                            {
                                periodList[1].OpenRate = periodList[0].OpenRate;
                                periodList[1].PeriodStart = periodList[0].PeriodStart;
                                periodList[1].PublicTrading += periodList[0].PublicTrading + GetExchangeDay(periodList[1].PeriodStart).PublicTrading;
                                periodList.RemoveAt(0);
                            }
                        }
                        else
                        {
                            if (periodList.Count == DesiredNumberOfPeriods + 1)
                            {
                                periodList.RemoveAt(0);
                                break;
                            }

                            periodList.Insert(0, period);
                        }
                    }
                    else
                    {
                        periodList.Add(period);
                    }
                }

                iterationDate = iterationDate.AddDays(-daysInterval);
            }

            return periodList;
        }
예제 #2
0
        public ICollection<Helper.Point> Star( Helper.Point posIni, Helper.Point posFinal, out int totalCost)
        {
            var heapBorder = new Heap<Elem>();

             //   Console.WriteLine("cheguei no astar");

            List<Elem> explored = new List<Elem>();
            /* Array to verify if a position was explored */
            var hasExpl = new bool[qtdNodes,qtdNodes];
            var inBorder = new bool[qtdNodes,qtdNodes];
            hasExpl.Initialize();
            inBorder.Initialize();

            Elem father = new Elem(0, posIni);
            heapBorder.HeapAdd( h(posIni,posFinal), father );

            while (heapBorder.HeapSize() > 0 )
            {
                father = heapBorder.HeapExtractMin().Item3 ;
                inBorder[father.pos.x, father.pos.y] = false;
                if( father.pos.Equals(posFinal) )
                    break;

                explored.Insert(0, father);
                hasExpl[father.pos.x, father.pos.y] = true;

                foreach (var child in father.pos.Neighborhood( posFinal) )
                {
                    int accChild = 0;
                    accChild = father.accCost + 1;

                    if (hasExpl[child.x, child.y] && accChild >= father.accCost)
                        continue;

                    if (inBorder[child.x, child.y] == false || accChild < father.accCost)
                    {
                        heapBorder.HeapAdd(h(child, posFinal) + accChild, new Elem(accChild, child, father.pos));
                        inBorder[child.x, child.y] = true;
                    }
                }
            }

            var pathReturn = new List<Helper.Point>();
            pathReturn.Insert(0, father.pos );
            totalCost = father.accCost;

            if (!father.parent.HasValue)
               return pathReturn;

            var currParent = father.parent.Value ;

            for (int i = 0 , j = 1; i < explored.Count; i++)
            {
                if (explored[i].pos.Equals(currParent) )
                {
                    pathReturn.Insert(j,explored[i].pos);
                    j++;
                    currParent = explored[i].parent.HasValue ? explored[i].parent.Value : posIni  ;
                    //Debug.WriteLine("custo "+explored[i].accCost);
                }
            }
            pathReturn.Reverse();
            return pathReturn.Skip(1).ToList();
        }
 /// <summary>
 /// Metoda pobierania dat notowań.
 /// </summary>
 /// <returns>Lista dat notowań.</returns>
 private List<DateTime> DownloadExchangeDates()
 {
     List<DateTime> result = new List<DateTime>();
     using (WebClient client = new WebClient())
     {
         string datesText = client.DownloadString("http://www.gpw.pl/notowania_archiwalne");
         datesText = datesText.Substring(datesText.IndexOf("calendarEnabledDates = {'") + "calendarEnabledDates = {'".Length);
         datesText = datesText.Remove(datesText.IndexOf("':1}"));
         datesText = datesText.Replace("':1,'", ",");
         string[] datesArray = datesText.Split(',');
         foreach (string date in datesArray)
         {
             string[] dateParts = date.Split('-');
             result.Insert(0,(new DateTime(Convert.ToInt32(dateParts[0]), Convert.ToInt32(dateParts[1]), Convert.ToInt32(dateParts[2]))));
         }
     }
     if (result.Count == 0)
     {
         return null;
     }
     return result;
 }
예제 #4
0
        private void UpOrder(object sender, EventArgs e)
        {
            if (dataGridView.SelectedRows.Count > 0)
            {
                listOrder = dataGridView.DataSource as List<SearchOrder>;

                int index = dataGridView.SelectedRows[0].Index;
                if (index >= 1)
                {
                    var temp = listOrder[index];
                    listOrder.RemoveAt(index);
                    listOrder.Insert(index - 1, temp);

                    dataGridView.ClearSelection();
                    dataGridView.Rows[index - 1].Selected = true;
                    dataGridView.Refresh();
                }
            }
        }
예제 #5
0
        public static void DrawOperation(OpenGL gl, Project testProject, Vector rotation, List<List<double[]>> detailCache)
        {
            var bill = testProject.Settings;

            gl.Translate(bill.Length / 2, bill.Height / 2, bill.Width / 2);//высчитывается из размера заготовки
            gl.Rotate((float)rotation.Y, (float)rotation.X, 0); // вращение с зажатой средней кнопкой мыши
            gl.Translate(-bill.Length / 2, -bill.Height / 2, -bill.Width / 2);

            //var Bill = this.testProject.Settings;
            Billet.Draw(gl, bill.Height, bill.Length, bill.Width); // заготовка

            var operations = testProject.Operations;//колличество операций

            var boltReg = new Regex("BoltHole");
            var pocketReg = new Regex("Pocket");
            if (detailCache.Count != operations.Count) detailCache.Clear();

            for (var i = 0; i < operations.Count; i++)//главный цикл отрисовки
            {
                var shapeName = operations[i].Shape.Name;

                if (boltReg.IsMatch(shapeName))
                {
                    var bolt = (Model.Primitives.BoltHole)operations[i].Shape;
                    var boltlocation = operations[i].Location.LocationsList.GetEnumerator();
                    while (boltlocation.MoveNext())
                    {
                        if (bolt.Modified || boltlocation.Current.Modified || detailCache.Count<=i)
                        {

                            try
                            {
                                detailCache.RemoveAt(i);
                            }
                            catch{}
                            var location = new Point(boltlocation.Current.X, boltlocation.Current.Y);
                            detailCache.Insert(i, BoltHole.ReCalc(bolt, 0.5, location)); //здесь уже всё ок, кроме величины шага
                            boltlocation.Current.IsDrawn();
                            bolt.IsDrawn();//значит в кэше лежит актуальная информация
                        }
                        else
                        {
                            var location = new Point(boltlocation.Current.X, boltlocation.Current.Y);
                            BoltHole.Draw(gl, detailCache[i]); //здесь уже всё ок, кроме величины шага
                        }
                    }
                }

                if (!pocketReg.IsMatch(shapeName)) continue;
                var poc = (Model.Primitives.Pocket)operations[i].Shape;
                var poclocation = operations[i].Location.LocationsList.GetEnumerator();
                while (poclocation.MoveNext())
                {
                    if (poc.Modified || poclocation.Current.Modified || detailCache.Count <= i)
                    {
                        try
                        {
                            detailCache.RemoveAt(i);
                        }
                        catch { }
                        var location = new Point(poclocation.Current.X, poclocation.Current.Y);
                        var p = Pocket.ReCalc(poc, 0.5, location);
                        detailCache.Insert(i, p); //здесь уже всё ок, кроме величины шага
                        poclocation.Current.IsDrawn();
                        poc.IsDrawn();//значит в кэше лежит актуальная информация
                    }
                    else
                    {
                        var location = new Point(poclocation.Current.X, poclocation.Current.Y);
                        Pocket.Draw(gl, detailCache[i]); //здесь уже всё ок, кроме величины шага
                    }
                }
            }

            //отрисовщик траекторий
            gl.Begin(OpenGL.GL_LINE_STRIP);
            gl.Color(1f, 0, 0);

            var trajectorys = GCodeGenerator.TrajectoryStor.GetTrajectorys();
            foreach (var point in trajectorys.SelectMany(operation => operation))
            {
                gl.Vertex(point.GetCoordinates());
            }
        }