Example #1
0
        public static BarInfo ConvertToWeekly(BarInfo data)
        {
            DateTime dt       = DateTime.MinValue;
            DateTime lastDate = DateTime.MinValue;

            data.Token.periodicity = Periodicity.Week;
            BarInfo ret = new BarInfo {
                Token = data.Token
            };
            var srtData = data.OrderBy(x => x.TimeStamp);

            foreach (var itm in srtData)
            {
                if (dt.Date < itm.TimeStamp.Date)
                {
                    dt = CloseWeekDate(itm.TimeStamp);
                    ret.Add(new Bar
                    {
                        Close     = itm.Close,
                        High      = itm.High,
                        Low       = itm.Low,
                        Open      = itm.Open,
                        TimeStamp = dt,
                        Volume    = itm.Volume
                    });
                }
                else
                {
                    var bar = ret[ret.Count - 1];
                    bar.Close   = itm.Close;
                    bar.High    = bar.High > itm.High ? bar.High : itm.High;
                    bar.Low     = bar.Low < itm.High ? bar.Low : itm.Low;
                    bar.Volume += itm.Volume;
                }
                lastDate = itm.TimeStamp;
            }
            if (ret.Count > 0)
            {
                ret[ret.Count - 1].TimeStamp = lastDate;
            }
            return(ret);
        }
Example #2
0
        /// <summary>
        /// Чтение данных из бд
        /// </summary>
        private static void ReadBD()
        {
            //выборка данных из бд
            Models.ModelOfBar       bar   = new Models.ModelOfBar();
            Models.ModelOfMenuItems items = new Models.ModelOfMenuItems();
            Models.ModelOfUserRate  rate  = new Models.ModelOfUserRate();

            string           connectionString = "Server=localhost;Port=5432;User ID=postgres;Password=3400430;Database=Menu;";
            NpgsqlConnection npgSqlConnection = new NpgsqlConnection(connectionString);

            npgSqlConnection.Open();
            Console.WriteLine("Соединение с БД открыто");
            NpgsqlCommand    npgSqlCommand    = new NpgsqlCommand("SELECT * FROM barinfo", npgSqlConnection);
            NpgsqlDataReader npgSqlDataReader = npgSqlCommand.ExecuteReader();

            if (npgSqlDataReader.HasRows)
            {
                Console.WriteLine("Таблица: BarInfo");
                Console.WriteLine("");
                foreach (DbDataRecord dbDataRecord in npgSqlDataReader)
                {
                    bar = new Models.ModelOfBar();
                    //Console.WriteLine(dbDataRecord["BarName"] + "   " + dbDataRecord["Latitude"] + "   " + dbDataRecord["Longitude"] + "   " + dbDataRecord["Phone"] + "   " + dbDataRecord["WorkTime"] + "   " + dbDataRecord["Pictures"]);
                    bar.BarName  = dbDataRecord["BarName"].ToString();
                    bar.Lat      = Convert.ToDouble(dbDataRecord["Latitude"]);
                    bar.Lng      = Convert.ToDouble(dbDataRecord["Longitude"]);
                    bar.Phone    = dbDataRecord["Phone"].ToString();
                    bar.WorkTime = dbDataRecord["WorkTime"].ToString();
                    bar.HasMenu  = Convert.ToBoolean(dbDataRecord["HasMenu"]);
                    string[] temp = dbDataRecord["Pictures"].ToString().Split("|");
                    foreach (var item in temp)
                    {
                        if (item != "")
                        {
                            bar.PictureLinks.Add(item);
                        }
                    }
                    BarInfo.Add(bar);
                }
            }
            else
            {
                Console.WriteLine("Запрос не вернул строк в BarInfo");
            }
            npgSqlDataReader.Close();



            npgSqlCommand    = new NpgsqlCommand("SELECT * FROM menuitems", npgSqlConnection);
            npgSqlDataReader = npgSqlCommand.ExecuteReader();
            if (npgSqlDataReader.HasRows)
            {
                Console.WriteLine("Таблица: MenuItems");
                Console.WriteLine("");
                foreach (DbDataRecord dbDataRecord in npgSqlDataReader)
                {
                    items = new Models.ModelOfMenuItems();
                    // Console.WriteLine(dbDataRecord["Title"] + "   " + dbDataRecord["Subtitle"] + "   " + dbDataRecord["Subtitle_2"] + "   " + dbDataRecord["Dish"] + "   " + dbDataRecord["Price"] + "   " + dbDataRecord["BarName"]);
                    items.Title      = dbDataRecord["Title"].ToString();
                    items.Subtitle   = dbDataRecord["Subtitle"].ToString();
                    items.Subtitle_2 = dbDataRecord["Subtitle_2"].ToString();
                    items.Dish       = dbDataRecord["Dish"].ToString();
                    items.Price      = Convert.ToInt32(dbDataRecord["Price"]);
                    items.BarName    = dbDataRecord["BarName"].ToString();
                    MenuItems.Add(items);
                }
            }
            else
            {
                Console.WriteLine("Запрос не вернул строк в MenuItems");
            }
            npgSqlDataReader.Close();


            npgSqlCommand    = new NpgsqlCommand("SELECT * FROM UserRate", npgSqlConnection);
            npgSqlDataReader = npgSqlCommand.ExecuteReader();
            if (npgSqlDataReader.HasRows)
            {
                Console.WriteLine("Таблица: UserRate");
                Console.WriteLine("");
                foreach (DbDataRecord dbDataRecord in npgSqlDataReader)
                {
                    rate = new Models.ModelOfUserRate();
                    // Console.WriteLine(dbDataRecord["Title"] + "   " + dbDataRecord["Subtitle"] + "   " + dbDataRecord["Subtitle_2"] + "   " + dbDataRecord["Dish"] + "   " + dbDataRecord["Price"] + "   " + dbDataRecord["BarName"]);
                    rate.BarName = dbDataRecord["BarName"].ToString();

                    string[] temp = dbDataRecord["Likes"].ToString().Split(",");
                    foreach (var item in temp)
                    {
                        if (item != "")
                        {
                            rate.Likes.Add(Convert.ToInt64(item));
                        }
                    }

                    temp = dbDataRecord["Dislikes"].ToString().Split(",");
                    foreach (var item in temp)
                    {
                        if (item != "")
                        {
                            rate.Dislikes.Add(Convert.ToInt64(item));
                        }
                    }


                    UserRate.Add(rate);
                }
            }
            else
            {
                Console.WriteLine("Запрос не вернул строк в MenuItems");
            }


            Console.WriteLine("чтение завершено");
            npgSqlDataReader.Close();
            npgSqlConnection.Close();
        }