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

location fallback #263

Merged
merged 57 commits into from
Feb 28, 2023
Merged

Conversation

seanbreckenridge
Copy link
Contributor

just basic restructuring/model for now, still a WIP

  • move home to fallback/via_home.py
  • move via_ip to fallback
  • add fallback model
  • add stub via_ip file
  • add fallback_locations for via_ip

@seanbreckenridge
Copy link
Contributor Author

Related #262

@seanbreckenridge
Copy link
Contributor Author

hmm tried to fix the
py: failed with pass_env values cannot contain whitespace, use comma to have multiple values in a single line, invalid values found 'CI CI_*', 'MYPY_CACHE_DIR PYTHONPYCACHEPREFIX' py: FAIL code 1 (0.00 seconds)
error but it just seems to skip running the CI

@seanbreckenridge
Copy link
Contributor Author

seanbreckenridge commented Jan 29, 2023

seems to be a breaking change with tox4.0 - https://tox.wiki/en/4.0.3/faq.html#tox-4-changed-ini-rules

I think I've fixed the passenv issue then, wasnt sure if it was passenv causing the tests to fail before

but tests still dont run -- looks like it just installs and then runs no more commands

Installing collected packages: distlib, zipp, typing-extensions, tomli, packaging, filelock, colorama, chardet, cachetools, pyproject-api, platformdirs, importlib-metadata, virtualenv, pluggy, tox
Successfully installed cachetools-5.3.0 chardet-5.1.0 colorama-0.4.6 distlib-0.3.6 filelock-3.9.0 importlib-metadata-6.0.0 packaging-23.0 platformdirs-2.6.2 pluggy-1.0.0 pyproject-api-1.5.0 tomli-2.0.1 tox-4.4.2 typing-extensions-4.4.0 virtualenv-20.17.1 zipp-3.12.0
.pkg: install_requires scripts> python -I -m pip install 'setuptools>=40.8.0' wheel
.pkg: _optional_hooks scripts> python /home/runner/.local/lib/python3.7/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
.pkg: get_requires_for_build_sdist scripts> python /home/runner/.local/lib/python3.7/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
.pkg: install_requires_for_build_sdist scripts> python -I -m pip install setuptools_scm
.pkg: freeze scripts> python -m pip freeze --all
.pkg: importlib-metadata==6.0.0,packaging==23.0,pip==22.3.1,setuptools==65.6.3,setuptools-scm==7.1.0,tomli==2.0.1,typing_extensions==4.4.0,wheel==0.38.4,zipp==3.12.0
.pkg: prepare_metadata_for_build_wheel scripts> python /home/runner/.local/lib/python3.7/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
.pkg: build_sdist scripts> python /home/runner/.local/lib/python3.7/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
py: install_package_deps scripts> python -I -m pip install appdirs 'click>=8.0' decorator more-itertools pytz
py: install_package scripts> python -I -m pip install --force-reinstall --no-deps /home/runner/work/HPI/HPI/.tox/.tmp/package/1/HPI-0.3.20220608.dev19.tar.gz
py: freeze scripts> python -m pip freeze --all
py: appdirs==1.4.4,click==8.1.3,decorator==5.1.1,HPI @ file:///home/runner/work/HPI/HPI/.tox/.tmp/package/1/HPI-0.3.20220608.dev19.tar.gz,importlib-metadata==6.0.0,more-itertools==9.0.0,pip==22.3.1,pytz==2022.7.1,setuptools==65.6.3,typing_extensions==4.4.0,wheel==0.38.4,zipp==3.12.0
.pkg: _exit scripts> python /home/runner/.local/lib/python3.7/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
  py: OK (12.01 seconds)
  congratulations :) (12.10 seconds)

lat: float
lon: float
dt: datetime
accuracy: Optional[float]
elevation: Optional[float]
datasource: Optional[str] = None # which module provided this, useful for debugging
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be kinda cool to have it for every data provider.. but haven't thought too much how to make it generic yet. In some cases possible to extract from the full class name, but only if inheritance is involved I guess

Copy link
Contributor Author

@seanbreckenridge seanbreckenridge Jan 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, something like a helper that adds a field to every NT/dataclass which could be used in all.py, but those tend to be readonly, so would likely need to do some sort of weird non-mypy-compliant magic with a proxy object which likely breaks cachew etc..., so not sure how automatic could be

@dataclass
class ObjProxy:
    _obj_proxy: Any
    datasource: Optional[str] = None

    def getattr(self, name: str) -> Any:
          return getattr(self._obj_proxy, name)

... doesnt seem great

For locations in particular I thought it'd be useful incase youre trying to exclude a faulty/wrong location geolocated from ip addresses for example

Copy link

@Joshfindit Joshfindit Jan 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be kinda cool to have it for every data provider.. but haven't thought too much how to make it generic yet.

