Skip to content

Commit

Permalink
Merge branch 'dev' into bug-2542-fix-newsflash-location-qualification…
Browse files Browse the repository at this point in the history
…-wrong-id
  • Loading branch information
shaked-hayek authored Jan 24, 2024
2 parents bfa20c9 + 1ec17e6 commit f2f9005
Show file tree
Hide file tree
Showing 43 changed files with 1,085 additions and 606 deletions.
14 changes: 10 additions & 4 deletions .github/ISSUE_TEMPLATE/localize_widget.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ Current Widget Title for localization, if exists.
(Note - if translation in file is not adequate - please create a better translation)

**Flask Babel**
For updating messages.pot with all strings for translation - use the following command: `pybabel extract -F babel.cfg -o messages.pot .`
For updating existing po files with new strings: `pybabel update -i messages.pot -d translations`
For compiling pybabel mo files use: `pybabel compile -d translations`
It's important to compile the files for the transations to take place
For updating messages.pot with all strings for translation - use the following commands:

1. Go to anyway container: `docker exec -it anyway bash`
2. Perform the following updates inside anyway container:
- `pybabel extract -F babel.cfg -o messages.pot .`
- For updating existing po files with new strings: `pybabel update -i messages.pot -d translations`
- Update manually the translations: modify translation files - po files per language.
- For compiling pybabel mo files use: `pybabel compile -d translations`
_It's important to compile the files for the transations to take place_
**Make sure to add all po, mo and pot files to pull request**
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ develop-eggs
lib
lib64

# newsflash-ifografics
anyway-newsflash-infographics/anyway-newsflash-infographics/

# Installer logs
pip-log.txt

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Contributing

## Getting the code

### If you are setting up anyway on Windows using WSL - PLEASE MAKE SURE TO COMPLETE THE FOLLOWING STEPS FROM YOUR WSL TERMINAL!!!
### NOTE: If you are setting up anyway on Windows using WSL - PLEASE MAKE SURE TO COMPLETE THE FOLLOWING STEPS FROM YOUR WSL TERMINAL!!!

1. [Fork](https://github.com/data-for-change/anyway/fork) this repository on GitHub
1. `git clone https://github.com/*you*/anyway`
Expand Down
36 changes: 36 additions & 0 deletions alembic/versions/7ea883c8a245_add_road_junction_km_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""add suburban junction table
Revision ID: 7ea883c8a245
Revises: 881e7b1dba8a
Create Date: 2023-06-04 17:43:13.170728
"""

# revision identifiers, used by Alembic.
revision = '7ea883c8a245'
down_revision = '881e7b1dba8a'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa


# noinspection PyUnresolvedReferences
def upgrade():
op.create_table("road_junction_km",
sa.Column('road', sa.Integer(), nullable=False),
sa.Column('non_urban_intersection', sa.Integer(), nullable=False),
sa.Column('km', sa.Float(), nullable=False),
sa.PrimaryKeyConstraint('road', 'non_urban_intersection')
)
op.create_index(op.f('road_junction_km_idx'),
"road_junction_km",
['road', 'non_urban_intersection'],
unique=True)


# noinspection PyUnresolvedReferences
def downgrade():
op.drop_index(op.f('road_junction_km_idx'), table_name="road_junction_km")
op.drop_table("road_junction_km")
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""add non_urban_intersection indexes
Revision ID: fe08b885a23f
Revises: 7ea883c8a245
Create Date: 2023-12-22 07:18:15.227413
"""

# revision identifiers, used by Alembic.
revision = 'fe08b885a23f'
down_revision = '7ea883c8a245'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa


tables = ["vehicles_markers_hebrew", "involved_markers_hebrew", "markers_hebrew"]


def upgrade():
for table in tables:
op.create_index(f'ix_{table}_non_urban_intersection',
table,
['non_urban_intersection'], unique=False
)


def downgrade():
for table in tables:
op.drop_index(op.f(f'ix_{table}_non_urban_intersection'), table_name=table)
53 changes: 36 additions & 17 deletions anyway/flask_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
get_downloaded_data,
DEFAULT_LIMIT_REQ_PARAMETER,
DEFAULT_OFFSET_REQ_PARAMETER,
DEFAULT_NUMBER_OF_YEARS_AGO
DEFAULT_NUMBER_OF_YEARS_AGO,
)
from anyway.views.schools.api import (
schools_description_api,
Expand Down Expand Up @@ -321,6 +321,7 @@ def schools():
else:
return Response("Method Not Allowed", 405)


@app.route("/markers", methods=["GET"])
def markers():
logging.debug("getting markers")
Expand Down Expand Up @@ -357,6 +358,7 @@ def markers():
accident_markers, rsa_markers, discussions, is_thin, total_records=result.total_records
)


