BrightSide Workbench Full Report + Source Code
org.turro.indicator.Statistics Class Reference

Public Member Functions

Statistics setEntityFields (String root, String id)
 
Statistics setDefaultSorting (String sortOrder)
 
Statistics setContact (IContact contact)
 
Statistics onCriteria (Consumer< WhereClause > onCriteria)
 
Statistics allowMatching (boolean allowMatching)
 
Statistics allowRanking (boolean allowRanking)
 
Statistics doMatching (boolean doIt)
 
Statistics setSortOrder (String sortOrder)
 
Statistics useDaoSearch (boolean doIt)
 
WhereClause getClause ()
 

Static Public Member Functions

static Statistics load (IConstructor constructor, String rankingInstance, String matchingInstance, WhereClause wc)
 
static Aggregates aggregates (Dao dao, String table, String aggregateField, Consumer< WhereClause > onFilter)
 

Detailed Description

Author
Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g

Definition at line 38 of file Statistics.java.

Member Function Documentation

◆ aggregates()

static Aggregates org.turro.indicator.Statistics.aggregates ( Dao  dao,
String  table,
String  aggregateField,
Consumer< WhereClause onFilter 
)
static

Definition at line 119 of file Statistics.java.

119  {
120  WhereClause wc = new WhereClause();
121  wc.addClause("select new org.turro.indicator.Aggregates(");
122  wc.addClause("count(t),");
123  wc.addClause("min(t." + aggregateField + "),");
124  wc.addClause("max(t." + aggregateField + "),");
125  wc.addClause("avg(t." + aggregateField + ")");
126  wc.addClause(")");
127  wc.addClause("from " + table + " t");
128  if(onFilter != null) onFilter.accept(wc);
129  Aggregates aggregates = (Aggregates) dao.getSingleResultOrNull(wc);
130  if(aggregates != null && aggregates.getCount() > 0) {
131  wc = new WhereClause();
132  wc.addClause("select t." + aggregateField + " from " + table + " t");
133  if(onFilter != null) onFilter.accept(wc);
134  wc.addClause("order by t." + aggregateField + " asc");
135  List<Double> values;
136  if(aggregates.getCount() % 2 == 0) {
137  values = dao.getResultList(wc, (int) Math.floor(aggregates.getCount() / 2), 2);
138  } else {
139  values = dao.getResultList(wc, (int) Math.floor(aggregates.getCount() / 2) + 1, 1);
140  }
141  if(values != null && !values.isEmpty()) {
142  if(values.size() == 1) {
143  aggregates.setMedian(values.get(0));
144  } else if(values.size() == 2) {
145  aggregates.setMedian((values.get(0) + values.get(1)) / 2.0);
146  }
147  }
148  }
149  return aggregates;
150  }
void setMedian(double median)
Definition: Aggregates.java:38
static Aggregates aggregates(Dao dao, String table, String aggregateField, Consumer< WhereClause > onFilter)
Here is the call graph for this function:

◆ allowMatching()

Statistics org.turro.indicator.Statistics.allowMatching ( boolean  allowMatching)

Definition at line 72 of file Statistics.java.

72  {
73  this.allowMatching = allowMatching && !Strings.isBlank(matchingInstance);
74  return this;
75  }

◆ allowRanking()

Statistics org.turro.indicator.Statistics.allowRanking ( boolean  allowRanking)

Definition at line 77 of file Statistics.java.

77  {
78  this.allowRanking = allowRanking && !Strings.isBlank(rankingInstance);
79  return this;
80  }

◆ doMatching()

Statistics org.turro.indicator.Statistics.doMatching ( boolean  doIt)

Definition at line 82 of file Statistics.java.

82  {
83  doMatching = doIt;
84  return this;
85  }

◆ getClause()

WhereClause org.turro.indicator.Statistics.getClause ( )

Definition at line 97 of file Statistics.java.

97  {
98  if(missingValues()) throw new NullPointerException("Missing values!");
99  readDaoSearchValues();
100  String orderBy = "";
101  if(allowMatching && contact != null && contact.isValid() && doMatching) {
102  Matchings.addJoin(wc, matchingInstance, entityRoot, entityId, contact, sortOrder);
103  orderBy += Matchings.getOrdering() + ", ";
104  sortOrder = "*";
105  }
106  if(allowRanking) {
107  Rankings.addJoin(wc, rankingInstance, entityRoot, entityId, sortOrder);
108  orderBy += Rankings.getOrdering() + ", ";
109  }
110  if(onCriteria != null) onCriteria.accept(wc);
111  wc.addClause("order by " + orderBy + defaultSorting);
112  return wc;
113  }
Here is the call graph for this function:

◆ load()

static Statistics org.turro.indicator.Statistics.load ( IConstructor  constructor,
String  rankingInstance,
String  matchingInstance,
WhereClause  wc 
)
static

Definition at line 115 of file Statistics.java.

115  {
116  return new Statistics(constructor, rankingInstance, matchingInstance, wc);
117  }
Here is the caller graph for this function:

◆ onCriteria()

Statistics org.turro.indicator.Statistics.onCriteria ( Consumer< WhereClause onCriteria)

Definition at line 67 of file Statistics.java.

67  {
68  this.onCriteria = onCriteria;
69  return this;
70  }

◆ setContact()

Statistics org.turro.indicator.Statistics.setContact ( IContact  contact)

Definition at line 62 of file Statistics.java.

62  {
63  this.contact = contact;
64  return this;
65  }

◆ setDefaultSorting()

Statistics org.turro.indicator.Statistics.setDefaultSorting ( String  sortOrder)

Definition at line 57 of file Statistics.java.

57  {
58  defaultSorting = sortOrder;
59  return this;
60  }

◆ setEntityFields()

Statistics org.turro.indicator.Statistics.setEntityFields ( String  root,
String  id 
)

Definition at line 51 of file Statistics.java.

51  {
52  entityRoot = root;
53  entityId = id;
54  return this;
55  }

◆ setSortOrder()

Statistics org.turro.indicator.Statistics.setSortOrder ( String  sortOrder)

Definition at line 87 of file Statistics.java.

87  {
88  this.sortOrder = sortOrder;
89  return this;
90  }

◆ useDaoSearch()

Statistics org.turro.indicator.Statistics.useDaoSearch ( boolean  doIt)

Definition at line 92 of file Statistics.java.

92  {
93  useDaoSearch = doIt;
94  return this;
95  }

The documentation for this class was generated from the following file: