diff options
| author | Ariel Costas Guerrero <ariel@costas.dev> | 2025-12-23 21:33:17 +0100 |
|---|---|---|
| committer | Ariel Costas Guerrero <ariel@costas.dev> | 2025-12-23 21:33:17 +0100 |
| commit | 4a866f5352a51916ddb9849b2d68213856196c9c (patch) | |
| tree | 3ba01ba01d5f6931adaf708b76ffccdd798fc78b /src/Costasdev.Busurbano.Backend/Services/Processors/AbstractProcessor.cs | |
| parent | 87417c313b455ba0dee19708528cc8d0b830a276 (diff) | |
Full real-time page, coruña real time
Diffstat (limited to 'src/Costasdev.Busurbano.Backend/Services/Processors/AbstractProcessor.cs')
| -rw-r--r-- | src/Costasdev.Busurbano.Backend/Services/Processors/AbstractProcessor.cs | 56 |
1 files changed, 56 insertions, 0 deletions
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; + } +} |
