Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Field changes to the territorial entity. #127

Merged
merged 12 commits into from
Jun 26, 2019
Merged

Field changes to the territorial entity. #127

merged 12 commits into from
Jun 26, 2019

Conversation

ataalik
Copy link
Contributor

@ataalik ataalik commented May 11, 2019

Adds start and end dates and a label for names to be displayed. Fixes #99

@@ -33,8 +33,12 @@ class TerritorialEntity(models.Model):
"""

wikidata_id = models.PositiveIntegerField() # Excluding the Q
label = models.TextField(max_length=90)
Copy link
Member

@quorth0n quorth0n May 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be a nullable PointField similar to visual_center, and updated as a post create hook

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, on second thought we should probably keep this field for #21. We will still need the PointField though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have Point Field for the visual center in STV's table

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, my comment was before the Slack post. Originally I was thinking a field here could correspond to P625 for a wikdiata entity but it doesn't seem that property does us much good in any situation.

@@ -33,8 +33,12 @@ class TerritorialEntity(models.Model):
"""

wikidata_id = models.PositiveIntegerField() # Excluding the Q
label = models.TextField(max_length=90)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have Point Field for the visual center in STV's table

color = ColorField()
admin_level = models.PositiveIntegerField()
inception_date = models.DecimalField(decimal_places=1, max_digits=10)
dissolution_date = models.DecimalField(decimal_places=1, max_digits=10)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume that inception or dissolution dates can be unknown. For example, countries that are existing right now does not have a dissolution date.

Probably we should add blank=True, null=True

@MiklerGM MiklerGM closed this May 13, 2019
@MiklerGM MiklerGM deleted the ata-99 branch May 13, 2019 13:25
@MiklerGM MiklerGM restored the ata-99 branch May 13, 2019 13:28
@MiklerGM MiklerGM reopened this May 13, 2019
@MiklerGM
Copy link
Contributor

Hey, probably it's time to add successor or predecessor field to the TE? (for #5)
Or it is a bad idea and I should forget about it.
What do you think?

@ataalik
Copy link
Contributor Author

ataalik commented May 17, 2019

Hey, probably it's time to add successor or predecessor field to the TE? (for #5)
Or it is a bad idea and I should forget about it.
What do you think?

I don't see why not. Many-to-Many relationships? It could be a PoliticalRelation too maybe.

@MiklerGM
Copy link
Contributor

We have a range of dates in Political Relations, probably it is not the best place to store this.

Many-to-Many will be the most accurate description for this field.

@MiklerGM
Copy link
Contributor

MiklerGM commented May 23, 2019

Well, I've noticed that we have lots of duplicate wikidata_id entities, it might be better to add information about total STVs under TE control to the search output.
As far as I understand we've got duplicate ids mostly because of disputed territories, probably some of them from processing errors. And for sure, some of them there because of incorrect labeling (entities without corresponding wikidata id). I think @v1kun should know more about this.

Can we do this? Do you find it valuable?

Thanks

@ataalik
Copy link
Contributor Author

ataalik commented Jun 8, 2019

Should we split the tests for api and models. The linter is giving too-many-lines errors

@quorth0n
Copy link
Member

quorth0n commented Jun 8, 2019

@ataalik I noticed that too, we definitely should

Copy link
Contributor

@MiklerGM MiklerGM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change the behavior of stv_count?

