コード例 #1
0
 private static void ReadInts(Statistics statics)
 {
     int value;
     for (int i = 0; i < 10; ++i)
     {
         while (!int.TryParse(Console.ReadLine(), out value))
         {
             Console.WriteLine("Du måste ange ett heltal!");
         }
         statics.Add(value);
     }
 }
コード例 #2
0
        public void AddBlock(IList <object> values)
        {
            var stats = new BooleanWriterStatistics();

            Statistics.Add(stats);
            foreach (var buffer in Buffers)
            {
                buffer.AnnotatePosition(stats, 0);
            }

            stats.NumValues += (uint)values.Count;
        }
コード例 #3
0
        public void AddBlock(IList <DateTime?> values)
        {
            var stats = new DateWriterStatistics();

            Statistics.Add(stats);
            foreach (var buffer in Buffers)
            {
                buffer.AnnotatePosition(stats, 0);
            }

            var datesList = new List <long>(values.Count);

            if (_isNullable)
            {
                var presentList = new List <bool>(values.Count);

                foreach (var value in values)
                {
                    if (!value.HasValue)
                    {
                        stats.AddValue(null);
                        presentList.Add(false);
                    }
                    else
                    {
                        var daysSinceEpoch = (int)(value.Value - _unixEpoch).TotalDays;
                        stats.AddValue(daysSinceEpoch);
                        presentList.Add(true);
                        datesList.Add(daysSinceEpoch);
                    }

                    var presentEncoder = new BitWriter(_presentBuffer);
                    presentEncoder.Write(presentList);
                    if (stats.HasNull)
                    {
                        _presentBuffer.MustBeIncluded = true;
                    }
                }
            }
            else
            {
                foreach (var value in values)
                {
                    var daysSinceEpoch = (int)(value.Value - _unixEpoch).TotalDays;
                    stats.AddValue(daysSinceEpoch);
                    datesList.Add(daysSinceEpoch);
                }
            }

            var datesEncoder = new IntegerRunLengthEncodingV2Writer(_dataBuffer);

            datesEncoder.Write(datesList, true, _shouldAlignEncodedValues);
        }
コード例 #4
0
ファイル: Character.cs プロジェクト: MickMelon/FRAGS
        /// <summary>
        /// Sets the specified Statistic to the given StatisticValue if it exists.
        /// Otherwise, add a new StatisticMapping entry to the list.
        /// </summary>
        /// <param name="stat">The statistic to set.</param>
        /// <param name="newValue">The StatisticValue to associate with the Statistic.</param>
        public void SetStatistic(Statistic stat, StatisticValue newValue)
        {
            var statMap = Statistics.FirstOrDefault(x => x.Statistic.Equals(stat));

            if (statMap == null)
            {
                Statistics.Add(new StatisticMapping(stat, newValue));
                return;
            }

            statMap.StatisticValue = newValue;
        }
コード例 #5
0
ファイル: StatisticsTest.cs プロジェクト: mbican/2048
        public void StandardDeviationRandomAutomaticTest1()
        {
            const int elements = 1000000;
            var       list     = new List <double>();
            var       rand     = new Random();

            for (var i = 0; i < elements; ++i)
            {
                list.Add(rand.NextDouble());
            }
            var statistics1 = list.Statistics();
            var statistics2 = new Statistics();

            Parallel.ForEach(
                list,
                (e) => statistics2.Add(e)
                );
            var statistics3 = new Statistics();

            Parallel.ForEach(
                list,
                () => new Statistics(),
                (e, loop, counter) =>
            {
                counter.Add(e);
                return(counter);
            },
                (counter) => statistics3.Add(counter)
                );
            Assert.IsTrue(statistics1.NearlyEquals(statistics2));
            Assert.IsTrue(statistics1.NearlyEquals(statistics3));
            int group = 1;

            do
            {
                int counter         = 0;
                var statistics4     = new Statistics();
                var temp_statistics = new Statistics();
                foreach (var e in list)
                {
                    temp_statistics.Add(e);
                    if (group <= ++counter)
                    {
                        counter = 0;
                        statistics4.Add(temp_statistics);
                        temp_statistics = new Statistics();
                    }
                }
                statistics4.Add(temp_statistics);
                Assert.IsTrue(statistics1.NearlyEquals(statistics4));
            } while ((group *= 2) < elements);
        }
