private static void Main(string[] args)
        {
            var data = File
                       .ReadAllLines(@"SwordForecasting.csv")
                       .Skip(1)
                       .Select(x => x.Split(','))
                       .ToDictionary(y => double.Parse(y[0]), y => double.Parse(y[1]));

            var points      = data.Values.ToArray();
            var bestDES     = DES.FindBestAlphaBeta(points, 0.1);
            var forecastDES = DES.ForeCast(points, 37, 48, bestDES.Item1, bestDES.Item2);
            var besSES      = SES.FindBestAlpha(points, 0.01);
            var forecastSES = SES.ForeCast(points, besSES, 37, 48);

            string original = "[";

            foreach (var num in points)
            {
                original += num + ",";
            }
            original += "]";

            string desforecastDES = "[";

            foreach (var num in forecastDES)
            {
                desforecastDES += num + ",";
            }
            desforecastDES += "]";

            string desforecastSES = "[";

            foreach (var num in forecastSES)
            {
                desforecastSES += num + ",";
            }
            desforecastSES += "]";

            var list = "[" + original + "," + desforecastDES + "," + desforecastSES + "]";
            // var i = 0;
            // // foreach (var point in smoothedPoints)
            // // {
            // //     Console.WriteLine(i + ": " + point);
            // //     i++;
            // // }
            var socket = new Client_Socket();

            socket.Publish(list);
        }
Exemple #2
0
        /// <summary>
        /// 充值
        /// </summary>
        /// <param name="channelId"></param>
        /// <param name="rechargeProductId"></param>
        public void Recharge(short channelId, int rechargeProductId)
        {
            //1.根据rechargeProductId 查询到充值产品信息
            RechargeProductEntity rechargeProductEntity = RechargeProductCacheModel.Instance.GetEntity(string.Format("[ChannelType]={0} and [ProductId]={1}", 0, rechargeProductId));
            int virtualMoney = rechargeProductEntity.Virtual;

            bool rechargeSuccess   = false;
            byte rechargeErrorType = 0;
            int  remainDays        = 0;

            //2.添加充值记录
            //⑴.检查充值的合法性
            //⑵.进行充值记录的添加

            //⑴.检查充值的合法性
            //如果是月卡 检查到期时间 是否可以购买
            //如果是礼包 检查是否已经购买过
            //如果是普通计费点 但是没有购买过 首充双倍

            RechargeRecordEntity monthCard = null;//定义月卡

            if (rechargeProductEntity.ProductType == 1)
            {
                //月卡
                //是否购买过月卡 或者购买时间超过一个月了
                MFReturnValue <List <RechargeRecordEntity> > retValue = RechargeRecordCacheModel.Instance.GetPageList(condition: string.Format("[RoleId]={0} and [ProductId]={1}", RoleId, rechargeProductId), orderby: "UpdateTime", pageSize: 1, pageIndex: 1);

                if (retValue.Value == null || retValue.Value.Count == 0)
                {
                    rechargeSuccess = true;
                }
                else
                {
                    //说明购买过月卡
                    monthCard = retValue.Value[0];

                    DateTime lastUpdateTime = retValue.Value[0].UpdateTime; //最后一次购买时间
                    remainDays = (DateTime.Now - lastUpdateTime).Days;

                    if (remainDays > 30)
                    {
                        //超过30天 可以购买
                        rechargeSuccess = true;
                    }
                    else
                    {
                        remainDays        = 30 - remainDays - 1;
                        rechargeErrorType = 1;
                    }
                }
            }
            else if (rechargeProductEntity.ProductType == 2)
            {
                //礼包
                RechargeRecordEntity rechargeRecordEntity = RechargeRecordCacheModel.Instance.GetEntity(string.Format("[RoleId]={0} and [ProductId]={1}", RoleId, rechargeProductId));
                if (rechargeRecordEntity == null) //没有买过礼包
                {
                    rechargeSuccess = true;
                }
                else
                {
                    rechargeErrorType = 2;
                }
            }
            else if (rechargeProductEntity.ProductType == 3)
            {
                rechargeSuccess = true;

                //检查是否已经购买过 没购买过就 首充双倍
                RechargeRecordEntity rechargeRecordEntity = RechargeRecordCacheModel.Instance.GetEntity(string.Format("[RoleId]={0} and [ProductId]={1}", RoleId, rechargeProductId));
                if (rechargeRecordEntity == null) //没有买过普通计费点
                {
                    virtualMoney *= 2;            //双倍
                }
            }

            //⑵.添加充值记录
            if (rechargeSuccess)
            {
                //查询是否有月卡记录 有的话先删除旧的
                if (monthCard != null)
                {
                    RechargeRecordCacheModel.Instance.Delete(monthCard.Id);
                }

                RechargeRecordEntity rechargeRecordEntity = new RechargeRecordEntity();
                rechargeRecordEntity.Status     = Mmcoy.Framework.AbstractBase.EnumEntityStatus.Released;
                rechargeRecordEntity.RoleId     = RoleId;
                rechargeRecordEntity.ProductId  = rechargeProductId;
                rechargeRecordEntity.CreateTime = DateTime.Now;
                rechargeRecordEntity.UpdateTime = DateTime.Now;

                RechargeRecordCacheModel.Instance.Create(rechargeRecordEntity);
            }


            //3.给玩家添加元宝 发放道具
            Dictionary <string, object> param = new Dictionary <string, object>();

            param["@Id"] = RoleId;


            RoleEntity entity    = RoleCacheModel.Instance.GetEntity(RoleId);
            int        currMoney = entity.Money; //角色当前身上的元宝

            currMoney += virtualMoney;           //加上充值后 获得的元宝

            param["@Money"]    = currMoney;
            param["@AddMoney"] = virtualMoney;

            this.Money += virtualMoney;

            RoleCacheModel.Instance.Update("[TotalRechargeMoney]=[TotalRechargeMoney]+@AddMoney, [Money]= @Money", "Id=@Id", param); //更新数据库

            //4.通知客户端元宝到账
            RoleData_RechargeReturnProto proto = new RoleData_RechargeReturnProto();

            proto.IsSuccess = rechargeSuccess;
            if (!rechargeSuccess)
            {
                switch (rechargeErrorType)
                {
                case 0:
                default:
                    proto.ErrorCode = 102002;
                    break;

                case 1:
                    proto.ErrorCode = 102004;     //月卡购买失败
                    proto.RemainDay = remainDays;
                    break;

                case 2:
                    proto.ErrorCode = 102005;     //礼包购买失败
                    break;
                }
            }
            else
            {
                proto.RechargeProductId   = rechargeProductId;
                proto.RechargeProductType = rechargeProductEntity.ProductType;
                proto.Money     = currMoney;
                proto.RemainDay = 29;
            }

            Client_Socket.SendMsg(proto.ToArray(this.SocketSendMS));
        }