Skip to content

Commit

Permalink
Added aircraft altitude and position recording
Browse files Browse the repository at this point in the history
  • Loading branch information
davewalker5 committed Sep 1, 2023
1 parent fe80ac2 commit db0a029
Show file tree
Hide file tree
Showing 40 changed files with 990 additions and 103 deletions.
File renamed without changes
Binary file added Diagrams/position_table.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
| ApplicationSettings | TimeToStale | --stale | -s | Threshold, in ms, after the most recent message at which an aircraft is considered "stale" (see states, below) |
| ApplicationSettings | TimeToRemoval | --remove | -x | Threshold, in ms, after the most recent message at which an aircraft is removed from tracking (see states, below) |
| ApplicationSettings | LogFile | --log-file | -l | Path and name of the log file |
| ApplicationSettings | MinimumLogLevel | --log-level | -ll | Minimum message severity to log (Debug, Info, Warning or Error) |
| ApplicationSettings | EnableSqlWriter | --enable-sql-writer | -w | Set to true to enable the SQL writer or false to disable it |
| ApplicationSettings | WriterInterval | --writer-interval | -i | Interval, in ms, at which the writer writes batches of changes from the queue to the database |
| ApplicationSettings | WriterBatchSize | --writer-batch-size | -b | Maximum number of changes to consider on each WriterInterval |
Expand Down Expand Up @@ -139,9 +140,14 @@
## SQLite Database

### Database Schema
- Tracking records are written to a single table, called AIRCRAFT, with each row summarising the detail from the messages received for a given aircraft:
- Each aircraft tracked in a given session has a record in the AIRCRAFT table that is created when the aircraft is first seen and updated as further messages are received from that aircraft:

![Tracking Table](Diagrams/database.png)
![Tracking Table](Diagrams/aircraft_table.png)

- The altitude, latitude and longitude of an aircraft are recorded in the AIRCRAFT_POSITION table as changes are reported
- The AIRCRAFT_POSITION table has a foreign key back to the related record in the AIRCRAFT table:

![Tracking Table](Diagrams/position_table.png)

### Database Management
- The application uses Entity Framework Core and initial creation and management of the database is achieved using EF Core database migrations
Expand Down
4 changes: 2 additions & 2 deletions src/BaseStationReader.Data/BaseStationReader.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>BaseStationReader.Data</PackageId>
<PackageVersion>1.17.0.0</PackageVersion>
<PackageVersion>1.18.0.0</PackageVersion>
<Authors>Dave Walker</Authors>
<Copyright>Copyright (c) Dave Walker 2023</Copyright>
<Owners>Dave Walker</Owners>
Expand All @@ -17,7 +17,7 @@
<PackageProjectUrl>https://github.com/davewalker5/ADS-B-BaseStationReader</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<ReleaseVersion>1.17.0.0</ReleaseVersion>
<ReleaseVersion>1.18.0.0</ReleaseVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
29 changes: 29 additions & 0 deletions src/BaseStationReader.Data/BaseStationReaderDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace BaseStationReader.Data
public partial class BaseStationReaderDbContext : DbContext
{
public virtual DbSet<Aircraft> Aircraft { get; set; }
public virtual DbSet<AircraftPosition> AircraftPositions { get; set; }

public BaseStationReaderDbContext(DbContextOptions<BaseStationReaderDbContext> options) : base(options)
{
Expand Down Expand Up @@ -50,6 +51,34 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.HasColumnName("LastSeen")
.HasColumnType("DATETIME");
});

modelBuilder.Entity<AircraftPosition>(entity =>
{
modelBuilder.Entity<AircraftPosition>().Ignore(e => e.Address);
entity.ToTable("AIRCRAFT_POSITION");
entity.Property(e => e.Id)
.HasColumnName("Id")
.ValueGeneratedOnAdd();
entity.Property(e => e.AircraftId)
.IsRequired()
.HasColumnName("AircraftId");
entity.Property(e => e.Latitude)
.IsRequired()
.HasColumnName("Latitude");
entity.Property(e => e.Longitude)
.IsRequired()
.HasColumnName("Longitude");
entity.Property(e => e.Timestamp)
.IsRequired()
.HasColumnName("Timestamp")
.HasColumnType("DATETIME");
});
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace BaseStationReader.Data.Migrations
{
/// <inheritdoc />
public partial class AircraftPositions : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "AIRCRAFT_POSITION",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
AircraftId = table.Column<int>(type: "INTEGER", nullable: false),
Altitude = table.Column<decimal>(type: "TEXT", nullable: false),
Latitude = table.Column<decimal>(type: "TEXT", nullable: false),
Longitude = table.Column<decimal>(type: "TEXT", nullable: false),
Timestamp = table.Column<DateTime>(type: "DATETIME", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AIRCRAFT_POSITION", x => x.Id);
});
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "AIRCRAFT_POSITION");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// <auto-generated />
using System;
using System.Diagnostics.CodeAnalysis;
using BaseStationReader.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
Expand All @@ -10,7 +9,6 @@

