public static async Task RegisterForecastTaskChainAsync(
            this ITaskManager taskManager,
            TimeSpan expiresAfter)
        {
            // Define workers parameters

            // datasource for PurchaseOutcomeModel projection
            var interactionDataSourceOptionsDictionary = new InteractionDataSourceOptionsDictionary(new InteractionExpandOptions(IpInfo.DefaultFacetKey), 5, 10);

            var modelTrainingOptions = new ModelTrainingTaskOptions(
                // assembly name of our processing engine model (PurchaseInteractionModel:IModel<Interaction>)
                typeof(PurchaseInteractionModel).AssemblyQualifiedName,
                // assembly name of entity for our processing engine model  (PurchaseInteractionModel:IModel<Interaction>)
                typeof(Interaction).AssemblyQualifiedName,
                // custom options that we pass to PurchaseInteractionModel
                new Dictionary <string, string> {
                ["TestCaseId"] = "Id"
            },
                // projection tableName of PurchaseOutcomeModel, must be equal to first parameter of 'CreateTabular' method => PurchaseInteractionModel.cs: CreateTabular("PurchaseOutcome", ...)
                "PurchaseOutcome",
                // name of resulted table (any name)
                "DemoResultTable");

            await taskManager.RegisterModelTrainingTaskChainAsync(modelTrainingOptions,
                                                                  interactionDataSourceOptionsDictionary, expiresAfter);
        }
        public async Task <ActionResult> RegisterInteractionsExportToJson()
        {
            using (IXdbContext client = SitecoreXConnectClientConfiguration.GetClient())
            {
                var interactionFacets = client.Model.Facets.Where(c => c.Target == EntityType.Interaction).Select(x => x.Name);
                var contactFacets     = client.Model.Facets.Where(c => c.Target == EntityType.Contact).Select(x => x.Name);

                var expandOptions = new InteractionExpandOptions(interactionFacets.ToArray())
                {
                    Contact = new RelatedContactExpandOptions(contactFacets.ToArray())
                };

                InteractionDataSourceOptionsDictionary interactionDataSourceOptionsDictionary =
                    new InteractionDataSourceOptionsDictionary(expandOptions, 1000, 1000);

                var workerOptions = new Dictionary <string, string>();

                var taskId = await _taskManager.RegisterDistributedTaskAsync(
                    interactionDataSourceOptionsDictionary,
                    new DistributedWorkerOptionsDictionary(
                        "XcExport.Cortex.Workers.ExportInteractionsToJson, XcExport.Cortex", workerOptions),
                    null,
                    TimeSpan.FromHours(1));

                return(Json(new { TaskId = taskId.ToString() }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 3
0
        public async Task RegisterAll()
        {
            try
            {
                var taskManager = ServiceLocator.ServiceProvider.GetService <ITaskManager>();

                var dataSourceOptions    = new InteractionDataSourceOptionsDictionary(new InteractionExpandOptions(IpInfo.DefaultFacetKey), 5, 10);
                var modelTrainingOptions = new ModelTrainingTaskOptions(typeof(GoalsProjectionModel).AssemblyQualifiedName, typeof(Interaction).AssemblyQualifiedName, new Dictionary <string, string> {
                    ["TestCaseId"] = "Id"
                }, Constants.DemoGoal.ProjectionTableName, Constants.DemoGoal.ProjectionResultTableName);

                var x = await taskManager.RegisterRfmModelTrainingTaskChainAsync(modelTrainingOptions, dataSourceOptions, TimeSpan.FromHours(5));

                Log.Info("TaskAgent RegisterAll taskId=" + x, this);
            }
            catch (Exception ex)
            {
                Log.Error("TaskAgent RegisterAll exception", ex, this);
            }
        }
Exemplo n.º 4
0
        public static async Task RegisterRfmModelTaskChainAsync(
            this ITaskManager taskManager,
            TimeSpan expiresAfter)
        {
            // Define workers parameters

            // datasource for PurchaseOutcomeModel projection
            var interactionDataSourceOptionsDictionary = new InteractionDataSourceOptionsDictionary(new InteractionExpandOptions(IpInfo.DefaultFacetKey), 5, 10);
            // datasource for ContactModel protection
            var contactDataSourceOptionsDictionary = new ContactDataSourceOptionsDictionary(new ContactExpandOptions(PersonalInformation.DefaultFacetKey,
                                                                                                                     EmailAddressList.DefaultFacetKey,
                                                                                                                     ContactBehaviorProfile.DefaultFacetKey,
                                                                                                                     RfmContactFacet.DefaultFacetKey)
                                                                                            , 5, 10);

            var modelTrainingOptions = new ModelTrainingTaskOptions(
                // assembly name of our processing engine model (PurchaseInteractionModel:IModel<Interaction>)
                typeof(PurchaseInteractionModel).AssemblyQualifiedName,
                // assembly name of entity for our processing engine model  (PurchaseInteractionModel:IModel<Interaction>)
                typeof(Interaction).AssemblyQualifiedName,
                // custom options that we pass to PurchaseInteractionModel
                new Dictionary <string, string> {
                ["TestCaseId"] = "Id"
            },
                // projection tableName of PurchaseOutcomeModel, must be equal to first parameter of 'CreateTabular' method => PurchaseOutcomeModel.cs: CreateTabular("PurchaseOutcome", ...)
                "PurchaseOutcome",
                // name of resulted table (any name)
                "DemoResultTable");

            var projectionDictionary = new ProjectionWorkerOptionsDictionary(
                modelTrainingOptions.ModelEntityTypeString,
                modelTrainingOptions.ModelTypeString, expiresAfter, modelTrainingOptions.SchemaName,
                modelTrainingOptions.ModelOptions);


            var evaluationDictionary = new EvaluationWorkerOptionsDictionary(
                typeof(RfmEvaluationWorker).AssemblyQualifiedName,
                typeof(ContactModel).AssemblyQualifiedName,
                new Dictionary <string, string> {
                ["TestCaseId"] = "Id"
            },
                "Evaluator.Schema",
                expiresAfter);


            // Register chain of Tasks

            // 1) Register Projection-worker
            Guid projectionTaskId = await taskManager.RegisterDistributedTaskAsync(
                interactionDataSourceOptionsDictionary,
                projectionDictionary,
                // no prerequisite tasks
                Enumerable.Empty <Guid>(),
                expiresAfter).ConfigureAwait(false);

            // 2) Register Merge-worker
            var mergeTaskIds = new List <Task <Guid> >();

            foreach (var targetTableNames in modelTrainingOptions.SourceTargetTableNamesMap)
            {
                var mergeWorkerOptionsDictionary = new MergeWorkerOptionsDictionary(targetTableNames.Value, targetTableNames.Key, expiresAfter, modelTrainingOptions.SchemaName);
                mergeTaskIds.Add(
                    taskManager.RegisterDeferredTaskAsync(
                        mergeWorkerOptionsDictionary,
                        // execute after Projection task
                        new[] { projectionTaskId },
                        expiresAfter));
            }
            await Task.WhenAll(mergeTaskIds).ConfigureAwait(false);


            // 3) Register Train-worker
            var trainWorkerOptionsDictionary = new RfmTrainingWorkerOptionsDictionary(
                modelTrainingOptions.ModelEntityTypeString,
                modelTrainingOptions.ModelTypeString,
                modelTrainingOptions.SchemaName,
                modelTrainingOptions.SourceTargetTableNamesMap.Values.ToList(),
                modelTrainingOptions.ModelOptions);

            Guid trainTaskId = await taskManager.RegisterDeferredTaskAsync(
                trainWorkerOptionsDictionary,
                // execute after Merge task
                mergeTaskIds.Select(t => t.Result),
                expiresAfter).ConfigureAwait(false);

            // 4) Register Evaluate worker
            Guid evaluateTaskId = await taskManager.RegisterDistributedTaskAsync(
                contactDataSourceOptionsDictionary,
                evaluationDictionary,
                // execute after Train worker
                new[] { trainTaskId },
                expiresAfter)
                                  .ConfigureAwait(false);
        }