Skip to content

Commit

Permalink
merge dev branch
Browse files Browse the repository at this point in the history
  • Loading branch information
atalyaalon committed Sep 7, 2024
2 parents c6b9353 + 2e57cba commit bd209bd
Show file tree
Hide file tree
Showing 67 changed files with 6,119 additions and 442 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ jobs:
cd ./anyway-newsflash-infographics/
bash run.bash
cd ../
docker-compose -f docker-compose.yml up -d --build anyway
docker compose -f docker-compose.yml up -d --build anyway
- name: Waiting for DB startup
run: |
bash ./wait_for_postgres.sh
- name: DB Initialization
run: |
docker exec anyway alembic upgrade head
docker exec anyway ./main.py process cities
docker exec anyway ./main.py process streets
docker exec anyway ./main.py process registered-vehicles
docker exec anyway ./main.py process cbs --source local_dir_for_tests_only
docker exec anyway ./main.py process road-segments
Expand Down Expand Up @@ -99,7 +101,7 @@ jobs:
docker logs --details db
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v4
with:
file: ./coverage.xml
flags: unittests
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ At ANYWAY we aim to reduce road accidents by:
1. Raising public awareness of existing road hazards, thereby leading towards safer road behaviour.
1. Collaborating with authorities in order to assist and drive them to find solutions in light of Vision Zero. Such solutions will improve road infrastructure and behavioural problems in attempt to prevent road fatalities.