namespace BaseStationReader.Data.Migrations
{
[ExcludeFromCodeCoverage]
[DbContext(typeof(BaseStationReaderDbContext))]
partial class BaseStationReaderDbContextModelSnapshot : ModelSnapshot
{
Expand Down Expand Up @@ -79,6 +77,37 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("AIRCRAFT", (string)null);
});

modelBuilder.Entity("BaseStationReader.Entities.Tracking.AircraftPosition", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER")
.HasColumnName("Id");
b.Property<int>("AircraftId")
.HasColumnType("INTEGER")
.HasColumnName("AircraftId");
b.Property<decimal>("Altitude")
.HasColumnType("TEXT");
b.Property<decimal>("Latitude")
.HasColumnType("TEXT")
.HasColumnName("Latitude");
b.Property<decimal>("Longitude")
.HasColumnType("TEXT")
.HasColumnName("Longitude");
b.Property<DateTime>("Timestamp")
.HasColumnType("DATETIME")
.HasColumnName("Timestamp");
b.HasKey("Id");
b.ToTable("AIRCRAFT_POSITION", (string)null);
});
#pragma warning restore 612, 618
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>BaseStationReader.Entities</PackageId>
<PackageVersion>1.17.0.0</PackageVersion>
<PackageVersion>1.18.0.0</PackageVersion>
<Authors>Dave Walker</Authors>
<Copyright>Copyright (c) Dave Walker 2023</Copyright>
<Owners>Dave Walker</Owners>
Expand All @@ -17,7 +17,7 @@
<PackageProjectUrl>https://github.com/davewalker5/ADS-B-BaseStationReader</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<ReleaseVersion>1.17.0.0</ReleaseVersion>
<ReleaseVersion>1.18.0.0</ReleaseVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion src/BaseStationReader.Entities/Config/ApplicationSettings.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Diagnostics.CodeAnalysis;
using BaseStationReader.Entities.Logging;
using System.Diagnostics.CodeAnalysis;

namespace BaseStationReader.Entities.Config
{
[ExcludeFromCodeCoverage]
public class ApplicationSettings
{
public Severity MinimumLogLevel { get; set; }
public string Host { get; set; } = "";
public int Port { get; set; }
public int SocketReadTimeout { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
public enum CommandLineOptionType
{
MinimumLogLevel,
Host,
Port,
SocketReadTimeout,
Expand All @@ -13,6 +14,7 @@ public enum CommandLineOptionType
EnableSqlWriter,
WriterInterval,
WriterBatchSize,
PositionInterval,
MaximumRows
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class AircraftNotificationEventArgs : EventArgs
#pragma warning disable CS8618
public Aircraft Aircraft { get; set; }
#pragma warning restore CS8618
public AircraftPosition? Position { get; set; }
public AircraftNotificationType NotificationType { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace BaseStationReader.Entities.Interfaces
{
public interface IAircraftManager
public interface IAircraftWriter
{
Task<Aircraft> GetAsync(Expression<Func<Aircraft, bool>> predicate);
Task<List<Aircraft>> ListAsync(Expression<Func<Aircraft, bool>> predicate);
Expand Down
12 changes: 12 additions & 0 deletions src/BaseStationReader.Entities/Interfaces/IPositionWriter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using BaseStationReader.Entities.Tracking;
using System.Linq.Expressions;

namespace BaseStationReader.Entities.Interfaces
{
public interface IPositionWriter
{
Task<AircraftPosition> GetAsync(Expression<Func<AircraftPosition, bool>> predicate);
Task<List<AircraftPosition>> ListAsync(Expression<Func<AircraftPosition, bool>> predicate);
Task<AircraftPosition> WriteAsync(AircraftPosition template);
}
}
3 changes: 1 addition & 2 deletions src/BaseStationReader.Entities/Interfaces/IQueuedWriter.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using BaseStationReader.Entities.Events;
using BaseStationReader.Entities.Tracking;

namespace BaseStationReader.Entities.Interfaces
{
public interface IQueuedWriter
{
event EventHandler<BatchWrittenEventArgs>? BatchWritten;
void Push(Aircraft aircraft);
void Push(object entity);
void Start();
void Stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace BaseStationReader.Entities.Interfaces
{
public interface ITrackerLogger
{
void Initialise(string logFile);
void Initialise(string logFile, Severity minimumSeverityToLog);
void LogMessage(Severity severity, string message);
void LogException(Exception ex);
}
Expand Down
Loading

0 comments on commit db0a029

Please sign in to comment.