コード例 #6
0
        public override Statistics GetStatistics()
        {
            var result = new Statistics();
            
            for(var index = 0; index < grades.Count; index += 1)
            {
                result.Add(grades[index]);                            
            }

            // write the the result to the console
            // done:
            return result;
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: 1dv402/kursmaterial
        private static void ReadInts(Statistics statics)
        {
            int value;

            for (int i = 0; i < 10; ++i)
            {
                while (!int.TryParse(Console.ReadLine(), out value))
                {
                    Console.WriteLine("Du måste ange ett heltal!");
                }
                statics.Add(value);
            }
        }
コード例 #8
0
        private void LoadStatistics()
        {
            Task.Run(async() =>
            {
                var statistics = await _api.Execute(new GetPlatformStatisticsAction());

                Statistics.Clear();

                foreach (var statistic in statistics)
                {
                    Statistics.Add(statistic);
                }
            });
        }
コード例 #9
0
ファイル: StatisticsTest.cs プロジェクト: mbican/2048
        public void StandardDeviationPredefinedValuesTest2()
        {
            var statistics = new[] { 1d, 3, 4 }.Statistics();

            Assert.AreEqual(3, statistics.Count);
            Assert.IsTrue(statistics.Mean.NearlyEquals(2.7, 0.02));
            Assert.IsTrue(statistics.StandardDeviation.NearlyEquals(1.24722, 0.00005));
            Assert.IsTrue(statistics.SampleStandardDeviation.NearlyEquals(1.52753, 0.00005));
            IStatistics statistics2 = new Statistics();

            statistics2.Add(1);
            IStatistics statistics3 = new Statistics();

            statistics3.Add(3);
            statistics2.Add(statistics3);
            statistics3 = new Statistics();
            statistics3.Add(4);
            IStatistics statistics4 = statistics3.Clone();

            statistics4.Add(statistics2);
            Assert.IsTrue(statistics4.NearlyEquals(statistics));
            statistics2.Add(statistics3);
            Assert.IsTrue(statistics.NearlyEquals(statistics2));
        }
コード例 #10
0
        public async Task UpdateStatistics()
        {
            var categoriesData = await CategoriesSortedData();

            Statistics.Clear();
            foreach (var categiryData in categoriesData)
            {
                Statistics.Add(new CategoryStats()
                {
                    Title   = categiryData.Category.Name,
                    Section = categiryData.Category.Section,
                    Count   = categiryData.Tasks.Count
                });
            }
        }
コード例 #11
0
        private void AddEntitiesToBaseDictionary <T>() where T : Statistic
        {
            PropertyInfo[] properties = typeof(PersonStatistics).GetProperties(BindingFlags.Public | BindingFlags.Instance);

            foreach (PropertyInfo p in properties)
            {
                if (p.PropertyType != typeof(T))
                {
                    continue;
                }

                var stat = (T)p.GetValue(this);
                Statistics.Add(stat.Name, stat);
            }
        }
コード例 #12
0
ファイル: DoubleWriter.cs プロジェクト: valxv/ApacheOrcDotNet
        public void AddBlock(IList <double?> values)
        {
            var stats = new DoubleWriterStatistics();

            Statistics.Add(stats);
            if (_isNullable)
            {
                _presentBuffer.AnnotatePosition(stats, rleValuesToConsume: 0, bitsToConsume: 0);
            }
            _dataBuffer.AnnotatePosition(stats);

            var valList = new List <double>(values.Count);

            if (_isNullable)
            {
                var presentList = new List <bool>(values.Count);

                foreach (var value in values)
                {
                    stats.AddValue(value);
                    if (value.HasValue)
                    {
                        valList.Add(value.Value);
                    }
                    presentList.Add(value.HasValue);
                }

                var presentEncoder = new BitWriter(_presentBuffer);
                presentEncoder.Write(presentList);
                if (stats.HasNull)
                {
                    _presentBuffer.MustBeIncluded = true;
                }
            }
            else
            {
                foreach (var value in values)
                {
                    stats.AddValue(value);
                    valList.Add(value.Value);
                }
            }

            foreach (var value in valList)
            {
                _dataBuffer.WriteDouble(value);
            }
        }
コード例 #13
0
        public void AddBlock(IList <long?> values)
        {
            var stats = new LongWriterStatistics();

            Statistics.Add(stats);
            if (_isNullable)
            {
                _presentBuffer.AnnotatePosition(stats, rleValuesToConsume: 0, bitsToConsume: 0);
            }
            _dataBuffer.AnnotatePosition(stats, rleValuesToConsume: 0);

            var valList = new List <long>(values.Count);

            if (_isNullable)
            {
                var presentList = new List <bool>(values.Count);

                foreach (var value in values)
                {
                    stats.AddValue(value);
                    if (value.HasValue)
                    {
                        valList.Add(value.Value);
                    }
                    presentList.Add(value.HasValue);
                }

                var presentEncoder = new BitWriter(_presentBuffer);
                presentEncoder.Write(presentList);
                if (stats.HasNull)
                {
                    _presentBuffer.MustBeIncluded = true;                         //A null occurred.  Make sure to write this stream
                }
            }
            else
            {
                foreach (var value in values)
                {
                    stats.AddValue(value);
                    valList.Add(value.Value);
                }
            }

            var valEncoder = new IntegerRunLengthEncodingV2Writer(_dataBuffer);

            valEncoder.Write(valList, true, _shouldAlignEncodedValues);
        }
コード例 #14
0
        public void AddBlock(IList <byte?> values)
        {
            var stats = new LongWriterStatistics();

            Statistics.Add(stats);
            foreach (var buffer in Buffers)
            {
                buffer.AnnotatePosition(stats, 0);
            }

            var valList = new List <byte>(values.Count);

            if (_isNullable)
            {
                var presentList = new List <bool>(values.Count);

                foreach (var value in values)
                {
                    stats.AddValue(value);
                    if (value.HasValue)
                    {
                        valList.Add(value.Value);
                    }
                    presentList.Add(value.HasValue);
                }

                var presentEncoder = new BitWriter(_presentBuffer);
                presentEncoder.Write(presentList);
                if (stats.HasNull)
                {
                    _presentBuffer.MustBeIncluded = true;
                }
            }
            else
            {
                foreach (var value in values)
                {
                    stats.AddValue(value);
                    valList.Add(value.Value);
                }
            }

            var valEncoder = new ByteRunLengthEncodingWriter(_dataBuffer);

            valEncoder.Write(valList);
        }
コード例 #15
0
    public override Statistics GetStatistics()
    {
        var result = new Statistics();

        using (var reader = File.OpenText($"{Name}.txt"))
        {
            var line = reader.ReadLine();
            while (line != null)
            {
                var number = double.Parse(line);
                result.Add(number);
                line = reader.ReadLine();
            }
        }

        return(result);
    }
コード例 #16
0
        //I have asked that this method return the type "Statistics" which is a class that I have created in another file.
        public override Statistics GetStatistics()
        {
            //List is not in the System namespace, to find what namespace a class is in do the following:
            //place your cursor on the class name and press ctrl+. then click on the "using ....." and it will add this as a 'using statement' at the top
            //A List type requires one type argument, this is put in the <>
            //You can use List similarly to an Array but the benefit of a List over an Array is that you can easily add things into a list (you can add things into an Array also, but it is not as easy).
            //A list is implemented from the start as a dynamically sizable collection that you can easily add to or take from
            //A List is storing data(aka state), in this case, the numbers
            //List<double> grades = new List<double>() {12.7, 10.3, 6.11, 4.1};
            //grades.Add(56.1);

            var result = new Statistics();

            //Same as the below foreach but gives control over when to stop or ignore something
            //Count is to Lists what Length is to Arrays
            for (var i = 0; i < grades.Count; i++)
            {
                // if (grades[i] == 42.1)
                // {
                //     //this would skip the loop when the grade[i] == 42.1 but would continue to loop through after this
                //     continue;
                // }
                result.Add(grades[i]);
            }

            //The same code as above, but writen as a foreach
            // foreach(var grade in grades){
            //     result.Low = Math.Min(grade, result.Low);
            //     result.High = Math.Max(grade, result.High);
            //     result.Average += grade;
            // }

            //You could also write the above foreach as while statement but I prefer the foreach
            //var index = 0;
            //while(index < grades.Count)
            //{
            //result.Low = Math.Min(grades[index], result.Low);
            //result.High = Math.Max(grades[index], result.High);
            //result.Average += grades[index];
            //index++;
            //};

            return(result);
        }
コード例 #17
0
ファイル: Config.cs プロジェクト: jeason0813/Mtn.Library
        /// <summary>
        /// Load the ajax list
        /// </summary>
        public static Dictionary <String, AjaxClassItem> LoadAjaxCollection()
        {
            var assemblies =
                AppDomain.CurrentDomain.GetAssemblies().Where(
                    i => i.ManifestModule.ScopeName != "RefEmit_InMemoryManifestModule");
            var list = new Dictionary <string, AjaxClassItem>();

            Parallel.ForEach(assemblies.Distinct(), asm =>
            {
                try
                {
                    var modulo =
                        asm.GetCustomAttributes(typeof(AssemblyCompanyAttribute), false).FirstOrDefault() as
                        AssemblyCompanyAttribute;

                    if (modulo == null ||
                        (Parameter.GetCompanyToIgnore.Any(company => modulo.Company.ToLower().Contains(company))))
                    {
                        return;
                    }

                    if (Parameter.GetAssemblies.Any())
                    {
                        if (
                            Parameter.GetAssemblies.Any(
                                assembly => asm.GetName().Name.ToLower().Contains(assembly)))
                        {
                            AddAjaxClassItem(asm, ref list);
                        }
                    }
                    else
                    {
                        AddAjaxClassItem(asm, ref list);
                    }
                }
                catch (Exception ex)
                {
                    Statistics.Add(ex.GetAllMessagesMtn());
                }
            });

            return(list);
        }
コード例 #18
0
        public void AddBlock(IList <byte[]> values)
        {
            var stats = new BinaryWriterStatistics();

            Statistics.Add(stats);
            foreach (var buffer in Buffers)
            {
                buffer.AnnotatePosition(stats, 0);
            }

            var bytesList   = new List <byte[]>(values.Count);
            var presentList = new List <bool>(values.Count);
            var lengthList  = new List <long>(values.Count);

            foreach (var bytes in values)
            {
                stats.AddValue(bytes);
                if (values != null)
                {
                    bytesList.Add(bytes);
                    lengthList.Add(bytes.Length);
                }
                presentList.Add(bytes != null);
            }

            var presentEncoder = new BitWriter(_presentBuffer);

            presentEncoder.Write(presentList);
            if (stats.HasNull)
            {
                _presentBuffer.MustBeIncluded = true;
            }

            foreach (var bytes in bytesList)
            {
                _dataBuffer.Write(bytes, 0, bytes.Length);
            }

            var lengthEncoder = new IntegerRunLengthEncodingV2Writer(_lengthBuffer);

            lengthEncoder.Write(lengthList, false, _shouldAlignLengths);
        }
コード例 #19
0
 private Task UpdateStatistic(Dictionary <string, int> statistic)
 {
     foreach (var newStatistic in statistic)
     {
         var index = Statistics.FindIndex(item => item.StatisticName == newStatistic.Key);
         if (index >= 0)
         {
             Statistics[index].Value = newStatistic.Value;
         }
         else
         {
             Statistics.Add(new StatisticValue
             {
                 StatisticName = newStatistic.Key,
                 Value         = newStatistic.Value
             });
         }
     }
     return(Task.CompletedTask);
 }
コード例 #20
0
ファイル: DirectoryWatcher.cs プロジェクト: Pzixel/InlineTest
        private void UpdateStatistics(string path, Statistics <char> statistics)
        {
            var descriptor = new FileDescriptor(path);

            lock (_syncRoot) // лочим всегда, т.к. статистику и хэш файла мы уже посчитали, поэтому осталось только обновить пару служебных таблиц, это можно сделать быстро, таким образом лок не должен сильно влиять на производительность
            {
                FileData existingFile;
                if (!_currentData.TryGetValue(descriptor, out existingFile))
                {
                    _currentData[descriptor] = new FileData(statistics, path);
                    _globalStatistics.Add(statistics);
                    OnUpdate();
                }
                else
                {
                    existingFile.Paths.Add(path);
                }
                _pathToDescriptor[path] = descriptor;
            }
        }
コード例 #21
0
        /// <summary>
        /// 添加 统计,默认socre是0即未达对
        /// </summary>
        /// <param name="voterid"></param>
        /// <param name="questionNumber"></param>
        /// <param name="select"></param>
        /// <param name="score"></param>
        public void AddStatistic(String voterid, int questionNumber, String select, int score = 0)
        {
            if (!Statistics.ContainsKey(questionNumber))
            {
                Statistics.Add(questionNumber, select);
            }
            else
            {
                Statistics[questionNumber] = select;
            }

            if (!StatisticsAnswer.ContainsKey(questionNumber))
            {
                StatisticsAnswer.Add(questionNumber, score);
            }
            else
            {
                StatisticsAnswer[questionNumber] = score;
            }
        }
コード例 #22
0
        /// <summary>
        /// Replaces the sequence item present in the specified position in this sequence with the specified sequence item.
        /// </summary>
        /// <param name="position">Position at which the sequence item has to be replaced.</param>
        /// <param name="item">Sequence item to be placed at the specified position.</param>
        private void Replace(long position, byte item)
        {
            if (position < 0 || position >= Count)
            {
                throw new ArgumentOutOfRangeException(
                          Properties.Resource.ParameterNamePosition,
                          Properties.Resource.ParameterMustLessThanCount);
            }

            if (item == 0)
            {
                if (sparseSeqItems.ContainsKey(position))
                {
                    Statistics.Remove((char)sparseSeqItems[position]);
                    sparseSeqItems.Remove(position);
                }
            }
            else
            {
                if (!Alphabet.ValidateSequence(new[] { item }, 0, 1))
                {
                    throw new ArgumentException(
                              string.Format(
                                  CultureInfo.CurrentCulture,
                                  Properties.Resource.InvalidSymbol,
                                  item));
                }

                if (sparseSeqItems.ContainsKey(position))
                {
                    Statistics.Remove((char)sparseSeqItems[position]);
                    sparseSeqItems[position] = item;
                }
                else
                {
                    sparseSeqItems.Add(position, item);
                }

                Statistics.Add((char)item);
            }
        }
コード例 #23
0
        private void LoadData()
        {
            var toSkip  = _sprints.Count - _settings.NumberOfLastSprintsAnalysed;
            var sprints = _sprints.Where(s => s.CompleteDate.HasValue).OrderBy(s => s.StartDate).Skip(toSkip);

            foreach (var sprint in sprints)
            {
                var commitment = _boardContent.IssuesInSprint(sprint.Id).Sum(i => i.StoryPoints);
                var completed  = _boardContent.IssuesInSprint(sprint.Id).Where(i => i.Resolved.HasValue && i.Resolved <= sprint.CompleteDate).Sum(i => i.StoryPoints);

                Statistics.Add(new SprintStatistic {
                    SprintName = sprint.Name, Velocity = completed, Commitment = commitment
                });
            }

            var minimumVelocity   = Statistics.Min(s => s.Velocity);
            var maximumVelocity   = Statistics.Max(s => s.Velocity);
            var averageVelocity   = Statistics.Average(s => s.Velocity);
            var minimumCommitment = Statistics.Min(s => s.Commitment);
            var maximumCommitment = Statistics.Max(s => s.Commitment);
            var averageCommitment = Statistics.Average(s => s.Commitment);

            Minimum.Add(new SprintStatistic {
                SprintName = Statistics.First().SprintName, Velocity = minimumVelocity, Commitment = minimumCommitment
            });
            Minimum.Add(new SprintStatistic {
                SprintName = Statistics.Last().SprintName, Velocity = minimumVelocity, Commitment = minimumCommitment
            });
            Maximum.Add(new SprintStatistic {
                SprintName = Statistics.First().SprintName, Velocity = maximumVelocity, Commitment = maximumCommitment
            });
            Maximum.Add(new SprintStatistic {
                SprintName = Statistics.Last().SprintName, Velocity = maximumVelocity, Commitment = maximumCommitment
            });
            Average.Add(new SprintStatistic {
                SprintName = Statistics.First().SprintName, Velocity = averageVelocity, Commitment = averageCommitment
            });
            Average.Add(new SprintStatistic {
                SprintName = Statistics.Last().SprintName, Velocity = averageVelocity, Commitment = averageCommitment
            });
        }
コード例 #24
0
        public void AddMedium()
        {
            var Stats = new Statistics(Intervals);

            Stats.Add("Test");
            Stats.Reset();

            //****************************************

            Stats.Increment("Test");

            WaitFor(MediumInterval);

            //****************************************

            var Results = Stats.GetRaw("Test");

            Assert.AreEqual(0, Results[0]);
            Assert.AreEqual(1, Results[1]);
            Assert.AreEqual(0, Results[2]);
        }
コード例 #25
0
ファイル: TextAnalyzer.cs プロジェクト: yzwbrian/NaiveIME
        public void Analyze(TextReader reader)
        {
            var builder = new StringBuilder("^");

            while (reader.Peek() != -1)
            {
                var pinyins  = reader.ReadLine().Split(' ');
                var sentence = reader.ReadLine();
                if (sentence.Length != pinyins.Length)
                {
                    throw new FormatException("拼音字数与句子长度不符合!句子:" + sentence);
                }
                builder.Append(sentence).Append('$');
                Statistics.Add("*", builder.Length);
                foreach (var strAndPy in SubStringSelector(builder.ToString(), pinyins))
                {
                    Statistics.Add(strAndPy.Chars + ':' + strAndPy.Pinyin);
                }
                builder.Clear();
                builder.Append('^');
            }
        }
コード例 #26
0
        public void AddLong()
        {
            var Stats = new Statistics(Intervals);

            Stats.Add("Test");
            Stats.Reset();

            //****************************************

            Stats.Increment("Test");

            // Need to wait 40ms for the medium interval to tick over
            WaitFor(LongInterval + ShortInterval);

            //****************************************

            var Results = Stats.GetRaw("Test");

            Assert.AreEqual(0, Results[0]);
            Assert.AreEqual(0, Results[1]);
            Assert.AreEqual(1, Results[2]);
        }
コード例 #27
0
        public void AddMatchAndSaveDatabase(bool addMatch, MatchStatistics ms)
        {
            // Skip adding stats if the game only had one player, make exception for co-op since it doesn't recognize pre-placed houses as players.
            if (ms.GetPlayerCount() <= 1 && !ms.MapIsCoop)
            {
                Logger.Log("Skipping adding match to statistics because game only had one player.");
                return;
            }

            if (ms.LengthInSeconds < 60)
            {
                Logger.Log("Skipping adding match to statistics because the game was cancelled.");
                return;
            }

            if (addMatch)
            {
                Statistics.Add(ms);
                GameAdded?.Invoke(this, EventArgs.Empty);
            }

            if (!File.Exists(ProgramConstants.GamePath + SCORE_FILE_PATH))
            {
                CreateDummyFile();
            }

            Logger.Log("Writing game info to statistics file.");

            using (FileStream fs = File.Open(ProgramConstants.GamePath + SCORE_FILE_PATH, FileMode.Open, FileAccess.ReadWrite))
            {
                fs.Position = 4; // First 4 bytes after the version mean the amount of games
                fs.WriteInt(Statistics.Count);

                fs.Position = fs.Length;
                ms.Write(fs);
            }

            Logger.Log("Finished writing statistics.");
        }
コード例 #28
0
        public void Handle(IMessage message)
        {
            _totalEvents++;

            var eventName = message.GetType().Name;

            DispatcherHelper.CheckBeginInvokeOnUI(() =>
            {
                var stat = Statistics.FirstOrDefault(s => s.EventName == eventName);
                if (stat != null)
                {
                    stat.Hits++;
                }
                else
                {
                    stat = new EventStats(eventName, message.GetType().Assembly.FullName)
                    {
                        Hits = 1
                    };
                    Statistics.Add(stat);
                }
            });
        }
コード例 #29
0
        public PvPProfileHistoryEntry EnsureStatistics(PlayerMobile pm, bool replace)
        {
            PvPProfileHistoryEntry entry;

            if (!Statistics.TryGetValue(pm, out entry))
            {
                Statistics.Add(pm, entry = new PvPProfileHistoryEntry(AutoPvP.CurrentSeason.Number));
            }
            else if (entry == null || replace)
            {
                Statistics[pm] = entry = new PvPProfileHistoryEntry(AutoPvP.CurrentSeason.Number);
            }

            if (!StatisticsCache.ContainsKey(pm))
            {
                StatisticsCache.Add(pm, entry);
            }
            else
            {
                StatisticsCache[pm] = entry;
            }

            return(entry);
        }
コード例 #30
0
        /// <summary>
        /// Loads and displays the list of Information depending on the current Mode
        /// </summary>
        public async void ReloadPlayers()
        {
            try
            {
                if (Common.Mode.HostStart == Mode)
                {
                    PlayersListHeader = LanguagePackage.GameIdTranslation + " " + cvm.SystemGameID;
                    var data = await dataService.GetPlayersInGame(cvm.SystemGameID);

                    if (Players.Count != 0)
                    {
                        foreach (var v in Players)
                        {
                            if (data.Where(x => x.ID == v.ID && x.Title == v.Title).Count() == 0)
                            {
                                Players.Remove(v);
                            }
                        }
                    }
                    foreach (var v in data)
                    {
                        if (Players.Where(x => x.ID == v.ID).Count() == 0)
                        {
                            Players.Add(v);
                        }
                    }
                }
                else if (Common.Mode.IsClient == Mode)
                {
                    PlayersListHeader = LanguagePackage.PlayersTranslation;

                    var data = await dataService.GetPlayersInGame(jvm.SystemGameID);

                    if (Players.Count != 0)
                    {
                        foreach (var v in Players)
                        {
                            if (data.Where(x => x.ID == v.ID && x.Title == v.Title).Count() == 0)
                            {
                                Players.Remove(v);
                            }
                        }
                    }
                    foreach (var v in data)
                    {
                        if (Players.Where(x => x.ID == v.ID).Count() == 0)
                        {
                            Players.Add(v);
                        }
                    }
                    NextAvailable = true;
                }
                else if (Common.Mode.ClientWait == Mode)
                {
                    PlayersListHeader = LanguagePackage.AnsweredPlayersTranslation;
                    NextAvailable     = await dataService.IsContinueAllowed(jvm.SystemGameID);

                    var data = await dataService.GetAnsweredUsers(jvm.SystemGameID);

                    if (Players.Count != 0)
                    {
                        foreach (var v in Players)
                        {
                            if (data.Where(x => x.ID == v.ID && x.Title == v.Title).Count() == 0)
                            {
                                Players.Remove(v);
                            }
                        }
                    }
                    foreach (var v in data)
                    {
                        if (Players.Where(x => x.ID == v.ID).Count() == 0)
                        {
                            Players.Add(v);
                        }
                    }
                }
                else if (Common.Mode.HostWait == Mode)
                {
                    PlayersListHeader = LanguagePackage.AnsweredPlayersTranslation;
                    var data = await dataService.GetAnsweredUsers(cvm.SystemGameID);

                    if (Players.Count != 0)
                    {
                        foreach (var v in Players)
                        {
                            if (data.Where(x => x.ID == v.ID && x.Title == v.Title).Count() == 0)
                            {
                                Players.Remove(v);
                            }
                        }
                    }
                    foreach (var v in data)
                    {
                        if (Players.Where(x => x.ID == v.ID).Count() == 0)
                        {
                            Players.Add(v);
                        }
                    }
                }
                else if (Common.Mode.ClientStatistic == Mode)
                {
                    NextAvailable = !await dataService.IsContinueAllowed(jvm.SystemGameID);

                    var data = await dataService.GetStatisticByGameId(jvm.SystemGameID);

                    if (Statistics.Count != 0)
                    {
                        foreach (var v in Statistics)
                        {
                            if (data.Where(x => x.ID == v.ID && x.Name == v.Name).Count() == 0)
                            {
                                Statistics.Remove(v);
                            }
                        }
                    }
                    foreach (var v in data)
                    {
                        if (Statistics.Where(x => x.ID == v.ID).Count() == 0)
                        {
                            Statistics.Add(v);
                        }
                    }
                    PlayersListHeader = LanguagePackage.YesVoteText + " " + Statistics.FirstOrDefault().Yesses;
                }
                else if (Common.Mode.HostStatistic == Mode)
                {
                    var data = await dataService.GetStatisticByGameId(cvm.SystemGameID);

                    if (Statistics.Count != 0)
                    {
                        foreach (var v in Statistics)
                        {
                            if (data.Where(x => x.ID == v.ID && x.Name == v.Name).Count() == 0)
                            {
                                Statistics.Remove(v);
                            }
                        }
                    }
                    foreach (var v in data)
                    {
                        if (Statistics.Where(x => x.ID == v.ID).Count() == 0)
                        {
                            Statistics.Add(v);
                        }
                    }
                    PlayersListHeader = LanguagePackage.YesVoteText + " " + Statistics.FirstOrDefault().Yesses;
                }
            }
            catch (Exception ex)
            {
                if (Mode == Common.Mode.ClientStatistic || Mode == Common.Mode.ClientWait || Mode == Common.Mode.IsClient)
                {
                    if (!await dataService.IsGameExisting(jvm.SystemGameID))
                    {
                        if (isActive)
                        {
                            var dialog = new MessageDialog(LanguagePackage.LobbyMsg1);
                            dialog.Title = LanguagePackage.NotificationTranslation;
                            dialog.Commands.Add(new UICommand {
                                Label = "Ok", Id = 0
                            });
                            var res = await dialog.ShowAsync();

                            if ((int)res.Id == 0)
                            {
                                navigationService.NavigateTo(Common.Navigation.CentralMenu);
                            }
                        }
                    }
                }
                else
                {
                    if (!await dataService.IsGameExisting(cvm.SystemGameID))
                    {
                        if (isActive)
                        {
                            var dialog = new MessageDialog(LanguagePackage.LobbyMsg1);
                            dialog.Title = LanguagePackage.NotificationTranslation;
                            dialog.Commands.Add(new UICommand {
                                Label = "Ok", Id = 0
                            });
                            var res = await dialog.ShowAsync();

                            if ((int)res.Id == 0)
                            {
                                navigationService.NavigateTo(Common.Navigation.CentralMenu);
                            }
                        }
                    }
                }
            }
        }
コード例 #31
0
        public void AddBlock(IList <DateTime?> values)
        {
            var stats = new TimestampWriterStatistics();

            Statistics.Add(stats);
            if (_isNullable)
            {
                _presentBuffer.AnnotatePosition(stats, rleValuesToConsume: 0, bitsToConsume: 0);
            }
            _dataBuffer.AnnotatePosition(stats, rleValuesToConsume: 0);
            _secondaryBuffer.AnnotatePosition(stats, rleValuesToConsume: 0);

            var secondsList   = new List <long>(values.Count);
            var fractionsList = new List <long>(values.Count);

            if (_isNullable)
            {
                var presentList = new List <bool>(values.Count);

                foreach (var value in values)
                {
                    if (!value.HasValue)
                    {
                        stats.AddValue(null);
                        presentList.Add(false);
                    }
                    else
                    {
                        long millisecondsSinceUnixEpoch;
                        long fraction;
                        var  seconds = GetValues(value.Value, out millisecondsSinceUnixEpoch, out fraction);
                        stats.AddValue(millisecondsSinceUnixEpoch);
                        presentList.Add(true);
                        secondsList.Add(seconds);
                        fractionsList.Add(fraction);
                    }
                }

                var presentEncoder = new BitWriter(_presentBuffer);
                presentEncoder.Write(presentList);
                if (stats.HasNull)
                {
                    _presentBuffer.MustBeIncluded = true;
                }
            }
            else
            {
                foreach (var value in values)
                {
                    long millisecondsSinceUnixEpoch;
                    long fraction;
                    var  seconds = GetValues(value.Value, out millisecondsSinceUnixEpoch, out fraction);
                    stats.AddValue(millisecondsSinceUnixEpoch);
                    secondsList.Add(seconds);
                    fractionsList.Add(fraction);
                }
            }

            var secondsEncoder = new IntegerRunLengthEncodingV2Writer(_dataBuffer);

            secondsEncoder.Write(secondsList, true, _shouldAlignEncodedValues);

            var fractionsEncoder = new IntegerRunLengthEncodingV2Writer(_secondaryBuffer);

            fractionsEncoder.Write(fractionsList, false, _shouldAlignEncodedValues);
        }