Apologies for the poor quality of this reply. I’m not feeling well and as much as I try I can’t understand the code that’s being worked on right now. I’m adding this in case it helps the project but I understand if it doesn’t fit.

When I was putting thought in to building something similar to HPI I was targeting a graph database so that each item would have (Item)->(Metadata) such as (jpg file)->(EXIF size), (jpg file)-(EXIF date), and so-on. That way each piece of metadata could have source (eg: “Josh’s iPhone”) and accuracy properties. In that scenario correcting the record was a matter of adding the new metadata node with a source of “User: Josh” and an accuracy of whatever they decided.
Because this type of correction is non-destructive there was just logic that pulled all sources of metadata from the API then displayed the user-defined source as the primary.

Copy link
Contributor Author

@seanbreckenridge seanbreckenridge Feb 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The graph database idea makes a lot of sense as a solution to structuring this data, but HPI in general tends to denormalize databases into single dataclasses/namedtuples so that its able to be cached with cachew and just easier to manage as an Iterator instead of downstream functions (other functions, hpi query) having to know the specifics of every API

Still not sure what my plan is on a separate repo/how much to put there, but will see if I can get some basic file-based graphdb working (though may be easier to just use a JSON file/sqlitedb instead?)

my/location/fallback/common.py Outdated Show resolved Hide resolved
tox.ini Outdated Show resolved Hide resolved
my/location/fallback/common.py Outdated Show resolved Hide resolved
seanbreckenridge and others added 4 commits January 30, 2023 15:19
seems that after version 4.0 it's necessary to specify environments to run
previosly it was picking them up automatically
seanbreckenridge added a commit to seanbreckenridge/HPI that referenced this pull request Feb 21, 2023
@seanbreckenridge
Copy link
Contributor Author

seanbreckenridge commented Feb 23, 2023

ok, worked through a lot of the CI errors, current error seems to be related to sqlalchemy on mac?

I remember seeing you switching something to do with dataset lib and I did merge master into this branch (to fix tox.ci conflicts) so I should be up to date on any changes you've made

Theres also this broken -qlalchemy package name thats installed/attempted on mac CI, not sure if that was a mistyped package name and pip package resolver doing backoff broke...

https://github.com/karlicoss/HPI/actions/runs/4250652886/jobs/7392019565#step:5:1983

@karlicoss
Copy link
Owner

I think easiest thing is to just add the stub config into tests, so will do that

yeah, I've basically added all reasonable configs stubs there when I did the change to tox file, I think that's the best way forward. The only exception is some modules which I don't feel generic enough and might just move to personal overlay later -- for them just did type: ignore

Theres also this broken -qlalchemy package name thats installed/attempted on mac CI, not sure if that was a mistyped package name and pip package resolver doing backoff broke...

Not sure what you mean about -qlalchemy, but I think I've seen this error before a couple of times on macos, it's transient, retried the CI for now. I think it's because the expecimental --parallel flag we use for hpi module install is sometimes breaking on osx for some reason. Which is kinda annoying because the point was to speed up the CI, and macos is already quite slow... Maybe we could add some sort of environment variable to make it defensive on CI only, e.g. give it 5 attempts to install.

@seanbreckenridge
Copy link
Contributor Author

seanbreckenridge commented Feb 27, 2023

Just for posterity (regarding -qlalchemy), from one of the CI runs above: https://github.com/karlicoss/HPI/actions/runs/4250652886/jobs/7392019565#step:5:1983

WARNING: Error parsing requirements for sqlalchemy: [Errno 2] No such file or directory: '/Users/runner/work/HPI/HPI/.tox/mypy-misc/lib/python3.9/site-packages/SQLAlchemy-2.0.4.dist-info/METADATA'
  Created wheel for rescuexport: filename=rescuexport-0.0.1.dev25-py3-none-any.whl size=11286 sha256=90b360993f757a0e24f6c99d516a14ea21b68baf2be60809eba38b791d2903e1
  Stored in directory: /private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/pip-ephem-wheel-cache-8fc0dqhn/wheels/f0/7b/d6/efee111bc0f5c7393a1fbd42adbb4d8f50104de2b77ef1836d