@@ -37,7 +39,8 @@ class TerritorialEntity(models.Model):
color = ColorField()
admin_level = models.PositiveIntegerField()
inception_date = models.DecimalField(decimal_places=1, max_digits=10)
dissolution_date = models.DecimalField(decimal_places=1, max_digits=10)
dissolution_date = models.DecimalField(decimal_places=1, max_digits=10, blank=True, null=True)
stv_count = models.IntegerField(default=0, null=True, blank=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this would be done via aggregate function, like it was done for the votes in #102

def get_votes(self, obj): # pylint: disable=R0201
"""
Returns dict of upvotes and downvotes
"""
qs = NarrativeVote.objects.filter(narrative=obj)
upvotes = qs.aggregate(upvotes=Count(Case(When(vote=True, then=1))))
downvotes = qs.aggregate(downvotes=Count(Case(When(vote=False, then=1))))
return {**upvotes, **downvotes}

Copy link
Contributor

@MiklerGM MiklerGM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, stv_count is working fine, but I forgot about #125 and nested STVs as an array.
I am sorry that I've asked you to add the counter when it can be relatively easy to calculate stv_count on the frontend.
We can keep the field or remove it, and it's up to you.

However, I would advise changing the restrictions for inception_date. I would go with the full restrictions in case we can guarantee that we've got the clean data from the Wikidata

color = ColorField()
admin_level = models.PositiveIntegerField()
inception_date = models.DecimalField(decimal_places=1, max_digits=10)
dissolution_date = models.DecimalField(
decimal_places=1, max_digits=10, blank=True, null=True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that we should do this strict validation on the inception date?

Especially when you are validating it for not null

def clean(self, *args, **kwargs): # pylint: disable=W0221
if not self.inception_date is None and not self.dissolution_date is None:
if self.inception_date > self.dissolution_date:
raise ValidationError(
"Inception date cannot be later than dissolution date"
)

postgres=# INSERT INTO api_territorialentity VALUES (1, 30, '10', 2, NULL, NULL, 'USA');
ERROR:  null value in column "inception_date" violates not-null constraint
DETAIL:  Failing row contains (1, 30, 10, 2, null, null, USA).
postgres=# INSERT INTO api_territorialentity (wikidata_id, color, admin_level, label) VALUES (30, '10', 2, 'USA');
ERROR:  null value in column "inception_date" violates not-null constraint
DETAIL:  Failing row contains (1, 30, 10, 2, null, null, USA).

postgres=# INSERT INTO api_territorialentity VALUES (1, 30, '10', 2, 0, 0, 'USA');
INSERT 0 1
postgres=# INSERT INTO api_territorialentity VALUES (2, 30, '10', 2, NULL, 0, 'USA2');
INSERT 0 1
postgres=# select * from api_territorialentity;
 id | wikidata_id | color | admin_level | dissolution_date | inception_date | label
----+-------------+-------+-------------+------------------+----------------+-------
  1 |          30 | 10    |           2 |              0.0 |            0.0 | USA
  2 |          30 | 10    |           2 |                  |            0.0 | USA2
(2 rows)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more question, why inception and dissolution date are returned as a string via API request?

{
  "id":2,
  "stvs":[],
  "stv_count":0,
  "wikidata_id":30,
  "label":"USA2",
  "color":"10",
  "admin_level":2,
  "inception_date":"0.0",
  "dissolution_date":null,
  "predecessor":[],
  "relations":[]
}

I've noticed that we have one more reserved SQL word as a column - references, #119

The response after adding an STV

    {
        "id": 1,
        "stvs": [ // This is an array of all stvs
            {
                "id": 1,
                "start_date": "1.0",
                "end_date": "0.0",
                "references": [
                    "qwe",
                    "qwee"
                ],
                "visual_center": {
                    "type": "Point",
                    "coordinates": [
                        -71.060316,
                        48.432044
                    ]
                },
                "entity": 1,
                "related_events": []
            }
        ],
        "stv_count": 1, // this is a new count field
        "wikidata_id": 30,
        "label": "USA",
        "color": "10",
        "admin_level": 2,
        "inception_date": "0.0",
        "dissolution_date": "0.0",
        "predecessor": [],
        "relations": []
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking thinking the dates as a user input but of course since we have gaps in wikidata both date fields should have less restriction. I guess they should be nullable?

I need to convert the dates using the library in the viewset I think. Will take care of it.

What should references be changed as. Citations comes to mind.

@MiklerGM
Copy link
Contributor

bors r+

bors bot added a commit that referenced this pull request Jun 14, 2019
127: Field changes to the territorial entity. r=MiklerGM a=ataalik

Adds start and end dates and a label for names to be displayed. Fixes #99 

Co-authored-by: ata <[email protected]>
@bors
Copy link
Contributor

bors bot commented Jun 14, 2019

Build failed

@ataalik
Copy link
Contributor Author

ataalik commented Jun 15, 2019

I was expecting the linting errors. Apparently pylint has a bug where you can not disable duplicate-code check on a per file basis with comments etc that they don't fix. We could disable it in the makefile for all the project.

Not sure about the test errors though. It runs fine on my end. I will check that out.

@MiklerGM
Copy link
Contributor

Can we disable this rule for whole tests directory?

@ataalik
Copy link
Contributor Author

ataalik commented Jun 24, 2019

I think the only thing that works is running the lint command two times, once for tests directory with disable duplicate code check flag and once for the general project.

@quorth0n
Copy link
Member

Could we try placing a new .pylintrc in the tests directory to disable the duplicate-code check?

@quorth0n
Copy link
Member

ERROR: unsatisfiable constraints:
  proj4-dev (missing):
    required by: .build-deps-testing-20190623.110637[proj4-dev]

This needs to be fixed, can we fix the apk add lines so that this dependency is accounted for? make clean is helpful in obtaining a clean testing environment to test docker setup with.

@ataalik
Copy link
Contributor Author

ataalik commented Jun 26, 2019

Could we try placing a new .pylintrc in the tests directory to disable the duplicate-code check?

I couldn't get that to work, maybe you should take a look

@MiklerGM

This comment has been minimized.

bors bot added a commit that referenced this pull request Jun 26, 2019
@bors

This comment has been minimized.

@MiklerGM

This comment has been minimized.

bors bot added a commit that referenced this pull request Jun 26, 2019
@bors

This comment has been minimized.

@MiklerGM
Copy link
Contributor

As it was discussed on slack:

I would propose to mock requests.get in unit tests.
Additionally, I would recommend mimicking browser behavior by adding the user-agent header. Current UA is set to python-requests/2.21.0.
Wikidata can ban all users by UA or network.

I've got next error page from wikidata

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 403 You have been banned until 2019-06-26T17:35:05.645Z, please respect throttling and retry-after headers.</title>
</head>
<body><h2>HTTP ERROR 403</h2>
<p>Problem accessing /bigdata/namespace/wdq/sparql. Reason:
<pre>    You have been banned until 2019-06-26T17:35:05.645Z, please respect throttling and retry-after headers.</pre></p><hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.12.v20180830</a><hr/>

</body>
</html>

@MiklerGM

This comment has been minimized.

bors bot added a commit that referenced this pull request Jun 26, 2019
@bors

This comment has been minimized.

@MiklerGM
Copy link
Contributor

bors r+

bors bot added a commit that referenced this pull request Jun 26, 2019
127: Field changes to the territorial entity. r=MiklerGM a=ataalik

Adds start and end dates and a label for names to be displayed. Fixes #99 

Co-authored-by: ata <[email protected]>
Co-authored-by: Michael Orlov <[email protected]>
@bors
Copy link
Contributor

bors bot commented Jun 26, 2019

Build succeeded

@bors bors bot merged commit 194202d into master Jun 26, 2019
@quorth0n quorth0n deleted the ata-99 branch June 30, 2019 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cache more info about TE
3 participants