Compare commits

...

12 Commits

Author SHA1 Message Date
0cf2360576 Updated Navdata view 2022-02-07 20:25:28 +00:00
5a49e270b9 Updated Navbar Layout 2022-02-07 20:00:51 +00:00
58eef9ea67 Added Navdata View (Needs Tweaking) 2022-02-01 20:25:31 +00:00
ef4d44d7d2 Added MergeSort Function for Navdata 2022-01-31 22:50:09 +00:00
c41f19811f Added Binary Search to Navdata 2022-01-31 15:59:44 +00:00
cd488440b9 Updated Populate Method to get data from DB
Runs extremely quickly ~150ms on my system in debug mode (10,000 records)
2022-01-31 15:07:16 +00:00
f0da93cdae Updated route controller to go through every response from the server to avoid missing a key item 2022-01-31 14:29:09 +00:00
9e00882743 Updated Route controller to adapt to new model 2022-01-31 14:23:23 +00:00
334ad6bce5 Altered user Model to allow for pure string value as oposed to object 2022-01-31 12:10:06 +00:00
3cb2b9c9b5 Updated Session extensions and Route Contoller
Increased the number of Poll requests and disabled an irrelevant error stating that there was a cyclical struture (Just a Doubly Linked List)
2022-01-27 09:46:38 +00:00
924e25e1c6 Update NavdataModel.cs 2022-01-26 13:34:49 +00:00
b68cc2ac3f Created NavData Model
Create Navdata Model and add Navata controller (Currently empty)
2022-01-26 13:11:04 +00:00
9 changed files with 315 additions and 14 deletions

View File

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using EFB.Models;
using EFB.Sessions;
namespace EFB.Controllers
{
//[Route("[controller]")]
public class NavdataController : Controller
{
private readonly ILogger<NavdataController> _logger;
public NavdataController(ILogger<NavdataController> logger)
{
_logger = logger;
}
public async Task<IActionResult> Index(string identifier)
{
if (identifier == null)
{//In the event we are just going to the base page1
return View();
}
NavdataModel[] data = null;
if (HttpContext.Session.GetObject<NavdataModel[]>("Navdata") == null)
{//If the navdata needs re-caching
data = await NavdataModel.Populate();
HttpContext.Session.SetObject("Navdata", NavdataModel.MergeSort(ref data, 0, data.Length-1));
}
//get the data out of tempdata and cast it into an array
data = HttpContext.Session.GetObject<NavdataModel[]>("Navdata");
NavdataModel navaid = NavdataModel.BinarySearch(ref data, 0, data.Length-1, identifier);
if (navaid == null)
{
TempData["Error"] = $"Sorry, no Navaid found with the name {identifier}";
}
return View(navaid);
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View("Error!");
}
}
}

View File

