Skip to content

Latest commit

 

History

History
73 lines (49 loc) · 6.46 KB

technical-overview.md

File metadata and controls

73 lines (49 loc) · 6.46 KB

Technical overview

Introduction

There are basically three main blocks in this simulation. Simulator and data-transmitter are both entirely written in Java. They are both maven modules. The third one is a frontend application, webapp-angular, that is coded in Dart using the AngularDart framework.

  • Simulator: Handles the simulation part, generates fake data and also provides them to Kapua via the MQTT protocol and the angular web application via the WebSocket protocol. It also accepts some "set" requests from the frontend concerning its parametrisation.

  • Data-transmitter: Subscribes via MQTT to every topics that creates simulator using the "#" wildcard and transmits the received data to angular via WebSocket.

  • Webapp-angular: Communicates with both simulator and data-transmitter through WebSocket in order to get telemetry and application data. Use this data in multiple forms (Map, Chart, etc). Also provides a settings section to allow the user to customise the simulation.

Here is a simple scheme describing the general flow of the simulation:

Simulator

The main simulator uses 3 sub-simulators: company, economy and telemetry simulators. One execution of any of these 3 simulators corresponds to 1 hour elapsed in virtual time. This virtual time is used to speed up the simulation, since we don't want to wait a week in front of our computer to see our first order, for example. The default simulation uses a virtual time 3600 times faster than real time, but it is obviously customisable.

The parametrizer is used to customise the simulation. For example, it can be used to stretch out the interval of time between each "publish" on Kapua.

The company simulator simulates everything related to the company and also acts as a "customer" simulator. By using randomness, it triggers events such as gaining or losing a customer, creating a new type of product, building products based on a product type, receiving orders from customers, planning deliveries, etc. These events are heavily correlated to the economy simulator, since their likelihood depends in majority on its attributes: growth, demand, concurrency, etc.

The economy simulator is a simple and purely random-based simulator which fluctuates the parameters defined in the Economy class.

Last but not least, the telemetry simulator reacts to some events triggered the company and generates data in consequence. For instance, if a delivery goes from state "warehouse" to "shipping", this simulator will start virtually moving the delivery towards its destination and update the underlying data (delivery position, transportation usage, etc)

Aside from the simulation, a service called DataSenderRunner is responsible for periodically sending telemetry data (generated by the telemetry simulator) to Kapua.

Finally, the simulator offers a WebSocket service that can interact with the frontend, either by answering to non-telemetry data requests or by modifying the simulation itself via parametrizer-related requests.

Data transmitter

This service takes care of subscribing to every topic. During its initialisation, it sends a message like "subscribe #" to the Kapua broker, which means the broker will send it copies of every data received from the simulator.

At the same time, the data transmitter opens a websocket server. Every time a client connects to this socket, it is added to the subscribers list.

Any package received from the broker is then broadcasted to the subscribers list.

Webapp-angular

AngularDart makes it possible to build a rich user interface without ever having to refresh the page. Data can go both ways, from the UI to angular and from angular to the UI. The simulation uses this system to dynamically update the graphical interface every time data is received through the WebSocket. It also makes it possible to update the parametrizer on user's inputs on the fly.

There are three views in the web application: Map, Company data and Settings.

Map displays deliveries in real time on a map, using Leaflet library. Clicking on a delivery marker will make a pop up appearing, showing a few information about the selected delivery. Deliveries not in transit anymore (cancelled, delivered, etc) will disappear from the map.

Company data shows the quantity evolution of each storage (e.g. customers, orders, deliveries) on two components: a chart and a table. The chart is generated with Chart.js.

Settings lets the user customise the simulation. He can change for example the simulation's time flow, name of the company, etc.

Technologies

  • Languages
    • Java: simulation, MQTT clients + WebSocket servers
    • Dart: AngularDart frontend app
  • Tests
    • JUnit with Java
  • Build automation tool
    • Apache Maven
  • Continous integration tool
    • Travis
  • Frontend package manager
    • Bower