Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.0.8 Release Candidate 1 #54

Merged
merged 33 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3ce6525
First draft of solution to #50
sampottinger Apr 17, 2023
760979f
All but one test for #52.
sampottinger Apr 17, 2023
aa63548
Fixed #52
sampottinger Apr 17, 2023
2e56f7a
Update apt prior to paper install.
sampottinger Apr 17, 2023
6ddf6d5
Fix some styling issues.
sampottinger Apr 17, 2023
467d4ee
One more try at #53
sampottinger Apr 17, 2023
a5f3880
Merge pull request #53 from SchmidtDSE/fix-paper-build
sampottinger Apr 17, 2023
d44dbef
Merge branch '100rc1' into query-builder
sampottinger Apr 17, 2023
f535a22
Merge pull request #52 from SchmidtDSE/query-builder
sampottinger Apr 17, 2023
6e31347
Stake out changes in model.
sampottinger Apr 17, 2023
0af306a
Another draft of new interface.
sampottinger Apr 17, 2023
7d807ad
Standardize docs
sampottinger Apr 17, 2023
c44b06f
Through refactor of ApiRecord for #55
sampottinger Apr 17, 2023
f9a489f
Draft of migration for ZeroCatchHaulDecorator
sampottinger Apr 17, 2023
2dd8ef7
Passing checks on #55
sampottinger Apr 17, 2023
8c6a1c4
Complete draft of #55
sampottinger Apr 18, 2023
5bdd99d
Merge pull request #55 from SchmidtDSE/consolidate-getter
sampottinger Apr 18, 2023
f498731
Make query setters non-keyword
sampottinger Apr 18, 2023
b832d69
Through to updates to notebook.
sampottinger Apr 18, 2023
a862932
Fix minor whitespace issue.
sampottinger Apr 18, 2023
7d58298
Updated README.
sampottinger Apr 18, 2023
1904fc9
Move chaining up.
sampottinger Apr 18, 2023
0ef9710
Fixes on README.
sampottinger Apr 18, 2023
c43b364
Fixes from README tests.
sampottinger Apr 18, 2023
e59c0ff
Fix percent complete example.
sampottinger Apr 18, 2023
f9a9c6c
Additional README updates for the RC.
sampottinger Apr 18, 2023
67c706d
Fix query util issue.
sampottinger Apr 18, 2023
d2dff4c
Another readme update.
sampottinger Apr 18, 2023
1ae419c
Update python generation.
sampottinger Apr 18, 2023
74696b5
Remove extra newline on Python generation.
sampottinger Apr 18, 2023
b343d86
Minor change on paper due to Query
sampottinger Apr 18, 2023
6a83153
Updated paper for 0.0.8
sampottinger Apr 18, 2023
04ea312
Add diagram file.
sampottinger Apr 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
395 changes: 252 additions & 143 deletions README.md

Large diffs are not rendered by default.

1,504 changes: 1,265 additions & 239 deletions afscgap/__init__.py

Large diffs are not rendered by default.

395 changes: 201 additions & 194 deletions afscgap/client.py

Large diffs are not rendered by default.

261 changes: 261 additions & 0 deletions afscgap/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"""
import re

from afscgap.typesdef import FLOAT_PARAM
from afscgap.typesdef import OPT_FLOAT
from afscgap.typesdef import STR_PARAM

DATE_REGEX = re.compile('(?P<month>\\d{2})\\/(?P<day>\\d{2})\\/' + \
Expand All @@ -20,6 +22,60 @@
'(?P<seconds>\\d{2})')
ISO_8601_TEMPLATE = '%s-%s-%sT%s:%s:%s'

AREA_CONVERTERS = {
'ha': lambda x: x,
'm2': lambda x: x * 10000,
'km2': lambda x: x * 0.01
}

AREA_UNCONVERTERS = {
'ha': lambda x: x,
'm2': lambda x: x / 10000,
'km2': lambda x: x / 0.01
}

DISTANCE_CONVERTERS = {
'm': lambda x: x,
'km': lambda x: x / 1000
}

DISTANCE_UNCONVERTERS = {
'm': lambda x: x,
'km': lambda x: x * 1000
}

TEMPERATURE_CONVERTERS = {
'c': lambda x: x,
'f': lambda x: x * 9 / 5 + 32
}

TEMPERATURE_UNCONVERTERS = {
'c': lambda x: x,
'f': lambda x: (x - 32) * 5 / 9
}

TIME_CONVERTERS = {
'day': lambda x: x / 24,
'hr': lambda x: x,
'min': lambda x: x * 60
}

TIME_UNCONVERTERS = {
'day': lambda x: x * 24,
'hr': lambda x: x,
'min': lambda x: x / 60
}

WEIGHT_CONVERTERS = {
'g': lambda x: x * 1000,
'kg': lambda x: x
}

WEIGHT_UNCONVERTERS = {
'g': lambda x: x / 1000,
'kg': lambda x: x
}


def convert_from_iso8601(target: STR_PARAM) -> STR_PARAM:
"""Convert strings from ISO 8601 format to API format.
Expand Down Expand Up @@ -112,3 +168,208 @@ def is_iso8601(target: str) -> bool:
True if it matches the expected format and false otherwise.
"""
return ISO_8601_REGEX.match(target) is not None


def convert_area(target: OPT_FLOAT, units: str) -> OPT_FLOAT:
"""Convert an area.

