示例#1
0
        private static void InitializeTableOfRank4(CATable caTable, Array array, object initialValue)
        {
            const int rank = 4;

            int[] indexArray = new int[rank];

            for (int n1 = 1; n1 < array.GetLength(0) + 1; n1++)
            {
                indexArray[0] = n1;

                for (int n2 = 1; n2 < array.GetLength(1) + 1; n2++)
                {
                    indexArray[1] = n2;

                    for (int n3 = 1; n3 < array.GetLength(2) + 1; n3++)
                    {
                        indexArray[2] = n3;

                        for (int n4 = 1; n4 < array.GetLength(3) + 1; n4++)
                        {
                            indexArray[3] = n4;

                            if (!caTable.SetDataByElements(initialValue, indexArray))
                            {
                                string message = $"aTable.SetDataByElements failed: indexArray = {indexArray} initialValue = {initialValue}";
                                Logger.Error(message);
                                throw new Exception(message);
                            }
                        }
                    }
                }
            }
        }
示例#2
0
        protected void LoadTables(Dictionary <string, string[]> tableIndicesDictionary, IReadOnlyDictionary <string, Dictionary <string, double> > modelData)
        {
            foreach (KeyValuePair <string, string[]> keyValuePair in tableIndicesDictionary)
            {
                string   tableName  = keyValuePair.Key;
                string[] indexArray = keyValuePair.Value;

                if (modelData.ContainsKey(tableName))
                {
                    CATable caTable = GetDefTable(tableName);
                    Dictionary <string, double> dictionary = modelData[tableName];
                    if (modelData[tableName] == null)
                    {
                        Logger.Info(tableName);
                    }
                    LoadTable(caTable, indexArray, dictionary, tableName);
                }
                else
                {
                    string message = $"ModelData does not contain dictionary {tableName}";
                    Logger.Error(message);
                    throw new Exception(message);
                }
            }
        }
示例#3
0
        private CATable GetResultTable(string tableName)
        {
            if (tableName.IsNullOrWhiteSpace())
            {
                const string message = "The tableName must not be null or whitespace";
                Logger.Error(message);
                throw new ArgumentException(message, nameof(tableName));
            }

            // todo how to check if table name exists in model?
            CAObject caObject = _caEngine.GetObjectByName(tableName);

            if (caObject == null)
            {
                const string message = "caObject is null : ";
                Logger.Error(message + tableName);
                throw new Exception(message);
            }

            CATable caTable = caObject.ResultTable();

            if (caTable == null)
            {
                const string message = "caTable is null";
                Logger.Error(message);
                throw new Exception(message);
            }

            return(caTable);
        }
示例#4
0
        protected CATable GetDefTable(string tableName)
        {
            if (tableName.IsNullOrWhiteSpace())
            {
                string message = $"The tableName must not be null or whitespace, tableName = {tableName}";
                throw new ArgumentException(message, nameof(tableName));
            }

            CAObject caObject = _caEngine.GetObjectByName(tableName);

            if (caObject == null)
            {
                string message = $"{tableName} CAObject is null";
                Logger.Error(message);
                throw new Exception(message);
            }

            CATable caTable = caObject.DefTable();

            if (caTable == null)
            {
                const string message = "CATable is null";
                Logger.Error(message);
                throw new Exception(message);
            }

            return(caTable);
        }
示例#5
0
        private void LoadTable(CATable caTable, string[] indexArray, Dictionary <string, double> dictionary, string tableName)
        {
            if (caTable == null)
            {
                string message = $"caTable name is null {tableName}";
                Logger.Error(message);
                throw new ArgumentNullException(nameof(caTable));
            }

            if (dictionary == null)
            {
                const string message = "dictionary is null";
                Logger.Error(message);
                throw new ArgumentNullException(nameof(dictionary));
            }

            if (!caTable.SetIndexOrder(indexArray))
            {
                string message = $"LoadTable() failed, SetIndexOrder() failed: indexArray = {ConvertIndexArrayToString(indexArray)}  {tableName}";
                Logger.Error(message);
                throw new Exception(message);
            }

            if (dictionary.Count == 0)
            {
                Logger.Error("LoadTable(): dictionary is empty");
                return;
            }

            foreach (KeyValuePair <string, double> keyValuePair in dictionary)
            {
                string key   = keyValuePair.Key;
                double value = keyValuePair.Value;

                const char comma       = ',';
                string[]   indexArray2 = key.Split(comma);

                if (!caTable.SetDataByLabels(value, indexArray2))
                {
                    string message = $"UpdateTable failed: SetDataByLabels() failed: indexArray = {ConvertIndexArrayToString(indexArray2)}, value = {value}, ErrorText = {_caEngine.ErrorText} {tableName}";
                    Logger.Error(message);
                    throw new Exception(message);
                }
            }

            if (!caTable.Update())
            {
                const string message = "Update() failed";
                Logger.Error(message);
                throw new Exception(message);
            }
        }
