コード例 #1
0
        /// <summary>
        /// 通过当前的菜品状态进行推荐。
        /// </summary>
        /// <returns></returns>
        public async System.Threading.Tasks.Task <List <FoodInformation> > ReFlashAsync()
        {
            // 如果没录入了文件
            if (foodInformationList == null)
            {
                userFavorInformationList = new List <FoodWeightChange>();
                foodInformationList      = await _loadJsonService.ReadJsonAsync();

                userFavorInformationList = await _userFavorService.ReadJsonAsync();

                //userChoiceList = await _userChoiceService.ReadJsonAsync();
                InitWeight(foodInformationList, userFavorInformationList);
            }
            //获得食物的种数
            //int len = foodInformationList.Capacity;
            if (weatherStatus == null)
            {
                WeatherRoot data = await _weatherService.GetWeatherAsync();

                weatherStatus             = new TempWeather();
                weatherStatus.Temperature = double.Parse(data.main.temp).ToTemperature();
                weatherStatus.Humidity    = double.Parse(data.main.humidity).ToHumidity();
            }

            //获取随机的食物
            int changeWeightPosition = (3 * (int)weatherStatus.Temperature) + (int)weatherStatus.Humidity;

            List <Vector> foodVector = getFoodVector((int)weatherStatus.Temperature, (int)weatherStatus.Humidity);

            List <int> cos = GetCos(foodVector);

            int numberFoodToReturn = 5;

            int[] arr      = new int[numberFoodToReturn]; // change
            int   numOfGet = 0;

            while (numOfGet < numberFoodToReturn)
            {
                int getFoodNum = GetOneFoodNum(cos);
                //该食物已经获取
                if (Array.IndexOf(arr, getFoodNum) != -1)
                {
                    continue;
                }
                arr.SetValue(getFoodNum, numOfGet++);
            }

            List <FoodInformation> get_foodInformation = new List <FoodInformation>();

            for (int i = 0; i < numberFoodToReturn; i++)
            {
                get_foodInformation.Add(foodInformationList[arr[i]]);
            }

            return(get_foodInformation);
        }
コード例 #2
0
        /// <summary>
        /// 初始化信息
        /// </summary>
        public async void InitRecommendationAsync()
        {
            userFavorInformationList = new List <FoodWeightChange>();
            foodInformationList      = await _loadJsonService.ReadJsonAsync();

            _foodFavorService.InitAsync(foodInformationList);
            await _logService.InitAsync();

            userFavorInformationList = await _userFavorService.ReadJsonAsync();

            InitWeight(foodInformationList, userFavorInformationList);
            WeatherRoot data = await _weatherService.GetWeatherAsync();

            weatherStatus             = new TempWeather();
            weatherStatus.Temperature = double.Parse(data.main.temp).ToTemperature();
            weatherStatus.Humidity    = double.Parse(data.main.humidity).ToHumidity();
        }