Revize 9e9e8d67
Přidáno uživatelem Michal Linha před téměř 5 roky(ů)
src/main/java/vldc/aswi/model/table/NameUserName.java | ||
---|---|---|
1 | 1 |
package vldc.aswi.model.table; |
2 | 2 |
|
3 |
/** |
|
4 |
* Class for connection between name of the column and the user name of the column. |
|
5 |
*/ |
|
3 | 6 |
public class NameUserName { |
4 | 7 |
|
8 |
/** |
|
9 |
* Name of the column. |
|
10 |
*/ |
|
11 |
|
|
5 | 12 |
private String name; |
13 |
/** |
|
14 |
* User name of the column. |
|
15 |
*/ |
|
6 | 16 |
private String userName; |
7 | 17 |
|
18 |
/** |
|
19 |
* Creates an instance of the class. |
|
20 |
* @param name name of the column |
|
21 |
* @param userName user name of the column |
|
22 |
*/ |
|
8 | 23 |
public NameUserName(String name, String userName) { |
9 | 24 |
this.name = name; |
10 | 25 |
this.userName = userName; |
11 | 26 |
} |
12 | 27 |
|
28 |
/** |
|
29 |
* Gets the column name. |
|
30 |
* @return column name |
|
31 |
*/ |
|
13 | 32 |
public String getName() { |
14 | 33 |
return name; |
15 | 34 |
} |
16 | 35 |
|
36 |
/** |
|
37 |
* Sets the column name. |
|
38 |
* @param name column name |
|
39 |
*/ |
|
17 | 40 |
public void setName(String name) { |
18 | 41 |
this.name = name; |
19 | 42 |
} |
20 | 43 |
|
44 |
/** |
|
45 |
* Gets the user column name. |
|
46 |
* @return user column name |
|
47 |
*/ |
|
21 | 48 |
public String getUserName() { |
22 | 49 |
return userName; |
23 | 50 |
} |
24 | 51 |
|
52 |
/** |
|
53 |
* Sets the user column name. |
|
54 |
* @param userName user column name |
|
55 |
*/ |
|
25 | 56 |
public void setUserName(String userName) { |
26 | 57 |
this.userName = userName; |
27 | 58 |
} |
src/main/java/vldc/aswi/model/table/Node.java | ||
---|---|---|
4 | 4 |
import java.util.Collection; |
5 | 5 |
import java.util.List; |
6 | 6 |
|
7 |
/** |
|
8 |
* Class representing a node in a tree of row or column values. |
|
9 |
*/ |
|
7 | 10 |
public class Node { |
8 | 11 |
|
12 |
/** |
|
13 |
* Values of the nodes on a path the the node. |
|
14 |
*/ |
|
9 | 15 |
private List<String> values; |
10 | 16 |
|
17 |
/** |
|
18 |
* Creates a node. |
|
19 |
*/ |
|
11 | 20 |
public Node() { |
12 | 21 |
this.values = new ArrayList<>(); |
13 | 22 |
} |
14 | 23 |
|
24 |
/** |
|
25 |
* Creates a node with the same values as the given node. |
|
26 |
* @param node node to be copied |
|
27 |
*/ |
|
15 | 28 |
public Node(Node node) { |
16 | 29 |
this.values = new ArrayList<>(node.values); |
17 | 30 |
} |
18 | 31 |
|
32 |
/** |
|
33 |
* Gets values. |
|
34 |
* @return values. |
|
35 |
*/ |
|
19 | 36 |
public List<String> getValues() { |
20 | 37 |
return values; |
21 | 38 |
} |
22 | 39 |
|
40 |
/** |
|
41 |
* Sets values. |
|
42 |
* @param values values. |
|
43 |
*/ |
|
23 | 44 |
public void setValues(List<String> values) { |
24 | 45 |
this.values = values; |
25 | 46 |
} |
src/main/java/vldc/aswi/model/table/ValueFunction.java | ||
---|---|---|
1 | 1 |
package vldc.aswi.model.table; |
2 | 2 |
|
3 |
|
|
4 |
/** |
|
5 |
* Class representing connection between a value and a function |
|
6 |
*/ |
|
3 | 7 |
public class ValueFunction { |
4 | 8 |
|
9 |
/** |
|
10 |
* Value |
|
11 |
*/ |
|
5 | 12 |
private String value; |
13 |
/** |
|
14 |
* Function |
|
15 |
*/ |
|
6 | 16 |
private String function; |
7 | 17 |
|
18 |
/** |
|
19 |
* Creates an instance of the class |
|
20 |
* @param value value |
|
21 |
* @param function function |
|
22 |
*/ |
|
8 | 23 |
public ValueFunction(String value, String function) { |
9 | 24 |
this.value = value; |
10 | 25 |
this.function = function; |
11 | 26 |
} |
12 | 27 |
|
28 |
/** |
|
29 |
* Gets value. |
|
30 |
* @return value |
|
31 |
*/ |
|
13 | 32 |
public String getValue() { |
14 | 33 |
return value; |
15 | 34 |
} |
16 | 35 |
|
36 |
/** |
|
37 |
* Sets value. |
|
38 |
* @param value value |
|
39 |
*/ |
|
17 | 40 |
public void setValue(String value) { |
18 | 41 |
this.value = value; |
19 | 42 |
} |
20 | 43 |
|
44 |
/** |
|
45 |
* Gets function. |
|
46 |
* @return function |
|
47 |
*/ |
|
21 | 48 |
public String getFunction() { |
22 | 49 |
return function; |
23 | 50 |
} |
24 | 51 |
|
52 |
/** |
|
53 |
* Sets function. |
|
54 |
* @param function function. |
|
55 |
*/ |
|
25 | 56 |
public void setFunction(String function) { |
26 | 57 |
this.function = function; |
27 | 58 |
} |
src/main/java/vldc/aswi/service/LocationManager.java | ||
---|---|---|
14 | 14 |
* @return List of locations. |
15 | 15 |
*/ |
16 | 16 |
List<Location> getLocations(); |
17 |
|
|
18 |
/** |
|
19 |
* Get location from database by ID. |
|
20 |
* @return location by ID. |
|
21 |
*/ |
|
22 |
public Location getLocationById(long id); |
|
17 | 23 |
} |
src/main/java/vldc/aswi/service/LocationManagerImpl.java | ||
---|---|---|
50 | 50 |
this.locationRepository.findAll().forEach(retVal::add); |
51 | 51 |
return retVal; |
52 | 52 |
} |
53 |
|
|
54 |
/** |
|
55 |
* Get location from database by ID. |
|
56 |
* @return location by ID. |
|
57 |
*/ |
|
58 |
@Override |
|
59 |
public Location getLocationById(long id) { |
|
60 |
return locationRepository.getById(id); |
|
61 |
} |
|
53 | 62 |
} |
src/main/java/vldc/aswi/service/SqlQueryManager.java | ||
---|---|---|
1 | 1 |
package vldc.aswi.service; |
2 | 2 |
|
3 |
import vldc.aswi.domain.Assembly; |
|
4 |
import vldc.aswi.domain.Configuration; |
|
3 | 5 |
import vldc.aswi.model.table.contingencyTable.ContingencyTableRow; |
4 | 6 |
|
5 | 7 |
import java.util.List; |
... | ... | |
11 | 13 |
|
12 | 14 |
/** |
13 | 15 |
* Get list of contingencyTableRow. |
14 |
* @param sqlQuery - SQL query.
|
|
16 |
* @param configuration - configuration from which table will be created.
|
|
15 | 17 |
* @return List of contingencyTableRow. |
16 | 18 |
*/ |
17 |
List<ContingencyTableRow> getContingencyTableRow(String sqlQuery);
|
|
19 |
List<ContingencyTableRow> getContingencyTableRow(Configuration configuration);
|
|
18 | 20 |
|
19 | 21 |
/** |
20 | 22 |
* Validate given SQL query. |
src/main/java/vldc/aswi/service/SqlQueryManagerImpl.java | ||
---|---|---|
4 | 4 |
import org.springframework.beans.factory.annotation.Autowired; |
5 | 5 |
import org.springframework.stereotype.Service; |
6 | 6 |
import vldc.aswi.database.DatabaseInterface; |
7 |
import vldc.aswi.domain.Assembly; |
|
8 |
import vldc.aswi.domain.Configuration; |
|
9 |
import vldc.aswi.domain.Function; |
|
10 |
import vldc.aswi.domain.parameter.ParameterInConfiguration; |
|
7 | 11 |
import vldc.aswi.model.table.NameUserName; |
8 | 12 |
import vldc.aswi.model.table.TableColumn; |
9 | 13 |
import vldc.aswi.model.table.ValueFunction; |
... | ... | |
11 | 15 |
import vldc.aswi.utils.Converter; |
12 | 16 |
|
13 | 17 |
import javax.sql.DataSource; |
14 |
import java.util.ArrayList; |
|
15 |
import java.util.List; |
|
16 |
import java.util.Map; |
|
18 |
import java.util.*; |
|
19 |
import java.util.concurrent.TimeUnit; |
|
17 | 20 |
|
18 | 21 |
/** |
19 | 22 |
* Manager for SqlQuery. |
... | ... | |
28 | 31 |
|
29 | 32 |
/** |
30 | 33 |
* Get list of contingencyTableRow. |
31 |
* @param sqlQuery - SQL query.
|
|
34 |
* @param configuration - configuration from which table will be created.
|
|
32 | 35 |
* @return List of contingencyTableRow. |
33 | 36 |
*/ |
34 | 37 |
@Override |
35 |
public List<ContingencyTableRow> getContingencyTableRow(String sqlQuery) { |
|
36 |
Map<String, TableColumn> tableColumns = this.databaseInterface.executeQueryAndReturnTableColumns(sqlQuery); |
|
38 |
public List<ContingencyTableRow> getContingencyTableRow(Configuration configuration) { |
|
39 |
long startTime = System.nanoTime(); |
|
40 |
Map<String, TableColumn> tableColumns = this.databaseInterface.executeQueryAndReturnTableColumns( |
|
41 |
configuration.getAssembly().getSQLQuery() |
|
42 |
); |
|
43 |
long stopTime = System.nanoTime(); |
|
44 |
System.out.println("Select:" + TimeUnit.MILLISECONDS.convert((stopTime - startTime), TimeUnit.NANOSECONDS)); |
|
37 | 45 |
List<NameUserName> rowNames = new ArrayList<>(); |
38 |
rowNames.add(new NameUserName("PROGRAM_STUDIA", "d")); |
|
39 |
rowNames.add(new NameUserName("TYP_STUDIA", "d")); |
|
40 |
|
|
41 | 46 |
List<NameUserName> columnNames = new ArrayList<>(); |
42 |
columnNames.add(new NameUserName("FAKULTA_STUDIA", "d")); |
|
43 |
columnNames.add(new NameUserName("FORMA_STUDIA", "d")); |
|
44 |
|
|
45 | 47 |
List<ValueFunction> valueFunctions = new ArrayList<>(); |
46 |
valueFunctions.add(new ValueFunction("VEK", "d")); |
|
47 |
Converter c = new Converter(); |
|
48 |
return c.convertTableColumnsToContingencyTableRows(tableColumns, rowNames, columnNames, valueFunctions); |
|
48 |
|
|
49 |
// sort parameters in configuration to have them in order set by user |
|
50 |
Collections.sort(configuration.getParametersInConfiguration()); |
|
51 |
|
|
52 |
// TODO: 28.05.2020 map would be better |
|
53 |
for(ParameterInConfiguration parameterInConfiguration : configuration.getParametersInConfiguration()) { |
|
54 |
if (parameterInConfiguration.getLocation() != null && parameterInConfiguration.getLocation().getName().equals("Řádek")) { |
|
55 |
rowNames.add(new NameUserName(parameterInConfiguration.getParameter().getNameOfSelect().toUpperCase(), |
|
56 |
parameterInConfiguration.getColumnName())); |
|
57 |
} |
|
58 |
else if (parameterInConfiguration.getLocation() != null && parameterInConfiguration.getLocation().getName().equals("Sloupec")) { |
|
59 |
columnNames.add(new NameUserName(parameterInConfiguration.getParameter().getNameOfSelect().toUpperCase(), |
|
60 |
parameterInConfiguration.getColumnName())); |
|
61 |
} |
|
62 |
else if(parameterInConfiguration.getLocation() != null && parameterInConfiguration.getLocation().getName().equals("Hodnota")) { |
|
63 |
for (Function function : parameterInConfiguration.getFunctions()) { |
|
64 |
valueFunctions.add(new ValueFunction(parameterInConfiguration.getParameter().getNameOfSelect().toUpperCase(), |
|
65 |
function.getName().toUpperCase())); |
|
66 |
} |
|
67 |
} |
|
68 |
} |
|
69 |
|
|
70 |
Converter converter = new Converter(); |
|
71 |
return converter.convertTableColumnsToContingencyTableRows(tableColumns, rowNames, columnNames, valueFunctions); |
|
49 | 72 |
} |
50 | 73 |
|
51 | 74 |
/** |
src/main/java/vldc/aswi/utils/Converter.java | ||
---|---|---|
7 | 7 |
import vldc.aswi.model.table.contingencyTable.ContingencyTableRow; |
8 | 8 |
import vldc.aswi.model.table.contingencyTable.ContingencyTableRowCell; |
9 | 9 |
|
10 |
import javax.persistence.criteria.CriteriaBuilder; |
|
10 | 11 |
import java.util.ArrayList; |
11 | 12 |
import java.util.List; |
12 | 13 |
import java.util.Map; |
14 |
import java.util.concurrent.TimeUnit; |
|
13 | 15 |
|
14 | 16 |
/** |
15 | 17 |
* Class for converting classes. |
... | ... | |
27 | 29 |
public List<ContingencyTableRow> convertTableColumnsToContingencyTableRows(Map<String, TableColumn> tableColumns, |
28 | 30 |
List<NameUserName> rowNames, |
29 | 31 |
List<NameUserName> columnNames, |
30 |
List<ValueFunction> valueFunctions) {
|
|
31 |
/*
|
|
32 |
List<ValueFunction> valueFunctions) { |
|
33 |
long startTime = System.nanoTime();
|
|
32 | 34 |
List<ContingencyTableRow> contingencyTableRows = new ArrayList<>(); |
33 | 35 |
|
34 |
// Create header row with column names. |
|
35 |
ContingencyTableRow contingencyTableRowHeader = new ContingencyTableRow(true, 0); |
|
36 |
for (String columnName : tableColumns.keySet()) { |
|
37 |
contingencyTableRowHeader.addTableRowCell(new ContingencyTableRowCell(columnName, 0)); |
|
38 |
} |
|
39 |
contingencyTableRows.add(contingencyTableRowHeader); |
|
40 |
|
|
41 |
boolean listExpanded = false; |
|
36 |
long startTime2 = System.nanoTime(); |
|
37 |
List<ContingencyTableRow> headerRows = createHeaderOnlyRows(tableColumns, columnNames, valueFunctions); |
|
38 |
long stopTime2 = System.nanoTime(); |
|
39 |
System.out.println("Headers:" + TimeUnit.MILLISECONDS.convert((stopTime2 - startTime2), TimeUnit.NANOSECONDS)); |
|
42 | 40 |
|
43 |
// Create contingency table row. |
|
44 |
for (TableColumn tableColumn : tableColumns.values()) { |
|
45 |
List<String> values = tableColumn.getValues(); |
|
46 |
|
|
47 |
// If list is not created, then create it. |
|
48 |
if (!listExpanded) { |
|
49 |
for (int j = 0; j < values.size(); j++) { |
|
50 |
ContingencyTableRow contingencyTableRow = new ContingencyTableRow(false, 0); |
|
51 |
contingencyTableRows.add(contingencyTableRow); |
|
52 |
} |
|
53 |
listExpanded = true; |
|
54 |
} |
|
55 |
|
|
56 |
// Iterate through all values and assign one value per one row. |
|
57 |
for (int j = 0; j < values.size(); j++) { |
|
58 |
ContingencyTableRowCell contingencyTableRowCell = new ContingencyTableRowCell(values.get(j), 0); |
|
59 |
contingencyTableRows.get(j + 1).addTableRowCell(contingencyTableRowCell); |
|
60 |
} |
|
61 |
} |
|
62 |
|
|
63 |
*/ |
|
64 |
List<ContingencyTableRow> contingencyTableRows = new ArrayList<>(); |
|
65 |
|
|
66 |
List<ContingencyTableRow> headerRows = createHeaderOnlyRows(tableColumns, columnNames); |
|
41 |
long startTime3 = System.nanoTime(); |
|
67 | 42 |
List<ContingencyTableRow> dataRows = createDataRows(tableColumns, columnNames, rowNames, valueFunctions); |
43 |
long stopTime3 = System.nanoTime(); |
|
44 |
System.out.println("Rows:" + TimeUnit.MILLISECONDS.convert((stopTime3 - startTime3), TimeUnit.NANOSECONDS)); |
|
68 | 45 |
|
69 | 46 |
contingencyTableRows.addAll(headerRows); |
70 | 47 |
contingencyTableRows.addAll(dataRows); |
71 | 48 |
|
49 |
long stopTime = System.nanoTime(); |
|
50 |
System.out.println("Converter:" + TimeUnit.SECONDS.convert((stopTime - startTime), TimeUnit.NANOSECONDS) + "s"); |
|
51 |
|
|
72 | 52 |
return contingencyTableRows; |
73 | 53 |
} |
74 | 54 |
|
75 |
private List<ContingencyTableRow> createHeaderOnlyRows(Map<String, TableColumn> tableColumns, List<NameUserName> columnNames) { |
|
55 |
/** |
|
56 |
* Generates header rows. |
|
57 |
* @param tableColumns Map of TableColumn |
|
58 |
* @param columnNames list of column and user column names |
|
59 |
* @param valueFunctions list of values and their functions |
|
60 |
* @return list of contingency table rows |
|
61 |
*/ |
|
62 |
private List<ContingencyTableRow> createHeaderOnlyRows(Map<String, TableColumn> tableColumns, |
|
63 |
List<NameUserName> columnNames, List<ValueFunction> valueFunctions) { |
|
76 | 64 |
List<List<String>> values = new ArrayList<>(); |
77 | 65 |
columnNodes = new ArrayList<>(); |
78 | 66 |
List<ContingencyTableRow> headerRows = new ArrayList<>(); |
67 |
|
|
68 |
List<String> valueOptions = new ArrayList<>(); |
|
69 |
for (ValueFunction valueFunction : valueFunctions) { |
|
70 |
valueOptions.add(valueFunction.getFunction() + " z " + valueFunction.getValue()); |
|
71 |
} |
|
72 |
values.add(valueOptions); |
|
73 |
headerRows.add(new ContingencyTableRow(true, 0)); |
|
74 |
|
|
79 | 75 |
for(NameUserName nameUserName : columnNames) { |
80 | 76 |
TableColumn column = tableColumns.get(nameUserName.getName()); |
81 | 77 |
values.add(getOriginalValuesFromList(column.getValues())); |
82 | 78 |
headerRows.add(new ContingencyTableRow(true, 0)); |
83 | 79 |
} |
84 | 80 |
|
85 |
Node node = new Node(); |
|
86 |
generateColumns(0, values, columnNodes, node); |
|
87 |
|
|
88 | 81 |
for (int i = 0; i < values.size(); i++) { |
89 | 82 |
int colSpan = 1; |
90 | 83 |
for (int j = values.size() - 1; j > i; j--) { |
... | ... | |
103 | 96 |
for (int k = 0; k < loopCount; k++) { |
104 | 97 |
for (String value : values.get(i)) { |
105 | 98 |
headerRows.get(i).addTableRowCell(new ContingencyTableRowCell(value, colSpan)); |
106 |
if (i != values.size() - 1) { |
|
99 |
if (i != values.size() - 1 && i != 0) {
|
|
107 | 100 |
headerRows.get(i).addTableRowCell(new ContingencyTableRowCell(value + " Celkem", 1)); |
108 | 101 |
} |
109 | 102 |
} |
110 | 103 |
|
111 |
for (int l = 0; l < i; l++) { |
|
104 |
for (int l = 0; l < i - 1; l++) {
|
|
112 | 105 |
headerRows.get(i).addTableRowCell(new ContingencyTableRowCell("", 1)); |
113 | 106 |
} |
114 | 107 |
} |
115 |
if (i == 0) { |
|
116 |
headerRows.get(i).addTableRowCell(new ContingencyTableRowCell("Celkový počet", 1)); |
|
117 |
} |
|
118 |
else { |
|
119 |
headerRows.get(i).addTableRowCell(new ContingencyTableRowCell("", 1)); |
|
108 |
for(ValueFunction valueFunction: valueFunctions) { |
|
109 |
if (i == 0) { |
|
110 |
headerRows.get(i).addTableRowCell(new ContingencyTableRowCell("Celkový " + valueFunction.getFunction() + |
|
111 |
" z " + valueFunction.getValue(), 1)); |
|
112 |
} else { |
|
113 |
headerRows.get(i).addTableRowCell(new ContingencyTableRowCell("", 1)); |
|
114 |
} |
|
120 | 115 |
} |
121 | 116 |
} |
122 | 117 |
|
118 |
long startTime = System.nanoTime(); |
|
119 |
values.remove(0); |
|
120 |
Node node = new Node(); |
|
121 |
generateColumns(0, values, columnNodes, node); |
|
122 |
long stopTime = System.nanoTime(); |
|
123 |
System.out.println("Colums list:" + TimeUnit.MILLISECONDS.convert((stopTime - startTime), TimeUnit.NANOSECONDS)); |
|
124 |
|
|
123 | 125 |
return headerRows; |
124 | 126 |
} |
125 | 127 |
|
128 |
/** |
|
129 |
* Gets original values of a given list. |
|
130 |
* @param list list from which original values should be taken |
|
131 |
* @return list of original values |
|
132 |
*/ |
|
126 | 133 |
private List<String> getOriginalValuesFromList(List<String> list) { |
127 | 134 |
List<String> origList = new ArrayList<>(); |
128 | 135 |
|
... | ... | |
135 | 142 |
return origList; |
136 | 143 |
} |
137 | 144 |
|
145 |
/** |
|
146 |
* Creates data rows. |
|
147 |
* @param tableColumns Map of TableColumn |
|
148 |
* @param columnNames list of column and user column names |
|
149 |
* @param rowNames list of row and user row names |
|
150 |
* @param valueFunctions list of values and their functions |
|
151 |
* @return list of contingency table rows |
|
152 |
*/ |
|
138 | 153 |
private List<ContingencyTableRow> createDataRows(Map<String, TableColumn> tableColumns, List<NameUserName> columnNames, |
139 | 154 |
List<NameUserName> rowNames, List<ValueFunction> valueFunctions) { |
140 | 155 |
List<ContingencyTableRow> dataRows = new ArrayList<>(); |
... | ... | |
145 | 160 |
values.add(getOriginalValuesFromList(column.getValues())); |
146 | 161 |
} |
147 | 162 |
|
163 |
long startTime = System.nanoTime(); |
|
148 | 164 |
Node node = new Node(); |
149 | 165 |
generateRows(dataRows, 0, values, rowNodes, node); |
166 |
long stopTime = System.nanoTime(); |
|
167 |
System.out.println("Rows List:" + TimeUnit.MILLISECONDS.convert((stopTime - startTime), TimeUnit.NANOSECONDS)); |
|
150 | 168 |
|
151 | 169 |
for (int i = 0; i < dataRows.size(); i++) { |
152 |
fillRowWithCountData(dataRows.get(i), tableColumns, rowNodes.get(i), rowNames, columnNames, valueFunctions);
|
|
170 |
fillRowWithData(dataRows.get(i), tableColumns, rowNodes.get(i), rowNames, columnNames, valueFunctions); |
|
153 | 171 |
} |
154 | 172 |
|
155 | 173 |
return dataRows; |
156 | 174 |
} |
157 | 175 |
|
176 |
/** |
|
177 |
* Recursively generates all possible row combinations, sorted as in contingency table. |
|
178 |
* @param rows list of sorted contingency table rows |
|
179 |
* @param index index in the values list |
|
180 |
* @param values list of lists of values of each query row |
|
181 |
* @param rowNodes list of row nodes |
|
182 |
* @param prevNode parent node of the nodes |
|
183 |
*/ |
|
158 | 184 |
private void generateRows(List<ContingencyTableRow> rows, int index, List<List<String>> values, List<Node> rowNodes, |
159 | 185 |
Node prevNode) { |
160 | 186 |
if (index < values.size()) { |
... | ... | |
177 | 203 |
} |
178 | 204 |
} |
179 | 205 |
|
206 |
/** |
|
207 |
* Recursively generates all possible column combinations, sorted as in contingency table. |
|
208 |
* @param index index in the values list |
|
209 |
* @param values list of lists of values of each query row |
|
210 |
* @param columnNodes list of column nodes |
|
211 |
* @param prevNode parent node of the nodes |
|
212 |
*/ |
|
180 | 213 |
private void generateColumns(int index, List<List<String>> values, List<Node> columnNodes, Node prevNode) { |
181 | 214 |
if (index < values.size()) { |
182 | 215 |
List<String> list = values.get(index); |
... | ... | |
190 | 223 |
} |
191 | 224 |
} |
192 | 225 |
|
193 |
private void fillRowWithCountData(ContingencyTableRow row, Map<String, TableColumn> tableColumns, Node node, |
|
194 |
List<NameUserName> rowNames, List<NameUserName> columnNames, List<ValueFunction> valueFunctions) { |
|
195 |
int totalCount = 0; |
|
196 |
//sloupec v kont. tabulce |
|
197 |
for (Node columnNode : columnNodes) { |
|
198 |
int count = 0; |
|
199 |
// radek v orig. tabulce |
|
200 |
for (int i = 0; i < tableColumns.get(rowNames.get(0).getName()).getValues().size(); i++) { |
|
201 |
boolean isUsable = true; |
|
202 |
//zvoleny sloupec z radku |
|
203 |
for (int j = 0; j < node.getValues().size(); j++) { |
|
204 |
if (!tableColumns.get(rowNames.get(j).getName()).getValues().get(i).equals(node.getValues().get(j))) { |
|
205 |
isUsable = false; |
|
206 |
break; |
|
207 |
} |
|
208 |
} |
|
209 |
int j; |
|
210 |
// zvoleny sloupec ze sloupcu |
|
211 |
for (j = 0; j < columnNode.getValues().size(); j++) { |
|
212 |
if (!tableColumns.get(columnNames.get(j).getName()).getValues().get(i).equals(columnNode.getValues().get(j))) { |
|
213 |
isUsable = false; |
|
214 |
break; |
|
226 |
/** |
|
227 |
* Fills each data row with data. |
|
228 |
* @param row row to ne filled with data |
|
229 |
* @param tableColumns Map of TableColumn |
|
230 |
* @param node node of the row |
|
231 |
* @param rowNames list of row names and user names |
|
232 |
* @param columnNames list of column names and user names |
|
233 |
* @param valueFunctions list of values and their functions |
|
234 |
*/ |
|
235 |
private void fillRowWithData(ContingencyTableRow row, Map<String, TableColumn> tableColumns, Node node, |
|
236 |
List<NameUserName> rowNames, List<NameUserName> columnNames, List<ValueFunction> valueFunctions) { |
|
237 |
if (columnNodes.size() == 0) { |
|
238 |
columnNodes.add(new Node()); |
|
239 |
} |
|
240 |
|
|
241 |
List<Integer> usableIDs = getUsableIDs(tableColumns, node, rowNames); |
|
242 |
|
|
243 |
int[] totals = new int[valueFunctions.size()]; |
|
244 |
//hodnota |
|
245 |
for (int v = 0; v < valueFunctions.size(); v++) { |
|
246 |
ValueFunction valueFunction = valueFunctions.get(v); |
|
247 |
//sloupec v kont. tabulce |
|
248 |
for (Node columnNode : columnNodes) { |
|
249 |
int result = 0; |
|
250 |
// radek v orig. tabulce |
|
251 |
for (Integer usableID : usableIDs) { |
|
252 |
boolean isUsable = true; |
|
253 |
int j; |
|
254 |
// zvoleny sloupec ze sloupcu |
|
255 |
for (j = 0; j < columnNode.getValues().size(); j++) { |
|
256 |
if (!tableColumns.get(columnNames.get(j).getName()).getValues().get(usableID).equals(columnNode.getValues().get(j))) { |
|
257 |
isUsable = false; |
|
258 |
break; |
|
259 |
} |
|
215 | 260 |
} |
216 |
} |
|
217 |
// zvoleny sloupec z hodnot |
|
218 |
for (ValueFunction valueFunction : valueFunctions) { |
|
219 |
if (tableColumns.get(valueFunction.getValue()).getValues().get(i) == null) { |
|
261 |
// zvoleny sloupec z hodnot |
|
262 |
if (tableColumns.get(valueFunction.getValue()).getValues().get(usableID) == null) { |
|
220 | 263 |
isUsable = false; |
221 |
break; |
|
222 | 264 |
} |
223 |
} |
|
224 | 265 |
|
225 |
if (isUsable) { |
|
226 |
count++; |
|
227 |
if (j - 1 == 0) { |
|
228 |
totalCount++; |
|
266 |
if (isUsable) { |
|
267 |
if (valueFunction.getFunction().equals("COUNT")) { |
|
268 |
result++; |
|
269 |
} else if (valueFunction.getFunction().equals("SUM")) { |
|
270 |
result += Integer.parseInt(tableColumns.get(valueFunction.getValue()).getValues().get(usableID)); |
|
271 |
} |
|
272 |
if (j - 1 == 0 || j == 0) { |
|
273 |
if (valueFunction.getFunction().equals("COUNT")) { |
|
274 |
totals[v]++; |
|
275 |
} else if (valueFunction.getFunction().equals("SUM")) { |
|
276 |
totals[v] += Integer.parseInt(tableColumns.get(valueFunction.getValue()).getValues().get(usableID)); |
|
277 |
} |
|
278 |
} |
|
229 | 279 |
} |
230 | 280 |
} |
281 |
row.addTableRowCell(new ContingencyTableRowCell(Integer.toString(result), 0)); |
|
231 | 282 |
} |
283 |
} |
|
284 |
for (int total : totals) { |
|
285 |
row.addTableRowCell(new ContingencyTableRowCell(Integer.toString(total), 0)); |
|
286 |
} |
|
287 |
} |
|
288 |
|
|
289 |
/** |
|
290 |
* Gets a list of IDs of the query rows that fit the contingency table row settings. |
|
291 |
* @param tableColumns Map of TableColumn |
|
292 |
* @param node node of the row |
|
293 |
* @param rowNames list of row names and user names |
|
294 |
* @return list of usable IDs |
|
295 |
*/ |
|
296 |
private List<Integer> getUsableIDs(Map<String, TableColumn> tableColumns, Node node, List<NameUserName> rowNames) { |
|
297 |
List<Integer> ids = new ArrayList<>(); |
|
232 | 298 |
|
233 |
row.addTableRowCell(new ContingencyTableRowCell(Integer.toString(count), 0)); |
|
299 |
for (int i = 0; i < tableColumns.get(rowNames.get(0).getName()).getValues().size(); i++) { |
|
300 |
for (int j = 0; j < node.getValues().size(); j++) { |
|
301 |
if (tableColumns.get(rowNames.get(j).getName()).getValues().get(i).equals(node.getValues().get(j))) { |
|
302 |
ids.add(i); |
|
303 |
} |
|
304 |
} |
|
234 | 305 |
} |
235 | 306 |
|
236 |
row.addTableRowCell(new ContingencyTableRowCell(Integer.toString(totalCount), 0));
|
|
307 |
return ids;
|
|
237 | 308 |
} |
238 | 309 |
} |
src/main/java/vldc/aswi/web/controller/AssemblyController.java | ||
---|---|---|
46 | 46 |
@Autowired |
47 | 47 |
private AssemblyManager assemblyManager; |
48 | 48 |
|
49 |
/** Autowired configuration manager */ |
|
50 |
@Autowired |
|
51 |
private ConfigurationManager configurationManager; |
|
52 |
|
|
49 | 53 |
/** Autowired role manager. */ |
50 | 54 |
@Autowired |
51 | 55 |
private RoleManager roleManager; |
... | ... | |
150 | 154 |
|
151 | 155 |
/** |
152 | 156 |
* Post method for form, where configuration is created from assembly. |
153 |
* @param assembly - Assembly values.
|
|
157 |
* @param newConfiguration - Configuration values.
|
|
154 | 158 |
* @param bindingResult - Error results from assembly validators. |
155 | 159 |
* @param atts - Redirect attributes. |
156 | 160 |
* @return ModelAndView for assembly. |
157 | 161 |
*/ |
158 | 162 |
@PostMapping("/assembly") |
159 |
public ModelAndView assemblyPost(Assembly assembly,
|
|
163 |
public ModelAndView assemblyPost(Configuration newConfiguration,
|
|
160 | 164 |
BindingResult bindingResult, |
161 | 165 |
RedirectAttributes atts, |
162 | 166 |
@RequestParam("assemblyID") String id, |
... | ... | |
165 | 169 |
@RequestParam(required=false, value="exportPdf") String exportPdf, |
166 | 170 |
@RequestParam(required=false, value="saveConfiguration") String saveConfiguration) |
167 | 171 |
{ |
172 |
ModelAndView modelAndView = new ModelAndView(); |
|
173 |
|
|
168 | 174 |
if (generateTable != null) |
169 | 175 |
{ |
170 | 176 |
System.out.println("Generuj tabulku"); |
177 |
prepareForTable(newConfiguration); |
|
178 |
System.out.println("Generuj tabulku"); |
|
179 |
ModelMap modelMap = modelAndView.getModelMap(); |
|
180 |
modelMap.addAttribute("configurationID", id); |
|
181 |
modelMap.addAttribute("contingencyTableRows", this.sqlQueryManager.getContingencyTableRow(newConfiguration)); |
|
182 |
Comparator<ParameterInConfiguration> comparator = Comparator.comparingInt(o -> o.getParameter().getParameterOrder()); |
|
183 |
initializeFields(newConfiguration); |
|
184 |
modelMap.addAttribute("configuration", newConfiguration); |
|
185 |
modelMap.addAttribute("comparator", comparator); |
|
186 |
modelMap.addAttribute("formAction", "/assembly?assemblyID=" + newConfiguration.getAssembly().getId()); |
|
187 |
modelAndView.setViewName("assembly"); |
|
171 | 188 |
} |
172 | 189 |
else if (exportXls != null) |
173 | 190 |
{ |
... | ... | |
180 | 197 |
else if (saveConfiguration != null) |
181 | 198 |
{ |
182 | 199 |
System.out.println("ulož konfiguraci"); |
183 |
} |
|
184 | 200 |
|
201 |
Configuration configuration = configurationManager.saveConfiguration(newConfiguration, ""); |
|
185 | 202 |
|
203 |
initializeFields(configuration); |
|
186 | 204 |
|
187 |
ModelAndView modelAndView = new ModelAndView("redirect:/assembly?assemblyID=" + id); |
|
205 |
modelAndView.setViewName("redirect:/configuration?configurationID=" + configuration.getId()); |
|
206 |
} |
|
188 | 207 |
|
189 | 208 |
return modelAndView; |
190 | 209 |
/* |
... | ... | |
348 | 367 |
|
349 | 368 |
return modelAndView; |
350 | 369 |
} |
370 |
|
|
371 |
/** |
|
372 |
* Initializes fields of a given configuration |
|
373 |
* @param configuration configuration which fields should be initialized |
|
374 |
*/ |
|
375 |
private void initializeFields(Configuration configuration) { |
|
376 |
for(ParameterInConfiguration parameterInConfiguration : configuration.getParametersInConfiguration()) { |
|
377 |
if(parameterInConfiguration.getLocation() == null) { |
|
378 |
parameterInConfiguration.setLocation(new Location()); |
|
379 |
} |
|
380 |
if(parameterInConfiguration.getOperator() == null) { |
|
381 |
parameterInConfiguration.setOperator(new Operator()); |
|
382 |
} |
|
383 |
if(parameterInConfiguration.getFunctions() == null) { |
|
384 |
parameterInConfiguration.setFunctions(new ArrayList<>()); |
|
385 |
} |
|
386 |
} |
|
387 |
} |
|
388 |
|
|
389 |
/** |
|
390 |
* Prepares the configuration for contingency table generation. Initializes assembly and parameters of parameters in |
|
391 |
* configuration. |
|
392 |
* @param configuration configuration to be prepared. |
|
393 |
*/ |
|
394 |
private void prepareForTable(Configuration configuration) { |
|
395 |
Assembly assembly = assemblyManager.getAssemblyById(configuration.getAssembly().getId()); |
|
396 |
configuration.setAssembly(assembly); |
|
397 |
|
|
398 |
for(int i = 0; i < configuration.getParametersInConfiguration().size(); i++) { |
|
399 |
ParameterInConfiguration parameterInConfiguration = configuration.getParametersInConfiguration().get(i); |
|
400 |
parameterInConfiguration.setParameter(assembly.getParameters().get(i)); |
|
401 |
if (parameterInConfiguration.getLocation() != null) { |
|
402 |
parameterInConfiguration.setLocation(locationManager.getLocationById(parameterInConfiguration.getLocation().getId())); |
|
403 |
} |
|
404 |
} |
|
405 |
} |
|
351 | 406 |
} |
src/main/java/vldc/aswi/web/controller/ConfigurationController.java | ||
---|---|---|
7 | 7 |
import org.springframework.stereotype.Controller; |
8 | 8 |
import org.springframework.ui.ModelMap; |
9 | 9 |
import org.springframework.validation.BindingResult; |
10 |
import org.springframework.web.bind.annotation.GetMapping; |
|
11 |
import org.springframework.web.bind.annotation.ModelAttribute; |
|
12 |
import org.springframework.web.bind.annotation.PostMapping; |
|
13 |
import org.springframework.web.bind.annotation.RequestParam; |
|
10 |
import org.springframework.web.bind.annotation.*; |
|
14 | 11 |
import org.springframework.web.servlet.ModelAndView; |
12 |
import vldc.aswi.domain.Assembly; |
|
15 | 13 |
import vldc.aswi.domain.Configuration; |
16 | 14 |
import vldc.aswi.domain.Location; |
17 | 15 |
import vldc.aswi.domain.Operator; |
18 | 16 |
import vldc.aswi.domain.parameter.ParameterInConfiguration; |
17 |
import vldc.aswi.model.table.contingencyTable.ContingencyTableRow; |
|
18 |
import vldc.aswi.service.AssemblyManager; |
|
19 | 19 |
import vldc.aswi.service.ConfigurationManager; |
20 |
import vldc.aswi.service.LocationManager; |
|
20 | 21 |
import vldc.aswi.service.SqlQueryManager; |
21 | 22 |
import vldc.aswi.utils.AuthControl; |
22 | 23 |
import vldc.aswi.utils.Utils; |
... | ... | |
32 | 33 |
@Controller |
33 | 34 |
public class ConfigurationController extends BasicController{ |
34 | 35 |
|
36 |
/** Autowired location manager. */ |
|
37 |
@Autowired |
|
38 |
private LocationManager locationManager; |
|
39 |
|
|
40 |
/** Autowired assembly manager. */ |
|
41 |
@Autowired |
|
42 |
private AssemblyManager assemblyManager; |
|
43 |
|
|
35 | 44 |
/** Autowired sql query manager. */ |
36 | 45 |
@Autowired |
37 | 46 |
private SqlQueryManager sqlQueryManager; |
... | ... | |
86 | 95 |
* @return modelAndView with redirection |
87 | 96 |
*/ |
88 | 97 |
@PostMapping("/configuration") |
89 |
public ModelAndView configurationPost( Configuration newConfiguration,
|
|
98 |
public ModelAndView configurationPost(Configuration newConfiguration, |
|
90 | 99 |
BindingResult bindingResult, |
91 | 100 |
@RequestParam("configurationID") String id, |
92 | 101 |
@RequestParam(required=false, value="generateTable") String generateTable, |
... | ... | |
94 | 103 |
@RequestParam(required=false, value="exportPdf") String exportPdf, |
95 | 104 |
@RequestParam(required=false, value="saveConfiguration") String saveConfiguration) |
96 | 105 |
{ |
106 |
ModelAndView modelAndView = new ModelAndView(); |
|
107 |
|
|
97 | 108 |
if (generateTable != null) |
98 | 109 |
{ |
110 |
prepareForTable(newConfiguration); |
|
99 | 111 |
System.out.println("Generuj tabulku"); |
112 |
ModelMap modelMap = modelAndView.getModelMap(); |
|
113 |
modelMap.addAttribute("configurationID", id); |
|
114 |
modelMap.addAttribute("contingencyTableRows", this.sqlQueryManager.getContingencyTableRow(newConfiguration)); |
|
115 |
Comparator<ParameterInConfiguration> comparator = Comparator.comparingInt(o -> o.getParameter().getParameterOrder()); |
|
116 |
initializeFields(newConfiguration); |
|
117 |
modelMap.addAttribute("configuration", newConfiguration); |
|
118 |
modelMap.addAttribute("comparator", comparator); |
|
119 |
modelMap.addAttribute("formAction", "/configuration?configurationID=" + id); |
|
120 |
modelAndView.setViewName("assembly"); |
|
100 | 121 |
} |
101 | 122 |
else if (exportXls != null) |
102 | 123 |
{ |
... | ... | |
109 | 130 |
else if (saveConfiguration != null) |
110 | 131 |
{ |
111 | 132 |
System.out.println("ulož konfiguraci"); |
112 |
}
|
|
133 |
Configuration configuration = configurationManager.saveConfiguration(newConfiguration, id);
|
|
113 | 134 |
|
135 |
initializeFields(configuration); |
|
114 | 136 |
|
115 |
ModelAndView modelAndView = new ModelAndView(); |
|
137 |
modelAndView.setViewName("redirect:/configuration?configurationID=" + configuration.getId()); |
|
138 |
} |
|
116 | 139 |
|
117 | 140 |
if (bindingResult.hasErrors()) { |
118 | 141 |
// TODO: 04.05.2020 Error message |
... | ... | |
123 | 146 |
|
124 | 147 |
|
125 | 148 |
|
126 |
Configuration configuration = configurationManager.saveConfiguration(newConfiguration, id); |
|
127 | 149 |
|
128 |
this.sqlQueryManager.getContingencyTableRow(configuration.getAssembly().getSQLQuery()); |
|
129 |
|
|
130 |
initializeFields(configuration); |
|
131 |
|
|
132 |
modelAndView.setViewName("redirect:/configuration?configurationID=" + configuration.getId()); |
|
133 | 150 |
|
134 | 151 |
return modelAndView; |
135 | 152 |
} |
... | ... | |
172 | 189 |
} |
173 | 190 |
} |
174 | 191 |
} |
192 |
|
|
193 |
/** |
|
194 |
* Prepares the configuration for contingency table generation. Initializes assembly and parameters of parameters in |
|
195 |
* configuration. |
|
196 |
* @param configuration configuration to be prepared. |
|
197 |
*/ |
|
198 |
private void prepareForTable(Configuration configuration) { |
|
199 |
Assembly assembly = assemblyManager.getAssemblyById(configuration.getAssembly().getId()); |
|
200 |
configuration.setAssembly(assembly); |
|
201 |
|
|
202 |
for(int i = 0; i < configuration.getParametersInConfiguration().size(); i++) { |
|
203 |
ParameterInConfiguration parameterInConfiguration = configuration.getParametersInConfiguration().get(i); |
|
204 |
parameterInConfiguration.setParameter(assembly.getParameters().get(i)); |
|
205 |
if (parameterInConfiguration.getLocation() != null) { |
|
206 |
parameterInConfiguration.setLocation(locationManager.getLocationById(parameterInConfiguration.getLocation().getId())); |
|
207 |
} |
|
208 |
} |
|
209 |
} |
|
175 | 210 |
} |
src/main/webapp/WEB-INF/templates/assembly.html | ||
---|---|---|
177 | 177 |
th:field="${configuration.parametersInConfiguration[__${itemStat.index}__].functions}" |
178 | 178 |
multiple> |
179 | 179 |
<option th:each="function : ${parameterInConfiguration.parameter.functions}" |
180 |
th:text="${function.name}" th:value="${{function.id}}"></option>
|
|
180 |
th:text="${function.name}" th:value="${function.id}"></option>
|
|
181 | 181 |
</select> |
182 | 182 |
</td> |
183 | 183 |
</tr> |
... | ... | |
212 | 212 |
<table class="tg table"> |
213 | 213 |
<tr th:each="contingencyTableRow : ${contingencyTableRows}"> |
214 | 214 |
<div class="tg-align" th:if="${contingencyTableRow.isHeader()}"> |
215 |
<th class="tg-align" th:each="contingencyTableRowCell : ${contingencyTableRow.getCells()}"> |
|
215 |
<th class="tg-align" th:each="contingencyTableRowCell : ${contingencyTableRow.getCells()}" th:colspan="${contingencyTableRowCell.getColSpan()}">
|
|
216 | 216 |
<span th:text="${contingencyTableRowCell.getValue()}"></span> |
217 | 217 |
</th> |
218 | 218 |
</div> |
Také k dispozici: Unified diff
re #7885 added SUM and ability to work with multiple values and sorted parameters in configuration, optimization