-
Notifications
You must be signed in to change notification settings - Fork 244
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
Ssafty-data api involved #2760
Open
ziv17
wants to merge
17
commits into
data-for-change:dev
Choose a base branch
from
ziv17:sd-api-involved
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Ssafty-data api involved #2760
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
04aaa73
wip
ziv17 3a0098d
WIP - creating satefty-data tables via alembic
ziv17 dab4787
WIP - defining safety-data tables and adding partial data to them
ziv17 7cbf9f1
WIP
ziv17 6f41c05
WIP - initial involved and accident tables, load, and simple query
ziv17 5c25f03
WIP load all data, filter first param
ziv17 59f228f
Adding accident_type and filters
ziv17 49b1491
WIP - fields change, create tables
ziv17 d948f94
Change field names, load vehicles field to sd_accident table
ziv17 2630145
vehicles work in query
ziv17 6a05c01
Using join for hebrew fields
ziv17 6a88300
WIP with vehicle_vehicle_type_hebrew
ziv17 f8e50ea
wip - implementing Aatalya comment from 1-Jan on issue 2734
ziv17 03ee28c
wip - implementing Aatalya comment from 1-Jan on issue 2734
ziv17 019f9b5
WIP implement Atalya comment from 9-Jan on issue 2734
ziv17 7338854
WIP implement Atalya comment from 9-Jan on issue 2734
ziv17 91740a7
Add loading of safety-data involved and accident table to process cbs…
ziv17 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
"""Add safety-data tables | ||
|
||
Revision ID: 99364b16374f | ||
Revises: e962054e4422 | ||
Create Date: 2024-11-15 11:03:26.435210 | ||
|
||
""" | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '99364b16374f' | ||
down_revision = 'e962054e4422' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
sd_involved_table = "safety_data_involved" | ||
sd_accident_table = "safety_data_accident" | ||
|
||
|
||
def downgrade(): | ||
op.drop_table(sd_involved_table) # pylint: disable=no-member | ||
op.drop_table(sd_accident_table) # pylint: disable=no-member | ||
|
||
|
||
def upgrade(): | ||
create_safety_data_accident_table() | ||
create_safety_data_involved_table() | ||
|
||
def create_safety_data_accident_table(): | ||
op.create_table( # pylint: disable=no-member | ||
sd_accident_table, | ||
sa.Column('accident_id', sa.BigInteger(), primary_key=True, autoincrement=False, nullable=False), | ||
sa.Column('accident_year', sa.Integer(), primary_key=True, autoincrement=False, nullable=False), | ||
sa.Column('provider_code', sa.Integer(), primary_key=True, autoincrement=False, nullable=False), | ||
sa.Column('accident_month', sa.Integer()), | ||
sa.Column('accident_timestamp', sa.TIMESTAMP()), | ||
sa.Column('accident_type', sa.Integer(), nullable=True), | ||
sa.Column('accident_yishuv_symbol', sa.Integer(), nullable=True), | ||
sa.Column('day_in_week', sa.Integer(), nullable=True), | ||
sa.Column('day_night', sa.Integer(), nullable=True), | ||
sa.Column('location_accuracy', sa.Integer(), nullable=True), | ||
sa.Column('multi_lane', sa.Integer(), nullable=True), | ||
sa.Column('one_lane', sa.Integer(), nullable=True), | ||
sa.Column('road1', sa.Integer(), nullable=True), | ||
sa.Column('road2', sa.Integer(), nullable=True), | ||
sa.Column('road_segment_number', sa.Integer(), nullable=True), | ||
sa.Column('road_type', sa.Integer(), nullable=True), | ||
sa.Column('road_width', sa.Integer(), nullable=True), | ||
sa.Column('speed_limit', sa.Integer(), nullable=True), | ||
sa.Column('street1', sa.Integer(), nullable=True), | ||
sa.Column('street2', sa.Integer(), nullable=True), | ||
sa.Column('vehicles', sa.Integer(), nullable=True), | ||
sa.Column('latitude', sa.Float(), nullable=True), | ||
sa.Column('longitude', sa.Float(), nullable=True), | ||
) | ||
for field in ['accident_year', 'accident_month', 'accident_timestamp', | ||
'accident_type', 'accident_yishuv_symbol', | ||
'day_night', 'multi_lane', 'one_lane', | ||
'road1', 'road2', 'road_segment_number', 'road_type', 'road_width', | ||
'speed_limit', | ||
'street1', 'street2', | ||
'latitude', 'longitude', | ||
]: | ||
# pylint: disable=no-member | ||
op.create_index(op.f(f'ix_{sd_accident_table}_{field}'), sd_accident_table, [field], unique=False) | ||
|
||
def create_safety_data_involved_table(): | ||
op.create_table( # pylint: disable=no-member | ||
sd_involved_table, | ||
sa.Column('_id', sa.Integer(), primary_key=True, autoincrement=False, nullable=False), | ||
sa.Column('accident_id', sa.BigInteger(), nullable=False), | ||
sa.Column('accident_year', sa.Integer(), nullable=False), | ||
sa.Column('provider_code', sa.Integer(), nullable=False), | ||
sa.Column('age_group', sa.Integer(), nullable=True), | ||
sa.Column('injured_type', sa.Integer(), nullable=True), | ||
sa.Column('injury_severity', sa.Integer(), nullable=True), | ||
sa.Column('population_type', sa.Integer(), nullable=True), | ||
sa.Column('sex', sa.Integer(), nullable=True), | ||
sa.Column('vehicle_type', sa.Integer(), nullable=True), | ||
) | ||
op.create_foreign_key(f'{sd_involved_table}_accident_id_fkey', # pylint: disable=no-member | ||
sd_involved_table, sd_accident_table, | ||
['accident_id', 'provider_code', 'accident_year'], | ||
['accident_id', 'provider_code', 'accident_year'], | ||
ondelete='CASCADE') | ||
op.create_index(op.f(f'ix_{sd_involved_table}_inv_acc'), sd_involved_table, # pylint: disable=no-member | ||
['accident_id', 'accident_year', 'provider_code'], unique=False) | ||
for field in ['injury_severity', 'injured_type', | ||
'age_group', 'sex', 'population_type', 'vehicle_type']: | ||
# pylint: disable=no-member | ||
op.create_index(op.f(f'ix_{sd_involved_table}_{field}'), sd_involved_table, [field], unique=False) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
ForeignKeyConstraint
should be added to table model class, just like in Involved tableThere 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.
And perhaps also
ForeignKey
like inLocationVefiricationHistory