示例#6
0
        private void InitializeTable(CATable caTable, object initialValue)
        {
            if (caTable == null)
            {
                const string message = "caTable is null";
                Logger.Error(message);
                throw new ArgumentNullException(nameof(caTable));
            }

            dynamic safeArray = caTable.GetSafeArray();
            Array   array     = (Array)safeArray;
            int     rank      = array.Rank;

            switch (rank)
            {
            case 2:
                InitializeTableOfRank2(caTable, array, initialValue);
                break;

            case 3:
                InitializeTableOfRank3(caTable, array, initialValue);
                break;

            case 4:
                InitializeTableOfRank4(caTable, array, initialValue);
                break;

            case 5:
                InitializeTableOfRank5(caTable, array, initialValue);
                break;

            case 6:
                InitializeTableOfRank6(caTable, array, initialValue);
                break;

            default:
                const string message = "Only tables of rank 2, 3, 4, 5, and 6 can be initialized";
                Logger.Error(message);
                throw new Exception(message);
            }

            if (!caTable.Update())
            {
                const string message = "CATable.Update() failed";
                Logger.Error(message);
                throw new Exception(message);
            }
        }
示例#7
0
        protected Array GetTableArray(string tableName, string[] indexArray)
        {
            CATable caTable = GetResultTable(tableName);

            if (!caTable.SetIndexOrder(indexArray))
            {
                const string message = "SetIndexOrder() failed";
                Logger.Error(message + " " + tableName);
                throw new Exception(message);
            }

            dynamic safeArray = caTable.GetSafeArray();
            Array   array     = (Array)safeArray;

            return(array);
        }
示例#8
0
        public void InitializeTables(Dictionary <string, string[]> tableIndicesDictionary)
        {
            foreach (KeyValuePair <string, string[]> keyValuePair in tableIndicesDictionary)
            {
                string   tableName  = keyValuePair.Key;
                string[] indexArray = keyValuePair.Value;

                CATable caTable = GetDefTable(tableName);

                if (!caTable.SetIndexOrder(indexArray))
                {
                    const string message = "SetIndexOrder() failed";
                    Logger.Error(message);
                    throw new Exception(message);
                }

                const double initialValue = 0L;
                InitializeTable(caTable, initialValue);
            }
        }
示例#9
0
        public Array LogTableValues(CATable caTable, string[] indexArray)
        {
            if (caTable == null)
            {
                const string message = "caTable is null";
                Logger.Error(message);
                throw new ArgumentNullException(nameof(caTable));
            }

            if (!caTable.SetIndexOrder(indexArray))
            {
                string message = $"SetIndexOrder() failed: indexArray = {ConvertIndexArrayToString(indexArray)}";
                Logger.Error(message);
                throw new Exception(message);
            }

            dynamic safeArray = caTable.GetSafeArray();
            Array   array     = (Array)safeArray;

            return(array);
        }
示例#10
0
        private void SetSecondFoulPossession(NbaGame nbaGame)
        {
            CATable caTable = GetDefTable("EGT");

            string[] indexArray = { "S" };
            int      seconds    = nbaGame.NbaScore.Seconds;

            if (!caTable.SetDataByLabels(seconds, indexArray))
            {
                string message = $"SetDataByLabels() failed: seconds = {seconds}, indexArray1 = {ConvertIndexArrayToString(indexArray)}";
                Logger.Error(message);
                throw new Exception(message);
            }

            indexArray = new[] { "F" };
            int foul = nbaGame.Foul;

            if (!caTable.SetDataByLabels(foul, indexArray))
            {
                string message = $"SetDataByLabels() failed: foul = {foul}, indexArray2 = {ConvertIndexArrayToString(indexArray)}";
                throw new Exception(message);
            }

            indexArray = new[] { "P" };
            string possession = $"{nbaGame.Possession}";

            Logger.Info($"possession = {possession}, indexArray3 = {ConvertIndexArrayToString(indexArray)}");

            // todo bug here
            if (!caTable.SetDataByLabels(possession, indexArray))
            {
                throw new Exception($"SetDataByLabels() failed: possession = {possession}, indexArray3 = {ConvertIndexArrayToString(indexArray)}");
            }

            if (!caTable.Update())
            {
                throw new Exception("Update() failed");
            }
        }