public override bool SetValues(ProcessingScope scope, IList<object> row) { if (_fields.Count == 0) return false; var index = 0; //Get metrics from current DimensionData (EaTableMapper) or calculate from context var metrics = scope.Current<DimensionData>().TryGet(data => data.MetricsValue) ?? scope.Current<IVisitAggregationContext>().TryGet(XaHelpers.CalculateMetrics); if (metrics != null) { if (FactTypes.HasFlag(FactTypes.Visits)) row[index++] = metrics.Visits; if (FactTypes.HasFlag(FactTypes.Value)) row[index++] = metrics.Value; if (FactTypes.HasFlag(FactTypes.Bounces)) row[index++] = metrics.Bounces; if (FactTypes.HasFlag(FactTypes.Conversions)) row[index++] = metrics.Conversions; if (FactTypes.HasFlag(FactTypes.TimeOnSite)) row[index++] = metrics.TimeOnSite; if (FactTypes.HasFlag(FactTypes.PageViews)) row[index++] = metrics.Pageviews; if (FactTypes.HasFlag(FactTypes.Count)) row[index++] = metrics.Count; return true; } return false; }
public bool SetValues(ProcessingScope scope, IList<object> target) { if (Value != null) { target[0] = Value; return true; } return false; }
protected virtual DimensionData GetDimensionDataFromContext(ProcessingScope context) { var ctx = context.Current<IVisitAggregationContext>(); if (ctx != null) { return Dimension.GetData(ctx).FirstOrDefault(); } return null; }
public void SimpleIndexIncrement() { var scope = new ProcessingScope(); scope.Set(new Level1()); Assert.AreEqual(1, scope.Index<Level1>()); scope.Set(new Level1()); Assert.AreEqual(2, scope.Index<Level1>()); }
public virtual void Process(ProcessingScope context) { //Increment indices relative to table mapper var childScope = context.CreateChildScope(this); foreach (var item in SelectRowItems(context)) { BuildRows(childScope.Set(item)); } }
public override bool SetValues(ProcessingScope scope, IList<object> row) { var val = Selector(scope); if (val != null) { row[0] = val; return true; } return false; }
protected override IEnumerable SelectRowItems(ProcessingScope context) { var ctx = context.Current<IVisitAggregationContext>(); if (ctx != null) { return Dimension.GetData(ctx).Where(d => d != null); } return Enumerable.Empty<object>(); }
public void Process(ProcessingScope context) { var i = 0; foreach (var split in Splitter.GetSplits(context)) { using (context.Swap(split)) { TableMappers[i++].Process(context); } } }
public override bool SetValues(ProcessingScope scope, IList<object> row) { var dimensionData = GetDimensionDataFromContext(scope); if (dimensionData != null) { row[0] = dimensionData.DimensionKey; return true; } return false; }
public bool AddRowFromContext(ProcessingScope context) { CurrentRow = null; var data = CreateEmptyRow(); if (SetValues(context, data)) { CurrentRow = AddData(data); return true; } return false; }
public override bool SetValues(ProcessingScope scope, IList<object> row) { var i = 0; var any = false; foreach (var split in Splitter.GetSplits(scope)) { using (scope.Swap(split)) { any = _iterators[i++].SetValues(row, scope) || any; } } return any; }
public void Process(IEnumerable data) { if (!_initialized) { Initialize(); } var scope = new ProcessingScope() { FieldLookup = FieldLookup }; scope.Set(WrapItems(data)); TableMapper.Process(scope); }
public void ReturnCorrectObject() { var scope = new ProcessingScope(); var o1 = new Level1(); var o2 = new Level1(); var o2_1 = new Level2(); scope.Set(o1); Assert.AreSame(o1, scope.Current<Level1>()); scope.Set(o2); Assert.AreSame(o2, scope.Current<Level1>()); var childScope = scope.CreateChildScope(new DummyMapper()).Set(o2_1); Assert.AreSame(o2_1, childScope.Current<Level2>()); Assert.AreSame(o2, childScope.Current<Level1>()); }
public override bool SetValues(ProcessingScope scope, IList<object> target) { var testPage = scope.Current<IVisitAggregationContext>().TryGet(v => v.Visit.Pages.FirstOrDefault(p => p.MvTest != null && p.MvTest.Id == TestSet.Id)); if (testPage != null) { var i = 0; foreach (var variable in TestSet.Variables) { var value = testPage.MvTest.Combination[i]; target[i * 2] = value; target[i * 2 + 1] = variable.Values[value].Label; ++i; } return true; } return false; }
public override bool SetValues(ProcessingScope scope, IList<object> row) { var ce = CalculateForEntireVisit ? null : scope.Current<PageEventData>(); var cp = CalculateForEntireVisit ? null : scope.Current<PageData>(); var cv = scope.Current<IVisitAggregationContext>().TryGet(v => v.Visit); if (cv == null) return false; var es = ce != null ? new[] { ce } : cp != null ? cp.PageEvents.OrEmpty() : cv.Pages.OrEmpty().SelectMany(p => p.PageEvents.OrEmpty()); var ps = cp != null ? new[] { cp } : cv.Pages.OrEmpty(); es = es.Where(e => e.IsGoal); var index = 0; if (FactTypes.HasFlag(FactTypes.Visits)) row[index++] = scope.OncePerScope<IVisitAggregationContext>(1); if (FactTypes.HasFlag(FactTypes.Value)) row[index++] = es.Sum(e => e.Value); if (FactTypes.HasFlag(FactTypes.Bounces)) row[index++] = cv.Pages.TryGet(_ => _.Count == 1 ? 1 : 0); if (FactTypes.HasFlag(FactTypes.Conversions)) row[index++] = es.Count(); if (FactTypes.HasFlag(FactTypes.TimeOnSite)) row[index++] = ps.Sum(p => DimensionBase.ConvertDuration(p.Duration)); if (FactTypes.HasFlag(FactTypes.PageViews)) row[index++] = cp != null ? scope.OncePerScope<PageData>(1) : ps.Count(); if (CalculateForEntireVisit) { for (var i = 0; i < index; i++) { if (!(row[i] is IDeferedValue)) { row[i] = scope.OncePerScope<IVisitAggregationContext>(row[i]); } } } if (FactTypes.HasFlag(FactTypes.Count)) row[index++] = 1; return true; }
public override bool SetValues(ProcessingScope scope, IList<object> target) { var values = Selector(scope); if (values == null) return false; var quotedValues = values.Cast<object>().Where(s => s != null).Select(s => "'" + s.ToString().Replace("'", @"\'") + "'").ToArray(); if (Type == SequenceType.Path) { target[0] = string.Join(",", quotedValues); } else if (Type == SequenceType.Set) { target[0] = string.Join(",", new HashSet<string>(quotedValues).OrderBy(s => s)); } else { target[0] = string.Join(",", quotedValues .ToLookup(s => s).OrderBy(kv => kv.Key).Select(kv => kv.Key + ": " + kv.Count())); } return true; }
public override bool SetValues(ProcessingScope scope, IList<object> target) { return Key.SetValues(scope, target); }
public IEnumerable<object> GetSplits(ProcessingScope scope) { return Selector(scope.CurrentObject); }
protected override IEnumerable SelectRowItems(ProcessingScope context) { return(Selector(context)); }
protected override DimensionData GetDimensionDataFromContext(ProcessingScope context) { return context.Current<DimensionData>(); }
public override bool SetValues(ProcessingScope scope, IList<object> row) { if (InlineFields) { return SetValues(FieldTarget.Inline, scope, row); } else { if (!LookupTableBuilder.AddRowFromContext(scope)) { return false; } return SetValues(FieldTarget.KeyReference, scope, row); } }
protected abstract IEnumerable SelectRowItems(ProcessingScope context);
public bool SetValues(IList<object> target, ProcessingScope context) { return Apply(target, (mapper, mapperTarget) => mapper.SetValues(context, mapperTarget)); }
protected virtual void BuildRows(ProcessingScope context) { foreach (var builderInfo in Builders) { //Add a row to each table builder if (builderInfo.Builder == null || builderInfo.Builder.AddRowFromContext(context)) { //Process nested table mappers foreach (var child in builderInfo.Children) { child.Process(context); } } } }
protected virtual bool SetValues(ProcessingScope context, object[] data) { return Iterator.SetValues(data, context); }
protected override DimensionData GetDimensionDataFromContext(ProcessingScope context) { return(context.Current <DimensionData>()); }
public IEnumerable <object> GetSplits(ProcessingScope scope) { var visitContext = scope.Current <IVisitAggregationContext>(); var vd = visitContext.Visit; var originalVisitPageCount = vd.VisitPageCount; var originalValue = vd.Value; var all = vd.Pages.ToList(); var lists = Enumerable.Range(0, Conditions.Length + 1).Select(c => new List <PageData>()).ToArray(); var targetIndex = 0; foreach (var page in all) { if (IncludeMatchBefore) { lists[targetIndex].Add(page); } if (targetIndex < Conditions.Length && Conditions[targetIndex](scope, page)) { ++targetIndex; } if (!IncludeMatchBefore) { lists[targetIndex].Add(page); } } if (targetIndex < lists.Length - 1 && EmptyIfConditionNotMet) { //All conditions were not met. Clear all lists foreach (var list in lists) { list.Clear(); } } var vals = new int[lists.Length]; var ix = 0; foreach (var list in lists) { vd.Pages = list; vd.VisitPageCount = list.Count; vd.Value = visitContext.Visit.Pages.Sum(p => p.PageEvents.Sum(pe => pe.Value)); vals[ix++] = vd.Value; yield return(visitContext); } vd.Pages = all; vd.VisitPageCount = originalVisitPageCount; vd.Value = originalValue; if (IncludeTotal) { yield return(visitContext); } }
protected override IEnumerable SelectRowItems(ProcessingScope context) { yield break; }
public void TestNesting() { var scope1 = new ProcessingScope(); var scope2 = scope1.CreateChildScope(new DummyMapper()); var scope3 = scope2.CreateChildScope(new DummyMapper()); var o1 = new Level1(); var o1_1 = new Level2(); var o1_1_1 = new Level3(); var o1_1_2 = new Level3(); var o1_2 = new Level2(); var o2 = new Level1(); var o2_1 = new Level2(); var o3 = new Level1(); var o3_1 = new Level2(); var o3_2 = new Level2(); var o3_2_1 = new Level3(); var o3_3 = new Level2(); var o3_3_1 = new Level3(); var o3_3_2 = new Level3(); scope1.Set(o1); Assert.AreEqual(1, scope1.GlobalIndex); scope2.Set(o1_1); Assert.AreEqual(1, scope2.Index<Level1>()); Assert.AreEqual(1, scope2.Index<Level2>()); scope3.Set(o1_1_1); Assert.AreEqual(1, scope3.Index<Level1>()); Assert.AreEqual(1, scope3.Index<Level2>()); Assert.AreEqual(1, scope3.Index<Level3>()); scope3.Set(o1_1_2); Assert.AreEqual(2, scope3.Index<Level1>()); Assert.AreEqual(2, scope3.Index<Level2>()); Assert.AreEqual(2, scope3.Index<Level3>()); Assert.AreEqual(2, scope3.ChildIndex); Assert.AreEqual(2, scope3.GlobalIndex); scope2.Set(o1_2); Assert.AreEqual(2, scope2.Index<Level1>()); Assert.AreEqual(2, scope2.Index<Level2>()); Assert.AreEqual(2, scope2.ChildIndex); Assert.AreEqual(2, scope3.GlobalIndex); scope1.Set(o2); Assert.AreEqual(2, scope1.GlobalIndex); scope2 = scope2.Set(o2_1); Assert.AreEqual(1, scope2.Index<Level1>()); Assert.AreEqual(3, scope2.GlobalIndex); scope1.Set(o3); Assert.AreEqual(3, scope1.GlobalIndex); scope2 = scope2.Set(o3_1); Assert.AreEqual(1, scope2.Index<Level1>()); Assert.AreEqual(4, scope2.GlobalIndex); scope2.Set(o3_2); Assert.AreEqual(2, scope2.Index<Level1>()); Assert.AreEqual(5, scope2.GlobalIndex); scope3.Set(o3_2_1); Assert.AreEqual(1, scope3.Index<Level1>()); Assert.AreEqual(1, scope3.Index<Level2>()); Assert.AreEqual(3, scope3.GlobalIndex); scope2.Set(o3_3); Assert.AreEqual(3, scope2.Index<Level1>()); Assert.AreEqual(6, scope2.GlobalIndex); scope3.Set(o3_3_1); Assert.AreEqual(2, scope3.Index<Level1>()); Assert.AreEqual(1, scope3.Index<Level2>()); Assert.AreEqual(4, scope3.GlobalIndex); scope3.Set(o3_3_2); Assert.AreEqual(3, scope3.Index<Level1>()); Assert.AreEqual(2, scope3.Index<Level2>()); Assert.AreEqual(5, scope3.GlobalIndex); //Check that the objects are correctly assigned Assert.AreSame(o3, scope3.Current<Level1>()); Assert.AreSame(o3_3, scope3.Current<Level2>()); Assert.AreSame(o3_3_2, scope3.Current<Level3>()); Assert.AreSame(o3, scope2.Current<Level1>()); Assert.AreSame(o3_3, scope2.Current<Level2>()); Assert.AreSame(o3, scope1.Current<Level1>()); }
public abstract bool SetValues(ProcessingScope scope, IList<object> target);
public void ScopeCanBeNull() { var scope = new ProcessingScope(); Assert.IsNull(scope.Current<Level1>()); }
protected bool SetValues(FieldTarget target, ProcessingScope context, IList<object> row) { switch (target) { case FieldTarget.Inline: return _iterator.SetValues(row, context); case FieldTarget.KeyReference: var i = 0; foreach(var key in LookupTableBuilder.Schema.Keys) { row[i] = LookupTableBuilder.CurrentRow[key.Index]; ++i; } return true; } throw new ArgumentOutOfRangeException("target"); }
protected override IEnumerable SelectRowItems(ProcessingScope context) { return Selector(context); }
public override bool SetValues(ProcessingScope scope, IList <object> row) { var ce = CalculateForEntireVisit ? null : scope.Current <PageEventData>(); var cp = CalculateForEntireVisit ? null : scope.Current <PageData>(); var cv = scope.Current <IVisitAggregationContext>().TryGet(v => v.Visit); if (cv == null) { return(false); } var es = ce != null ? new[] { ce } : cp != null?cp.PageEvents.OrEmpty() : cv.Pages.OrEmpty().SelectMany(p => p.PageEvents.OrEmpty()); var ps = cp != null ? new[] { cp } : cv.Pages.OrEmpty(); es = es.Where(e => e.IsGoal); var index = 0; if (FactTypes.HasFlag(FactTypes.Visits)) { row[index++] = scope.OncePerScope <IVisitAggregationContext>(1); } if (FactTypes.HasFlag(FactTypes.Value)) { row[index++] = es.Sum(e => e.Value); } if (FactTypes.HasFlag(FactTypes.Bounces)) { row[index++] = cv.Pages.TryGet(_ => _.Count == 1 ? 1 : 0); } if (FactTypes.HasFlag(FactTypes.Conversions)) { row[index++] = es.Count(); } if (FactTypes.HasFlag(FactTypes.TimeOnSite)) { row[index++] = ps.Sum(p => DimensionBase.ConvertDuration(p.Duration)); } if (FactTypes.HasFlag(FactTypes.PageViews)) { row[index++] = cp != null?scope.OncePerScope <PageData>(1) : ps.Count(); } if (CalculateForEntireVisit) { for (var i = 0; i < index; i++) { if (!(row[i] is IDeferedValue)) { row[i] = scope.OncePerScope <IVisitAggregationContext>(row[i]); } } } if (FactTypes.HasFlag(FactTypes.Count)) { row[index++] = 1; } return(true); }