-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from arthur-schnitzler/280-problems-with-csv-…
…export 280 problems with csv export
- Loading branch information
Showing
3 changed files
with
120 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "080d64de-e40b-4aa3-94a0-adcc59c2c508", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# run against production 2024-12-19\n", | ||
"from tqdm import tqdm\n", | ||
"from django.core.exceptions import ObjectDoesNotExist\n", | ||
"from dumper.utils import gsheet_to_df\n", | ||
"from apis_core.utils import get_object_from_pk_or_uri\n", | ||
"import pandas as pd" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "10b4da98-ca52-4049-8d95-214a7ee019e9", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"relation_type = PersonPlaceRelation.objects.get(id=1181)\n", | ||
"relation_type" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "69207701-41c4-4151-b36a-037613baa634", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df = gsheet_to_df(\"1F7Ha6gkYmjtxjNguAuKEP3slbedAQkPWfHO1NG3QnpA\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "19b0c441-b061-443c-ab9d-f895c2666c46", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "a908121f-c91c-425c-bfac-9c15c4740502", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"no_places = set()\n", | ||
"person = Person.objects.get(id=2121)\n", | ||
"for g, ndf in tqdm(df.groupby(\"target_id\")):\n", | ||
" try:\n", | ||
" place = Place.objects.get(id=g)\n", | ||
" except ObjectDoesNotExist:\n", | ||
" try:\n", | ||
" place = get_object_from_pk_or_uri(g)\n", | ||
" except:\n", | ||
" no_places.add(g)\n", | ||
" continue\n", | ||
" for i, row in ndf.iterrows():\n", | ||
" rel, _ = PersonPlace.objects.get_or_create(\n", | ||
" related_person=person,\n", | ||
" related_place=place,\n", | ||
" relation_type=relation_type,\n", | ||
" start_date_written=row[\"relation_start_date_written\"],\n", | ||
" end_date_written=row[\"relation_end_date_written\"]\n", | ||
" )" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "b408468a-ef9d-4569-a2fa-b98d39d0785a", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"no_places" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "348a6de2-8a06-42b1-a6ce-671c8def53b0", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Django Shell-Plus", | ||
"language": "python", | ||
"name": "django_extensions" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.12.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |