/CertainSix

Shipping Container Spoilage

Primary LanguageC#MIT LicenseMIT

CertainSix Build Status

Shipping Container Spoilage

Build an API to track shipping container temperature sensors to extract useful insights.

Stack

  • 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)

Tools Used

  • 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

How to run locally

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 SqlConnection property so that it points to your database server
  • Switch the project to the Release configuration
  • Using the Package Manager, execute the command Update-Database

Known Issues

  • 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)

Generate test data

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.

Basic usage

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).

Advanced usage

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:

  • x is the name of an optional setting
  • y is the value of x
  • x1 is the name of another optional setting
  • y1 is the value of x1
  • etc...

The arguments available to this script are:

Argument NameTypeUsage
fileNamestringWhere to write the resulting json
containerNamestringThe name of the container
productCountintThe amount of product in the container
minTempintMinimum temperature for generated samples
maxTempintMaximum temperature for generated samples
intervalfloatThe temperature variance, per sample
dropRatefloatPercentage of samples to drop (To simulate sensor inaccuracy)
sampleRateintThe frequency of temperature sampling (in seconds)
daysintThe number of day's worth of data to generate