Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Milind220 committed Mar 13, 2022
2 parents 4efcbda + ff063df commit 045d98c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = ozon3
version = 1.3.1
version = 1.4.0
author = Milind Sharma
author_email = [email protected]
description = A package to get air quality data using the WAQI API
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
description="A package to get air quality data using the WAQI API",
license="GPLv3+",
url="https://github.com/Milind220/Ozone",
version="1.3.1",
download_url="https://github.com/Milind220/Ozone/archive/refs/tags/v1.3.1.tar.gz",
version="1.4.0",
download_url="https://github.com/Milind220/Ozone/archive/refs/tags/v1.4.0.tar.gz",
packages=setuptools.find_packages(),
install_requires=[
"numpy; python_version>='3'",
Expand Down
30 changes: 21 additions & 9 deletions src/ozone/ozone.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,7 @@ def _AQI_meaning(self, aqi: float) -> Tuple[str, str]:
return AQI_meaning, AQI_health_implications

def _locate_all_coordinates(
self,
lower_bound: Tuple[float, float],
upper_bound: Tuple[float, float]
self, lower_bound: Tuple[float, float], upper_bound: Tuple[float, float]
) -> List[Tuple]:
"""Get all locations between two pair of coordinates
Expand All @@ -232,19 +230,29 @@ def _locate_all_coordinates(
Returns:
list: a list of all coordinates located between lower_bound and
upper_bound
upper_bound. If API request fails then returns [(-1, -1)].
"""

coordinates_flattened: List[float] = list(itertools.chain(lower_bound, upper_bound))
coordinates_flattened: List[float] = list(
itertools.chain(lower_bound, upper_bound)
)
latlng: str = ",".join(map(str, coordinates_flattened))
response = self._make_api_request(
f"{URLs.find_coordinates_url}bounds/?token={self.token}&latlng={latlng}"
)
if self._check_status_code(response):
data = json.loads(response.content)["data"]
coordinates: List[Tuple] = [(element['lat'], element['lon']) for element in data]
coordinates: List[Tuple] = [
(element["lat"], element["lon"]) for element in data
]
return coordinates

# This is a bit of a hack to ensure that the function always returns a
# list of coordinates. Required to make mypy happy.

# Return an invalid coordinate if API request fails.
return [(-1, -1)]

def get_coordinate_air(
self,
lat: float,
Expand Down Expand Up @@ -347,7 +355,7 @@ def get_range_coordinates_air(
upper_bound: Tuple[float, float],
data_format: str = "df",
df: pandas.DataFrame = pandas.DataFrame(),
params: List[str] = [""]
params: List[str] = [""],
) -> pandas.DataFrame:
"""Get air quality data for range of coordinates between lower_bound and upper_bound
Expand All @@ -363,8 +371,12 @@ def get_range_coordinates_air(
pandas.DataFrame: The dataframe containing the data. (If you
selected another data format, this dataframe will be empty)
"""
locations = self._locate_all_coordinates(lower_bound=lower_bound, upper_bound=upper_bound)
return self.get_multiple_coordinate_air(locations, data_format=data_format, df=df, params=params)
locations = self._locate_all_coordinates(
lower_bound=lower_bound, upper_bound=upper_bound
)
return self.get_multiple_coordinate_air(
locations, data_format=data_format, df=df, params=params
)

def get_multiple_city_air(
self,
Expand Down

0 comments on commit 045d98c

Please sign in to comment.