-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
@@ -33,8 +33,12 @@ class TerritorialEntity(models.Model): | |||
""" | |||
|
|||
wikidata_id = models.PositiveIntegerField() # Excluding the Q | |||
label = models.TextField(max_length=90) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
project/api/models.py
Outdated
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) |
There was a problem hiding this comment.
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
Hey, probably it's time to add |
I don't see why not. Many-to-Many relationships? It could be a PoliticalRelation too maybe. |
We have a range of dates in Many-to-Many will be the most accurate description for this field. |
Well, I've noticed that we have lots of duplicate Can we do this? Do you find it valuable? Thanks |
Should we split the tests for api and models. The linter is giving too-many-lines errors |
@ataalik I noticed that too, we definitely should |
There was a problem hiding this 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
?
project/api/models.py
Outdated
@@ -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) |
There was a problem hiding this comment.
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
backend/project/api/serializers.py
Lines 200 to 208 in 7b75b9d
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} |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
Lines 55 to 60 in 88e5fc7
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)
There was a problem hiding this comment.
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": []
}
There was a problem hiding this comment.
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.
bors r+ |
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]>
Build failed |
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. |
Can we disable this rule for whole tests directory? |
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. |
Could we try placing a new |
This needs to be fixed, can we fix the |
I couldn't get that to work, maybe you should take a look |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
As it was discussed on slack: I would propose to mock I've got next error page from wikidata
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bors r+ |
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]>
Build succeeded |
Adds start and end dates and a label for names to be displayed. Fixes #99