-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDesign.html
249 lines (238 loc) · 17.7 KB
/
Design.html
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<!DOCTYPE HTML>
<!--
Spectral by HTML5 UP
html5up.net | @ajlkn
Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
-->
<html>
<head>
<title>Systems Engineering HCI</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!--[if lte IE 8]><script src="assets/js/ie/html5shiv.js"></script><![endif]-->
<link rel="stylesheet" href="assets/css/main.css" />
<!--[if lte IE 8]><link rel="stylesheet" href="assets/css/ie8.css" /><![endif]-->
<!--[if lte IE 9]><link rel="stylesheet" href="assets/css/ie9.css" /><![endif]-->
</head>
<body>
<!-- Page Wrapper -->
<div id="page-wrapper">
<!-- Header -->
<header id="header">
<h1><a href="index.html">Systems Engineering </a></h1>
<nav id="nav">
<ul>
<li class="special">
<a href="#menu" class="menuToggle"><span>Menu</span></a>
<div id="menu">
<ul>
<li><a href="index.html">Overview</a></li>
<li><a href="Requirements2.html">Requirements</a></li>
<li><a href="Research2.html">Research</a></li>
<li><a href="HCI.html">HCI</a></li>
<li><a href="Design.html">Design</a></li>
<li><a href="Testing.html">Testing</a></li>
<li><a href="Evaluation2.html">Evaluation</a></li>
<li><a href="Management.html">Management</a></li>
</ul>
</div>
</li>
</ul>
</nav>
</header>
<!-- Main -->
<article id="main">
<header>
<h2>Design</h2>
</header>
<section class="wrapper style5">
<div class="inner">
<section>
<h3>System Architecture</h3>
<h5>System Architecture Diagram</h5>
<section>
<img src="images/landscape_diagram.png" style="margin-left: 10%;width: 80%;">
</section>
<br>
<p>
The system is built on top of the Microsoft Azure Cloud Computing Platform. Weather data is delivered to Renewables.ai platform from a number of APIs including the Dark Sky API. Similarly, farm-specific solar energy output is delivered to the platform that has been collected on-site. The Service Fabric joins the APIs together and sends the data to the Event Hubs where the data is queued for consumption.
</p>
<p>
Upon consumption the Stream Analytics ensures that the data is in the correct format and it then stores this data in a SQL Server database. In addition, it applies the energy output prediction model to the data to generate (or update) a forecast, for the specific solar energy farm, and stores this prediction in the SQL Server database. The data in the SQL Server database is then used to in the dynamically generated Azure Web Application that presents the user with a personalised of their solar plant data and predictions. Furthermore, the data in the SQL Server database can be used to answer questions that the chatbot is asked by the user using a wide variety of channels, such as Facebook messenger, Skype, and Slack.
</p>
<p>
The relevant data from the SQL Server database is retrieved using Azure Search. Moreover, when the user asks the chatbot a question using one of its channels it uses the LUIS API to for language understanding so that it can determine the user’s intent and extract relevant entities from the question.
</p>
<hr />
<h3>CLass Diagram</h3>
<h5>Chatbot Class Diagram</h5>
<section>
<img src="images/class.jpg" style="margin-left: 10%;width: 80%;">
</section>
<hr />
<h3>Design Patterns</h3>
<h5>Singleton</h5>
<p>
The singleton pattern is a Gang of Four design pattern. It is a creational pattern as it is used to control class instantiation. The pattern ensures that only one object of a particular class is ever created. All further references to objects of the singleton class refer to the same underlying instance.
The singleton pattern is useful when a single, global point of access to a limited resource is required. [1]
</p>
<p>
We used the singleton design pattern a number of times in the code for the chatbot. We did this to ensure that we only ever had 1 database connection and did not connect to the same API multiple times within one session, as this would be costly over a long period of time and may cause us to exceed our API quota.
</p>
<h5>Observer</h5>
<p>
The observer pattern is a Gang of Four design pattern. This is a behavioural pattern as it defines a manner for controlling communication between classes or entities. The observer pattern is used to allow a single object, known as the subject, to publish changes to its state. Many other observer objects that depend upon the subject can subscribe to it so that they are immediately and automatically notified of any changes to the subject's state.
</p>
<p>
The pattern gives loose coupling between the subject and its observers. The subject holds a collection of observers that are set only at run-time. Each observer may be of any class that inherits from a known base class or implements a common interface. The actual functionality of the observers and their use of the state data need not be known by the subject. [2]
</p>
<p>
We implemented the Observer design pattern in the chatbot code intent dialog to be notified whenever the chatbot received a message from one of its channels through the ChatConnector.
</p>
<h5>Strategy</h5>
<p>
The strategy pattern is a Gang of Four design pattern. This is a behavioural pattern as it defines a manner for controlling communication between classes or entities. The strategy pattern is used to create an interchangeable family of algorithms from which the required process is chosen at run-time. This allows the behaviour of a program to change dynamically according to configuration details or user preferences. It also increases flexibility by allowing new algorithms to be easily incorporated in the future.
</p>
<p>
As an example, the strategy pattern could be used within the scoring system of a fictitious game. In the game, players must run around a circuit that includes a series of checkpoints. At each checkpoint, the player must throw projectiles at a target. Points are scored for successful hits and removed for a slow time around the entire circuit. It may be that men, women and children use different scoring systems. In this case, a set of scoring algorithms could be developed and the decision of which to use be made at run-time, according to the sex and age of each competitor.[3]
</p>
<p>
This design pattern was used in the chatbot code as depicted by the class diagram above. The IntentsHelper is the strategy base which at runtime has 4 dependencies injected into it which are used to answer different categories of user questions. The advantage of using the strategy design pattern is that the implementation of any of the injected classes can be changed which reduces dependencies and increases cohesion making the system more flexible to change in the future.
</p>
<h5>Memento</h5>
<p>
The memento pattern is a Gang of Four design pattern. This is a behavioural pattern as it defines a manner for controlling communication between classes or entities. The memento pattern is used to capture the current state of an object and store it in such a manner that it can be restored at a later time. Importantly, the pattern allows for the internal state of an object to be saved without breaking the rules of encapsulation.
</p>
<p>
We used this design pattern in the chatbot in order to enable the chatbot to remember what the user had said previously in a dialog.
</p>
<h5>Proxy</h5>
<p>
The proxy pattern is a Gang of Four design pattern. This is a structural pattern as it defines a manner for creating relationships between classes or entities. The proxy design pattern is used to provide a surrogate or placeholder object, which references an underlying object. The proxy provides the same public interface as the underlying subject class. It adds a level of indirection by accepting requests from a client object and passing these to the real subject object as necessary. This can improve the efficiency of access to objects that you do not wish to access directly, perhaps because they are slow to execute or are resource-intensive, or because you wish to add extra functionality. [5]
</p>
<p>
We used this design pattern in the chatbot to the number of calls made to the LUIS API because we wanted to reduce the number of API calls so that we did not risk exceeding the API quota. We did this by storing the result of the most recent 500 API calls, along with their timestamp, made to LUIS and if the same call was made twice within 24 hours it would use the stored result, as opposed to making an unnecessary LUIS API call.
</p>
<hr />
<h3>Data Storage</h3>
<p>
The solar energy plant data, weather data, and energy prediction data were stored in a MySQL (relational) database.
</p>
<h5>Data Schema</h5>
<section>
<img src="images/dataschema.jpg" style="margin-left: 10%;width: 80%;">
</section>
<hr />
<h3>Implementation of Key Functionalities</h3>
<h4>Chatbot Implementation of Key Functionalities</h4>
<p>
Here we summarise a number of key code snippets for the chatbot.
</p>
<h5>Energy Output for a Plant Question Call to Helper Method</h5>
<section>
<img src="images/ss1.jpg" style="margin-left: 10%;width: 80%;">
</section>
<br>
<p>
After the LUIS API matches the user’s question to the “Production.Plant” intent the code above is executed. This code checks to see whether 2 date entities have been extracted from the user’s question and if so it calls a helper method to calculate the total energy output for the given farm between the two dates. Similarly, if only 1 date entity has been extracted from the user’s question the helper method used to calculate the energy output of a single farm is used. Otherwise, the chatbot starts a dialog with the user asking them to provide it with at least one date - this is performed by the getDateStep1 method which is passed into the matches 2nd argument array.
</p>
<h5>Top N Performing Plants Helper Method</h5>
<section>
<img src="images/ss2.jpg" style="margin-left: 10%;width: 80%;">
</section>
<br>
<p>
When the LUIS API matches the “BestWorstDays” intent, the above helper method is called from chatbot.js. This helper method is passed a plant name, start date, and an end date which it uses to construct a SQL query to the MySQL database containing the plant’s data. It then formats the result of the query to a response string and returns it.
</p>
<h5>The Chatbot Asks for the Missing Date(s) Entity</h5>
<section>
<img src="images/ss3.jpg" style="margin-left: 10%;width: 80%;">
</section>
<br>
<p>
The code above is executed whenever an intent is matched whose helper methods require a date entity to be extracted from the question and LUIS was unable to extract any date entities and thus the chatbot was forced to ask the user for the date(s). The code uses the Chrono library to extract at most 2 date entities from the user’s response and converts them into a specific format (Chrono lacks a string formatting method so a temporary hack (JSON.stringify) was used to get around this but note that in the final code this should be removed).
</p>
<h5>Generate a Graph for a Given Metric for a Plant Helper Method</h5>
<section>
<img src="images/ss4.jpg" style="margin-left: 10%;width: 80%;">
</section>
<br>
<p>
The above code is the helper method within the IntentsHelper module that is used to generate an inline graph for the chabot to respond with if the user asks to see a specific graph. It does this by taking in the axis variables, plant name, start date, and end date. It first converts the extracts the relevant data from the axis variables and stores it in a trace variable. Then it creates a write stream which pipes data to png image file on the server. Once the image has finished being uploaded to the server it is asynchronous read and converted into an inline png bit string which is subsequently sent to the user and rendered by the user.
</p>
<hr />
<h4>Data Science - Energy Prediction Implementation of Key Functionalities</h4>
<h5>Importing The Data From the CSV Files</h5>
<section>
<img src="images/ss5.jpg" style="margin-left: 10%;width: 80%;">
</section>
<br>
<h5>Regularizing The Data</h5>
<section>
<img src="images/ss6.jpg" style="margin-left: 10%;width: 80%;">
</section>
<br>
<h5>Detecting and Removing Outliers in The Data</h5>
<section>
<img src="images/ss7.jpg" style="margin-left: 10%;width: 80%;">
</section>
<br>
<h5>Ensures The Data Does Not Start Half-Way Through a Day</h5>
<section>
<img src="images/ss8.jpg" style="margin-left: 10%;width: 80%;">
</section>
<br>
<h5>Fill in Missing Data That is in a Sequence of Less Than or Equal to 2 by Interpolation</h5>
<section>
<img src="images/ss9.jpg" style="margin-left: 10%;width: 80%;">
</section>
<br>
<h5>Fill in Missing Data That is in a Sequence of Greater Than or Equal to 2 by Interpolation With Previous and Next Days</h5>
<section>
<img src="images/ss10.jpg" style="margin-left: 10%;width: 80%;">
</section>
<br>
<h5>Training Prophet Model</h5>
<section>
<img src="images/ss11.jpg" style="margin-left: 10%;width: 80%;">
</section>
<br>
<h5>Generating Energy Prediction Using The Prophet Model Comparing and It With Linear Regression</h5>
<section>
<img src="images/ss12.jpg" style="margin-left: 10%;width: 80%;">
</section>
<hr/>
<h4>References</h4>
<ul class="alt">
<li>
[1] = http://www.blackwasp.co.uk/Singleton.aspx
</li>
<li>
[2] = http://www.blackwasp.co.uk/Observer.aspx
</li>
<li>
[3] = http://www.blackwasp.co.uk/Strategy.aspx
</li>
<li>
[4] = http://www.blackwasp.co.uk/Memento.aspx
</li>
<li>
[5] = http://www.blackwasp.co.uk/Proxy.aspx
</li>
</ul>
<hr />
</section>
</div>
</section>
</article>
</div>
<!-- Scripts -->
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/jquery.scrollex.min.js"></script>
<script src="assets/js/jquery.scrolly.min.js"></script>
<script src="assets/js/skel.min.js"></script>
<script src="assets/js/util.js"></script>
<!--[if lte IE 8]><script src="assets/js/ie/respond.min.js"></script><![endif]-->
<script src="assets/js/main.js"></script>
</body>
</html>