-
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 #79 from arthur-schnitzler/main
updates
- Loading branch information
Showing
22 changed files
with
362 additions
and
9 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,85 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "51cca613", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# run against production 2024-04-18\n", | ||
"import pandas as pd\n", | ||
"from tqdm import tqdm\n", | ||
"from django.core.exceptions import MultipleObjectsReturned" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "733e8089", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df = pd.read_table(\"./featureCodes_en.tsv\", sep=\"\\t\", header=None)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "b41f79d4", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"print(PlaceType.objects.all().count())" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "f380fb44", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"for i, row in tqdm(df.iterrows()):\n", | ||
" exists = PlaceType.objects.filter(name=row[0])\n", | ||
" if exists:\n", | ||
" pass\n", | ||
" else:\n", | ||
" try:\n", | ||
" new_place = PlaceType.objects.create(name=row[0], description=row[1])\n", | ||
" except:\n", | ||
" pass\n", | ||
"print(PlaceType.objects.all().count()) " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "bb3f96c3", | ||
"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.10.12" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,130 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "f47bcd68", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# run against production 2024-04-18\n", | ||
"import pandas as pd" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "f820cd7f", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"props = [\"id\", \"name\"] " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "fe06fca6", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df = pd.DataFrame(\n", | ||
" PlaceType.objects.all().values_list(*props),\n", | ||
" columns=props,\n", | ||
").astype(\"str\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "e6c74cfd", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "9c0cca8a", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"to_process = []\n", | ||
"for g, ndf in df.groupby(\"name\"):\n", | ||
" if len(ndf) > 1:\n", | ||
" to_process.append([int(x) for x in ndf['id'].tolist()])\n", | ||
" " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "0a73dbb6", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"len(to_process)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "fd48e0e6", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"print(f\"Nr. of place types before: {PlaceType.objects.all().count()}\")\n", | ||
"for x in to_process:\n", | ||
" good_type = PlaceType.objects.get(id=x[0])\n", | ||
" bad_type = PlaceType.objects.get(id=x[1])\n", | ||
" bad_type_base = VocabsBaseClass.objects.get(id=x[1])\n", | ||
" for place in Place.objects.filter(kind=bad_type):\n", | ||
" place.kind = good_type\n", | ||
" place.save()\n", | ||
" bad_type_base.delete()\n", | ||
"print(f\"Nr. of place types after: {PlaceType.objects.all().count()}\")\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "bd2993ae", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"PlaceType.objects.filter(name=\"A.ADM1\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "313cea39", | ||
"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.10.12" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
Oops, something went wrong.