Esempio n. 1
0
        /// <summary>
        /// 查找与指定用户衣物喜好相似的用户
        /// </summary>
        /// <param name="id">源用户ID</param>
        /// <returns>找到的所有相似用户ID列表</returns>
        public static IEnumerable <User> similarUsers(string id)
        {
            User user = userDb.GetById(id);

            if (user == null || WardrobeManager.getByUser(id).wardrobes.Count() == 0)
#if DEBUG
            { throw new Exception(); }
#else
            { return(new List <User>()); }
#endif

            //获取源用户衣物列表
            IEnumerable <int> wardrobeIDs = WardrobeManager.getByUser(user.id).wardrobes.ToList().Select(x => x.id);

            IEnumerable <IEnumerable <int> > clothesIDLists = wardrobeIDs.Select(x => ClothesManager.getByWardrobe(x).clothes.Select(y => y.id));

            List <Clothes.Clothes> clothes = new List <Clothes.Clothes>();

            foreach (var clothesIDs in clothesIDLists)
            {
                foreach (var clothesID in clothesIDs)
                {
                    clothes.Add(ClothesManager.get(clothesID));
                }
            }

            Dictionary <double, User> similarUsers = new Dictionary <double, User>();

            foreach (User anotherUser in userDb.GetList())
            {
                if (anotherUser.id == user.id)
                {
                    continue;
                }

                double similarity = calculateUserSimilarity(anotherUser, clothes);

                if (similarUsers.Count == 0 || similarity > similarUsers.Keys.Min())
                {
                    if (similarUsers.Count == 0)
                    {
                        similarUsers.Add(similarity, anotherUser);
                    }

                    if (similarUsers.Count >= Config.matchUserNum)
                    {
                        similarUsers.Remove(similarUsers.Min().Key);
                    }

                    if (similarUsers.ContainsKey(similarity))
                    {
                        similarity += 0.000001;
                    }

                    similarUsers.Add(similarity, anotherUser);
                }
            }

            return(similarUsers.Values);
        }
