Created
June 22, 2023 16:32
-
-
Save webstrand/0e045b40227843a83630fd46ba83eebe to your computer and use it in GitHub Desktop.
Sort list by distance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def PI: 3.14159265359; | |
def Radians(deg): deg * (PI / 180); | |
def Degrees(rad): rad * (180 / PI); | |
def a: 6378.137; #equitorial radius in km | |
def b: 6356.752; #polar radius in km | |
def radius_of_earth(lat1): | |
(((pow(((a*a)*(lat1 | cos));2))+(pow(((b*b)*(lat1 | sin));2)))/(pow((a*(lat1 | cos));2)+pow((b*(lat1 | sin));2))) | sqrt; | |
def Distance1(lat1;long1;lat2;long2): | |
(radius_of_earth(lat1)) as $R1 | | |
($R1*(lat1 | cos)*(long1 | cos)) as $x1 | | |
($R1*(lat1 | cos)*(long1 | sin)) as $y1 | | |
($R1*(lat1 | sin)) as $z1 | | |
(radius_of_earth(lat2)) as $R2 | | |
($R2*(lat2 | cos)*(long2 | cos)) as $x2 | | |
($R2*(lat2 | cos)*(long2 | sin)) as $y2 | | |
($R2*(lat2 | sin)) as $z2 | | |
((pow(($x1-$x2);2))+(pow(($y1-$y2);2))+(pow(($z1-$z2);2))) | sqrt; | |
def Distance(lat1;long1;lat2;long2): | |
Distance1(Radians(lat1);Radians(long1);Radians(lat2);Radians(long2)); | |
# Converts integers to streams of bits for bitwise operations | |
def stream: | |
recurse(if . > 0 then (. / 2 | floor) else empty end) | . % 2; | |
# The acqual query | |
.LogicalServers | map(. + { Distance: Distance(.Location.Lat;.Location.Long;40.0000;-83.0000) } | select(.Distance < 1000)) | sort_by(.Load) | map(select(.Tier == 2 and (.Features | [stream] | .[0] == 1 or .[1] == 1 or .[2] == 1 | not))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment