It’s Python/Jython project.
he code itself is very simple and it has two parts to achieve it:
1. Initial input file has a store location, latitude @ longitude
NAME OF STORE LATITUDE LONGITUDE
A ---- ----
B ----- ----
C ----- ------
The objective is to determine a sorted list of the stores closer to a given one. For that purpose, the Appendix below contains the subroutine to do it.
The output is then that for each store that I call by its name a list with the names of the rest of the stores can be given ordered in closest way.
2. The second part of the code is that I have an original input file that contains a number of inspections (health, food and acustic for example. The thing is that they are the same for all the stores) for each store and the results.
NAME OF STORE Inspection Grade (A,B,C,D ..) Punctuation Average
A health B 3.8 2.0
A food C 1.8 1.04
A acustic D 2.1 2.1
B health A 3.4 2.0
B food C 1.2 1.04
B acustic D 2.09 2.1
I’m gonna call an increasing number N 3,4,5,6,7 … such that when I call 3, I want see the 2 closest stores to the selected storeX and the test those. An output file like the following will be then generated parsed containing:
Store X Store A Store C
Grade Punctuation Average Grade Punctuation Average Grade Punctuation Average
Store X health A 2.1 3.5 C 3.2 2.1 A 2.3 4.2
Store X food A 2.1 3.5 C 3.2 2.3 C 2.3 4.2
Store X acustic A 2.1 4.5 C 3.2 2.3 C 2.3 4.2
So for when N=3 then the Store X will have an output containing in that format the values of the grade, punctuation and average for itself and for the 3 closest stores for each kind of inspection type. Hence another 3 columns in this case will be added.
It’s basically a problem of parsing the values of the original table to create a determined output file in that specific format based on the Store selected and how many closer stores to have the data for.
I don’t want to use any pandas or anything like that, but just parsing it and loop statements. The reason is that I want it to be done in Jython and not having to call any library or something like that. So the python code can’t have those.
I believe that it’s very simple programming exercise for someone having deep knowledge of the parsing through list of objects, ….
Script to calculate distance
from math import sin, cos, sqrt, atan2, radians
# approximate radius of earth in km
R = 6373.0
lat1 = radians(52.2296756)
lon1 = radians(21.0122287)
lat2 = radians(52.406374)
lon2 = radians(16.9251681)
dlon = lon2 - lon1
dlat = lat2 - lat1
a = sin(dlat / 2)**2 + cos(lat1) * cos(lat2) * sin(dlon / 2)**2
c = 2 * atan2(sqrt(a), sqrt(1 - a))
distance = R * c
print("Should be:", 278.546, "km")
29 freelancers are bidding on average $107 for this job
Hi, there I have read your description and your post is attractive to me. I have high Python skill and can do this work as you want. Please contact me and discuss more, Thanks.