Projekt

Obecné

Profil

Project architecture » Historie » Verze 52

Alex Konig, 2021-06-11 10:09

1 1 Alex Konig
h1. Project architecture
2
3 2 Alex Konig
The application consists of two parts
4 1 Alex Konig
5 2 Alex Konig
* Server
6
* Client application
7 1 Alex Konig
8 25 Alex Konig
9 2 Alex Konig
h1. Server architecture
10
11 8 Alex Konig
In the following text will be specified the architecture of and the communication between parts of the server application.
12 1 Alex Konig
13 30 Alex Konig
14
h2. Architecture overview
15
16 8 Alex Konig
In the simple visualisation below are displayed classes that are relevant for more than one main package of the server and requests that take place between the main packages.
17
Main packages of the server are the following: 
18
* DataLoader
19
* Parser
20
* Model
21
* Connection
22 1 Alex Konig
* WeatherPredictionParser
23 30 Alex Konig
* UserCommunication
24 1 Alex Konig
25 8 Alex Konig
Main requests that take place within this system are:
26 30 Alex Konig
* Administrator asks UserCommunication for downloading new data or for the retraining of model
27
* Connection asks for prediction for an input from user
28 8 Alex Konig
* Model asks Parser for information acquired from data
29 1 Alex Konig
* Parser asks DataLoader for path to folder containing data
30
* Model asks WeatherPredictionParser for information about current weather prediction for today/tommorrow/day after tommorrow if those data is required to fullfil a request from client
31
32 46 Alex Konig
!basic_architecture_v10.png!
33 30 Alex Konig
34
35 8 Alex Konig
h3. Configuration
36 17 Eliška Mourycová
37
When launching the server application a configuration file must be passed as a command line argument.
38
39 18 Eliška Mourycová
h4. Configuration file
40
41 31 Alex Konig
The configuration file must contain the following lines:
42 18 Eliška Mourycová
43 26 Alex Konig
* site for opendata
44 18 Eliška Mourycová
* naming_convention
45
* data_root_dir
46 1 Alex Konig
* port
47 26 Alex Konig
* site for weather prediction (optional)
48 18 Eliška Mourycová
49
These lines must be followed by lines containing the desired values. 
50 1 Alex Konig
Default setting of the config file is as follows:
51 18 Eliška Mourycová
52 26 Alex Konig
h5. site for opendata
53 18 Eliška Mourycová
54 1 Alex Konig
The site configuration specifies the website where the UWB open data can be downloaded.
55 25 Alex Konig
It is by default set to *http://openstore.zcu.cz/*
56
57 18 Eliška Mourycová
h5. naming_convention
58
59
The naming convention specifies how the archives available for download are named.
60
It is by default set to *OD_ZCU_{type}_{month}_{year}_{format}.zip*
61
Variables in this string must keep their name, cannot be excluded and others cannot be added. They must be enclosed in {} brackets.
62
{} characters are treated as special characters and cannot be used as a part of the name.
63
64
65
h5. data_root_dir
66
67
The data root directory specifies where the downloaded data will be stored. In this root directory subdirectories are created for individual data types.
68 22 Eliška Mourycová
It is by default set to *.\data\auto* (relative to the config file's path)
69 18 Eliška Mourycová
70 1 Alex Konig
h5. port
71 26 Alex Konig
72 1 Alex Konig
The port specifies the port number at which the part of the server listens for clients' connections.
73
It is by default set to *10000*
74 27 Alex Konig
75
h5. site for weather prediction
76
77
Furthermore the configuration file can contain link to the site from which the weather prediction is downloaded. If no page is specified the default site http://wttr.in/Pilsen?format=j1 is used. Used link must lead to a page with a json file in format that satisfies the format specified on page [[Data file structure]]
78 1 Alex Konig
79 15 Eliška Mourycová
h2. DataLoader architecture
80
81 16 Eliška Mourycová
The DataLoader package takes care of downloading data from the specified website, saving them to a specified directory and providing them to the Parser.
82
83
h3. Date class
84
85
The Date class represents a date given by a month and a year. It contains overloaded operators for comparison, these operators are >, <, >=, <=, ==, != . The date is equal if both month and year match. The date is greater than other date if it is after the other date and vice versa.
86
This class also provides a method for increasing a month by one. This method returns a new date with the month increased by one, possibly the year increased by one and the month set to 1 if the original month was 12.
87
88
This class is used by the DataDownloader class to be passed as an argument to various methods (see the server architecture diagram). 
89
90
h3. DataDownloader class
91
92
todo: rename to DataLoader
93
94
This class takes care of data download, storing and providing it to the Parser.
95
The constructor of this class takes 3 arguments 
96
<pre><code class="java">
97
  public DataDownloader(string rootDataDir, string website, string namingConvention)
98
</code></pre>
99
100 21 Eliška Mourycová
The values for these arguments are found in the configuration file.
101 16 Eliška Mourycová
102
It provides public fields
103
<pre><code class="java">
104
  public string RootDataDirectory { get; }
105
  public Dictionary<DataType, string> DataSubDirectories { get; }
106
  public bool OverwriteExisting { get; set; }
107
</code></pre>
108
109
110
h4. Data download
111
112
Data is downloaded using the method 
113
114
<pre><code class="java">
115
  public List<string> DownloadData(DataType type, DataFormat format, Date startDate, Date endDate)
116
</code></pre>
117
118
Data type and format need to be specified (see enums in server architecture for supported types and formats). Also date range needs to be specified using the startDate and endDate arguments. This method then attempts to download all files falling within the range of this date span. It returns a list of full paths to all successfully saved data files.
119
120
121
h4. Data retrieving
122
123
Saved data is retrieved using the method
124 1 Alex Konig
125
<pre><code class="java">
126 16 Eliška Mourycová
  public List<string> GetData(string subDirectory, Date startDate, Date endDate)
127
</code></pre>
128
129
The first argument specifies which subdirectory should be searched. Argumnets startDate and endDate specify the time range.
130 19 Eliška Mourycová
This method returns a list of full paths to all data files corresponding to the specified date range. If not enough files were found (meaning some months for the specified range are missing because they were not downloaded) and a file with month 0 exists in the directory for the year in question, then this file is returned as well.
131 16 Eliška Mourycová
132 30 Alex Konig
h2. UserCommunication architecture
133 16 Eliška Mourycová
134 1 Alex Konig
The UserCommunication package contains a class with a method accepting user's (admin's) commands. This method runs in a separate thread from the rest of the server program. It waits for commands to be input from the command line. 
135 31 Alex Konig
The command can either be a command for retraining of the model which is passed to the Model, or a command for downloading new data files which is passed to DataLoader.
136
137
Model retraining command: "retrain"
138
139
Download command: "dwn <month>" or "dnw <month_from> <moth_to>" where <moth(_from/_to)> is an int between 1-12
140
141 12 Eliška Mourycová
142 1 Alex Konig
h2. Connection architecture
143 20 Eliška Mourycová
144 43 Eliška Mourycová
The connection package takes care of receiving requests from clients and sending responses. It does this using the .NET HttpListener class.
145 47 Eliška Mourycová
It is built upon official example code by Microsoft (https://docs.microsoft.com/en-us/dotnet/api/system.net.httplistener.begingetcontext?view=net-5.0).
146 20 Eliška Mourycová
147 24 Alex Konig
Communication with client driven by rules specfied on page [[Server-client communication]].
148 9 Alex Konig
149 1 Alex Konig
h2. Model architecture
150
151 41 Roman Kalivoda
The model consists of several parts. One part of the module is responsible for extracting features from data sources and for preparing corresponding labels. These classes interact with the parser module. Another part of the module is a class with the implementation of the selected classifier. At the moment, the only classifier planned is the Naive Bayes classifier. 
152
153
The expected control flow of this module is following:
154
* The server handler calls for model re-training: The model receives attendance data from corresponding parsers. It labels received data based on the percentual distribution of activity in the building. The model receives corresponding weather data to the attendance information. The model also receives the identifier of the building. The module selects an existing classifier that is linked with the received building identifier. It extracts the features from weather data so that the feature vectors fit the selected classifier. Then, the created feature vectors and the created labels are used to re-train the model.
155
* The server handler receives a client request for prediction -> it calls prediction from the model module: The model selects a classifier corresponding to the requested building, receives current weather info and extracts features from that. Then, it predicts a possible attendance label based on the features.
156 24 Alex Konig
157 1 Alex Konig
h2. Interface model-parser
158 2 Alex Konig
159 32 Alex Konig
Model can request parsing new data files. This request is done by calling the method Parse() from the class DataParser. 
160 1 Alex Konig
161 32 Alex Konig
<pre><code class="java">
162
  public bool Parse(DateTime startTime, DateTime endTime, int interval = 1, bool wholeDay = true)
163
</code></pre>
164 2 Alex Konig
165 32 Alex Konig
Model specifies the time period in which it is interested (using parameters startTime and endTime, allowing to specify dd:mm:yyyy-dd:mm:yyyy), whether it wants to aggregate data from one day into one information piece (setting parameter wholeDay to true) or into how long intervals (in hours) it wants to divide the days (setting parameters wholeDay to false and interval to the number of hours). 
166
167 10 Alex Konig
For example if the request is done with parameters wholeDay set as false and intervalLength set as 3, days will be divided with a 3h interval. For each day are created entries for the following times:
168 3 Alex Konig
169 10 Alex Konig
* 7-10h
170
* 10-13h
171 1 Alex Konig
* 13-16h
172
* 16-19h
173
174 32 Alex Konig
If request is done with parameter wholeDay set as true, for each day is created only one entry for all events between 7am to 19pm.
175
176
The parsed information is afterwards stored in attributes of DataParser class: WeatherList and AttendanceList. WeatherList contains weather information obtained from data files, and AttendanceList contains the information about the amount of activity (jis activations plus webAuth data) that took place.
177
178 1 Alex Konig
h2. Parser architecture
179
180 29 Alex Konig
Parser part of the server is responsible for reading and parsing data from separate files and aggregating data in a way that was requested by model. It expects input in format specified in [[Data file structure]] and outputs a relatively universal set of information.
181 1 Alex Konig
182
However both output and input are dependant on specific tags used in data. If the only subject of change were these tags, then the only class that needs changing would be TagInfo. If the input data file format was changed then the class CsvDataLoader would need to be changed. If there would be different data input than jis and webauth activity then package InputInfo and Parsers would need to change. Output classes are written to be general (as general weather informationa and activity information), however if there were big changes in input or output specification (for instance new added weather input - fog) it would be better to rewrite (or accordingly modify) this whole module. As long as the interface of DataParser is respected. There is a risk that some changes might interfere with Model too because the model is to a degree dependant on given information derived from, as it extracts symptoms from this information, and we cannot predict which extra symptoms could be added.
183
184 51 Alex Konig
Important classes (some of which were already mentioned above) to note are:
185 1 Alex Konig
186 10 Alex Konig
h3. CsvLoader
187 1 Alex Konig
188 50 Alex Konig
Class responsible for loading input data files into memory. Can be swapped for a class processing different types of files as long as it provides the same methods.
189 1 Alex Konig
190 50 Alex Konig
h4. Methods
191 1 Alex Konig
192 50 Alex Konig
h5. List<JisInstance> LoadJisFile(string pathToFile)
193
194 49 Alex Konig
Method that loads jis file into memory and returns each line translated into an instance of class JisInstance.
195
196 50 Alex Konig
h5. List<LogInInstance> LoadLoginFile(string pathToFile)
197 49 Alex Konig
198
Method that loads computer login file into memory and returns each line translated into an instance of class LogInInstance.
199
200 50 Alex Konig
h5. List<WeatherInstance> LoadWeatherFile(string pathToFile)
201 49 Alex Konig
202
Method that loads weather file into memory and returns each line translated into an instance of class WeatherInstance.
203 48 Alex Konig
204 10 Alex Konig
h3. DataParser
205
206
Class responsible for parsing the input data into information. Can be swapped for a class processing different input files as long as it provides the same methods.
207 1 Alex Konig
208 48 Alex Konig
h4. Attributes
209
210
Important attributes this class has to provide are  the following:
211
212
* List<WeatherInfo> WeatherList - list of WeatherInfo representing overall weather
213
* List<ActivityInfo> AttendanceList - list of ActivityInfo repersenting overall activity
214
* List<string> WeatherDataUsed - list of weather file names the parser was last used on
215
* List<string> ActivityDataUsed - list of activity file names the parser was last used on
216
217
h4. Methods
218
219
Important methods this class has to provide are the following:
220
221
h5. bool Parse(DateTime startTime, DateTime endTime, int interval = 1, bool wholeDay = true)
222
223
Parameters:
224
* DateTime startTime - start time of the time window we're interested in
225
* DateTime endTime - end time of the time window we're interested in 
226
* int interval - by how many hours should be data parsed (not taken into account if wholeDay is false)
227
* bool wholeDay - true if data should be parsed as days, false if by intervals
228
229
Returns true if successful, false if not.
230
231
This method has to fill WeatherList, AttendanceList, WeatherDataUsed and ActivityDataUsed with current information. It uses separate data parsers for Jis, Computer and Weather data (JisParser, LoginParser and WeatherParser, as seen in UML below) which use DataDownloader to download source files, use CsvDataLoader for loading said files into memory, and for parsing them into input data, and then parse them into output information.
232
233
234 1 Alex Konig
h3. TagInfo
235
236 48 Alex Konig
Tags specified in this class correspond to the tables with buildings and locations written down in [[Data sources]].
237 46 Alex Konig
238 9 Alex Konig
!parser_architecture_v3.png!
239 25 Alex Konig
240 1 Alex Konig
h2. WeatherPredictionParser architecture
241 9 Alex Konig
242
This part of the server application is responsible for downloading new information about current weather predictions. It is created to work with the following data source http://wttr.in/?format=j1
243
244 52 Alex Konig
Specific website source to download predictions from can be specified through a config file mentioned in a chapter above.
245 1 Alex Konig
246 52 Alex Konig
h3. Attributes
247
248
* WeatherInfo Current - current weather
249
* List<WeatherInfo> Predictions - weather predictions, in case of JsonParser those are predictions for today, tommorrow and day after tommorrow
250
251
h3. Methods
252
253
h4. void ParsePrediction()
254
255
Parse weather prediction
256
Results is in attributes current for current weather and pred for weather prediction for today, tommorrow and day after tommorrow
257
        
258
259
h4. List<WeatherInfo> GetPredictionForTime(DateTime from, DateTime to)
260
261
This method gets the predictions from Predictions that are within specified time span.
262
263
Paramters
264
* DateTime from - starting time of the timespan we're interested in
265
* DateTime to - end time of the timespan we're interested in
266
267
Returns a List of predictions that fit specified criteria
268 2 Alex Konig
269 1 Alex Konig
h2. Interface Parser-DataLoader
270 2 Alex Konig
271
Parser requests path to folder with data files. Further it can request from DataLoader to filter through data file names and return only those that are from a specified time period (mm:yyyy-mm:yyyy).
272
273 34 Zuzana Káčereková
h1. Client application architecture
274 1 Alex Konig
275 34 Zuzana Káčereková
The client application is a Unity application, therefore creating a UML diagram could prove to be misleading as most classes are scripts attached to objects in the scene.
276 1 Alex Konig
277 34 Zuzana Káčereková
Two client applications exist - an Android client and a WebGL browser client app. Unity WebGL applications are not, generally, supported on mobile platforms. The Unity project is organized in two scenes - Android and WebGL, to be built under their respective platforms. The central component of each scene is the Unity Canvas, set to scale with screen size. Within the hierarchy of the Canvas, customized UI components are used to create the interface, along with a layered map.
278 1 Alex Konig
279 35 Zuzana Káčereková
Unity version 2019.4.20f1 (LTS) was used during development.
280
281
282 34 Zuzana Káčereková
h2. Android client
283
284
The minimum supported Android version is KitKat (4.4).
285
286
h2. WebGL client
287
288 1 Alex Konig
The client has been tested in the following browsers:
289
290 34 Zuzana Káčereková
* Vivaldi (3.6.2165.40)
291 37 Alex Konig
* Chrome (90.0.4430.93)
292
* Mozilla Firefox (80.0)
293 34 Zuzana Káčereková
294 36 Alex Konig
295
WebGL and Android client design history is available on the page [[Client application design]].
296 1 Alex Konig
297 45 Zuzana Káčereková
The WebGL application uses a template container site available at https://github.com/greggman/better-unity-webgl-template by user greggman. (Licensed as CC0)
298 32 Alex Konig
299
h2. Client-Server communication
300
301
Client-server communication is described on a separate page [[Server-client communication]]