Args:
target: The value to convert in hectares.
units: Desired units.

Returns:
The converted value. Note that, if target is None, will return None.
"""
if target is None:
return None

return AREA_CONVERTERS[units](target)


def unconvert_area(target: FLOAT_PARAM, units: str) -> FLOAT_PARAM:
"""Standardize an area to the API-native units (hectare).

Args:
target: The value to convert in hectares.
units: The units of value.

Returns:
The converted value. Note that, if target is None, will return None.
"""
if target is None:
return None

if isinstance(target, dict):
return target

return AREA_UNCONVERTERS[units](target)


def convert_degrees(target: OPT_FLOAT, units: str) -> OPT_FLOAT:
"""Convert targets from degrees to another units.

Args:
target: The value to convert which may be None.
units: Desired units.

Returns:
The same value input after asserting that units are dd, the only
supported units.
"""
assert units == 'dd'
return target


def unconvert_degrees(target: FLOAT_PARAM, units: str) -> FLOAT_PARAM:
"""Standardize a degree to the API-native units (degrees).

Args:
target: The value to convert which may be None.
units: The units of value.

Returns:
The same value input after asserting that units are dd, the only
supported units.
"""
assert units == 'dd'
return target


def convert_distance(target: OPT_FLOAT, units: str) -> OPT_FLOAT:
"""Convert a linear distance.

Args:
target: The value to convert in meters.
units: Desired units.

Returns:
The converted value. Note that, if target is None, will return None.
"""
if target is None:
return None

return DISTANCE_CONVERTERS[units](target)


def unconvert_distance(target: FLOAT_PARAM, units: str) -> FLOAT_PARAM:
"""Convert a linear distance to the API-native units (meters).

Args:
target: The value to convert in meters.
units: The units of value.

Returns:
The converted value. Note that, if target is None, will return None.
"""
if target is None:
return None

if isinstance(target, dict):
return target

return DISTANCE_UNCONVERTERS[units](target)


def convert_temperature(target: OPT_FLOAT, units: str) -> OPT_FLOAT:
"""Convert a temperature.

Args:
target: The value to convert in Celcius.
units: Desired units.

Returns:
The converted value. Note that, if target is None, will return None.
"""
if target is None:
return None

return TEMPERATURE_CONVERTERS[units](target)


def unconvert_temperature(target: FLOAT_PARAM, units: str) -> FLOAT_PARAM:
"""Convert a linear temperature to the API-native units (Celsius).

Args:
target: The value to convert in Celcius.
units: The units of value.

Returns:
The converted value. Note that, if target is None, will return None.
"""
if target is None:
return None

if isinstance(target, dict):
return target

return TEMPERATURE_UNCONVERTERS[units](target)


def convert_time(target: OPT_FLOAT, units: str) -> OPT_FLOAT:
"""Convert a time.

Args:
target: The value to convert in hours.
units: Desired units.

Returns:
The converted value. Note that, if target is None, will return None.
"""
if target is None:
return None

return TIME_CONVERTERS[units](target)


def unconvert_time(target: FLOAT_PARAM, units: str) -> FLOAT_PARAM:
"""Convert a time to the API-native units (hours).

Args:
target: The value to convert in hours.
units: The units of value.

Returns:
The converted value. Note that, if target is None, will return None.
"""
if target is None:
return None

if isinstance(target, dict):
return target

return TIME_UNCONVERTERS[units](target)


def convert_weight(target: OPT_FLOAT, units: str) -> OPT_FLOAT:
"""Convert a weight.

Args:
target: The value to convert in kilograms.
units: Desired units.

Returns:
The converted value. Note that, if target is None, will return None.
"""
if target is None:
return None

return WEIGHT_CONVERTERS[units](target)


def unconvert_weight(target: FLOAT_PARAM, units: str) -> FLOAT_PARAM:
"""Convert a weight to the API-native units (kilograms).

Args:
target: The value to convert in kilograms.
units: The units of value.

Returns:
The converted value. Note that, if target is None, will return None.
"""
if target is None:
return None

if isinstance(target, dict):
return target

return WEIGHT_UNCONVERTERS[units](target)
Loading