-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
executable file
·184 lines (150 loc) · 6.5 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace UDM
{
public class Program
{
static void Main(string[] args)
{
// ------------------------ FIRST TABLE --------------------------------------
Cell c1 = new Cell(2011);
Cell c2 = new Cell(2012);
Cell c3 = new Cell(2013);
Cell s1 = new Cell("Kraków");
Cell s2 = new Cell("Kraków");
Cell s3 = new Cell("Gdańsk");
Cell s4 = new Cell("Gdańsk");
Cell s5 = new Cell("Wrocław");
Cell s6 = new Cell("Poznań");
Cell s7 = new Cell("Wawa");
Cell s8 = new Cell("Gdańsk");
Cell s9 = new Cell("Rzym");
Cell l1 = new Cell((int)15);
Cell l2 = new Cell((int)20);
Cell l3 = new Cell((int)20);
Cell l4 = new Cell((int)30);
Cell l5 = new Cell((int)40);
Cell l6 = new Cell((int)50);
Cell l7 = new Cell((int)60);
Cell l8 = new Cell((int)80);
Cell l9 = new Cell((int)11);
Cell p1 = new Cell(2);
Column c = new Column("Rok", DataType.StringDimension);
c.AddCell(c1);
c.AddCell(c1);
c.AddCell(c2);
c.AddCell(c3);
c.AddCell(c2);
c.AddCell(c3);
c.AddCell(c1);
c.AddCell(c1);
Column s = new Column("Miasto", DataType.StringDimension);
s.AddCell(s1);
s.AddCell(s2);
s.AddCell(s3);
s.AddCell(s4);
s.AddCell(s5);
s.AddCell(s6);
s.AddCell(s7);
s.AddCell(s8);
Column l = new Column("Sprzedaż", DataType.FloatFact);
l.AddCell(l1);
l.AddCell(l2);
l.AddCell(l3);
l.AddCell(l4);
l.AddCell(l5);
l.AddCell(l6);
l.AddCell(l7);
l.AddCell(l8);
Column p = new Column("Coś", DataType.IntegerFact);
p.AddCell(p1);
p.AddCell(p1);
p.AddCell(p1);
p.AddCell(p1);
p.AddCell(p1);
p.AddCell(p1);
p.AddCell(p1);
p.AddCell(p1);
List<Column> mylist = new List<Column>();
//mylist.Add(c);
mylist.Add(s);
mylist.Add(l);
mylist.Add(p);
Table first_table = new Table("Dane1", null, mylist);
//Console.WriteLine(first_table);
first_table.print();
// ------------------------ SECOND TABLE --------------------------------------
Cell s11 = new Cell("Berlin");
Cell s21 = new Cell("Kolonia");
Cell s31 = new Cell("Hamburg");
Cell l11 = new Cell(70.5);
Cell l21 = new Cell(65);
Cell l31 = new Cell((double)15);
Column ss = new Column("Miasto", DataType.StringDimension);
ss.AddCell(s11);
ss.AddCell(s21);
ss.AddCell(s31);
Column ll = new Column("Sprzedaż", DataType.FloatFact);
ll.AddCell(l11);
ll.AddCell(l21);
ll.AddCell(l31);
Column pp = new Column("Coś", DataType.IntegerFact);
pp.AddCell(p1);
pp.AddCell(p1);
pp.AddCell(p1);
List<Column> mylist1 = new List<Column>();
mylist1.Add(ss);
mylist1.Add(ll);
mylist1.Add(pp);
Table second_table = new Table("Dane2", null, mylist1);
// ------------------------ TABLE --------------------------------------------
mylist = new List<Column>();
mylist.Add(c);
mylist.Add(s);
mylist.Add(l);
mylist.Add(p);
Table second = new Table("Tabeleczka", null, mylist);
//Console.WriteLine(second);
second.print();
// ------------------------ GROUP COMMAND -----------------------------------
Dictionary<Column, Aggregation> dict = new Dictionary<Column, Aggregation>();
dict.Add(l, new AverageAggregation());
dict.Add(p, new SumAggregation());
Command cmd = new GroupCommand(new List<Column> { s }, dict);
first_table.Execute(cmd).print();
//Console.WriteLine(first_table.Execute(cmd));
dict[l] = new CountAggregation();
//Console.WriteLine(first_table.Execute(cmd));
first_table.Execute(cmd).print();
dict = new Dictionary<Column, Aggregation>();
dict.Add(l, new AverageAggregation());
dict.Add(p, new SumAggregation());
cmd = new GroupCommand(new List<Column> { c, s }, dict);
//Console.WriteLine(second.Execute(cmd));
second.Execute(cmd).print();
//------------------------- OTHER COMMANDS -----------------------------------
first_table.Execute(new SelectCommand(new List<int> { 0 })).print();
first_table.Execute(new SelectCommand(new List<int> { 1 })).print();
first_table.Execute(new FilterCommand(first_table.Columns[1], cellContent => (double)cellContent > 20)).print();
first_table.Execute(new ComputationOfTwoColumnsCommand(first_table.Columns[1], first_table.Columns[2], (cellContent, cell2Content) => (double)cellContent + (double)cell2Content)).print();
Table result = first_table.Execute(new ComputationOfOneColumnCommand(first_table.Columns[1], cellContent => (double)cellContent * 2));
Table modified = new Table(result.Name, first_table, result.Columns);
modified.print();
modified.Undo().print();
first_table.Execute(new VerticalJoinCommand(second_table)).print();
// ------------------------ AGGREGATION TESTS ---------------------------------------
List<Cell> cells = new List<Cell>();
cells.Add(l11);
cells.Add(l21);
cells.Add(l31);
Console.WriteLine((double)(new SumAggregation()).GetAggregatedValue(cells));
Console.WriteLine((double)(new MaxAggregation()).GetAggregatedValue(cells));
Console.WriteLine((int)(new CountAggregation()).GetAggregatedValue(cells));
Console.WriteLine((double)(new MinAggregation()).GetAggregatedValue(cells));
Console.WriteLine((double)(new AverageAggregation()).GetAggregatedValue(cells));
Console.ReadKey();
}
}
}