<commit_before>﻿using NetMud.DataAccess; using NetMud.DataAccess.Cache;
using NetMud.DataStructure.Base.Supporting;
using NetMud.Utility;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;

namespace NetMud.Data.Reference
{
    /// <summary>
    /// The live version of a dimensional model
    /// </summary>
    [Serializable]
    public class DimensionalModel : IDimensionalModel
    {
        [JsonProperty("BackingDataId")]
        private long _backingDataId { get; set; }

        /// <summary>
        /// Y axis of the 11 plane model
        /// </summary>
        public int Length { get; set; }

        /// <summary>
        /// Measurement of all 11 planes vertically
        /// </summary>
        public int Height { get; set; }

        /// <summary>
        /// X axis of the 11 plane model
        /// </summary>
        public int Width { get; set; }

        /// <summary>
        /// The model we're following
        /// </summary>
        [ScriptIgnore]
        public IDimensionalModelData ModelBackingData 
        {
            get
            {
                // TODO: Impl the BackingDataCache once it is written
               // if (_backingDataId >= 0)
                 //   return LiveCache.Get<IDimensionalModelData>(new LiveCacheKey(typeof(IDimensionalModelData), _backingDataId.ToString()));

                return null;
            }
            set
            {
                if (value == null)
                    return;

                //UpsertToLiveWorldCache();
            }
        }

        /// <summary>
        /// Collection of model section name to material composition mappings
        /// </summary>
        public IDictionary<string, IMaterial> Composition { get; set; }

        /// <summary>
        /// Constructor for dimensional model based on a datarow
        /// </summary>
        /// <param name="dr">the row from the db</param>
        public DimensionalModel(global::System.Data.DataRow dr)
        {
            Length = DataUtility.GetFromDataRow<int>(dr, "DimensionalModelLength");
            Height = DataUtility.GetFromDataRow<int>(dr, "DimensionalModelHeight");
            Width = DataUtility.GetFromDataRow<int>(dr, "DimensionalModelWidth");

            long outDimModId = DataUtility.GetFromDataRow<long>(dr, "DimensionalModelID");

            if (outDimModId > 0)
            {
                ModelBackingData = ReferenceWrapper.GetOne<DimensionalModelData>(outDimModId);

                string materialComps = DataUtility.GetFromDataRow<string>(dr, "DimensionalModelMaterialCompositions");
                Composition = DeserializeMaterialCompositions(materialComps);<commit_msg>like super minor change, got to make some methods to deserialize these bits<commit_after>﻿using NetMud.DataAccess; using NetMud.DataAccess.Cache;
using NetMud.DataStructure.Base.Supporting;
using NetMud.Utility;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;

namespace NetMud.Data.Reference
{
    /// <summary>
    /// The live version of a dimensional model
    /// </summary>
    [Serializable]
    public class DimensionalModel : IDimensionalModel
    {
        /// <summary>
        /// Y axis of the 11 plane model
        /// </summary>
        public int Length { get; set; }

        /// <summary>
        /// Measurement of all 11 planes vertically
        /// </summary>
        public int Height { get; set; }

        /// <summary>
        /// X axis of the 11 plane model
        /// </summary>
        public int Width { get; set; }

        [JsonProperty("BackingDataId")]
        private long _backingDataId { get; set; }

        /// <summary>
        /// The model we're following
        /// </summary>
        [ScriptIgnore]
        public IDimensionalModelData ModelBackingData 
        {
            get
            {
                if (_backingDataId >= 0)
                    return BackingDataCache.Get<IDimensionalModelData>(new BackingDataCacheKey(typeof(IDimensionalModelData), _backingDataId));

                return null;
            }
            set
            {
                if (value == null)
                    return;

                _backingDataId = value.ID;
            }
        }

        [JsonProperty("MaterialComposition")]
        private IDictionary<string, long> _materialComposition { get; set; }

        /// <summary>
        /// Collection of model section name to material composition mappings
        /// </summary>
        [ScriptIgnore]
        public IDictionary<string, IMaterial> Composition 
        {
            get
            {
                if (_materialComposition != null)
                    return BackingDataCache.Get<IDimensionalModelData>(new BackingDataCacheKey(typeof(IDimensionalModelData), _backingDataId));

                return null;
            }
            set
            {
                if (value == null)
                    return;
            }
        }

        /// <summary>
        /// Constructor for dimensional model based on a datarow
        /// </summary>
        /// <param name="dr">the row from the db</param>
        public DimensionalModel(global::System.Data.DataRow dr)
        {
            Length = DataUtility.GetFromDataRow<int>(dr, "DimensionalModelLength");
            Height = DataUtility.GetFromDataRow<int>(dr, "DimensionalModelHeight");
            Width = DataUtility.GetFromDataRow<int>(dr, "DimensionalModelWidth");

            long outDimModId = DataUtility.GetFromDataRow<long>(dr, "DimensionalModelID");

            if (outDimModId > 0)
            {
                ModelBackingData = ReferenceWrapper.GetOne<DimensionalModelData>(outDimModId);

                string materialComps = DataUtility.GetFromDataRow<string>(dr, "DimensionalModelMaterialCompositions");
                Composition = DeserializeMaterialCompositions(materialComps);
{'fraction_non_alphanumeric': 0.10077011305915123, 'fraction_numerical': 0.002621661477961658, 'mean_word_length': 1.9136038186157518, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7545384', 'n_tokens_mistral': 1621, 'n_tokens_neox': 1540, 'n_words': 383}