@ -127,21 +127,22 @@ namespace EFB.Controllers
Dictionary<string, string> headerData = new Dictionary<string, string>();
headerData.Add("Authorization", $"Bearer {user.UserToken.TokenValue}");
while (collected == false && pollCount < 3)
while (collected == false && pollCount < 15)
{
//Make Polling Request
var pollingRequest = API.Put<List<PollResponse>>($"https://api.autorouter.aero/v1.0/router/{user.RouteToken.TokenValue}/longpoll", headerData, null);
ResponseModel<List<PollResponse>> responsePoll = await pollingRequest;
int routePos = responsePoll.Result.Count - 1;
if (responsePoll.Result[routePos].Command == "solution")
foreach (var item in responsePoll.Result)
{
if (item.Command == "fpl" || item.Command == "solution")
{
collected = true;
routeString = responsePoll.Result[routePos].FlightPlan;
routeString = item.FlightPlan;
break;
}
}
Thread.Sleep(3000);
pollCount++;
@ -152,9 +153,7 @@ namespace EFB.Controllers
{
//fill in route
string finalRoute = RouteModel.ParseRoute(routeString);
RouteModel route = RouteModel.StringToRoute(departure, arrival, cruise, finalRoute);
user.Route = route;
user.Route = finalRoute;
HttpContext.Session.SetObject("User", user);
return RedirectToAction("Index", "Route");

View File

@ -4,5 +4,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1"/>
<PackageReference Include="MySql.Data" Version="*"/>
</ItemGroup>
</Project>

147
Models/NavdataModel.cs Normal file
View File

@ -0,0 +1,147 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
using Newtonsoft.Json;
using Microsoft.AspNetCore.Mvc;
using EFB.Sessions;
namespace EFB.Models
{
public class NavdataModel
{
public int Id { get; set; }
public string Name { get; set; }
public string Type { get; set; }
public int? Frequency { get; set; }
public string Latitude { get; set; }
public string Longitude { get; set; }
public NavdataModel(int id, string name, string type, string latitude, string longitude){
Id = id;
Name = name;
Type = type;
Frequency = null;
Latitude = latitude;
Longitude = longitude;
}
[JsonConstructor]
public NavdataModel(int id, string name, string type, int? frequency, string latitude, string longitude){
Id = id;
Name = name;
Type = type;
Frequency = frequency;
Latitude = latitude;
Longitude = longitude;
}
public static async Task<NavdataModel[]> Populate(){
MySqlConnection con = new MySqlConnection("server=server.luke-else.co.uk;userid=root;password=;database=EFB");
con.Open();
// Console.WriteLine($"MySQL version : {con.ServerVersion}");
string query = "SELECT * FROM waypoints";
MySqlCommand command = new MySqlCommand(query, con);
MySqlDataReader reader = (MySqlDataReader) await command.ExecuteReaderAsync();
List<NavdataModel> navdata = new List<NavdataModel>();
while (reader.Read())
{
int id = reader.GetInt32(0);
string name = reader.GetString(1);
string type = reader.GetString(2);
string latitude = reader.GetString(4);
string longitude = reader.GetString(5);
if (type == "VOR" || type == "NDB")
{
// int? frequency = reader.GetInt32(3);
int? frequency = null;
navdata.Add(
new NavdataModel(id, name, type, frequency, latitude, longitude)
);
}else{
navdata.Add(
new NavdataModel(id, name, type, latitude, longitude)
);
}
}
return navdata.ToArray<NavdataModel>();
}
public static NavdataModel BinarySearch(ref NavdataModel[] data, int start, int end, string target){
int midpoint = start + ((end - start) / 2);
target = target.ToUpper().Trim();
string mid = data[midpoint].Name;
if (start == end-1)
{
if (mid == target)
{
return data[midpoint];
}
return null;
}
if (String.Compare(target, mid) < 0)
{
return BinarySearch(ref data, start, midpoint, target);
}
return BinarySearch(ref data, midpoint, end, target);
}
public static NavdataModel[] MergeSort(ref NavdataModel[] data, int start, int end)
{
if (start == end)
{//If we have narrowed it down to a single Item
return new NavdataModel[] { data[start] };
}
int midpoint = start + ((end - start) / 2);
//Split the data down to the left and the right portions
NavdataModel[] left = MergeSort(ref data, start, midpoint);
NavdataModel[] right = MergeSort(ref data, midpoint+1, end);
List<NavdataModel> combined = new List<NavdataModel>();
int leftPointer = 0;
int rightPointer = 0;
while (leftPointer <= left.Length-1 || rightPointer <= right.Length-1)
{
if (leftPointer == left.Length)
{//Take a value only from the right (left pointer had reached the end)
AddValue(ref combined, right[rightPointer], ref rightPointer);
}else if (rightPointer == right.Length)
{//Take a value only from the left (right pointer has reached the end)
AddValue(ref combined, left[leftPointer], ref leftPointer);
}else{
if (String.Compare(left[leftPointer].Name, right[rightPointer].Name) <= 0)
{//Take a value from the left hand side of the list. (Left value is considered 'smaller')
AddValue(ref combined, left[leftPointer], ref leftPointer);
}else{//Take a value from the right (right value is considered smaller)
AddValue(ref combined, right[rightPointer], ref rightPointer);
}
}
}
return combined.ToArray();
}
private static void AddValue(ref List<NavdataModel> data, NavdataModel value, ref int pointer){
pointer++;
data.Add(value);
}
}
}

View File

@ -88,7 +88,7 @@ namespace EFB.Models
route.Current.Next = route.Arrival;
route.Arrival.Previous = route.Current;
route.Current = null;
route.Current = route.Departure;
return route;
}

View File

@ -21,7 +21,7 @@ namespace EFB.Models
public TokenModel UserToken { get; set; } = null;
//Contains the most recent route generated by the user through the App
public RouteModel Route { get; set; } = null;
public string Route { get; set; }
public TokenModel RouteToken { get; set; } = null;
//Contains the most recently stored position of the user in the simulator

View File

@ -7,7 +7,11 @@ namespace EFB.Sessions
{
public static void SetObject(this ISession session, string key, object value)
{//Sets the object of a session to Object
session.SetString(key, JsonConvert.SerializeObject(value));
session.SetString(key, JsonConvert.SerializeObject(value, Formatting.None,
new JsonSerializerSettings(){
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
}
));
}
public static T GetObject<T>(this ISession session, string key)

View File

@ -0,0 +1,63 @@
@model EFB.Models.NavdataModel
@{
ViewData["Title"] = "Welcome";
}
<div class="row d-flex justify-content-center">
<div class="card-body col-md-6">
<div class="container jumbotron">
<h3>Navdata Lookup</h3>
<br />
<br />
<form asp-controller="Navdata" asp-action="Index">
<div class="form-group">
<input type="text" class="form-control" placeholder="Identifier" name="identifier" value="@TempData["identifier"]">
</div>
<button type="submit" class="btn btn-secondary">Search</button>
@{
if (TempData["Error"] != null)
{//If an error has been flagged, information will be displayed to the user
<br />
<br />
<div class="alert alert-danger">
<strong>Warning!</strong> @TempData["Error"] <button type='button' class='close' data-dismiss='alert' aria-hidden='true' />&times;
</div>
}
}
</form>
</div>
</div>
@{
if(Model != null){
<div class="card-body bg-warning col-md-6">
<div class="container jumbotron">
<h3>@Model.Name (@Model.Type) [@Model.Id]</h3>
<br />
<h4>Latitude</h4>
@Model.Latitude
<h4>Longitude</h4>
@Model.Longitude
@{
if(Model.Frequency != null){
<h4>Frequency</h4>
@Model.Frequency
}
}
</div>
</div>
}
}
</div>

View File

@ -1,4 +1,8 @@
<!DOCTYPE html>
@using Microsoft.AspNetCore.Http;
@using Microsoft.AspNetCore.Mvc;
@using EFB.Sessions;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
@ -21,7 +25,34 @@
<li class="nav-item">
<a class="nav-link text-light" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-light" asp-area="" asp-controller="Route" asp-action="Index">Route</a>
</li>
<li class="nav-item">
<a class="nav-link text-light" asp-area="" asp-controller="Navdata" asp-action="Index">Navdata</a>
</li>
<li class="nav-item">
<a class="nav-link text-light" asp-area="" asp-controller="" asp-action="Index">Charts</a>
</li>
<li class="nav-item">
<a class="nav-link text-light" asp-area="" asp-controller="" asp-action="Index">FlightSim</a>
</li>
@{
UserModel user = Context.Session.GetObject<UserModel>("User");
if (user != null && user.UserToken.TokenValue != null)
{
<div class="ml-auto">
<li class="nav-item">
<a class="nav-link text-light" asp-area="" asp-controller="User" asp-action="Logout">Logout (@user.UserToken.TokenValue)</a>
</li>
</div>
}
}
</ul>
</div>
</div>
</nav>