-
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
27 create db tables aka django modelspy #50
Changes from 3 commits
de0c95a
545a894
279867b
deef36a
599d50a
4c79a72
99c4b4e
6077998
df8dcaa
6e76e2c
8a7e7b0
cc17642
fa016c2
4cee4a0
e5278e1
b72d0c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,91 @@ | ||
from django.db import models | ||
from django.contrib.gis.db import models | ||
|
||
# from django.db import models | ||
|
||
##TODO: Update function that can extract the census tract from the location | ||
## using the Census API | ||
|
||
|
||
def get_census_tract(location) -> str: | ||
pass | ||
|
||
|
||
################################# | ||
######## TRANSIT MODELS ######### | ||
################################# | ||
|
||
|
||
class Demographics(models.Model): | ||
census_tract = models.CharField( | ||
max_length=15 | ||
) # Check length of census tract if its uniform to enforce it here | ||
state = models.CharField( | ||
max_length=15 | ||
) # Check if it's worth to keep or if we should add a method | ||
county = models.CharField(max_length=15) # Same as above | ||
population = models.IntegerField() | ||
# age = models.IntegerField() | ||
median_income = models.IntegerField() | ||
transportation_to_work = models.CharField( | ||
verbose_name="Means of Transportation to Work" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. max chars? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixing it! |
||
) | ||
work_commute_time = models.FloatField(verbose_name="Time of commuto to work") | ||
vehicles_available = models.IntegerField() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would help at some point maybe from @benjaleivas to clarify the units commute in min? hour? |
||
disability_status = models.IntegerField() # Check the type | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would this be a float median/mean estimate? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this field is a count of vehicles |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe an enum? disabled, not disabled, temporarily disabled? |
||
|
||
class TransitStation(models.Model): | ||
station_id = models.CharField(max_length=30, primary_key=True) | ||
location = models.PointField() | ||
route = models.CharField(max_length=30) | ||
census_tract = models.CharField(max_length=30, null=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a route name (like "Red Line") or route_id like "Chicago_CTA_R" or whatever it ends up being? Given that it's set up way, I take it we went with separate entities for each line for a multi-line stop There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think multiple routes have the same station_id (if we go along with the |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be a foreign key to the census tract? |
||
def get_census_tract(self): | ||
self.census_tract = get_census_tract(self.location) | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For @jamesturk and @divij-sinha we decided to go with these For now it seems like we will have to create one view for Portland ridership and one view for Chicago/NYC ridership since they will pull from different tables so if you suggest handling this differently, i.e. add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JPMartinezClaeys depending on the response to this question, the |
||
class TransitRidership(models.Model): | ||
station = models.CharField(max_length=30) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this table needs a primary key (id or station/date combination) and foreign key to |
||
date = models.DateField() | ||
ridership = models.IntegerField() | ||
|
||
|
||
class BikeStation(models.Model): | ||
station_id = models.CharField(max_length=30, primary_key=True) | ||
location = models.PointField() | ||
census_tract = models.CharField(max_length=30, null=True) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. foreign key |
||
def get_census_tract(self): | ||
self.census_tract = get_census_tract(self.location) | ||
|
||
|
||
class BikeRidership(models.Model): | ||
station = models.ForeignKey(BikeStation, on_delete=models.PROTECT) | ||
date = models.DateField() | ||
n_started = models.IntegerField() | ||
n_ended = models.IntegerField() | ||
|
||
|
||
################################# | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you JP! This looks great, the models are consistent with what we were expecting based on the documentation. |
||
######## SURVEY MODELS ########## | ||
################################# | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. small note, these would typically be in their own app when they are this distinct. not necessary for the project, but wanted to mention as a "best practice" |
||
|
||
class Survey(models.Model): | ||
name = models.CharField(max_length=30) | ||
created_at = models.DateTimeField("Created at", auto_now_add=True) | ||
questionnaire = models.JSONField() | ||
|
||
|
||
class SurveyAnswer(models.Model): | ||
user_id = models.CharField(max_length=30) | ||
response_date = models.DateTimeField("Survey response date", auto_now_add=True) | ||
city = models.CharField(max_length=30) | ||
survey = models.ForeignKey(Survey, on_delete=models.PROTECT) | ||
answers = models.JSONField() | ||
|
||
|
||
class PlannedRoute(models.Model): | ||
user_id = models.CharField(max_length=30) | ||
response_date = models.DateTimeField("Survey response date", auto_now_add=True) | ||
route = models.JSONField() |
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 remember @benjaleivas was ingesting at the block level, so as long as he is good with aggregating to the tract level by the time it goes to the db and that wont lose info for the frontend needs (I am pretty sure this is ok but want to double check)
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.
Modified to the block level