<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Mat.Common.Extensions;

namespace Mat.Common
{
    public class CommonQueueManager : IQueueManager
    {
        private readonly IList<Media> _media = new List<Media>();
        private int _position;
        public int Seed { get; set; }

        public CommonQueueManager()
        {
            Seed = new Random().Next(int.MaxValue);
            _media = SourceContainer.GetInstance().Sources
                .SelectMany(s => s.Media)
                .OrderBy(i => (~(i.Ordering() & Seed)) & (i.Ordering() | Seed))
                .ToList();
        }

        public IEnumerable<Media> Queue
        {
            get { return _media.Skip(_position); }
        }

        public IEnumerable<Media> History
        {
            get { return _media.Take(_position); }
        }

        public Media Next()
        {
            _position++;
            if (_media.Count <= _position)
            {
                if (SourceContainer.GetInstance().Sources.OfType<IUpdatableMediaSource>().Any())
                {
                    var updatableSources = SourceContainer.GetInstance().Sources.OfType<IUpdatableMediaSource>();
                    Task.WaitAll(updatableSources.Select(s => s.UpdateAsync()).ToArray(), new TimeSpan(0, 0, 1, 0));

                    _media.AddRange(updatableSources
                                        .SelectMany(s => s.Media)
                                        .Where(m => !_media.Contains(m, new MediaEqualityComparer()))
                                        .OrderBy(i => (~(i.Ordering() & Seed)) & (i.Ordering() | Seed)));
                }
                _position = 0;
            }
            return Current;
        }

        public Media Previous()
        {
            _position--;
            if (_position < 0)
            {
                _position = _media.Count - 1;
            }
            return Current;
        }

        public Media Current
        {
            get { return _media[_position]; }
        }
<commit_msg>Fixes bug with updatable sources.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Mat.Common.Extensions;

namespace Mat.Common
{
    public class CommonQueueManager : IQueueManager
    {
        private readonly IList<Media> _media = new List<Media>();
        private int _position;
        public int Seed { get; set; }

        public CommonQueueManager()
        {
            Seed = new Random().Next(int.MaxValue);
            _media = SourceContainer.GetInstance().Sources
                .SelectMany(s => s.Media)
                .OrderBy(i => (~(i.Ordering() & Seed)) & (i.Ordering() | Seed))
                .ToList();
        }

        public IEnumerable<Media> Queue
        {
            get { return _media.Skip(_position); }
        }

        public IEnumerable<Media> History
        {
            get { return _media.Take(_position); }
        }

        public Media Next()
        {
            _position++;
            if (_media.Count <= _position)
            {
                if (SourceContainer.GetInstance().Sources.OfType<IUpdatableMediaSource>().Any())
                {
                    var updatableSources = SourceContainer.GetInstance().Sources.OfType<IUpdatableMediaSource>();
                    Task.WaitAll(updatableSources.Select(s => s.UpdateAsync()).ToArray(), new TimeSpan(0, 0, 1, 0));

                    _media.AddRange(updatableSources
                                        .SelectMany(s => s.Media)
                                        .Where(m => !_media.Contains(m, new MediaEqualityComparer()))
                                        .OrderBy(i => (~(i.Ordering() & Seed)) & (i.Ordering() | Seed)));
                }
                else
                {
                    _position = 0;
                }
            }
            return Current;
        }

        public Media Previous()
        {
            _position--;
            if (_position < 0)
            {
                _position = _media.Count - 1;
            }
            return Current;
        }

        public Media Current
        {
            get { return _media[_position]; }
        }

{'fraction_non_alphanumeric': 0.10869061413673232, 'fraction_numerical': 0.0032444959443800694, 'mean_word_length': 1.380584666298952, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5427222', 'n_tokens_mistral': 1130, 'n_tokens_neox': 1063, 'n_words': 225}