示例#1
0
 /// <summary>
 /// Trains a new model
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='modelParameters'>
 /// The new model parameters
 /// </param>
 public static Model TrainNewModel(this IModels operations, ModelParameters modelParameters)
 {
     return(System.Threading.Tasks.Task.Factory.StartNew(s => ((IModels)s).TrainNewModelAsync(modelParameters), operations, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskCreationOptions.None, System.Threading.Tasks.TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
示例#2
0
 public Servicio(IModels models)
 {
     this.models = models;
 }
示例#3
0
 private void VerifySourceColumn(Column sourceColumn, string exceptionParamName, IModels sourceModelSet, bool allowsAggregate)
 {
     VerifyScalarSourceModels(sourceModelSet, sourceColumn, exceptionParamName);
     if (allowsAggregate)
     {
         VerifyAggregateSourceModels(sourceColumn, exceptionParamName, sourceModelSet);
     }
     else if (sourceColumn.AggregateSourceModels.Count > 0)
     {
         throw new ArgumentException(DiagnosticMessages.DbQueryBuilder_AggregateNotAllowed, exceptionParamName);
     }
 }
 public TestingBootstrapper([NotNull] ITestOutputHelper output, [NotNull] IModels mockModels)
 {
     this.output = output;
     this.mockModels = mockModels;
 }
 /// <summary>
 /// Get recommendations using the default model
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='usageEvents'>
 /// The usage events to get recommendations for
 /// </param>
 /// <param name='userId'>
 /// An optional id of the user to provide recommendations for. Any stored
 /// usage events associated with this user will be considered when getting
 /// recommendations
 /// </param>
 /// <param name='recommendationCount'>
 /// The number of requested recommendations
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async System.Threading.Tasks.Task <System.Collections.Generic.IList <RecommendationResult> > GetPersonalizedRecommendationsFromDefaultModelAsync(this IModels operations, System.Collections.Generic.IList <UsageEvent> usageEvents, string userId = default(string), int?recommendationCount = default(int?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
 {
     using (var _result = await operations.GetPersonalizedRecommendationsFromDefaultModelWithHttpMessagesAsync(usageEvents, userId, recommendationCount, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Lists all the models
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async System.Threading.Tasks.Task <System.Collections.Generic.IList <Model> > GetModelsAsync(this IModels operations, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
 {
     using (var _result = await operations.GetModelsWithHttpMessagesAsync(null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Lists all the models
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 public static IList <Model> GetModels(this IModels operations)
 {
     return(Task.Factory.StartNew(s => ((IModels)s).GetModelsAsync(), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
 /// <summary>
 /// Lists all the models
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 public static System.Collections.Generic.IList <Model> GetModels(this IModels operations)
 {
     return(System.Threading.Tasks.Task.Factory.StartNew(s => ((IModels)s).GetModelsAsync(), operations, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskCreationOptions.None, System.Threading.Tasks.TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
 /// <summary>
 /// Sets a model as the default model
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='modelId'>
 /// The model id to set as default
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task SetDefaultModelAsync(this IModels operations, Guid modelId, CancellationToken cancellationToken = default(CancellationToken))
 {
     await operations.SetDefaultModelWithHttpMessagesAsync(modelId, null, cancellationToken).ConfigureAwait(false);
 }
示例#10
0
 /// <summary>
 /// Get recommendations using the default model
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='itemId'>
 /// Item id to get recommendations for
 /// </param>
 /// <param name='recommendationCount'>
 /// The number of requested recommendations
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <IList <RecommendationResult> > GetItemRecommendationsFromDefaultModelAsync(this IModels operations, string itemId, int?recommendationCount = default(int?), CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.GetItemRecommendationsFromDefaultModelWithHttpMessagesAsync(itemId, recommendationCount, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
示例#11
0
        async Task ImportTextFile(string filePath, Encoding encoding, int maxElementsInDictionary)
        {
            const int         DefaultBufferSize = 4096;
            const FileOptions DefaultOptions    = FileOptions.Asynchronous | FileOptions.SequentialScan;
            string            nameColumns       = null;
            string            currentRow;
            IModels           models;

            columnNames      = new ModelCommonStore();
            listCommonModels = new List <IModels>(maxElementsInDictionary);

            using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read, DefaultBufferSize, DefaultOptions))
            {
                using (var reader = new StreamReader(stream, encoding))
                {
                    while ((currentRow = await reader.ReadLineAsync())?.Trim()?.Length > 10)
                    {
                        if (nameColumns == null)
                        {
                            importedRows = 0;

                            parsedModel = new ParserRowModelCommon(currentRow);
                            columnNames = parsedModel.MatchColumnToAlias();
                            nameColumns = parsedModel.ImportedColumnName;

                            EvntHeaderReady?.Invoke(this, new BoolEventArgs(true));//cHeader is ready
                        } //first found not_empty_line containes name columns
                        else
                        {
                            parsedModel = new ParserRowModelCommon(currentRow, nameColumns);

                            models = parsedModel?.ConvertRowToModels();

                            if (models?.list?.Count > 0)
                            {
                                importedRows++;
                                listCommonModels.Add(models);

                                if (importedRows > 0 && importedRows % maxElementsInDictionary == 0)
                                {
                                    EvntCollectionFull?.Invoke(this, new BoolEventArgs(true));//collection is full
                                    EvntInfoMessage?.Invoke(this, new TextEventArgs($"lastRow: {currentRow}" +
                                                                                    $"{Environment.NewLine}parsed: {models.ToString()}" +
                                                                                    $"{Environment.NewLine}Ожидаю пока запишутся данные(до 5 сек.)..."));

                                    FileReaderModels.evntWaitHandle.WaitOne(5000);

                                    listCommonModels = new List <IModels>(maxElementsInDictionary);
                                }
                            }
                        }
                    }
                }
            }

            if (listCommonModels?.Count > 0)
            {
                EvntCollectionFull?.Invoke(this, new BoolEventArgs(true));//last part of the collection
                EvntInfoMessage?.Invoke(this, new TextEventArgs($"Ожидаю пока запишется последняя часть данных(до 2 сек.)..."));
                FileReaderModels.evntWaitHandle.WaitOne(2000);
            }
        }
示例#12
0
        private void ImportExcelFile(string filePath, int maxElementsInDictionary)
        {
            string  nameColumns = null;
            string  currentRow;
            IModels models;

            columnNames      = new ModelCommonStore();
            listCommonModels = new List <IModels>(maxElementsInDictionary);
            var fi = new FileInfo(filePath);

            using (var package = new ExcelPackage(fi))
            {
                var workbook  = package.Workbook;
                var worksheet = workbook.Worksheets.First();

                //get the first worksheet in the workbook
                int colCount = worksheet.Dimension.End.Column;  //get Column Count
                int rowCount = worksheet.Dimension.End.Row;     //get row count

                EvntInfoMessage?.Invoke(this, new TextEventArgs($"File contains: {colCount} columns{Environment.NewLine}and {rowCount} rows"));
                for (int row = 1; row <= rowCount; row++)
                {
                    currentRow = string.Empty;
                    for (int col = 1; col <= colCount; col++)
                    {
                        currentRow += $"{worksheet.Cells[row, col]?.Value?.ToString()?.Trim()}|";
                    }

                    currentRow = currentRow?.TrimEnd('|');

                    if (!currentRow.Contains("|"))
                    {
                        continue;
                    }
                    if (nameColumns == null)
                    {
                        importedRows = 0;

                        parsedModel = new ParserRowModelCommon(currentRow);
                        columnNames = parsedModel.MatchColumnToAlias();
                        nameColumns = parsedModel.ImportedColumnName;

                        EvntHeaderReady?.Invoke(this, new BoolEventArgs(true));//cHeader is ready
                    } //first found not_empty_line will be contained name columns
                    else
                    {
                        parsedModel = new ParserRowModelCommon(currentRow, nameColumns);

                        models = parsedModel?.ConvertRowToModels();

                        if (!(models?.list?.Count > 0))
                        {
                            continue;
                        }
                        importedRows++;
                        listCommonModels.Add(models);

                        if (importedRows <= 0 || importedRows % maxElementsInDictionary != 0)
                        {
                            continue;
                        }
                        EvntCollectionFull?.Invoke(this, new BoolEventArgs(true));//collection is full
                        EvntInfoMessage?.Invoke(this, new TextEventArgs($"lastRow: {currentRow}" +
                                                                        $"{Environment.NewLine}parsed: {models.ToString()}" +
                                                                        $"{Environment.NewLine}Ожидаю пока данные запишутся (до 5 сек.)..."));

                        FileReaderModels.evntWaitHandle.WaitOne(5000);
                        listCommonModels = new List <IModels>(maxElementsInDictionary);
                    }
                }
            }

            if (!(listCommonModels?.Count > 0))
            {
                return;
            }
            EvntCollectionFull?.Invoke(this, new BoolEventArgs(true));//last part of the collection
            EvntInfoMessage?.Invoke(this, new TextEventArgs($"Ожидаю пока запишется последняя часть данных (до 5 сек.)..."));
            FileReaderModels.evntWaitHandle.WaitOne(5000);
        }
示例#13
0
 private static void VerifyAggregateSourceModels(Column sourceColumn, string exceptionParamName, IModels modelSet)
 {
     foreach (var model in sourceColumn.AggregateSourceModels)
     {
         if (!modelSet.Contains(model))
         {
             throw new ArgumentException(DiagnosticMessages.DbQueryBuilder_InvalidAggregateSourceModel(model), exceptionParamName);
         }
     }
 }
 /// <summary>
 /// Sets a model as the default model
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='modelId'>
 /// The model id to set as default
 /// </param>
 public static void SetDefaultModel(this IModels operations, System.Guid modelId)
 {
     System.Threading.Tasks.Task.Factory.StartNew(s => ((IModels)s).SetDefaultModelAsync(modelId), operations, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskCreationOptions.None, System.Threading.Tasks.TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
示例#15
0
 /// <summary>
 /// Get recommendations using the default model
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='usageEvents'>
 /// The usage events to get recommendations for
 /// </param>
 /// <param name='userId'>
 /// An optional id of the user to provide recommendations for. Any stored
 /// usage events associated with this user will be considered when getting
 /// recommendations
 /// </param>
 /// <param name='recommendationCount'>
 /// The number of requested recommendations
 /// </param>
 public static IList <RecommendationResult> GetPersonalizedRecommendationsFromDefaultModel(this IModels operations, IList <UsageEvent> usageEvents, string userId = default(string), int?recommendationCount = default(int?))
 {
     return(Task.Factory.StartNew(s => ((IModels)s).GetPersonalizedRecommendationsFromDefaultModelAsync(usageEvents, userId, recommendationCount), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
 /// <summary>
 /// Sets a model as the default model
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='modelId'>
 /// The model id to set as default
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async System.Threading.Tasks.Task SetDefaultModelAsync(this IModels operations, System.Guid modelId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
 {
     await operations.SetDefaultModelWithHttpMessagesAsync(modelId, null, cancellationToken).ConfigureAwait(false);
 }
示例#17
0
 /// <summary>
 /// Get recommendations using the requested model
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='modelId'>
 /// The model id to use when scoring
 /// </param>
 /// <param name='itemId'>
 /// Item id to get recommendations for
 /// </param>
 /// <param name='recommendationCount'>
 /// The number of requested recommendations
 /// </param>
 public static IList <RecommendationResult> GetItemRecommendations(this IModels operations, Guid modelId, string itemId, int?recommendationCount = default(int?))
 {
     return(Task.Factory.StartNew(s => ((IModels)s).GetItemRecommendationsAsync(modelId, itemId, recommendationCount), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
 /// <summary>
 /// Get recommendations using the default model
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='itemId'>
 /// Item id to get recommendations for
 /// </param>
 /// <param name='recommendationCount'>
 /// The number of requested recommendations
 /// </param>
 public static System.Collections.Generic.IList <RecommendationResult> GetItemRecommendationsFromDefaultModel(this IModels operations, string itemId, int?recommendationCount = default(int?))
 {
     return(System.Threading.Tasks.Task.Factory.StartNew(s => ((IModels)s).GetItemRecommendationsFromDefaultModelAsync(itemId, recommendationCount), operations, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskCreationOptions.None, System.Threading.Tasks.TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
示例#19
0
 /// <summary>
 /// Get recommendations using the requested model
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='modelId'>
 /// The model id to use when scoring
 /// </param>
 /// <param name='usageEvents'>
 /// The usage events to get recommendations for
 /// </param>
 /// <param name='userId'>
 /// An optional id of the user to provide recommendations for. Any stored
 /// usage events associated with this user will be considered when getting
 /// recommendations
 /// </param>
 /// <param name='recommendationCount'>
 /// The number of requested recommendations
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <IList <RecommendationResult> > GetPersonalizedRecommendationsAsync(this IModels operations, Guid modelId, IList <UsageEvent> usageEvents, string userId = default(string), int?recommendationCount = default(int?), CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.GetPersonalizedRecommendationsWithHttpMessagesAsync(modelId, usageEvents, userId, recommendationCount, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Get recommendations using the requested model
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='modelId'>
 /// The model id to use when scoring
 /// </param>
 /// <param name='itemId'>
 /// Item id to get recommendations for
 /// </param>
 /// <param name='recommendationCount'>
 /// The number of requested recommendations
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async System.Threading.Tasks.Task <System.Collections.Generic.IList <RecommendationResult> > GetItemRecommendationsAsync(this IModels operations, System.Guid modelId, string itemId, int?recommendationCount = default(int?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
 {
     using (var _result = await operations.GetItemRecommendationsWithHttpMessagesAsync(modelId, itemId, recommendationCount, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
示例#21
0
 /// <summary>
 /// Gets a model by id
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='modelId'>
 /// The model id to retrieve
 /// </param>
 public static Model GetModel(this IModels operations, Guid modelId)
 {
     return(Task.Factory.StartNew(s => ((IModels)s).GetModelAsync(modelId), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
 /// <summary>
 /// Get recommendations using the requested model
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='modelId'>
 /// The model id to use when scoring
 /// </param>
 /// <param name='usageEvents'>
 /// The usage events to get recommendations for
 /// </param>
 /// <param name='userId'>
 /// An optional id of the user to provide recommendations for. Any stored
 /// usage events associated with this user will be considered when getting
 /// recommendations
 /// </param>
 /// <param name='recommendationCount'>
 /// The number of requested recommendations
 /// </param>
 public static System.Collections.Generic.IList <RecommendationResult> GetPersonalizedRecommendations(this IModels operations, System.Guid modelId, System.Collections.Generic.IList <UsageEvent> usageEvents, string userId = default(string), int?recommendationCount = default(int?))
 {
     return(System.Threading.Tasks.Task.Factory.StartNew(s => ((IModels)s).GetPersonalizedRecommendationsAsync(modelId, usageEvents, userId, recommendationCount), operations, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskCreationOptions.None, System.Threading.Tasks.TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
示例#23
0
 internal static Base ContravariantFunction(IModels param)
 {
     return(param as Base);
 }