Esempio n. 2
0
        public static void BusDriverStart(Client player, Character character, string startData, int traceNum,
                                          float firstPosX, float firstPosY, float firstPosZ)
        {
            if (character.Level < 2)
            {
                API.shared.sendNotificationToPlayer(player, "Вы не можете работать на этой работе. Она доступна со 2 уровня");
                return;
            }
            if (!player.hasData(startData))
            {
                switch (traceNum)
                {
                case 1: character.JobId = JobsIdNonDataBase.BusDriver1; break;

                case 2: character.JobId = JobsIdNonDataBase.BusDriver2; break;

                case 3: character.JobId = JobsIdNonDataBase.BusDriver3; break;

                case 4: character.JobId = JobsIdNonDataBase.BusDriver4; break;
                }
                ContextFactory.Instance.SaveChanges();
                API.shared.triggerClientEvent(player, "bus_marker", firstPosX, firstPosY, firstPosZ);
                API.shared.triggerClientEvent(player, "markonmap", firstPosX, firstPosY);
                player.setData(startData, null);
                ClothesManager.SetPlayerSkinClothes(player, 5, character, 1);
            }
            else
            {
                API.shared.sendNotificationToPlayer(player, "Вы уже выбрали свой маршрут! Садитесь в автобус.");
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 计算从源用户到目标用户的相似度
        /// </summary>
        /// <param name="user">目标用户</param>
        /// <param name="srcClothesList">源用户衣物列表用户</param>
        /// <returns>相似度值 范围为0-1 值越大相似度越高</returns>
        private static double calculateUserSimilarity(User user, List <Clothes.Clothes> srcClothesList)
        {
            //获取匹配目标用户最近常穿的衣橱
            IEnumerable <int> wardrobeIDs = WardrobeManager.getByUser(user.id).wardrobes.ToList().Select(x => x.id);

            IEnumerable <IEnumerable <int> > clothesIDLists = wardrobeIDs.Select(x => ClothesManager.getByWardrobe(x).clothes.Select(y => y.id));

            List <Clothes.Clothes> clothesList = new List <Clothes.Clothes>();

            foreach (var clothesIDs in clothesIDLists)
            {
                foreach (var clothesID in clothesIDs)
                {
                    clothesList.Add(ClothesManager.get(clothesID));
                }
            }

            IEnumerable <Clothes.Clothes> mostDressedClothes = clothesList.OrderByDescending(x => x.wearingFrequency).OrderByDescending(x => x.lastWearingTime).Take(Config.matchClothesNum);

            double ans = 0;

            foreach (var clothes in mostDressedClothes)
            {
                double maxSimilarity = double.MinValue;

                foreach (var targetClothes in srcClothesList)
                {
                    double temp = ClothesManager.getSimilarity(new KeyValuePair <Clothes.Clothes, Clothes.Clothes>(targetClothes, clothes));

                    if (temp > maxSimilarity)
                    {
                        maxSimilarity = temp;
                    }
                }

                if (maxSimilarity > double.MinValue)
                {
                    ans += maxSimilarity * Config.clothesTypeCoeffiencient[clothes.type];
                }
            }

            if (mostDressedClothes.Any())
            {
                ans /= mostDressedClothes.Sum(x => Config.clothesTypeCoeffiencient[x.type]);
            }

            return(ans);
        }
Esempio n. 4
0
        /// <summary>
        /// 穿着指定穿搭
        /// </summary>
        /// <param name="suitID">穿搭ID</param>
        /// <returns>操作结果 是否成功对指定穿搭完成穿着操作</returns>
        public static bool wear(int suitID)
        {
            //找到指定穿搭
            Suit suit = suitDb.GetById(suitID);

            //确保穿搭存在
            if (suit == null)
            {
                return(false);
            }

            //进行穿着操作
            suit.wear();

            //更新信息并返回更新结果
            return(suitDb.Update(suit) && ClothesManager.wear(clothes_suitDb.GetList(x => x.suitID == suitID).Select(x => x.clothesID)));
        }
Esempio n. 5
0
        /// <summary>
        /// 添加穿搭
        /// </summary>
        /// <param name="suitPic">穿搭图片</param>
        /// <param name="name">穿搭名称</param>
        /// <param name="wardobeID">穿搭所属衣橱ID</param>
        /// <param name="clothesIDs">穿搭包含衣物ID列表</param>
        /// <returns>操作结果 是否成功添加</returns>
        public static bool add(IFormFile suitPic, string name, int wardobeID, int[] clothesIDs)
        {
            Suit suit = new Suit(name, wardobeID, ClothesManager.calculateWarmthDegree(clothesIDs).Value);

            suit.id = suitDb.InsertReturnIdentity(suit);

            List <Clothes_Suit> list = new List <Clothes_Suit>();

            foreach (int clothesID in clothesIDs)
            {
                list.Add(new Clothes_Suit(clothesID, suit.id));
            }

            if (suitPic != null)
            {
                savePic(suitPic, suit);
            }

            //插入数据库并返回操作结果
            return(clothes_suitDb.InsertRange(list.ToArray()));
        }
Esempio n. 6
0
        /// <summary>
        /// 依据有修改的衣物编号重新生成相关穿搭的适宜温度
        /// </summary>
        /// <param name="clothesID">有变更的衣物ID</param>
        public static void regenerateWarmthDegreeByClothes(int clothesID)
        {
            //找到衣物相关的所有穿搭
            foreach (int suitID in clothes_suitDb.GetList(x => x.clothesID == clothesID).Select(x => x.suitID))
            {
                Suit suit = suitDb.GetById(suitID);

                //确保穿搭存在
                if (suit != null)
                {
                    suit.warmthDegree = ClothesManager.calculateWarmthDegree(getClothes(suitID).clothes.Select(x => x.id).ToArray()).Value;
                    suitDb.Update(suit);
                }
#if DEBUG
                else
                {
                    throw new Exception();
                }
#endif
            }
        }
Esempio n. 7
0
        /// <summary>
        /// 删除指定衣橱
        /// </summary>
        /// <param name="wardrobeID">需要删除的衣橱ID</param>
        /// <returns>删除结果 是否成功删除</returns>
        public static bool delete(int wardrobeID)
        {
            ClothesManager.deleteByWardrobe(wardrobeID);

            return(wardrobeDb.DeleteById(wardrobeID));
        }
Esempio n. 8
0
 public BooleanResponse deleteClothes(int[] ids)
 {
     return(new BooleanResponse(ClothesManager.delete(ids)));
 }
Esempio n. 9
0
 public BooleanResponse addClothes(IFormFile pic, int wardrobe_id, string name, ClothesType type, int thickness)
 {
     return(new BooleanResponse(ClothesManager.add(pic, wardrobe_id, name, type, thickness)));
 }
Esempio n. 10
0
 public ClothesResponseList getByWardrobe(int id)
 {
     return(ClothesManager.getByWardrobe(id));
 }
Esempio n. 11
0
 public ClothesInfoResponse getClothesInfo(int id)
 {
     return(ClothesManager.getInfo(id));
 }
Esempio n. 12
0
 public BooleanResponse modifyClothes(IFormFile pic, int id, string name, ClothesType type, int thickness)
 {
     return(new BooleanResponse(ClothesManager.modify(pic, id, name, type, thickness)));
 }
Esempio n. 13
0
 public BooleanResponse changeClothesWardrobe(int[] clothes_ids, int wardrobe_id)
 {
     return(new BooleanResponse(ClothesManager.changeWardrobe(clothes_ids, wardrobe_id)));
 }
Esempio n. 14
0
        /// <summary>
        /// 获取指定穿搭包含的所有衣物列表
        /// </summary>
        /// <param name="suitID">穿搭ID</param>
        /// <returns>其包含的衣物信息列表</returns>
        public static ClothesResponseList getClothes(int suitID)
        {
            //确保穿搭存在
            if (suitDb.GetById(suitID) == null)
            {
                return(new ClothesResponseList());
            }

            return(new ClothesResponseList(clothes_suitDb.GetList(x => x.suitID == suitID).Select(x => new ClothesResponse(ClothesManager.get(x.clothesID))).ToArray()));
        }
Esempio n. 15
0
        /// <summary>
        /// 对一套混搭的保暖程度进行评价
        /// </summary>
        /// <param name="clothes">混搭中的所有衣物</param>
        /// <param name="temperature">当前温度</param>
        /// <returns>评价结果</returns>
        public static EvaluationResponse evaluate(int[] clothes, double temperature)
        {
            KeyValuePair <bool, double> ans = ClothesManager.calculateWarmthDegree(clothes);

            return(new EvaluationResponse(ans.Key, evaluate(ans.Value, temperature)));
        }
Esempio n. 16
0
 /// <summary>
 /// 穿着一套衣物混搭
 /// </summary>
 /// <param name="clothesIDs">混搭包含的衣物编号列表</param>
 /// <returns>操作结果</returns>
 public static bool wear(int[] clothesIDs)
 {
     return(ClothesManager.wear(clothesIDs));
 }