Skip to content

Commit

Permalink
Merge pull request #1086 from hasadna/dev
Browse files Browse the repository at this point in the history
performance improvements and js dict update
  • Loading branch information
atalyaalon authored Jan 15, 2020
2 parents a5ea943 + 4b0bf74 commit 7c38c36
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 54 deletions.
38 changes: 38 additions & 0 deletions alembic/versions/7574885e1fed_remove_unecessary_table_index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""remove unecessary table index
Revision ID: 7574885e1fed
Revises: 98ad75de45b2
Create Date: 2020-01-15 05:43:48.413248
"""

# revision identifiers, used by Alembic.
revision = '7574885e1fed'
down_revision = '98ad75de45b2'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index('acc_long_lat_idx', table_name='markers')
op.drop_index('provider_and_id_idx_markers', table_name='markers')
op.drop_index('provider_and_id_idx_involved', table_name='involved')
op.drop_index('provider_and_id_idx_vehicles', table_name='vehicles')
op.drop_index('geom_gix', table_name='markers')
op.drop_index('discussions_gix', table_name='discussions')
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_index('acc_long_lat_idx', 'markers', ['latitude', 'longitude'], unique=False)
op.create_index('provider_and_id_idx_markers', 'markers', ['provider_and_id'], unique=False)
op.create_index('provider_and_id_idx_involved', 'involved', ['provider_and_id'], unique=False)
op.create_index('provider_and_id_idx_vehicles', 'vehicles', ['provider_and_id'], unique=False)
conn.execute('CREATE INDEX geom_gix ON markers USING GIST (geography(geom));')
conn.execute('CREATE INDEX discussions_gix ON discussions USING GIST (geography(geom));')
# ### end Alembic commands ###
9 changes: 5 additions & 4 deletions anyway/flask_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,18 @@ def shutdown_session(exception=None):

def generate_json(accidents, rsa_markers, discussions, is_thin, total_records=None):
markers = accidents.all()
markers += rsa_markers.all()
total_accidents = len(markers)

rsa = rsa_markers.all()
total_rsa = len(rsa)
markers += rsa

if not is_thin:
markers += discussions.all()

if total_records is None:
total_records = len(markers)

total_accidents = accidents.count()
total_rsa = rsa_markers.count()

entries = [marker.serialize(is_thin) for marker in markers]
return jsonify({"markers": entries, 'pagination': {'totalRecords': total_records,
'totalAccidents': total_accidents,
Expand Down
15 changes: 6 additions & 9 deletions anyway/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ def update(self, data, current_user):

@staticmethod
def bounding_box_query(is_thin=False, yield_per=None, involved_and_vehicles=False, **kwargs):

approx = kwargs.get('approx', True)
accurate = kwargs.get('accurate', True)
page = kwargs.get('page')
Expand Down Expand Up @@ -384,12 +383,10 @@ def bounding_box_query(is_thin=False, yield_per=None, involved_and_vehicles=Fals

if not kwargs['show_rsa']:
rsa_markers = db.session.query(AccidentMarker).filter(sql.false())

if not kwargs['show_accidents']:
markers = markers.filter(and_(AccidentMarker.provider_code != CONST.CBS_ACCIDENT_TYPE_1_CODE,
AccidentMarker.provider_code != CONST.CBS_ACCIDENT_TYPE_3_CODE,
AccidentMarker.provider_code != CONST.UNITED_HATZALA_CODE))

if yield_per:
markers = markers.yield_per(yield_per)
if accurate and not approx:
Expand All @@ -414,7 +411,7 @@ def bounding_box_query(is_thin=False, yield_per=None, involved_and_vehicles=Fals
else:
return MarkerResult(accident_markers=db.session.query(AccidentMarker).filter(sql.false()),
rsa_markers=rsa_markers,
total_records=rsa_markers.count())
total_records=None)
if kwargs.get('show_intersection', 3) != 3:
if kwargs['show_intersection'] == 2:
markers = markers.filter(AccidentMarker.road_type != 2).filter(AccidentMarker.roadType != 4)
Expand All @@ -423,7 +420,7 @@ def bounding_box_query(is_thin=False, yield_per=None, involved_and_vehicles=Fals
else:
return MarkerResult(accident_markers=db.session.query(AccidentMarker).filter(sql.false()),
rsa_markers=rsa_markers,
total_records=rsa_markers.count())
total_records=None)
if kwargs.get('show_lane', 3) != 3:
if kwargs['show_lane'] == 2:
markers = markers.filter(AccidentMarker.one_lane >= 2).filter(AccidentMarker.one_lane <= 3)
Expand All @@ -432,7 +429,7 @@ def bounding_box_query(is_thin=False, yield_per=None, involved_and_vehicles=Fals
else:
return MarkerResult(accident_markers=db.session.query(AccidentMarker).filter(sql.false()),
rsa_markers=rsa_markers,
total_records=rsa_markers.count())
total_records=None)

if kwargs.get('show_day', 7) != 7:
markers = markers.filter(func.extract("dow", AccidentMarker.created) == kwargs['show_day'])
Expand Down Expand Up @@ -478,10 +475,10 @@ def bounding_box_query(is_thin=False, yield_per=None, involved_and_vehicles=Fals

if kwargs.get('age_groups'):
age_groups_list = kwargs.get('age_groups').split(',')
markers = markers.filter(AccidentMarker.involved.any(Involved.age_group.in_(age_groups_list)))
if len(age_groups_list) < (CONST.AGE_GROUPS_NUMBER + 1):
markers = markers.filter(AccidentMarker.involved.any(Involved.age_group.in_(age_groups_list)))
else:
markers = db.session.query(AccidentMarker).filter(sql.false())
total_records = markers.count() + rsa_markers.count()

if page and per_page:
markers = markers.offset((page - 1) * per_page).limit(per_page)
Expand All @@ -508,7 +505,7 @@ def bounding_box_query(is_thin=False, yield_per=None, involved_and_vehicles=Fals
else:
return MarkerResult(accident_markers=markers,
rsa_markers=rsa_markers,
total_records=total_records)
total_records=None)

@staticmethod
def get_marker(marker_id):
Expand Down
62 changes: 32 additions & 30 deletions static/js/inv_dict.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
var inv_dict =
{
"SUG_MEORAV": {
var inv_dict = {
"SUG_MEORAV": {
"1": "נהג שלא נפגע",
"2": "נהג נפגע",
"3": "נפגע שאינו נהג",
},
"MIN": {
},
"MIN": {
"1": "זכר",
"2": "נקבה",
},
"SUG_REHEV_NASA_LMS": {
},
"SUG_REHEV_NASA_LMS": {
"1": "רכב נוסעים פרטי",
"2": "משא עד 3.5 טון אחוד",
"3": "משא עד 3.5 טון לא אחוד",
Expand All @@ -26,23 +25,28 @@ var inv_dict =
"14": "טרקטור",
"15": "אופניים",
"16": "רכבת",
"17": "אחר",
"17": "אחר ולא ידוע",
"18": "אוטובוס זעיר",
"19": "אופנוע 501+ סמ״ק",
},
"EMZAE_BETIHUT": {
"19": "אופנוע 401+ סמ״ק",
"21": "קורקינט חשמלי",
"22": "קלנועית חשמלית",
"23": "אופניים חשמליים",
"24": "משא 3.6 עד 9.9 טון",
"25": "משא 10.0 עד 12.0 טון",
},
"EMZAE_BETIHUT": {
"1": "חגר חגורה",
"2": "חבש קסדת מגן (רק לאופנוע)",
"3": "ישב במושב/ריתמה לילדים (רק לנפגע ילד)",
"4": "לא השתמש באמצעי",
"5": "לא ידוע",
},
"HUMRAT_PGIA": {
},
"HUMRAT_PGIA": {
"1": "הרוג",
"2": "פצוע קשה",
"3": "פצוע קל",
},
"SUG_NIFGA_LMS": {
},
"SUG_NIFGA_LMS": {
"1": "הולך רגל",
"2": "נהג-רכב בעל 4+ גלגלים",
"3": "נוסע- רכב בעל 4+ גלגלים",
Expand All @@ -52,8 +56,8 @@ var inv_dict =
"7": "נוסע-אופניים (לא נהג)",
"8": "נהג-רכב לא ידוע",
"9": "נוסע-רכב לא ידוע",
},
"PEULAT_NIFGA_LMS": {
},
"PEULAT_NIFGA_LMS": {
"1": "ישב ברכב במושב קדמי",
"2": "ישב ברכב במושב אחורי",
"3": "ישב ברכב בארגז מאחור",
Expand All @@ -63,33 +67,31 @@ var inv_dict =
"7": "פעולה אחרת",
"8": "לא ידוע",
"9": "הולך רגל",
},
"PAZUA_USHPAZ": {
},
"PAZUA_USHPAZ": {
"1": "אשפוז עד 24 שעות",
"2": "אשפוז מעל 24 שעות",
},
"MADAD_RAFUI": {
},
"MADAD_RAFUI": {
"1": "קל (1-8)",
"2": "בינוני (9-15)",
"3": "קשה (16-24)",
"4": "קשה מאוד (25-75)",
},
"YAAD_SHIHRUR": {
},
"YAAD_SHIHRUR": {
"1": "בית",
"2": "בית חולים אחר",
"3": "מוסד שיקומי/ מחלקה שיקומית",
"4": "מוות",
"5": "אחר",
},
"SHIMUSH_BE_AVIZAREY_BETIHOT": {
},
"SHIMUSH_BE_AVIZAREY_BETIHOT": {
"1": "כן",
"2": "לא",
"3": "לא ידוע",
},
"PTIRA_MEUHERET": {
},
"PTIRA_MEUHERET": {
"1": "פטירה רגילה עד 30 יום",
"2": "פטירה מאוחרת מעל 30 יום",
}
}
};


26 changes: 15 additions & 11 deletions static/js/veh_dict.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
var veh_dict =
{
"MATZAV_REHEV": {
var veh_dict = {
"MATZAV_REHEV": {
"1": "גנוב",
"2": "השכרה",
"3": "לימוד",
"4": "הסעת ילדים",
},
"SHIYUH_REHEV_LMS": {
},
"SHIYUH_REHEV_LMS": {
"0": "לא מנועי",
"1": "ישראלי",
"2": "צבאי",
Expand All @@ -15,8 +14,8 @@ var veh_dict =
"5": "דיפלומטי",
"6": "יש״ע",
"9": "אלמוני",
},
"SUG_REHEV_LMS": {
},
"SUG_REHEV_LMS": {
"1": "רכב נוסעים פרטי",
"2": "משא עד 4 טון אחוד",
"3": "משא עד 4 טון לא אחוד",
Expand All @@ -33,8 +32,13 @@ var veh_dict =
"14": "טרקטור",
"15": "אופניים",
"16": "רכבת",
"17": "אחר",
"17": "אחר ולא ידוע",
"18": "אוטובוס זעיר",
"19": "אופנוע מעל 500 סמ״ק",
}
};
"19": "אופנוע 401+ סמ״ק",
"21": "קורקינט חשמלי",
"22": "קלנועית חשמלית",
"23": "אופניים חשמליים",
"24": "משא 3.6 עד 9.9 טון",
"25": "משא 10.0 עד 12.0 טון",
}
};

0 comments on commit 7c38c36

Please sign in to comment.