Class DataCalc
- Namespace
- Queryabl
- Assembly
- Queryabl.dll
Main class for extended functionality. Includes implementation of linq fluent clauses for "Where", "Select" with relevent customizations.
public static class DataCalc
- Inheritance
-
DataCalc
- Inherited Members
Methods
CollEvenLength<T>(IEnumerable<IEnumerable<T>>)
Retrieves an IEnumerable of generic collections that have an odd/even length and uses fluent syntax.
public static IEnumerable<IEnumerable<T>> CollEvenLength<T>(this IEnumerable<IEnumerable<T>> source)
Parameters
source
IEnumerable<IEnumerable<T>>Input data source of IEnumerable of enumerations
Returns
- IEnumerable<IEnumerable<T>>
Filtered IEnumerable list of generic collections of odd or even lengths.
Type Parameters
T
Examples
Filtering of nested lists based on their odd/even size.
var test_list = new {new List{1,3,4,4},
new List{43,54,32},
new List{99,10,403,10,20,10},
new List{1},
new List{90,40} }.AsQueryable();
test_list.CollEvenLength(); //returns all lists that have even size.
test_list.CollEvenLength().Take(1); //returns first list of elements that has even size.
test_list.CollEvenLength().Take(2)); //retruns two lists of elements that have even size.
CollEvenLength<T>(IQueryable<IEnumerable<T>>)
Retrieves a Queryable of IEnumerable collections that have an odd/even length and uses fluent syntax.
public static IQueryable<IEnumerable<T>> CollEvenLength<T>(this IQueryable<IEnumerable<T>> source)
Parameters
source
IQueryable<IEnumerable<T>>Input data source of IQueryable of enumerations
Returns
- IQueryable<IEnumerable<T>>
Filtered IQueryable list of generic collections of odd or even lengths.
Type Parameters
T
Examples
Filtering of lists based on their odd/even size.
var test_list = new {new List{1,3,4,4},
new List{43,54,32},
new List{99,10,403,10,20,10},
new List{1},
new List{90,40} }.AsQueryable();
test_list.CollEvenLength(); //returns all lists that have even size.
test_list.CollEvenLength().Take(1); //returns first list of elements that has even size.
test_list.CollEvenLength().Take(2)); //retruns two lists of elements that have even size.
FilterNumerics<T>(IEnumerable<T>)
NOTE: This is an example of how this should be done if implemented in code using methods (still Where(), Select() can be used). Allows for mixed generic enumerated data type filtering, retrieves and filters all numerical values only from the generic IEnumerable list.
public static IEnumerable<T> FilterNumerics<T>(this IEnumerable<T> source)
Parameters
source
IEnumerable<T>Input data source of IEnumerable
Returns
- IEnumerable<T>
Filtered generic IEnumerable list of values
Type Parameters
T
Examples
Get the numbers from a mixed data type list.
var ienum_mixed = new List{ 103,"vffsd","fmos",new List{"gfdfs","fsd","3489"},9.0,89.3m,99.42m,1,90000000000};
var ienum_nums = ienum_mixed.FilterNumerics();
FilterNumerics<T>(IEnumerable<T>, Func<T, bool>)
NOTE: This is an example of how this should be done if implemented in code using methods (still Where(), Select() can be used). Additional examples displaying extended usage on generic IEnumerables/IQueryables on mixed data types, uses anonymous function(s) for filtering.
public static IEnumerable<T> FilterNumerics<T>(this IEnumerable<T> source, Func<T, bool> predicate)
Parameters
source
IEnumerable<T>Input data source of IEnumerable
predicate
Func<T, bool>Anonymous function used as a predicate-based filter
Returns
- IEnumerable<T>
Filtered generic enumerable list of values
Type Parameters
T
Examples
Get the numbers from a mixed data type list, simple examples with filters on queryable parts for extended numerical filtering on data cleanup operations. NOTE: FilterNumerics is used only for removing all non-numerical datatypes at once.
IQueryable alldata = new List { 103, "vffsd", "fmos", new List { "gfdfs", "fsd", "3489" }, 9.0, 89.3m, 99.42m, 1, 90000000000 }.AsQueryable();
var numericValues = alldata.FilterNumerics();
//Sample Default Usage - With/Without FilterNumerics()
// .Where(n => n is long); //select only long
// .Where(n => n.ToString().Length > 10 == true); // select numeric values of prespecified length
// .Where(n => n is UInt32); // select only uint
// .Where(n => (n is Double) AND ((double)n >= 1)); //select only doubles 'AND' should be replaced with appropriate sign
FreqObjsOccur<T>(IQueryable<T>)
Retrieves a Queryable listing of the top most frequently occuring objects in the IQueryable input source of object type T.
public static IQueryable<T> FreqObjsOccur<T>(this IQueryable<T> source)
Parameters
source
IQueryable<T>Input data source of IQueryable of generic enumerations
Returns
- IQueryable<T>
Filtered IQueryable list of the most frequently occuring objects of types T - Can return multiple types of objects.
Type Parameters
T
Examples
Retrieval of all most frequently occuring objects in the input IQueryable of objects type. Multiple return types included in the results. NOTE: Prespecified class definitions for tests provided at 'code' section.
public class Person { public string name = ""; public string surname = ""; public int age = 0; public Person(string n, string sn) { this.name = n; this.surname = sn; } }
public class Animal { public string species = ""; public Animal(string spec) { this.species = spec; } }
public class Dog { public string name = ""; public Dog(string n) { this.name = n; } }
var per1 = new Person("john", "six");
var anim3 = new Animal("Reptile");
var anim2 = new Animal("canine");
var anim1 = new Animal("feline");
var dog1 = new Dog("spok");
var per2 = new Person("john", "1");
var dog2 = new Dog("tim");
var per3 = new Person("john", "test");
IQueryable Freq1 = new List { "gtes", 11, 15, 15, anim3, anim2, dog2, dog2, dog2, dog2, dog1, per4, per4, per1, per2, per3, 190, 190, 190, "vdvd", "3489" }.AsQueryable();
Freq1.FreqObjsOccur(); //example for return types of T = Object
FreqOccur<T>(IQueryable<T>)
Retrieves the most frequently occuring object in the IQueryable input source of object type T.
public static T FreqOccur<T>(this IQueryable<T> source)
Parameters
source
IQueryable<T>Input data source of IQueryable of generic enumerations
Returns
- T
The single most frequently-occuring object of type T
Type Parameters
T
Examples
Retrieval of the most frequently occuring value of either int/string other from IQueryable. NOTE: Prespecified class definitions for tests provided at 'code' section.
public class Person { public string name = ""; public string surname = ""; public int age = 0; public Person(string n, string sn) { this.name = n; this.surname = sn; } }
public class Animal { public string species = ""; public Animal(string spec) { this.species = spec; } }
public class Dog { public string name = ""; public Dog(string n) { this.name = n; } }
var per1 = new Person("john", "six");
var anim3 = new Animal("Reptile");
var anim2 = new Animal("canine");
var anim1 = new Animal("feline");
var dog1 = new Dog("spok");
var per2 = new Person("john", "1");
var dog2 = new Dog("tim");
var per3 = new Person("john", "test");
IQueryable testFreqOcc = new List{1,5,5,6,7,7,7,7,72,2,1,4,6,11,11,11,11,11,88,88,7,34,43,5,88,61,14,23,11,100}.AsQueryable();
IQueryable freqSeq2 = new List { "gg", "4334", "4334", "4554", "gg", "gg", "gg", "9000" }.AsQueryable();
IQueryable Freq1 = new List { "gtes", 11, 15, 15, anim3, anim2, dog2, dog2, dog2, dog2, dog1, per4, per4, per1, per2, per3, 190, 190, 190, "vdvd", "3489" }.AsQueryable();
testFreqOcc.FreqOccur(); //example for return types of T = int
freqSeq2.FreqOccur(); //example for return types of T = string
Freq1.FreqOccur(); //example for return types of T = Object
SelectIntMatrix(IQueryable<string>, params Func<string, bool>[])
Retrieves a filtered IQueryable list of integer matrices, based on their corresponding filtering condition of the anonymous function as parameter.
public static IQueryable<int[,]> SelectIntMatrix(this IQueryable<string> source, params Func<string, bool>[] conditions)
Parameters
source
IQueryable<string>Input data source IQueryable of Large strings of Numerical values
conditions
Func<string, bool>[]Anonymous function used for conditional predicate selections for retrieving IQueryable of transformed 2-dim matrices
Returns
- IQueryable<int[,]>
Filtered IQueryable list of integer matrices transformed based on the conditional predicate of the anonymous parameter function as an input
Examples
Retrieval cases for filtered/transformed input strings that require also data input cleanup. NOTE: WILL THROW a System.OutofMemoryException for 2-Dim matrix values of sizes 1000x1000. Output matrices accomodate string representation of numeric integer values of up to 1M of digits with no issues. Larger values of above 1M require more detailed testing.
IQueryable BigNumStrs = new List { null, "", "0", "1", "0", "99999999004444444444444444444444444444444444444444444499999999000007777777777777777777777777777777777000000000000000009999999900000iiiiiiiiiii20202282828991111000009999888888888888888888888888888888888888888888888888888888888uu929192919uuuu00000000000013131313444(*)444_(*)99999999004444444444444444444444444444444444444444444499999999000007777777777777777777777777777777777000000000000000009999999900000iiiiiiiiiii20202282828991111000009999888888888888888888888888888888888888888888888888888888888uu929192919uuuu00000000000013131313444(*)444_(*)99999999004444444444444444444444444444444444444444444499999999000007777777777777777777777777777777777000000000000000009999999900000iiiiiiiiiii20202282828991111000009999888888888888888888888888888888888888888888888888888888888uu929192919uuuu00000000000013131313444(*)444_(*)99999999004411111111111111111111111111111111111111111111111111111555555555555555555555555444444444444499999999000007777777777777777777777777777777777000000000000000009999999900000iiiiiiiiiii20202282828991111000009999888888888888888888888888888888888888888888888888888888888uu929192919uuuu00000000000013131313444(*)444_(*)99999999004444444444444444444444444444444444444444444499999999000007777777777777777777777777777777777000000000000000009999999900000iiiiiiiiiii20202282828991111000009999888888888888888888888888888888888888888888888888888888888uu929192919uuuu00000000000013131313444(*)444_(*)99999999004444444444444444444444444444444444444444444499999999000007777777777777777777777777777777777000000000000000009999999900000iiiiiiiiiii20202282828991111000009999888888888888888888888888888888888888888888888888888888888uu929192919uuuu00000000000013131313444(*)444_(*)99999999004444444444444444444444444444444444444444444499999999000007777777777777777777777777777777777000000000000000009999999900000iiiiiiiiiii20202282828991111000009999888888888888888888888888888888888888888888888888888888888uu929192919uuuu00000000000013131313444(*)444_(*)99999999004444444444444444444444444444444444444444444499999999000007777777777777777777777777777777777000000000000000009999999900000iiiiiiiiiii20202282828991111000009999888888888888888888888888888888888888888888888888888888888uu929192919uuuu00000000000013131313444(*)444_(*)", "99999999004444444444444444444444444444444444444444444499999999000007777777777777777777777777777777777000000000000000009999999900000iiiiiiiiiii20202282828991111000009999888888888888888888888888888888888888888888888888888888888uu929192919uuuu00000000000013131313444(*)444_(*)", "999999990000000000000000000000000000000000000000", "ABD34783489BSNCI328932902309239032092390320dnsjiansiNDUsA9802398nfuiwn3e80c9unu2289cn2", "2962728abcs1119__1", null, "89348934988324934438492", "547849823200%$9232", string.Empty, "$7823934222220.00943", @"99999999999\99999.999999\.999" }.AsQueryable();
IQueryable BigNumStrsAdded = new List { null, "111133354421999999990111110434341113443492-0323--0222999", "999000===493", "84848349349999hsus29229cusudshu0992", "34r4f3f3f3343", }.AsQueryable();
IQueryable BigNumStrs2 = new List { null, "9999999900", "4389433493", "34r4f3f3f3343", " 83483943fd43f_0f34043f0)/__f34/" }.AsQueryable();
IQueryable NullSeq = new List { null, null, "", string.Empty, " 334", "b 889 //" }.AsQueryable();
var EmptySetNullChecks = null ?? new List { }.AsQueryable();
BigNumStrs.SelectIntMatrix(n => n.Length > 3422 || n.Length != 2232); // will return all that match string size of above 3422 as a 1-dim array and everything that is of string size 2232 as a 2-dim one.
BigNumStrs.SelectIntMatrix(); // wille return all input string-based integer representation as 2-dim arrays in an IQueryable.
BigNumStrsAdded.SelectIntMatrix(n => n.Length == 900); // will return all predicate conditional matches as a 1-dim array if not matched returns a 2-dim one.
BigNumStrsAdded.SelectIntMatrix(n => n.Length != 9000); //will return all predicate conditional matches as a 1-dim array if not matched returns a 2-dim one.
EmptySetNullChecks .SelectIntMatrix() //Result N/A, will throw an exception if left with no null default.
SelectIntMatrix(IQueryable<string>, int)
Retrieves a filtered IQueryable list of integer matrices such that their total dimensions equals to the maximum string length of defaultLen that is prespecified as input parameter.
public static IQueryable<int[,]> SelectIntMatrix(this IQueryable<string> source, int defaultLen = 0)
Parameters
source
IQueryable<string>Input data source IQueryable of Large strings of Numerical values
defaultLen
intMaximum used length of the string to be output as an integer matrix Notes: - Defaults to value of zero if none specified as an argument and outputs unfiltered list of transformed strings to matrices. - When a value above 900 is specified, strings are transformed to 1 dimensional arrays.
Returns
- IQueryable<int[,]>
Filtered IQueryable list of integer matrices based on their string input value counterparts of length = defaultLen
Examples
Retrieval cases for filtered/transformed input strings that require also data input cleanup. NOTE: WILL THROW a System.OutofMemoryException for 2-Dim matrix values of sizes 1000x1000. Output matrices accomodate string representation of numeric integer values of up to 1M of digits with no issues. Larger values of above 1M require more detailed testing.
IQueryable BigNumStrs = new List { null, "", "0", "1", "0", "99999999004444444444444444444444444444444444444444444499999999000007777777777777777777777777777777777000000000000000009999999900000iiiiiiiiiii20202282828991111000009999888888888888888888888888888888888888888888888888888888888uu929192919uuuu00000000000013131313444(*)444_(*)99999999004444444444444444444444444444444444444444444499999999000007777777777777777777777777777777777000000000000000009999999900000iiiiiiiiiii20202282828991111000009999888888888888888888888888888888888888888888888888888888888uu929192919uuuu00000000000013131313444(*)444_(*)99999999004444444444444444444444444444444444444444444499999999000007777777777777777777777777777777777000000000000000009999999900000iiiiiiiiiii20202282828991111000009999888888888888888888888888888888888888888888888888888888888uu929192919uuuu00000000000013131313444(*)444_(*)99999999004411111111111111111111111111111111111111111111111111111555555555555555555555555444444444444499999999000007777777777777777777777777777777777000000000000000009999999900000iiiiiiiiiii20202282828991111000009999888888888888888888888888888888888888888888888888888888888uu929192919uuuu00000000000013131313444(*)444_(*)99999999004444444444444444444444444444444444444444444499999999000007777777777777777777777777777777777000000000000000009999999900000iiiiiiiiiii20202282828991111000009999888888888888888888888888888888888888888888888888888888888uu929192919uuuu00000000000013131313444(*)444_(*)99999999004444444444444444444444444444444444444444444499999999000007777777777777777777777777777777777000000000000000009999999900000iiiiiiiiiii20202282828991111000009999888888888888888888888888888888888888888888888888888888888uu929192919uuuu00000000000013131313444(*)444_(*)99999999004444444444444444444444444444444444444444444499999999000007777777777777777777777777777777777000000000000000009999999900000iiiiiiiiiii20202282828991111000009999888888888888888888888888888888888888888888888888888888888uu929192919uuuu00000000000013131313444(*)444_(*)99999999004444444444444444444444444444444444444444444499999999000007777777777777777777777777777777777000000000000000009999999900000iiiiiiiiiii20202282828991111000009999888888888888888888888888888888888888888888888888888888888uu929192919uuuu00000000000013131313444(*)444_(*)", "99999999004444444444444444444444444444444444444444444499999999000007777777777777777777777777777777777000000000000000009999999900000iiiiiiiiiii20202282828991111000009999888888888888888888888888888888888888888888888888888888888uu929192919uuuu00000000000013131313444(*)444_(*)", "999999990000000000000000000000000000000000000000", "ABD34783489BSNCI328932902309239032092390320dnsjiansiNDUsA9802398nfuiwn3e80c9unu2289cn2", "2962728abcs1119__1", null, "89348934988324934438492", "547849823200%$9232", string.Empty, "$7823934222220.00943", @"99999999999\99999.999999\.999" }.AsQueryable();
IQueryable BigNumStrsAdded = new List { null, "111133354421999999990111110434341113443492-0323--0222999", "999000===493", "84848349349999hsus29229cusudshu0992", "34r4f3f3f3343", }.AsQueryable();
IQueryable BigNumStrs2 = new List { null, "9999999900", "4389433493", "34r4f3f3f3343", " 83483943fd43f_0f34043f0)/__f34/" }.AsQueryable();
IQueryable NullSeq = new List { null, null, "", string.Empty, " 334", "b 889 //" }.AsQueryable();
var EmptySetNullChecks = null ?? new List { }.AsQueryable();
BigNumStrs.SelectIntMatrix(); //return all input string-based integer representation as 2-dimensional arrays in an IQueryable.
BigNumStrsAdded.SelectIntMatrix(2232); // return the input string-based integer representation of specified length as a 1-dimensional array.
BigNumStrsAdded.SelectIntMatrix(237); //return the input string-based integer representation of specified length as a 2-dimensional array.
EmptySetNullChecks .SelectIntMatrix(); //Result N/A, will throw an exception if left with no null default.
Select<TSource, T>(IQueryable<TSource>, Expression<Func<TSource, T>>)
Source Implementation for custom "Select()"
public static IQueryable<TSource> Select<TSource, T>(this IQueryable<TSource> source, Expression<Func<TSource, T>> predicate)
Parameters
source
IQueryable<TSource>predicate
Expression<Func<TSource, T>>
Returns
- IQueryable<TSource>
Type Parameters
TSource
T
WhereDist(IQueryable<string>, string, int)
Retrieves a Queryable of string based on IEnumerable of string data types that equal to a current hamming value of N and input type str2 that are checked against.
public static IQueryable<string> WhereDist(this IQueryable<string> str1, string str2, int distCheck)
Parameters
str1
IQueryable<string>The leftmost string part to compare with
str2
stringThe rightmost string part to compare against
distCheck
intThe hamming value to check per string comparison
Returns
- IQueryable<string>
Filtered IQueryable list of generic strings with same resulting hamming comparison value.
Examples
Filtering per string and hamming code comparison part.
IQueryable hamCheckStr = new List{"test1","test2","test3","test2","10times49","20times46","times"}.AsQueryable();
var sourceStrings = new List { "abc", "def", "xyz" }.AsQueryable();
sourceStrings.WhereDist("abg",1);
sourceStrings.WhereDist("aee",2);
hamCheckStr.WhereDist("test3",1); // all return the appropriate filtered queryable search results.
Where<TSource>(IQueryable<TSource>, Expression<Func<TSource, bool>>)
Source Implementation for custom "Where()"
public static IQueryable<TSource> Where<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
Parameters
source
IQueryable<TSource>predicate
Expression<Func<TSource, bool>>
Returns
- IQueryable<TSource>
Type Parameters
TSource