@app.route("/markers_by_yishuv_symbol", methods=["GET"])
def markers_by_yishuv_symbol():
logging.debug("getting markers by yishuv symbol")
Expand Down Expand Up @@ -1165,14 +1167,21 @@ def datetime_to_str(val: datetime.datetime) -> str:
)


@api.route("/api/news-flash/<int:news_flash_id>")
class RetrieveSingleNewsFlash(Resource):
@api.route("/api/news-flash/<int:news_flash_id>", methods=["GET", "PATCH"])
class ManageSingleNewsFlash(Resource):
@api.doc("get single news flash")
@api.response(404, "News flash not found")
@api.response(200, "Retrieve single news-flash item", news_flash_fields_model)
def get(self, news_flash_id):
return single_news_flash(news_flash_id)

@api.doc("update single news flash")
@api.response(400, "News flash new location is bad")
@api.response(404, "News flash not found")
@api.response(200, "Retrieve single news-flash item", news_flash_fields_model)
def patch(self, news_flash_id):
return update_news_flash_qualifying(news_flash_id)


@api.route("/api/news-flash-new", methods=["GET"])
class RetrieveNewsFlash(Resource):
Expand All @@ -1194,9 +1203,12 @@ def get(self):
Returns infographics-data API
"""
parser = reqparse.RequestParser()
parser.add_argument("id", type=int, help="News flash id")
parser.add_argument("news_flash_id", type=int, help="News flash id")
parser.add_argument(
"years_ago", type=int, default=DEFAULT_NUMBER_OF_YEARS_AGO, help=f"Number of years back to consider accidents. Default is {DEFAULT_NUMBER_OF_YEARS_AGO} years"
"years_ago",
type=int,
default=DEFAULT_NUMBER_OF_YEARS_AGO,
help=f"Number of years back to consider accidents. Default is {DEFAULT_NUMBER_OF_YEARS_AGO} years",
)
parser.add_argument("lang", type=str, default="he", help="Language")

Expand Down Expand Up @@ -1254,7 +1266,10 @@ def gps_to_cbs_location():
idbl_parser = reqparse.RequestParser()
idbl_parser.add_argument("road_segment_id", type=int, help="Road Segment id")
idbl_parser.add_argument(
"years_ago", type=int, default=DEFAULT_NUMBER_OF_YEARS_AGO, help=f"Number of years back to consider accidents. Default is {DEFAULT_NUMBER_OF_YEARS_AGO} years"
"years_ago",
type=int,
default=DEFAULT_NUMBER_OF_YEARS_AGO,
help=f"Number of years back to consider accidents. Default is {DEFAULT_NUMBER_OF_YEARS_AGO} years",
)
idbl_parser.add_argument("lang", type=str, default="he", help="Language")

Expand Down Expand Up @@ -1455,6 +1470,7 @@ def post(self):
"road_segment_id", type=int, required=True, help="road segment id"
)


@api.route("/api/streets")
@api.expect(get_streets_parser)
class GetAllStreetsOfYishuv(Resource):
Expand Down Expand Up @@ -1492,24 +1508,27 @@ def get(self):
return City.get_all_cities()


@api.route("/api/news-flash/<int:id>", methods=["PUT"])
class SetNewsflashLocationQualification(Resource):
def put(self, id):
return update_news_flash_qualifying(id)


download_data_parser = reqparse.RequestParser()
download_data_parser.add_argument("format", type=str, default="csv",
help="Format for downloaded data (.csv/.xlsx)")
download_data_parser.add_argument("years_ago", type=int, default=DEFAULT_NUMBER_OF_YEARS_AGO,
help=f"Number of years back to consider accidents. Default is {DEFAULT_NUMBER_OF_YEARS_AGO} years")
download_data_parser.add_argument(
"format", type=str, default="csv", help="Format for downloaded data (.csv/.xlsx)"
)
download_data_parser.add_argument(
"years_ago",
type=int,
default=DEFAULT_NUMBER_OF_YEARS_AGO,
help=f"Number of years back to consider accidents. Default is {DEFAULT_NUMBER_OF_YEARS_AGO} years",
)
"""
Download accidents data with regards to news flash/location
"""


@api.route("/api/download-data", methods=["GET"])
class DownloadData(Resource):
@api.doc("download data")
@api.expect(parser)
def get(self):
args = download_data_parser.parse_args()
return get_downloaded_data(args.get('format', 'csv'), args.get('years_ago', DEFAULT_NUMBER_OF_YEARS_AGO))
return get_downloaded_data(
args.get("format", "csv"), args.get("years_ago", DEFAULT_NUMBER_OF_YEARS_AGO)
)
5 changes: 0 additions & 5 deletions anyway/infographics_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ def get_request_params(
location_info = extract_news_flash_location(news_flash_obj)
if location_info is None:
return None
logging.debug("location_info:{}".format(location_info))
location_text = get_news_flash_location_text(news_flash_obj)
logging.debug("location_text:{}".format(location_text))
gps = location_info["gps"]
Expand Down Expand Up @@ -137,7 +136,6 @@ def get_request_params(
lang=lang,
news_flash_description=news_flash_description
)
logging.debug(f"Ending get_request_params. params: {request_params}")
return request_params


Expand All @@ -148,7 +146,6 @@ def create_infographics_data(news_flash_id, number_of_years_ago, lang: str) -> s


def create_infographics_data_for_location(vals: dict) -> str:
logger.debug(f"create_infographics_data_for_location({vals})")
try:
request_params = get_request_params_from_request_values(vals)
output = create_infographics_items(request_params)
Expand Down Expand Up @@ -181,8 +178,6 @@ def get_dates_comment():
return {}
if number_of_years_ago < 0 or number_of_years_ago > 100:
return {}
logging.debug("location_info:{}".format(request_params.location_info))
logging.debug("location_text:{}".format(request_params.location_text))
output["meta"] = {
"location_info": request_params.location_info.copy(),
"location_text": request_params.location_text,
Expand Down
17 changes: 16 additions & 1 deletion anyway/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ def set_critical(
suburban_road_killed_value=3,
urban_severe_value=2,
):
from anyway.widgets.road_segment_widgets.injured_count_by_severity_widget import (
from anyway.widgets.all_locations_widgets.injured_count_by_severity_widget import (
InjuredCountBySeverityWidget,
)
from anyway.request_params import get_latest_accident_date
Expand Down Expand Up @@ -1258,6 +1258,21 @@ def serialize(self):
}


class RoadJunctionKM(Base):
__tablename__ = "road_junction_km"
MAX_NAME_LEN = 100
road = Column(Integer(), primary_key=True, nullable=False)
non_urban_intersection = Column(Integer(), primary_key=True, nullable=False)
km = Column(Float(), nullable=False)

def serialize(self):
return {
"road": self.road,
"non_urban_intersection": self.non_urban_intersection,
"km": self.km,
}


class RegisteredVehicle(Base):
__tablename__ = "cities_vehicles_registered"
id = Column(Integer(), primary_key=True)
Expand Down
1 change: 1 addition & 0 deletions anyway/parsers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"road1",
"road2",
"road_segment_name",
"road_segment_id",
],
}

Expand Down
Loading

0 comments on commit f2f9005

Please sign in to comment.