<commit_before>//Copyright 2014 Spin Services Limited

//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at

//    http://www.apache.org/licenses/LICENSE-2.0

//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.

using System;
using System.Collections.Generic;
using System.Linq;
using SS.Integration.Adapter.MarketRules.Interfaces;
using SS.Integration.Adapter.Model;
using SS.Integration.Adapter.Model.Interfaces;

namespace SS.Integration.Adapter.MarketRules.Model
{
    [Serializable]
    internal class MarketState : IUpdatableMarketState
    {
        private readonly Dictionary<string, IUpdatableSelectionState> _selectionStates;
        private Dictionary<string, string> _tags;

        /// <summary>
        /// DO NOT USE it's for copying object purpose only!
        /// </summary>
        public MarketState() 
        {
            _selectionStates = new Dictionary<string, IUpdatableSelectionState>();
            _tags = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
        }

        internal MarketState(string Id)
            : this()
        {
            this.Id = Id;
        }

        public MarketState(Market market, bool fullSnapshot)
            : this(market.Id)
        {
            IsRollingMarket = market is RollingMarket;
            this.Update(market, fullSnapshot);                
        }


        #region IMarketState

        public string Id { get; private set; }

        public string Name { get { return GetTagValue("name"); } }

        public bool IsActive
        {
            get 
            { 
                return _selectionStates.Any(s => s.Value.Status == SelectionStatus.Active); 
            }
        }

        public bool IsSuspended
        {
            get
            {
                return _selectionStates.Where(s => s.Value.Status == SelectionStatus.Active && s.Value.Tradability.HasValue).All(s => !s.Value.Tradability.Value);
            }
        }

        public bool IsPending
        {
            get
            {
                return _selectionStates.All(s => s.Value.Status == SelectionStatus.Pending);
            }
        }

        public bool IsResulted 
        { 
            get
            {
                // market is resulted if at least one selection has a price of 1.0 and status settled and the rest are settled or void
                // alternatively all selections need to be void
                return (Selections.Any(x => x.Status == SelectionStatus.Settled && x.Price == 1.0) &&
                        Selections.All(x => x.Status == SelectionStatus.Settled || x.Status == SelectionStatus.Void)) ||
                        IsVoided;
            } 
        }

        public bool IsVoided
        {
            get
            {
                return Selections.All(x => x.Status == SelectionStatus.Void);
            }
        }

        public bool IsTradedInPlay { get; set; }

        public bool HasBeenActive { get; set; }

        public bool HasBeenProcessed { get; set; }

        public bool IsForcedSuspended { get; private set; }

        public bool IsRollingMarket { get; private set; }

        public double? Line { get; set; }
<commit_msg>IsResulted flag improved logic for markets with 1 selection<commit_after>//Copyright 2014 Spin Services Limited

//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at

//    http://www.apache.org/licenses/LICENSE-2.0

//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.

using System;
using System.Collections.Generic;
using System.Linq;
using SS.Integration.Adapter.MarketRules.Interfaces;
using SS.Integration.Adapter.Model;
using SS.Integration.Adapter.Model.Interfaces;

namespace SS.Integration.Adapter.MarketRules.Model
{
    [Serializable]
    internal class MarketState : IUpdatableMarketState
    {
        private readonly Dictionary<string, IUpdatableSelectionState> _selectionStates;
        private Dictionary<string, string> _tags;

        /// <summary>
        /// DO NOT USE it's for copying object purpose only!
        /// </summary>
        public MarketState() 
        {
            _selectionStates = new Dictionary<string, IUpdatableSelectionState>();
            _tags = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
        }

        internal MarketState(string Id)
            : this()
        {
            this.Id = Id;
        }

        public MarketState(Market market, bool fullSnapshot)
            : this(market.Id)
        {
            IsRollingMarket = market is RollingMarket;
            this.Update(market, fullSnapshot);                
        }


        #region IMarketState

        public string Id { get; private set; }

        public string Name { get { return GetTagValue("name"); } }

        public bool IsActive
        {
            get 
            { 
                return _selectionStates.Any(s => s.Value.Status == SelectionStatus.Active); 
            }
        }

        public bool IsSuspended
        {
            get
            {
                return _selectionStates.Where(s => s.Value.Status == SelectionStatus.Active && s.Value.Tradability.HasValue).All(s => !s.Value.Tradability.Value);
            }
        }

        public bool IsPending
        {
            get
            {
                return _selectionStates.All(s => s.Value.Status == SelectionStatus.Pending);
            }
        }

        public bool IsResulted 
        { 
            get
            {
                // market is resulted if at least one selection has a price of 1.0 and status settled and the rest are settled or void
                // alternatively all selections need to be void
                return (Selections.Any(x => x.Status == SelectionStatus.Settled && x.Price == 1.0) || Selections.Count() == 1) &&
                        Selections.All(x => x.Status == SelectionStatus.Settled || x.Status == SelectionStatus.Void) ||
                        IsVoided;
            } 
        }

        public bool IsVoided
        {
            get
            {
                return Selections.All(x => x.Status == SelectionStatus.Void);
            }
        }

        public bool IsTradedInPlay { get; set; }

        public bool HasBeenActive { get; set; }

        public bool HasBeenProcessed { get; set; }

        public bool IsForcedSuspended { get; private set; }

        public bool IsRollingMarket { get; private set; }

        public double? Line { get; set; }

{'fraction_non_alphanumeric': 0.0846802044481282, 'fraction_numerical': 0.0035916563061196296, 'mean_word_length': 1.8913738019169328, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4623206', 'n_tokens_mistral': 1900, 'n_tokens_neox': 1789, 'n_words': 562}