I store custom outcomes in interaction repository and want to build projection model for my machine learning model.

public class PurchaseInvoiceOutcome
    public string ProductId { get; set; }
    public decimal Price { get; set; }
    public int Quantity { get; set; }
    public DateTime TimeStamp { get; set; }

I need grouped data that looks like:

ProductId: product identifier

Year: grouping by year

Month: grouping by month

Units: total amount of product units sold in month

Max: max amount of product units sold per order

Min: min amount of product units sold per order

Avr: average amount of product units sold per order

I want to achieve following grouping (LINQ example):

.GroupBy(x => new { x.ProductId, x.TimeStamp.Year, x.TimeStamp.Month })
.Select(x => new ProductStats
    ProductId  = x.Key.ProductId,
    Year = x.Key.Year,
    Month = x.Key.Month,

    Units = x.Sum(y => y.Quantity),
    Max = x.Max(y => y.Quantity)
    Min = x.Min(y => y.Quantity),
    Avg = (int)Math.Ceiling(x.Average(y => y.Quantity)),

My projection looks like:

Projection = Sitecore.Processing.Engine.Projection.Projection.Of<Interaction>()
                interaction => interaction.Events.OfType<PurchaseInvoiceOutcome>(),
                cfg => cfg

                .Key("ProductId", x => x.ProductId)
                .Key("Year", x => x.Timestamp.Year)
                .Key("Month", x => x.Timestamp.Month)
                    .Measure("Count", x => 1)
                    .Measure("Units", x => x.Quantity)
                    //.Measure("Max", x => Min(x.Quantity))
                    //.Measure("Min", x => Max(x.Quantity))
                    //.Measure("Avr", x => Average(x.Quantity))

As I know "Measure" property can only calculates sum of grouping items. As a workaround I can calculate Average by projecting Count and Units and then calculate Units/Count.

But I have no idea how to calculate Min and Max. I know that as a workaround I can remove grouping in projection and move this part of job to training worker, but I don`t want to increase projection data set.

Do you have any suggestions how to implement above scenario? Any advice would be much appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.