-
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 #105 from arthur-schnitzler/244-default-sort-of-en…
…tites-by-last-edited 244 default sort of entites by last edited
- Loading branch information
Showing
5 changed files
with
243 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[flake8] | ||
ignore = D203 W504 | ||
ignore = D203 W504 W503 | ||
max-line-length = 120 | ||
exclude = | ||
*/migrations, | ||
|
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
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,210 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "abdba1e8-027e-4931-a35b-03aaf8aa9464", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# run against production 2024-11-06\n", | ||
"from django.core.exceptions import ObjectDoesNotExist\n", | ||
"from tqdm import tqdm\n", | ||
"from dumper.utils import gsheet_to_df" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "cdb36196-46aa-4b7b-9871-0a8a3dd279ea", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df = gsheet_to_df(\"1-_WXbdmpLzz_9vBiZ1y9v2tle_26m4tAhPTGzkkin5E\")\n", | ||
"col, _= Collection.objects.get_or_create(name=\"Schnitzler-Veranstaltungen\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "682d2d62-1e30-4db5-8323-c07a3f62222e", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df.head(3)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "342c4e3d-39c5-4f8b-b0b0-950cde457983", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"relation_type_lookup = {\n", | ||
" \"1049\": {\n", | ||
" \"relation_type\":PersonWork,\n", | ||
" \"relation\": PersonWorkRelation.objects.get(id=1049),\n", | ||
" \"source_class\": Person,\n", | ||
" \"target_class\": Work,\n", | ||
" },\n", | ||
" \"1181\": {\n", | ||
" \"relation_type\": PersonPlace,\n", | ||
" \"relation\": PersonPlaceRelation.objects.get(id=1181),\n", | ||
" \"source_class\": Person,\n", | ||
" \"target_class\": Place,\n", | ||
" },\n", | ||
" \"1201\": {\n", | ||
" \"relation_type\": EventWork,\n", | ||
" \"relation\": EventWorkRelation.objects.get(id=1201),\n", | ||
" \"source_class\": Event,\n", | ||
" \"target_class\": Work,\n", | ||
" },\n", | ||
" \"1204\": {\n", | ||
" \"relation_type\": EventWork,\n", | ||
" \"relation\": EventWorkRelation.objects.get(id=1204),\n", | ||
" \"source_class\": Event,\n", | ||
" \"target_class\": Work,\n", | ||
" },\n", | ||
" \"1206\": {\n", | ||
" \"relation_type\": EventWork,\n", | ||
" \"relation\": EventWorkRelation.objects.get(id=1206),\n", | ||
" \"source_class\": Event,\n", | ||
" \"target_class\": Work,\n", | ||
" },\n", | ||
" \"1224\": {\n", | ||
" \"relation_type\": PersonWork,\n", | ||
" \"relation\": PersonWorkRelation.objects.get(id=1224),\n", | ||
" \"source_class\": Person,\n", | ||
" \"target_class\": Work,\n", | ||
" },\n", | ||
" \"1252\": {\n", | ||
" \"relation_type\": EventWork,\n", | ||
" \"relation\": EventWorkRelation.objects.get(id=1252),\n", | ||
" \"source_class\": Event,\n", | ||
" \"target_class\": Work,\n", | ||
" },\n", | ||
" \"1256\": {\n", | ||
" \"relation_type\": PersonEvent,\n", | ||
" \"relation\": PersonEventRelation.objects.get(id=1256),\n", | ||
" \"source_class\": Person,\n", | ||
" \"target_class\": Event,\n", | ||
" },\n", | ||
" \"1351\": {\n", | ||
" \"relation_type\": InstitutionEvent,\n", | ||
" \"relation\": InstitutionEventRelation.objects.get(id=1351),\n", | ||
" \"source_class\": Institution,\n", | ||
" \"target_class\": Event,\n", | ||
" },\n", | ||
" \"1369\": {\n", | ||
" \"relation_type\": PlaceEvent,\n", | ||
" \"relation\": PlaceEventRelation.objects.get(id=1369),\n", | ||
" \"source_class\": Place,\n", | ||
" \"target_class\": Event,\n", | ||
" },\n", | ||
" \"1369\": {\n", | ||
" \"relation_type\": PlaceEvent,\n", | ||
" \"relation\": PlaceEventRelation.objects.get(id=1369),\n", | ||
" \"source_class\": Place,\n", | ||
" \"target_class\": Event,\n", | ||
" },\n", | ||
" \"1370\": {\n", | ||
" \"relation_type\": PersonEvent,\n", | ||
" \"relation\": PersonEventRelation.objects.get(id=1370),\n", | ||
" \"source_class\": Person,\n", | ||
" \"target_class\": Event,\n", | ||
" },\n", | ||
" \"1527\": {\n", | ||
" \"relation_type\": EventWork,\n", | ||
" \"relation\": EventWorkRelation.objects.get(id=1527),\n", | ||
" \"source_class\": Event,\n", | ||
" \"target_class\": Work,\n", | ||
" },\n", | ||
" \"1528\": {\n", | ||
" \"relation_type\": EventWork,\n", | ||
" \"relation\": EventWorkRelation.objects.get(id=1528),\n", | ||
" \"source_class\": Event,\n", | ||
" \"target_class\": Work,\n", | ||
" },\n", | ||
" \"4362\": {\n", | ||
" \"relation_type\": EventWork,\n", | ||
" \"relation\": EventWorkRelation.objects.get(id=4362),\n", | ||
" \"source_class\": Event,\n", | ||
" \"target_class\": Work,\n", | ||
" },\n", | ||
" \n", | ||
"}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "6748b522-2617-4436-ab9b-0c46c1867e6a", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"does_not_exist = set()\n", | ||
"for g, ndf in df.groupby(\"relation-id\"):\n", | ||
" relation = relation_type_lookup[str(g)][\"relation\"]\n", | ||
" relation_class = relation_type_lookup[str(g)][\"relation_type\"]\n", | ||
" source_class = relation_type_lookup[str(g)][\"source_class\"]\n", | ||
" target_class = relation_type_lookup[str(g)][\"target_class\"]\n", | ||
" print(relation, relation_class, target_class)\n", | ||
" for i, row in tqdm(ndf.iterrows(), total=len(ndf)):\n", | ||
" try:\n", | ||
" source = source_class.objects.get(pk=int(row[\"source_id\"]))\n", | ||
" except (ObjectDoesNotExist, ValueError):\n", | ||
" does_not_exist.add(row[\"source_id\"])\n", | ||
" continue\n", | ||
" try:\n", | ||
" target = target_class.objects.get(pk=int(row[\"target_id\"]))\n", | ||
" except ObjectDoesNotExist:\n", | ||
" does_not_exist.add(row[\"target_id\"])\n", | ||
" if isinstance(row[\"relation_start_date_written\"], str):\n", | ||
" start_date_written = row[\"relation_start_date_written\"]\n", | ||
" end_date_written = row[\"relation_end_date_written\"]\n", | ||
" else:\n", | ||
" start_date_written = None\n", | ||
" end_date_written = None\n", | ||
" relation_object = {\n", | ||
" relation_class.get_related_entity_field_namea(): source,\n", | ||
" relation_class.get_related_entity_field_nameb(): target,\n", | ||
" \"relation_type\": relation,\n", | ||
" \"start_date_written\": start_date_written,\n", | ||
" \"end_date_written\": end_date_written\n", | ||
" }\n", | ||
" created_relation, _ = relation_class.objects.get_or_create(**relation_object)\n", | ||
" created_relation.collection.add(col)\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "3193d0cb-c5b9-45cc-ad16-ba18843f3a4a", | ||
"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 | ||
} |