Skip to content

Commit

Permalink
Merge pull request #116 from arthur-schnitzler/280-problems-with-csv-…
Browse files Browse the repository at this point in the history
…export

280 problems with csv export
  • Loading branch information
csae8092 authored Dec 19, 2024
2 parents c368cfa + 63e79c7 commit e208e8b
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 2 deletions.
2 changes: 1 addition & 1 deletion network/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ def test_03_map_view(self):
self.assertEqual(response.status_code, 200)

def test_04_geojson_view(self):
url = reverse("network:map")
url = reverse("network:geojson")
response = client.get(url)
self.assertEqual(response.status_code, 200)
3 changes: 2 additions & 1 deletion network/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import csv
import json
import pandas as pd
from django.apps import apps
Expand Down Expand Up @@ -100,7 +101,7 @@ def network_data(request):
content_type="text/csv",
headers={"Content-Disposition": 'attachment; filename="relations.csv"'},
)
df.to_csv(response, index=False)
df.to_csv(response, index=False, quoting=csv.QUOTE_ALL, quotechar='"')
return response
elif format == "json":
df = df.set_index("edge_id")
Expand Down
117 changes: 117 additions & 0 deletions notebooks/issue__281_aufenthaltsorte.ipynb
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
}

0 comments on commit e208e8b

Please sign in to comment.