From 4a866f5352a51916ddb9849b2d68213856196c9c Mon Sep 17 00:00:00 2001 From: Ariel Costas Guerrero Date: Tue, 23 Dec 2025 21:33:17 +0100 Subject: Full real-time page, coruña real time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Processors/AbstractProcessor.cs | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/Costasdev.Busurbano.Backend/Services/Processors/AbstractProcessor.cs (limited to 'src/Costasdev.Busurbano.Backend/Services/Processors/AbstractProcessor.cs') diff --git a/src/Costasdev.Busurbano.Backend/Services/Processors/AbstractProcessor.cs b/src/Costasdev.Busurbano.Backend/Services/Processors/AbstractProcessor.cs new file mode 100644 index 0000000..343f511 --- /dev/null +++ b/src/Costasdev.Busurbano.Backend/Services/Processors/AbstractProcessor.cs @@ -0,0 +1,56 @@ +using Costasdev.Busurbano.Backend.Services; + +public abstract class AbstractRealTimeProcessor : IArrivalsProcessor +{ + public abstract Task ProcessAsync(ArrivalsContext context); + + protected static List<(double Lat, double Lon)> Decode(string encodedPoints) + { + if (string.IsNullOrEmpty(encodedPoints)) + return new List<(double, double)>(); + + var poly = new List<(double, double)>(); + char[] polylineChars = encodedPoints.ToCharArray(); + int index = 0; + + int currentLat = 0; + int currentLng = 0; + int next5bits; + int sum; + int shifter; + + while (index < polylineChars.Length) + { + // calculate next latitude + sum = 0; + shifter = 0; + do + { + next5bits = (int)polylineChars[index++] - 63; + sum |= (next5bits & 31) << shifter; + shifter += 5; + } while (next5bits >= 32 && index < polylineChars.Length); + + if (index >= polylineChars.Length) + break; + + currentLat += (sum & 1) == 1 ? ~(sum >> 1) : (sum >> 1); + + // calculate next longitude + sum = 0; + shifter = 0; + do + { + next5bits = (int)polylineChars[index++] - 63; + sum |= (next5bits & 31) << shifter; + shifter += 5; + } while (next5bits >= 32 && index < polylineChars.Length); + + currentLng += (sum & 1) == 1 ? ~(sum >> 1) : (sum >> 1); + + poly.Add((Convert.ToDouble(currentLat) / 100000.0, Convert.ToDouble(currentLng) / 100000.0)); + } + + return poly; + } +} -- cgit v1.3