Skip to content

Commit

Permalink
Merge pull request #172 from arthur-schnitzler/164-wrong-iso-dates-07…
Browse files Browse the repository at this point in the history
…-01-07-02

164 wrong iso dates 07 01 07 02
  • Loading branch information
csae8092 authored Mar 5, 2024
2 parents 3360786 + 039f9d0 commit f8d8beb
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 9 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ in order to avoid errors on a new instance you'll need to set an environment var

* bundling js-code (used for network-vis) is not part of the docker-setup
* for development make sure the vite-dev-server is running `pnpm run vite`
* for building new bundle, run `pn run build`
* for building new bundle, run `pn run build`


## reset sequence
```SQL
BEGIN;
SELECT setval(pg_get_serial_sequence('"django_migrations"','id'), coalesce(max("id"), 1), max("id") IS NOT null) FROM "django_migrations";
COMMIT;
```
26 changes: 26 additions & 0 deletions apis_core/apis_entities/management/commands/save_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os
import warnings

from datetime import datetime
from tqdm import tqdm
from django.conf import settings
from django.core.management.base import BaseCommand

from apis_core.apis_metainfo.models import TempEntityClass
from dumper.utils import write_report

warnings.filterwarnings("ignore")


class Command(BaseCommand):
help = "saves all TempEntity objects"

def handle(self, *args, **kwargs):
start_time = datetime.now().strftime(settings.PMB_TIME_PATTERN)
items = TempEntityClass.objects.all()
print(f"{items.count()} objects to save")
for x in tqdm(items, total=items.count()):
x.save()
end_time = datetime.now().strftime(settings.PMB_TIME_PATTERN)
report = [os.path.basename(__file__), start_time, end_time]
write_report(report)
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Generated by Django 5.0.1 on 2024-03-01 14:24

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("apis_entities", "0002_initial"),
]

operations = [
migrations.AlterModelOptions(
name="event",
options={
"ordering": ["id"],
"verbose_name": "Ereignis",
"verbose_name_plural": "Ereignisse",
},
),
migrations.AlterModelOptions(
name="institution",
options={
"ordering": ["id"],
"verbose_name": "Institution",
"verbose_name_plural": "Institutionen",
},
),
migrations.AlterModelOptions(
name="person",
options={
"ordering": ["id"],
"verbose_name": "Person",
"verbose_name_plural": "Personen",
},
),
migrations.AlterModelOptions(
name="place",
options={
"ordering": ["id"],
"verbose_name": "Ort",
"verbose_name_plural": "Orte",
},
),
migrations.AlterModelOptions(
name="work",
options={
"ordering": ["id"],
"verbose_name": "Werk",
"verbose_name_plural": "Werke",
},
),
]
14 changes: 14 additions & 0 deletions apis_core/apis_entities/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from apis_core.apis_entities.forms import get_entities_form
from apis_core.apis_entities.models import Person, Place
from apis_core.helper_functions.DateParser import parse_date
from apis_core.apis_metainfo.models import Uri
from normdata.forms import NormDataImportForm
from normdata.utils import (
Expand Down Expand Up @@ -402,3 +403,16 @@ def test_028_beacons(self):
url = reverse("apis_core:wikidata_beacon")
r = client.get(url)
self.assertEqual(r.status_code, 200)

def test_029_parse_date(self):
dates = [
["1900", ["1900-01-01", "1900-01-01", "1900-12-31"]],
["1800-02", ["1800-02-01", "1800-02-01", "1800-02-28"]],
["1800-02-02", ["1800-02-02", "None", "None"]],
["um 1900<1900-03-03>", ["1900-03-03", "None", "None"]],
]
for x in dates:
results = parse_date(x[0])
for i, r in enumerate(results):
date_str = f"{r}"[:10]
self.assertEqual(date_str, x[1][i])
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Generated by Django 5.0.1 on 2024-03-01 14:24

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("apis_relations", "0002_initial"),
]

operations = [
migrations.AlterModelOptions(
name="eventevent",
options={
"default_manager_name": "objects",
"ordering": ["start_date", "id"],
},
),
migrations.AlterModelOptions(
name="eventwork",
options={
"default_manager_name": "objects",
"ordering": ["start_date", "id"],
},
),
migrations.AlterModelOptions(
name="institutionevent",
options={
"default_manager_name": "objects",
"ordering": ["start_date", "id"],
},
),
migrations.AlterModelOptions(
name="institutioninstitution",
options={
"default_manager_name": "objects",
"ordering": ["start_date", "id"],
},
),
migrations.AlterModelOptions(
name="institutionplace",
options={
"default_manager_name": "objects",
"ordering": ["start_date", "id"],
},
),
migrations.AlterModelOptions(
name="institutionwork",
options={
"default_manager_name": "objects",
"ordering": ["start_date", "id"],
},
),
migrations.AlterModelOptions(
name="personevent",
options={
"default_manager_name": "objects",
"ordering": ["start_date", "id"],
},
),
migrations.AlterModelOptions(
name="personinstitution",
options={
"default_manager_name": "objects",
"ordering": ["start_date", "id"],
},
),
migrations.AlterModelOptions(
name="personperson",
options={
"default_manager_name": "objects",
"ordering": ["start_date", "id"],
},
),
migrations.AlterModelOptions(
name="personplace",
options={
"default_manager_name": "objects",
"ordering": ["start_date", "id"],
},
),
migrations.AlterModelOptions(
name="personwork",
options={
"default_manager_name": "objects",
"ordering": ["start_date", "id"],
},
),
migrations.AlterModelOptions(
name="placeevent",
options={
"default_manager_name": "objects",
"ordering": ["start_date", "id"],
},
),
migrations.AlterModelOptions(
name="placeplace",
options={
"default_manager_name": "objects",
"ordering": ["start_date", "id"],
},
),
migrations.AlterModelOptions(
name="placework",
options={
"default_manager_name": "objects",
"ordering": ["start_date", "id"],
},
),
migrations.AlterModelOptions(
name="workwork",
options={
"default_manager_name": "objects",
"ordering": ["start_date", "id"],
},
),
]
10 changes: 2 additions & 8 deletions apis_core/helper_functions/DateParser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import math
import re
from datetime import datetime, timedelta
from datetime import datetime


def parse_date(date_string: str) -> (datetime, datetime, datetime):
Expand Down Expand Up @@ -303,12 +302,7 @@ def parse_iso_date(date_string):
if date_ab > date_bis:
raise ValueError("'ab-date' must be before 'bis-date' in time")

# calculate difference between start and end date of range,
# and use it to calculate a single date for usage as median.
days_delta_half = math.floor(
(date_bis - date_ab).days / 2,
)
date_single = date_ab + timedelta(days=days_delta_half)
date_single = date_ab

elif date_ab is not None and date_bis is None:
# date is only the start of a range, save it also as the single date
Expand Down

0 comments on commit f8d8beb

Please sign in to comment.