示例#1
0
        public NormalizedRemoteSystem SelectHighScoreItem()
        {
            lock (RemoteSystems)
            {
                try
                {
                    if (RemoteSystems.Count == 0)
                    {
                        return(null);
                    }

                    SelectedRemoteSystem = null;
                    Sort();

                    if (RemoteSystems.Count == 0)
                    {
                        return(null);
                    }

                    NormalizedRemoteSystem output = RemoteSystems[0];
                    Select(output, false);
                    return(output);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine($"Exception in SelectHighScoreItem(): {ex.Message}");
                    return(null);
                }
            }
        }
示例#2
0
        public List <NormalizedRemoteSystem> GetSortedList(NormalizedRemoteSystem selected)
        {
            lock (RemoteSystems)
            {
                var output = new List <NormalizedRemoteSystem>();
                foreach (var item in devices.Select(x => attrNormalizer.Normalize(x)).Where(x => x.Kind != "Unknown").OrderBy(x => x.DisplayName).OrderBy(x => CalculateScore(x)).OrderByDescending(x => x.IsAvailableByProximity))
                {
                    if (item.Id != selected?.Id)
                    {
                        output.Add(item);
                    }
                }

                return(output);
            }
        }
示例#3
0
        private async void Select(object o, bool updateHistory)
        {
            if (!(o is NormalizedRemoteSystem))
            {
                Select(attrNormalizer.Normalize(o), updateHistory);
                return;
            }

            var rs = o as NormalizedRemoteSystem;

            if (updateHistory)
            {
                if (selectCounts.ContainsKey(rs.Id))
                {
                    selectCounts[rs.Id]++;
                }
                else
                {
                    selectCounts[rs.Id] = _initialCountValue;
                }

                await DataStorageProviders.SettingsManager.OpenAsync();

                lock (dbLock)
                {
                    DataStorageProviders.SettingsManager.Add("selectCounts", JsonConvert.SerializeObject(selectCounts));
                    DataStorageProviders.SettingsManager.Close();
                }
            }

            SelectedRemoteSystem = rs;
            Sort();

            System.Diagnostics.Debug.WriteLine("Scores are:");
            foreach (var item in RemoteSystems)
            {
                System.Diagnostics.Debug.WriteLine(item.DisplayName + " : " + CalculateScore(item));
            }
            System.Diagnostics.Debug.WriteLine("");
            System.Diagnostics.Debug.WriteLine("");
        }
示例#4
0
        private double CalculateScore(NormalizedRemoteSystem rs)
        {
            if (!selectCounts.ContainsKey(rs.Id))
            {
                if (rs.IsAvailableByProximity)
                {
                    return(0.1);
                }
                return(0);
            }

            uint   maximum = selectCounts.Values.Max();
            double selectScore;

            if (maximum < 10)
            {
                selectScore = selectCounts[rs.Id];
            }
            else if (maximum < 20)
            {
                selectScore = 3.0 * Math.Ceiling(((double)selectCounts[rs.Id]) / 3.0);
            }
            else
            {
                selectScore = 5.0 * Math.Ceiling(((double)selectCounts[rs.Id]) / 5.0);
            }

            double proximityCoeff = 1.0;

            if (rs.IsAvailableByProximity)
            {
                proximityCoeff = 1.2;
            }

            return(proximityCoeff * selectScore);
        }