Projekt

Obecné

Profil

Project architecture » Historie » Verze 36

Alex Konig, 2021-05-01 16:06

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 33 Alex Konig
!basic_architecture_v7.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
The Connection package takes care of receiving connection requests from clients. 
145
The server is built with an asynchronous socket, so execution of the server application is not suspended while it waits for a connection from a client.
146
See https://docs.microsoft.com/en-us/dotnet/framework/network-programming/asynchronous-server-socket-example for details of used classes. 
147
148 24 Alex Konig
Communication with client driven by rules specfied on page [[Server-client communication]].
149 9 Alex Konig
150 1 Alex Konig
h2. Model architecture
151
152 32 Alex Konig
As model are used multiple Naive Bayes Classifiers, each for each building.
153 24 Alex Konig
154 1 Alex Konig
h2. Interface model-parser
155 2 Alex Konig
156 32 Alex Konig
Model can request parsing new data files. This request is done by calling the method Parse() from the class DataParser. 
157 1 Alex Konig
158 32 Alex Konig
<pre><code class="java">
159
  public bool Parse(DateTime startTime, DateTime endTime, int interval = 1, bool wholeDay = true)
160
</code></pre>
161 2 Alex Konig
162 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). 
163
164 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:
165 3 Alex Konig
166 10 Alex Konig
* 7-10h
167
* 10-13h
168 1 Alex Konig
* 13-16h
169
* 16-19h
170
171 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.
172
173
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.
174
175
176 1 Alex Konig
h2. Parser architecture
177
178 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.
179 1 Alex Konig
180
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.
181
182
Interesting classes (some of which were already mentioned above) to note are:
183
184 10 Alex Konig
h3. CsvLoader
185 1 Alex Konig
186 9 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.
187
188 10 Alex Konig
h3. DataParser
189
190
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.
191
192 9 Alex Konig
h3. TagInfo
193 1 Alex Konig
194
Tags specified in this class correspond to the ones used in [[Data sources]].
195
196
!parser_architecture_v2.png!
197 9 Alex Konig
198 25 Alex Konig
199 1 Alex Konig
h2. WeatherPredictionParser architecture
200 9 Alex Konig
201
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
202
203
Specific place can be specified through a config file mentioned in a chapter above.
204
205 2 Alex Konig
206 1 Alex Konig
h2. Interface Parser-DataLoader
207 2 Alex Konig
208
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).
209
210 34 Zuzana Káčereková
h1. Client application architecture
211 1 Alex Konig
212 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.
213 1 Alex Konig
214 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.
215 1 Alex Konig
216 35 Zuzana Káčereková
Unity version 2019.4.20f1 (LTS) was used during development.
217
218
219 34 Zuzana Káčereková
h2. Android client
220
221
The minimum supported Android version is KitKat (4.4).
222
223
224
h2. WebGL client
225
226 1 Alex Konig
The client has been tested in the following browsers:
227
228 34 Zuzana Káčereková
* Vivaldi (3.6.2165.40)
229
230 36 Alex Konig
231
WebGL and Android client design history is available on the page [[Client application design]].
232 32 Alex Konig
233
234
h2. Client-Server communication
235
236
Client-server communication is described on a separate page [[Server-client communication]]