public int Count(AggrFn fn, string scope, bool runningValue) { Context ctxt = _currentContext; PushContextState(); try { if (scope != null && scope != string.Empty) { ctxt = ctxt.FindContextByGroupName(scope, _rpt); } int ct = 0; int top = (runningValue) ? ctxt.RowIndex : ctxt.Rows.Count - 1; for (int i = 0; i <= top; i++) { ctxt.RowIndex = i; object value = fn(); if (value != null && !Convert.IsDBNull(value)) { ct++; } } return(ct); } finally { PopContextState(); } }
public object Previous(AggrFn fn, string scope) { Context ctxt = _currentContext; PushContextState(); try { if (scope != null && scope != string.Empty) { ctxt = ctxt.FindContextByGroupName(scope, _rpt); } if (ctxt.RowIndex > 0) { ctxt.RowIndex--;; object value = fn(); return(value); } else { return(null); } } finally { PopContextState(); } }
public object RunningValue(AggrFn fn, RunningValueFunction function, string scope) { switch (function) { case RunningValueFunction.Sum: return(Sum(fn, scope, true)); case RunningValueFunction.Avg: return(Avg(fn, scope, true)); case RunningValueFunction.Max: return(Max(fn, scope, true)); case RunningValueFunction.Min: return(Min(fn, scope, true)); case RunningValueFunction.Count: return(Count(fn, scope, true)); case RunningValueFunction.CountDistinct: return(CountDistinct(fn, scope, true)); case RunningValueFunction.StDev: return(StDev(fn, scope, true)); case RunningValueFunction.StDevP: return(StDevP(fn, scope, true)); default: throw new Exception("Unknown function " + function + " in RunningValue"); } }
public object First(AggrFn fn, string scope) { try { PushContextState(); if (scope != null && scope != string.Empty) { _currentContext = _currentContext.FindContextByGroupName(scope, _rpt); } if (_currentContext.Rows.Count > 0) { _currentContext.RowIndex = 0; object value = fn(); return(value); } else { return(null); } } finally { PopContextState(); } }
public object sum(AggrFn fn) { int rowIndex = _currentContext.RowIndex; bool doub = false; decimal decValue = 0; double doubValue = 0; for (int i = 0; i < _currentContext.Rows.Count; i++) { _currentContext.RowIndex = i; object value = fn(); if (value is System.Single || value is System.Double && !doub) { doub = true; doubValue = (double)decValue; } if (doub) { doubValue += (double)value; } else { decValue += Convert.ToDecimal(value); } } _currentContext.RowIndex = rowIndex; return((doub) ? (object)doubValue : (object)decValue); }
public object Avg(AggrFn fn, string scope, bool runningValue) { Context ctxt = _currentContext; PushContextState(); try { if (scope != null && scope != string.Empty) { ctxt = ctxt.FindContextByGroupName(scope, _rpt); } int ct = 0; bool dec = false; decimal decValue = 0; double doubValue = 0; int top = (runningValue) ? ctxt.RowIndex : ctxt.Rows.Count - 1; for (int i = 0; i <= top; i++) { ctxt.RowIndex = i; object value = fn(); if (value != null && !Convert.IsDBNull(value)) { if (value is decimal && !dec) { dec = true; decValue = Convert.ToDecimal(doubValue); } if (dec) { decValue += Convert.ToDecimal(value); } else { doubValue += Convert.ToDouble(value); } ct++; } } return((dec) ? (object)(decValue / ct) : (object)(doubValue / ct)); } finally { PopContextState(); } }
public float StDevP(AggrFn fn, string scope, bool runningValue) { Context ctxt = _currentContext; PushContextState(); try { if (scope != null && scope != string.Empty) { ctxt = ctxt.FindContextByGroupName(scope, _rpt); } int ct = 0; double sum1 = 0; double sum2 = 0; int top = (runningValue) ? ctxt.RowIndex : ctxt.Rows.Count - 1; for (int i = 0; i <= top; i++) { ctxt.RowIndex = i; object value = fn(); if (value != null && !Convert.IsDBNull(value)) { sum1 += Convert.ToDouble(value); sum2 += (Convert.ToDouble(value) * Convert.ToDouble(value)); ct++; } } if (ct > 1) { return((float)(Math.Sqrt((ct * sum2) - (sum1 * sum1)) / (ct - 1))); } else { return(0); } } finally { PopContextState(); } }
public int CountDistinct(AggrFn fn, string scope, bool runningValue) { Context ctxt = _currentContext; PushContextState(); try { if (scope != null && scope != string.Empty) { ctxt = ctxt.FindContextByGroupName(scope, _rpt); } List <object> valueList = new List <object>(); int top = (runningValue) ? ctxt.RowIndex : ctxt.Rows.Count - 1; for (int i = 0; i <= top; i++) { ctxt.RowIndex = i; object value = fn(); if (value != null && !Convert.IsDBNull(value)) { valueList.Add(value); } } valueList.Sort(delegate(object v1, object v2) { return(Compare.CompareTo(v1, v2)); }); int ct = (valueList.Count == 0) ? 0 : 1; for (int i = 0; i < valueList.Count - 1; i++) { if (Compare.CompareTo(valueList[i], valueList[i + 1]) != 0) { ct++; } } return(ct); } finally { PopContextState(); } }
public object Min(AggrFn fn, string scope, bool runningValue) { PushContextState(); Context ctxt = _currentContext; try { if (scope != null && scope != string.Empty) { ctxt = ctxt.FindContextByGroupName(scope, _rpt); } object maxVal = null; int top = (runningValue) ? ctxt.RowIndex : ctxt.Rows.Count - 1; for (int i = 0; i <= top; i++) { ctxt.RowIndex = i; object value = fn(); if (value != null && !Convert.IsDBNull(value)) { if (maxVal == null) { maxVal = value; } else if (Compare.CompareTo(value, maxVal) < 0) { maxVal = value; } } } return(maxVal); } finally { PopContextState(); } }
public object CountDistinct(AggrFn fn) { List <object> valueList = new List <object>(); int rowIndex = _currentContext.RowIndex; for (int i = 0; i < _currentContext.Rows.Count; i++) { _currentContext.RowIndex = i; valueList.Add(fn()); } valueList.Sort(RdlEngine.Utility.ApplyCompare); int ct = (valueList.Count == 0)?0:1; for (int i = 0; i < valueList.Count - 1; i++) { if (RdlEngine.Utility.ApplyCompare(valueList[i], valueList[i + 1]) != 0) { ct++; } } return(ct); }
public object Avg(AggrFn fn, string scope) { return(Avg(fn, scope, false)); }
public object Avg(AggrFn fn) { return(Avg(fn, null)); }
public object RunningValue(AggrFn fn, RunningValueFunction function) { return(RunningValue(fn, function)); }
public object Sum(AggrFn fn) { return(Sum(fn, null)); }
public object Previous(AggrFn fn) { return(Previous(fn, null)); }
public int CountDistinct(AggrFn fn, string scope) { return(CountDistinct(fn, scope, false)); }
public object Sum(AggrFn fn, string scope) { return(Sum(fn, scope, false)); }
public object Min(AggrFn fn) { return(Min(fn, null)); }
public float StDevP(AggrFn fn, string scope) { return(StDevP(fn, scope, false)); }
public float StDevP(AggrFn fn) { return(StDevP(fn, null)); }
public object Min(AggrFn fn, string scope) { return(Min(fn, scope, false)); }
public object Last(AggrFn fn) { return(Last(fn, null)); }
public object Count(AggrFn fn) { return(_currentContext.Rows.Count); }
public int CountDistinct(AggrFn fn) { return(CountDistinct(fn, null)); }
public object First(AggrFn fn) { return(First(fn, null)); }
public object Max(AggrFn fn) { return(Max(fn, null)); }