Shipping Container Spoilage
Build an API to track shipping container temperature sensors to extract useful insights.
- DotNet Core 2.1 WebAPI (a modern, clean, cross-platform framework that promotes good development practices, such as DI and separation of concerns)
- EF Core (InMemory and MS SQL Server provider)
- PowerShell for data generation (cross platform)
- Swagger UI (Development / DEBUG mode only), which provides a nice way to navigate the api spec and exercise its implementation from within a browser (avoiding the need for external tools like Postman)
- Travis CI for on-commit unit testing
- Open API Tools for generating api view models and controller signatures from the api spec https://github.com/OpenAPITools/openapi-generator
Simply clone the repository, and run the solution in the Debug configuration in Visual Studio (2017 or Mac). Storage defaults to an in-memory (transient) data store.
To use an MS SQL database:
- Edit appSettings.json and update the
SqlConnectionproperty so that it points to your database server - Switch the project to the Release configuration
- Using the Package Manager, execute the command
Update-Database
- As it stands, there is no authentication required to use this api (per the spec)
- The ETag provided in the
\trips\{tripId}endpoint isn't actually enforced (per the spec)
In the .\Scripts folder, there is a PowerShell script that can be used to generate container payloads for the \trips\{tripId}/containers endpoint.
The script generates an oscillating range of temperature sensor data, the frequency, speed and range of which may all be optionally configured.
To execute, run the following command: powershell .\GenerateData.ps1 (which will generate a file called output.json, containing enough data to simulate 5 day's worth of data collection).
The script may be executed with one or more optional configuration arguments. Here's an example that uses 2 optional arguments:
powershell .\GenerateData.ps1 -x y -x1 y2
Where:
xis the name of an optional settingyis the value ofxx1is the name of another optional settingy1is the value ofx1- etc...
The arguments available to this script are:
| Argument Name | Type | Usage |
| fileName | string | Where to write the resulting json |
| containerName | string | The name of the container |
| productCount | int | The amount of product in the container |
| minTemp | int | Minimum temperature for generated samples |
| maxTemp | int | Maximum temperature for generated samples |
| interval | float | The temperature variance, per sample |
| dropRate | float | Percentage of samples to drop (To simulate sensor inaccuracy) |
| sampleRate | int | The frequency of temperature sampling (in seconds) |
| days | int | The number of day's worth of data to generate |