Skip to content

Commit

Permalink
fix: tweak airtable script, disable from CI for now
Browse files Browse the repository at this point in the history
  • Loading branch information
machow committed Dec 18, 2021
1 parent 63ca10a commit 8c55e5e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ jobs:
python -m pip install airtable-python-wrapper==0.15.0
- name: Upload spec
run: |
python docs/scripts/upload_airtable.py
echo "TODO: skipping upload for now"
#python docs/scripts/upload_airtable.py
env:
AIRTABLE_API_KEY: ${{ secrets.AIRTABLE_API_KEY }}

35 changes: 17 additions & 18 deletions docs/scripts/upload_airtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# extension: .py
# format_name: light
# format_version: '1.5'
# jupytext_version: 1.5.2
# jupytext_version: 1.11.5
# kernelspec:
# display_name: venv-siuba
# language: python
Expand All @@ -17,7 +17,7 @@
import os

from airtable import Airtable
from siuba.spec import series
from siuba.ops.support import spec

from siuba import _, select, inner_join, unnest, mutate, left_join, filter, pipe

Expand Down Expand Up @@ -53,32 +53,32 @@ def record_needs_update(src, dst):

# +

raw_methods = air_methods.get_all()
air_methods_records = air_methods.get_all()

tbl_methods = (
pd.DataFrame(raw_methods)
tbl_air_methods = (
pd.DataFrame(air_methods_records)
>> mutate(fields = _.fields.apply(pd.DataFrame, index = [0]))
>> unnest("fields")
)

# +
raw_spec = pd.json_normalize([{"method": k, **v} for k,v in series.spec.items()])
siu_raw_spec = pd.json_normalize([{"method": k, **v} for k,v in spec.items()])

spec_methods = (raw_spec
tbl_siu_methods = (siu_raw_spec
.siu_select(-_.startswith('backend'), -_.expr_frame, -_.expr_series)
.rename(columns = lambda s: s.replace('.', '_'))
)

joined_methods = (
spec_methods
>> left_join(_, select(tbl_methods, _.id, _.method), ['method'])
tbl_joined_methods = (
tbl_siu_methods
>> left_join(_, select(tbl_air_methods, _.id, _.method), ['method'])
)

methods = joined_methods >> pipe(_.to_dict(orient = "records"))
methods = tbl_joined_methods >> pipe(_.to_dict(orient = "records"))


# +
raw_map = {x['fields']['method']: x['fields'] for x in raw_methods}
raw_map = {x['fields']['method']: x['fields'] for x in air_methods_records}

inserts = []
updated = []
Expand All @@ -88,7 +88,6 @@ def record_needs_update(src, dst):

if record_needs_update(fields, dst_fields):
updated.append(fields)

air_methods.update_by_field("method", entry["method"], fields = fields)

if pd.isna(entry["id"]):
Expand All @@ -106,16 +105,16 @@ def record_needs_update(src, dst):

# ## Link method records to backends

raw_backend = {x['fields']['backend_method']: x['fields'] for x in air_backends.get_all()}
air_backend_records = {x['fields']['backend_method']: x['fields'] for x in air_backends.get_all()}

spec_backend_entries = sum(
[get_backend_records(k, entry.get('backends', [])) for k, entry in series.spec.items()],
siu_backend_entries = sum(
[get_backend_records(k, entry.get('backends', [])) for k, entry in spec.items()],
[]
)

for fields in spec_backend_entries:
for fields in siu_backend_entries:
indx = fields["name"] + "-" + fields["method_name"]
dst_fields = raw_backend.get(indx, {})
dst_fields = air_backend_recods.get(indx, {})
if not dst_fields:
air_backends.insert(fields)

Expand Down

0 comments on commit 8c55e5e

Please sign in to comment.