Take a look at our [facebook page](https://www.facebook.com/anywayisrael). See also our [Android app](https://github.com/samuelregev/anywayAndroidApp/) and [iOS app](https://github.com/data-for-change/Anyway-iOS/) on GitHub.
Take a look at our [facebook page](https://www.facebook.com/anywayisrael). See also our [Android app](https://github.com/data-for-change/anywayAndroidApp/) and [iOS app](https://github.com/data-for-change/Anyway-iOS/) on GitHub.


### ANYWAY’s Interactive Map:
Expand Down
30 changes: 30 additions & 0 deletions alembic/versions/53d0b00fb750_add_non_urban_intersection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""add non_urban_intersection
Revision ID: 53d0b00fb750
Revises: 11ddb0cff075
Create Date: 2024-06-16 15:05:30.522542
"""

# revision identifiers, used by Alembic.
revision = '53d0b00fb750'
down_revision = '11ddb0cff075'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('involved_markers_hebrew', sa.Column('urban_intersection', sa.Integer(), nullable=True))
op.add_column('vehicles_markers_hebrew', sa.Column('urban_intersection', sa.Integer(), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('vehicles_markers_hebrew', 'urban_intersection')
op.drop_column('involved_markers_hebrew', 'urban_intersection')
# ### end Alembic commands ###
36 changes: 36 additions & 0 deletions alembic/versions/97740b33407d_add_numeric_indexes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""add numeric indexes
Revision ID: 97740b33407d
Revises: 53d0b00fb750
Create Date: 2024-08-24 11:19:33.674396
"""

# revision identifiers, used by Alembic.
revision = '97740b33407d'
down_revision = '53d0b00fb750'
branch_labels = None
depends_on = None

from alembic import op
# import sqlalchemy as sa


# pylint: disable=E1101
def upgrade():
for table in ['markers', 'markers_hebrew']:
for field in ['yishuv_symbol', 'street1', 'street2']:
op.create_index(f'ix_{table}_{field}', table, [field], unique=False)
for table in ['markers_hebrew']:
for field in ['yishuv_name', 'street1_hebrew', 'street2_hebrew']:
op.drop_index(f'ix_{table}_{field}', table_name=table)


# pylint: disable=E1101
def downgrade():
for table in ['markers', 'markers_hebrew']:
for field in ['yishuv_symbol', 'street1', 'street2']:
op.drop_index(f'ix_{table}_{field}', table_name=table)
for table in ['markers_hebrew']:
for field in ['yishuv_name', 'street1_hebrew', 'street2_hebrew']:
op.create_index(f'ix_{table}_{field}', table, [field], unique=False)
31 changes: 31 additions & 0 deletions alembic/versions/mn9px8cacn24_add_house_number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""add house number
Revision ID: mn9px8cacn24
Revises: 97740b33407d
Create Date: 2024-06-16 15:05:30.522542
"""

# revision identifiers, used by Alembic.
revision = 'mn9px8cacn24'
down_revision = '97740b33407d'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('involved_markers_hebrew', sa.Column('house_number', sa.Integer(), nullable=True))
op.add_column('vehicles_markers_hebrew', sa.Column('house_number', sa.Integer(), nullable=True))

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('vehicles_markers_hebrew', 'house_number')
op.drop_column('involved_markers_hebrew', 'house_number')
# ### end Alembic commands ###
7 changes: 7 additions & 0 deletions anyway/backend_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ class ResolutionCategories(Enum):
ResolutionCategories.SUBURBAN_JUNCTION
]

RESOLUTION_ACCURACY_VALUES: dict = {
ResolutionCategories.SUBURBAN_JUNCTION: [1, 3, 4],
ResolutionCategories.SUBURBAN_ROAD: [1, 3, 4],
ResolutionCategories.URBAN_JUNCTION: [1, 3],
ResolutionCategories.STREET: [1, 3],
}

class Source(Enum):
@classmethod
def _missing_(cls, value):
Expand Down
4 changes: 4 additions & 0 deletions anyway/db_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,9 +638,11 @@ def create_involved_hebrew_markers_hebrew_view(self):
AccidentMarkerView.street1_hebrew,
AccidentMarkerView.street2,
AccidentMarkerView.street2_hebrew,
AccidentMarkerView.house_number,
AccidentMarkerView.non_urban_intersection,
AccidentMarkerView.non_urban_intersection_hebrew,
AccidentMarkerView.non_urban_intersection_by_junction_number,
AccidentMarkerView.urban_intersection,
AccidentMarkerView.accident_day,
AccidentMarkerView.accident_hour_raw,
AccidentMarkerView.accident_hour_raw_hebrew,
Expand Down Expand Up @@ -835,9 +837,11 @@ def create_vehicles_markers_hebrew_view(self):
AccidentMarkerView.street1_hebrew,
AccidentMarkerView.street2,
AccidentMarkerView.street2_hebrew,
AccidentMarkerView.house_number,
AccidentMarkerView.non_urban_intersection,
AccidentMarkerView.non_urban_intersection_hebrew,
AccidentMarkerView.non_urban_intersection_by_junction_number,
AccidentMarkerView.urban_intersection,
AccidentMarkerView.accident_day,
AccidentMarkerView.accident_hour_raw,
AccidentMarkerView.accident_hour_raw_hebrew,
Expand Down
18 changes: 16 additions & 2 deletions anyway/flask_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
from flask_babel import Babel, gettext
from flask_compress import Compress
from flask_cors import CORS
from flask_restx import Resource, fields, reqparse
from flask_restx import Resource, fields, reqparse, Model
from sqlalchemy import and_, not_, or_
from sqlalchemy import func
from webassets import Environment as AssetsEnvironment, Bundle as AssetsBundle
from webassets.ext.jinja2 import AssetsExtension
from werkzeug.exceptions import BadRequestKeyError
import json

from anyway import utilities, secrets
from anyway.app_and_db import api, get_cors_config
Expand Down Expand Up @@ -57,7 +58,8 @@
City,
Streets,
Comment,
TelegramForwardedMessages
TelegramForwardedMessages,
NewsFlash
)
from anyway.request_params import get_request_params_from_request_values
from anyway.views.news_flash.api import (
Expand All @@ -68,6 +70,7 @@
DEFAULT_LIMIT_REQ_PARAMETER,
DEFAULT_OFFSET_REQ_PARAMETER,
DEFAULT_NUMBER_OF_YEARS_AGO,
search_newsflashes_by_resolution
)
from anyway.views.schools.api import (
schools_description_api,
Expand Down Expand Up @@ -1124,6 +1127,17 @@ def acc_in_area_query():
help="limit number of retrieved items to given limit",
)

newsflash_fields = tuple(column.name for column in NewsFlash.__table__.columns)
nfbr_parser = reqparse.RequestParser()
nfbr_parser.add_argument("resolutions", type=str, action="append", required=True,
help="List of resolutions to filter by")
nfbr_parser.add_argument("include", type=str, required=True, choices=["True", "False"],
help="Flag to include or exclude the specified resolutions (True\False)")
nfbr_parser.add_argument("limit", type=int, help="Maximum number of records to return")
nfbr_parser.add_argument("fields", type=str, choices=(*newsflash_fields, ""), action="append",
help=f"List of fields to include in the response (Empty array to fetch all).\n"
f"Available values: {', '.join(newsflash_fields)}")


def datetime_to_str(val: datetime.datetime) -> str:
return val.strftime("%Y-%m-%d %H:%M:%S") if isinstance(val, datetime.datetime) else "None"
Expand Down
9 changes: 0 additions & 9 deletions anyway/localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import pandas as pd

from anyway import field_names
from typing import Optional

import logging

Expand Down Expand Up @@ -214,11 +213,3 @@ def get_field(field, value=None):

def get_supported_tables():
return _tables.keys()


def get_city_name(symbol_id, lang: str = "he") -> Optional[str]:
column_to_fetch = field_names.name if lang == "he" else "ENGLISH_NAME"
try:
return _cities.loc[symbol_id, column_to_fetch]
except Exception:
return None
Loading

0 comments on commit bd209bd

Please sign in to comment.