Skip to content

Commit

Permalink
Merge branch 'feature/group-by_with_predicates_bis_(#380)' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	NBi.NUnit/Builder/ResultSetRowCountBuilder.cs
#	NBi.Testing/Acceptance/Resources/Positive/ResultSetConstraint.nbits
  • Loading branch information
Cédric L. Charlier committed Nov 21, 2019
2 parents 431c372 + ecb907e commit d62b742
Show file tree
Hide file tree
Showing 99 changed files with 1,688 additions and 1,028 deletions.
20 changes: 11 additions & 9 deletions NBi.Core/Calculation/BaseRankingFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using NBi.Core.Calculation.Ranking.Scoring;
using NBi.Core.Evaluate;
using NBi.Core.ResultSet;
using NBi.Core.ResultSet.Filtering;
using NBi.Core.Variable;
using System;
using System.Collections.Generic;
using System.Data;
Expand All @@ -13,17 +15,17 @@ namespace NBi.Core.Calculation
{
public abstract class BaseRankingFilter : IResultSetFilter
{
protected readonly IColumnIdentifier operand;
protected readonly ColumnType columnType;
protected readonly IEnumerable<IColumnAlias> aliases;
protected readonly IEnumerable<IColumnExpression> expressions;
protected IColumnIdentifier Operand { get; }
protected ColumnType ColumnType { get; }
protected IEnumerable<IColumnAlias> Aliases { get; }
protected IEnumerable<IColumnExpression> Expressions { get; }

protected BaseRankingFilter(IColumnIdentifier operand, ColumnType columnType, IEnumerable<IColumnAlias> aliases, IEnumerable<IColumnExpression> expressions)
{
this.operand = operand;
this.columnType = columnType;
this.aliases = aliases;
this.expressions = expressions;
this.Operand = operand;
this.ColumnType = columnType;
this.Aliases = aliases;
this.Expressions = expressions;
}

public ResultSet.ResultSet AntiApply(ResultSet.ResultSet rs)
Expand All @@ -32,7 +34,7 @@ public ResultSet.ResultSet AntiApply(ResultSet.ResultSet rs)
public ResultSet.ResultSet Apply(ResultSet.ResultSet rs)
{
IList<ScoredObject> subset = new List<ScoredObject>();
var scorer = new DataRowScorer(operand, aliases, expressions);
var scorer = new DataRowScorer(Operand, Aliases, Expressions);
foreach (DataRow row in rs.Rows)
{
var score = scorer.Execute(row);
Expand Down
35 changes: 0 additions & 35 deletions NBi.Core/Calculation/Combination/AndCombinationPredicateFilter.cs

This file was deleted.

43 changes: 0 additions & 43 deletions NBi.Core/Calculation/Combination/BaseCombinationPredicateFilter.cs

This file was deleted.

35 changes: 0 additions & 35 deletions NBi.Core/Calculation/Combination/OrCombinationPredicateFilter.cs

This file was deleted.

34 changes: 0 additions & 34 deletions NBi.Core/Calculation/Combination/XOrCombinationPredicateFilter.cs

This file was deleted.

47 changes: 0 additions & 47 deletions NBi.Core/Calculation/FilterGroupByFilter.cs

This file was deleted.

19 changes: 19 additions & 0 deletions NBi.Core/Calculation/Grouping/CaseBased/CaseGroupByArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using NBi.Core.Calculation.Predication;
using NBi.Core.Variable;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NBi.Core.Calculation.Grouping.CaseBased
{
public class CaseGroupByArgs : IGroupByArgs
{
public IEnumerable<IPredication> Cases { get; set; }
public Context Context { get; set; }

public CaseGroupByArgs(IEnumerable<IPredication> cases, Context context)
=> (Cases, Context) = (cases, context);
}
}
44 changes: 44 additions & 0 deletions NBi.Core/Calculation/Grouping/CaseBased/CaseGrouping.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using NBi.Core.Calculation.Predication;
using NBi.Core.Variable;
using NBi.Extensibility;
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NBi.Core.Calculation.Grouping.CaseBased
{
class CaseGrouping : IGroupBy
{
protected IEnumerable<IPredication> Cases { get; }
protected Context Context { get; }

public CaseGrouping(IEnumerable<IPredication> cases, Context context)
=> (Cases, Context) = (cases, context);

public IDictionary<ResultSet.KeyCollection, DataTable> Execute(ResultSet.ResultSet resultSet)
{
var stopWatch = new Stopwatch();
var dico = new Dictionary<ResultSet.KeyCollection, DataTable>();
stopWatch.Start();

foreach (DataRow row in resultSet.Rows)
{
Context.Switch(row);
var index = Cases.Select((p, i) => new { Predication = p, Index = i })
.FirstOrDefault(x => x.Predication.Execute(Context))
?.Index ?? -1;
var key = new ResultSet.KeyCollection(new object[] { index });
if (!dico.ContainsKey(key))
dico.Add(key, row.Table.Clone());
dico[key].ImportRow(row);
}

Trace.WriteLineIf(NBiTraceSwitch.TraceInfo, $"Building rows' groups by cases: {dico.Count} [{stopWatch.Elapsed.ToString(@"d\d\.hh\h\:mm\m\:ss\s\ \+fff\m\s")}");
return dico;
}
}
}
20 changes: 20 additions & 0 deletions NBi.Core/Calculation/Grouping/ColumnBased/ColumnGroupByArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using NBi.Core.ResultSet;
using NBi.Core.Variable;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NBi.Core.Calculation.Grouping.ColumnBased
{
public class ColumnGroupByArgs : IGroupByArgs
{

public IEnumerable<IColumnDefinitionLight> Columns { get; set; }
public Context Context { get; set; }

public ColumnGroupByArgs(IEnumerable<IColumnDefinitionLight> columns, Context context)
=> (Columns, Context) = (columns, context);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NBi.Core.ResultSet;
using NBi.Core.Variable;
using NBi.Extensibility;
using System;
using System.Collections.Generic;
Expand All @@ -8,33 +9,32 @@
using System.Text;
using System.Threading.Tasks;

namespace NBi.Core.Calculation.Grouping
namespace NBi.Core.Calculation.Grouping.ColumnBased
{
public abstract class AbstractByColumnGrouping : IByColumnGrouping
public abstract class ColumnGrouping : IGroupBy
{
protected ISettingsResultSet Settings { get; }
protected Context Context { get; }

public AbstractByColumnGrouping(ISettingsResultSet settings)
{
Settings = settings;
}
protected ColumnGrouping(ISettingsResultSet settings, Context context)
=> (Settings, Context) = (settings, context);

public IDictionary<KeyCollection, DataTable> Execute(ResultSet.ResultSet resultSet)
{
var stopWatch = new Stopwatch();
var dico = new Dictionary<KeyCollection, DataTable>();
var dico = new Dictionary<KeyCollection, DataTable>(new KeyCollectionEqualityComparer());
var keyComparer = BuildDataRowsKeyComparer(resultSet.Table);

stopWatch.Start();
foreach (DataRow row in resultSet.Rows)
{
Context.Switch(row);
var key = keyComparer.GetKeys(row);
if (!dico.ContainsKey(key))
dico.Add(key, row.Table.Clone());
dico[key].ImportRow(row);
}
Trace.WriteLineIf(NBiTraceSwitch.TraceInfo, string.Format("Building rows' groups: {0} [{1}]", dico.Count, stopWatch.Elapsed.ToString(@"d\d\.hh\h\:mm\m\:ss\s\ \+fff\m\s")));

Trace.WriteLineIf(NBiTraceSwitch.TraceInfo, $"Building rows' groups: {dico.Count} [{stopWatch.Elapsed.ToString(@"d\d\.hh\h\:mm\m\:ss\s\ \+fff\m\s")})]");
return dico;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
using System.Text;
using System.Threading.Tasks;
using NBi.Core.ResultSet;
using NBi.Core.Variable;

namespace NBi.Core.Calculation.Grouping
namespace NBi.Core.Calculation.Grouping.ColumnBased
{
class NameByColumnGrouping : AbstractByColumnGrouping
class NameColumnGrouping : ColumnGrouping
{
protected new SettingsNameResultSet Settings { get => base.Settings as SettingsNameResultSet; }

public NameByColumnGrouping(SettingsNameResultSet settings)
: base(settings) { }
public NameColumnGrouping(SettingsNameResultSet settings, Context context)
: base(settings, context) { }

protected override DataRowKeysComparer BuildDataRowsKeyComparer(DataTable x)
=> new DataRowKeysComparerByName(Settings);
Expand Down
Loading

0 comments on commit d62b742

Please sign in to comment.