|
2 | 2 | import re |
3 | 3 | from itertools import combinations |
4 | 4 |
|
5 | | -import pandas as pd |
6 | 5 | import sqlalchemy as sa |
7 | 6 | from sqlalchemy import ( |
8 | 7 | Boolean, |
@@ -296,35 +295,35 @@ class Volgistics(Base): |
296 | 295 | json = Column(JSONB) |
297 | 296 | created_date = Column(DateTime, default=datetime.datetime.utcnow) |
298 | 297 |
|
299 | | - @classmethod |
300 | | - def insert_from_file(cls, xl_file, conn): |
301 | | - df = pd.read_excel(xl_file, sheet_name="Master") |
302 | | - |
303 | | - column_translation = get_source_column_translation(cls) |
304 | | - df = df[column_translation.keys()] |
305 | | - df = df.rename(columns=column_translation) |
306 | | - |
307 | | - df["home"] = df["home"].apply(normalize_phone_number) |
308 | | - df["work"] = df["work"].apply(normalize_phone_number) |
309 | | - df["cell"] = df["cell"].apply(normalize_phone_number) |
310 | | - |
311 | | - dedup_on = [col for col in cls.__table__.columns if col.name in df.columns] |
312 | | - df["created_date"] = datetime.datetime.utcnow() |
313 | | - df.to_sql( |
314 | | - cls.__tablename__, |
315 | | - conn, |
316 | | - if_exists="append", |
317 | | - index=False, |
318 | | - ) |
319 | | - conn.execute( |
320 | | - dedup_consecutive( |
321 | | - cls.__table__, |
322 | | - unique_id=cls._id, |
323 | | - id=cls.number, |
324 | | - order_by=cls.created_date, |
325 | | - dedup_on=tuple_(*dedup_on), |
326 | | - ) |
327 | | - ) |
| 298 | + # @classmethod |
| 299 | + # def insert_from_file(cls, xl_file, conn): |
| 300 | + # df = pd.read_excel(xl_file, sheet_name="Master") |
| 301 | + |
| 302 | + # column_translation = get_source_column_translation(cls) |
| 303 | + # df = df[column_translation.keys()] |
| 304 | + # df = df.rename(columns=column_translation) |
| 305 | + |
| 306 | + # df["home"] = df["home"].apply(normalize_phone_number) |
| 307 | + # df["work"] = df["work"].apply(normalize_phone_number) |
| 308 | + # df["cell"] = df["cell"].apply(normalize_phone_number) |
| 309 | + |
| 310 | + # dedup_on = [col for col in cls.__table__.columns if col.name in df.columns] |
| 311 | + # df["created_date"] = datetime.datetime.utcnow() |
| 312 | + # df.to_sql( |
| 313 | + # cls.__tablename__, |
| 314 | + # conn, |
| 315 | + # if_exists="append", |
| 316 | + # index=False, |
| 317 | + # ) |
| 318 | + # conn.execute( |
| 319 | + # dedup_consecutive( |
| 320 | + # cls.__table__, |
| 321 | + # unique_id=cls._id, |
| 322 | + # id=cls.number, |
| 323 | + # order_by=cls.created_date, |
| 324 | + # dedup_on=tuple_(*dedup_on), |
| 325 | + # ) |
| 326 | + # ) |
328 | 327 |
|
329 | 328 | @classmethod |
330 | 329 | def insert_into_pdp_contacts(cls): |
@@ -356,29 +355,29 @@ class ManualMatches(Base): |
356 | 355 | source_type_2 = Column(String, primary_key=True) |
357 | 356 | source_id_2 = Column(String, primary_key=True) |
358 | 357 |
|
359 | | - @classmethod |
360 | | - def insert_from_df(cls, df, conn): |
361 | | - # Our input csv has columns like "salesforcecontacts," "volgistics," and |
362 | | - # "shelterluvpeople," where two columns are non-null if there is an |
363 | | - # association between those two ids. We massage this table into one that |
364 | | - # is easier to join on. |
| 358 | + # @classmethod |
| 359 | + # def insert_from_df(cls, df, conn): |
| 360 | + # # Our input csv has columns like "salesforcecontacts," "volgistics," and |
| 361 | + # # "shelterluvpeople," where two columns are non-null if there is an |
| 362 | + # # association between those two ids. We massage this table into one that |
| 363 | + # # is easier to join on. |
365 | 364 |
|
366 | | - match_dicts = df.to_dict(orient="records") |
367 | | - |
368 | | - matched_pairs = [] |
369 | | - for match in match_dicts: |
370 | | - non_nulls = {k: v for (k, v) in match.items() if not pd.isna(v)} |
371 | | - for ((st1, sid1), (st2, sid2)) in combinations(non_nulls.items(), 2): |
372 | | - matched_pairs.append( |
373 | | - { |
374 | | - "source_type_1": st1, |
375 | | - "source_id_1": sid1, |
376 | | - "source_type_2": st2, |
377 | | - "source_id_2": sid2, |
378 | | - } |
379 | | - ) |
380 | | - |
381 | | - conn.execute(insert(cls).values(matched_pairs).on_conflict_do_nothing()) |
| 365 | + # match_dicts = df.to_dict(orient="records") |
| 366 | + |
| 367 | + # matched_pairs = [] |
| 368 | + # for match in match_dicts: |
| 369 | + # non_nulls = {k: v for (k, v) in match.items() if not pd.isna(v)} |
| 370 | + # for ((st1, sid1), (st2, sid2)) in combinations(non_nulls.items(), 2): |
| 371 | + # matched_pairs.append( |
| 372 | + # { |
| 373 | + # "source_type_1": st1, |
| 374 | + # "source_id_1": sid1, |
| 375 | + # "source_type_2": st2, |
| 376 | + # "source_id_2": sid2, |
| 377 | + # } |
| 378 | + # ) |
| 379 | + |
| 380 | + # conn.execute(insert(cls).values(matched_pairs).on_conflict_do_nothing()) |
382 | 381 |
|
383 | 382 | class SalesforceDonations(Base): |
384 | 383 | __tablename__ = "salesforcedonations" |
|
0 commit comments