/// <summary>
        /// Save recommendation prediction result using model parameters.
        /// </summary>
        /// <param name="modelConfig">Model config.</param>
        /// <param name="predictionResult">Prediction result.</param>
        public virtual void SaveRecommendationPrediction(MLModelConfig modelConfig,
                                                         RecommendationResponse predictionResult)
        {
            EntitySchema       schema           = _userConnection.EntitySchemaManager.GetInstanceByUId(modelConfig.CFResultSchemaUId);
            var                entityCollection = new EntityCollection(_userConnection, schema);
            EntitySchemaColumn userColumn       = schema.GetSchemaColumnByPath(modelConfig.CFResultUserColumnName);
            EntitySchemaColumn itemColumn       = schema.GetSchemaColumnByPath(modelConfig.CFResultItemColumnName);
            EntitySchemaColumn valueColumn      = modelConfig.CFResultValueColumnName.IsNotNullOrWhiteSpace()
                                ? schema.FindSchemaColumnByPath(modelConfig.CFResultValueColumnName)
                                : null;
            EntitySchemaColumn modelColumn = modelConfig.CFResultModelColumnName.IsNotNullOrWhiteSpace()
                                ? schema.FindSchemaColumnByPath(modelConfig.CFResultModelColumnName)
                                : null;
            EntitySchemaColumn timestampColumn = modelConfig.CFResultTimestampColumnName.IsNotNullOrWhiteSpace()
                                ? schema.FindSchemaColumnByPath(modelConfig.CFResultTimestampColumnName)
                                : null;

            foreach (RecommendationOutput output in predictionResult.Outputs)
            {
                foreach (RecommendedItem item in output.Items)
                {
                    Entity entity = schema.CreateEntity(_userConnection);
                    entity.UseAdminRights = UseAdminRights;
                    entity.SetColumnValue("Id", Guid.NewGuid());
                    entity.SetColumnValue(userColumn, output.UserId);
                    entity.SetColumnValue(itemColumn, item.ItemId);
                    if (valueColumn != null)
                    {
                        entity.SetColumnValue(valueColumn, item.Score);
                    }
                    if (modelColumn != null)
                    {
                        entity.SetColumnValue(modelColumn, modelConfig.Id);
                    }
                    if (timestampColumn != null)
                    {
                        entity.SetColumnValue(timestampColumn, DateTime.UtcNow);
                    }
                    entityCollection.Add(entity);
                }
            }
            entityCollection.Save();
        }
Esempio n. 2
0
        private JObject GetGridColumnConfig(EntitySchema entitySchema, string columnPath)
        {
            EntitySchemaColumn column = entitySchema.FindSchemaColumnByPath(columnPath);
            var data = new JObject();

            data.Add(new JProperty("caption", (string)column.Caption));
            data.Add(new JProperty("metaPath", columnPath));
            DataValueType columnValueType = column.DataValueType;

            data.Add(new JProperty("dataValueType", (int)Nui.ServiceModel.Extensions.DataValueTypeExtension.ToEnum(columnValueType)));
            return(data);
        }
        private Dictionary <string, object> GetPredictionInputData(Entity entity,
                                                                   List <ColumnMapItem> entityColumnPathMap)
        {
            var          result = new Dictionary <string, object>();
            EntitySchema schema = entity.Schema;

            foreach (ColumnMapItem item in entityColumnPathMap)
            {
                var    column = schema.FindSchemaColumnByPath(item.Path);
                object value  = entity.GetColumnValue(column);
                result.Add(item.Alias, value);
            }
            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// Gets a column configuration object for displaying data.
        /// </summary>
        /// <param name="entitySchema">Schema of column.</param>
        /// <param name="columnPath">Column path.</param>
        /// <returns>Column config.</returns>
        public static JObject GetGridColumnConfig(EntitySchema entitySchema, string columnPath)
        {
            EntitySchemaColumn column = entitySchema.FindSchemaColumnByPath(columnPath);
            var data = new JObject();

            data.Add(new JProperty("caption", (string)column.Caption));
            data.Add(new JProperty("metaPath", columnPath));
            Terrasoft.Core.DataValueType columnValueType = column.DataValueType;
            data.Add(new JProperty("dataValueType", (int)Nui.ServiceModel.Extensions.DataValueTypeExtension.ToEnum(columnValueType)));
            if (column.ReferenceSchema != null)
            {
                data.Add(new JProperty("referenceSchemaName", column.ReferenceSchema.Name));
            }
            return(data);
        }
Esempio n. 5
0
        private void SetReferenceSchemaNames(string rootSchemaName, JArray gridColumns)
        {
            EntitySchema entitySchema = null;

            foreach (JObject columnItem in gridColumns)
            {
                if (columnItem.Value <int>("dataValueType") == (int)Terrasoft.Nui.ServiceModel.DataContract.DataValueType.Lookup &&
                    string.IsNullOrEmpty(columnItem.Value <string>("referenceSchemaName")))
                {
                    string columnPath = DashboardDataUtils.GetColumnPath(columnItem);
                    columnPath = DashboardDataUtils.ClearColumnPathSuffix(columnPath);
                    if (entitySchema == null)
                    {
                        entitySchema = UserConnection.EntitySchemaManager.GetInstanceByName(rootSchemaName);
                    }
                    EntitySchemaColumn column = entitySchema.FindSchemaColumnByPath(columnPath);
                    if (column.ReferenceSchema != null)
                    {
                        columnItem["referenceSchemaName"] = column.ReferenceSchema.Name;
                    }
                }
            }
        }