Successfully built rescuexport
WARNING: Ignoring invalid distribution -qlalchemy (/Users/runner/work/HPI/HPI/.tox/mypy-misc/lib/python3.9/site-packages)
Successfully installed certifi-2022.12.7 charset-normalizer-3.0.1 idna-3.4 pocket-0.3.6 pockexport-0.0.0 requests-2.28.2 urllib3-1.26.14
WARNING: Ignoring invalid distribution -qlalchemy (/Users/runner/work/HPI/HPI/.tox/mypy-misc/lib/python3.9/site-packages)
WARNING: Ignoring invalid distribution -qlalchemy (/Users/runner/work/HPI/HPI/.tox/mypy-misc/lib/python3.9/site-packages)
WARNING: Ignoring invalid distribution -qlalchemy (/Users/runner/work/HPI/HPI/.tox/mypy-misc/lib/python3.9/site-packages)
WARNING: Ignoring invalid distribution -qlalchemy (/Users/runner/work/HPI/HPI/.tox/mypy-misc/lib/python3.9/site-packages)
WARNING: Ignoring invalid distribution -qlalchemy (/Users/runner/work/HPI/HPI/.tox/mypy-misc/lib/python3.9/site-packages)
WARNING: Ignoring invalid distribution -qlalchemy (/Users/runner/work/HPI/HPI/.tox/mypy-misc/lib/python3.9/site-packages)
Installing collected packages: charset-normalizer, urllib3, idna, certifi, backoff, requests, rescuexport
WARNING: Ignoring invalid distribution -qlalchemy (/Users/runner/work/HPI/HPI/.tox/mypy-misc/lib/python3.9/site-packages)
WARNING: Ignoring invalid distribution -qlalchemy (/Users/runner/work/HPI/HPI/.tox/mypy-misc/lib/python3.9/site-packages)
Collecting wrapt<2,>=1.10
Successfully installed certifi-2022.12.7 charset-normalizer-3.0.1 endoapi-1.0 endoexport-0.0.0 idna-3.4 requests-2.28.2 urllib3-1.26.14
WARNING: Ignoring invalid distribution -qlalchemy (/Users/runner/work/HPI/HPI/.tox/mypy-misc/lib/python3.9/site-packages)
WARNING: Ignoring invalid distribution -qlalchemy (/Users/runner/work/HPI/HPI/.tox/mypy-misc/lib/python3.9/site-packages)
WARNING: Ignoring invalid distribution -qlalchemy (/Users/runner/work/HPI/HPI/.tox/mypy-misc/lib/python3.9/site-packages)
WARNING: Ignoring invalid distribution -qlalchemy (/Users/runner/work/HPI/HPI/.tox/mypy-misc/lib/python3.9/site-packages)
WARNING: Ignoring invalid distribution -qlalchemy (/Users/runner/work/HPI/HPI/.tox/mypy-misc/lib/python3.9/site-packages)
  Downloading wrapt-1.14.1-cp39-cp39-macosx_10_9_x86_64.whl (35 kB)
Collecting pycparser

Copy link
Owner

@karlicoss karlicoss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, looks good! Hope I get to work more on my locations stuff soon and try it

my/location/fallback/via_home.py Show resolved Hide resolved
logger.debug(f"no. of items being used from fallback locations: {len(use_fallback_days)}")

# combine local_dates and missing days from fallback into a sorted list
all_dates = heapq.merge(local_dates, use_fallback_days, key=lambda p: p.day)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh nice, didn't know heapq.merge works on iterators!

my/location/fallback/common.py Outdated Show resolved Hide resolved
@@ -41,17 +41,23 @@ class config(user_config):
# if the accuracy for the location is more than 5km, don't use
require_accuracy: float = 5_000

# how often (hours) to refresh the cachew timezone cache
# this may be removed in the future if we opt for dict-based caching
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or maybe we'll have support for cache expiry in cachew -- wouldn't be too hard to add, and kinda useful anyway

@seanbreckenridge
Copy link
Contributor Author

👍 will fix the issues and add a test for the sorted ip bisect later today

@seanbreckenridge
Copy link
Contributor Author

Added a tests/shared_config.py and imported that in tz.py/location.py/location_fallback.py

They key parameter for bisect.bisect_left isnt there till python3.10, so I vendorized it to core/compat.py

I think thats everything, will probably do a follow up PR to fix some CI issues/link to my repo as examples for denylist

otherwise, it seems to use my config
from ~/.config/my/my... instead of
relying on the defaults in each module
@karlicoss
Copy link
Owner

Nice! Happy to merge, but looks like there are still some git conflicts?

@seanbreckenridge
Copy link
Contributor Author

seanbreckenridge commented Feb 28, 2023

Ah strange GitHub UI didn't give me any indication there was a conflict (though not surprising)

Don't have power at my house right now but will do a local merge against master and push the merge commit when I can

@karlicoss
Copy link
Owner

ah sorry! I think we had different idea about conflicts because my default PR merge action is "rebase and merge"! If I choose "Squash and merge", it's good now!

@seanbreckenridge
Copy link
Contributor Author

Ah all good, this has been complex with me merging the master into here a few times, so to be expected

Was just looking into squashing the commit myself but if you can just squash it in github ui that would be great

@seanbreckenridge
Copy link
Contributor Author

seanbreckenridge commented Feb 28, 2023

Same transient -qlalhemy error on mac

@karlicoss karlicoss merged commit 98b086f into karlicoss:master Feb 28, 2023
@karlicoss
Copy link
Owner

ah! rushed the merge a bit 😅 either way, since it's transient should be fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants