Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/tkalir/anyway into bug-2548-…
Browse files Browse the repository at this point in the history
…fix-translation-in-killed_and_injured_count_per_age_group

# Conflicts:
#	translations/en/LC_MESSAGES/messages.mo
#	translations/en/LC_MESSAGES/messages.po
  • Loading branch information
tkalir committed Jan 13, 2024
2 parents 8e30acc + 30003a4 commit 6e59713
Show file tree
Hide file tree
Showing 38 changed files with 621 additions and 489 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**
4 changes: 2 additions & 2 deletions CBS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Introduction

This document describes the contents of the directory [cbs](https://drive.google.com/file/d/1lRl5ZMfXuGTEjvpdXL8lI8UKcrVDK9ne/view?usp=sharing), which is used in the ANYWAY project in the [Public Knowledge Workshop](http://www.hasadna.org.il). The file was acquired from the Israeli Central Bureau of Statistics (הלשכה המרכזית לסטטיסטיקה, למ”ס), for the purposes of the ANYWAY project.
It contains information about traffic accidents from 2005-2017, including location, time, vehicles and individuals involved, and more.
This document describes the contents of the original CBS files (saved in our S3 using [this ETL]([url](https://github.com/data-for-change/anyway-etl/blob/main/airflow_server/dags/cbs_import_from_s3.py)) or [this ETL]([url](https://github.com/data-for-change/anyway-etl/blob/main/airflow_server/dags/import_email_to_s3_and_update_data.py))), which is used in the ANYWAY project in Data For Change (נתון לשינוי). The file was acquired from the Israeli Central Bureau of Statistics (הלשכה המרכזית לסטטיסטיקה, למ”ס), for the purposes of the ANYWAY project.
It contains information about traffic accidents from 2008, including location, time, vehicles and individuals involved, and more.
See the data on a map on http://oway.org.il/

## Directory structure
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
32 changes: 32 additions & 0 deletions alembic/versions/881e7b1dba8a_track_telegram_messages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""track telegram messages
Revision ID: 881e7b1dba8a
Revises: 664f8a93794e
Create Date: 2023-11-21 12:39:32.931262
"""

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

from alembic import op
import sqlalchemy as sa

def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('telegram_forwarded_messages',
sa.Column('message_id', sa.String(), nullable=True),
sa.Column('newsflash_id', sa.Integer(), nullable=False),
sa.Column('group_sent', sa.String(), nullable=False),
sa.PrimaryKeyConstraint('message_id')
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('telegram_forwarded_messages')
# ### end Alembic commands ###
44 changes: 35 additions & 9 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 @@ -1194,9 +1196,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 +1259,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 @@ -1335,6 +1343,14 @@ def embedded_reports_api():
return response


@app.route("/api/telegram/webhook", methods=["POST"])
def telegram_webhook():
update = request.json # Telegram sends updates in JSON format
logging.info(f"Received Telegram update: {update}")

return jsonify(success=True)


# User system API
app.add_url_rule("/user/add_role", view_func=add_role, methods=["POST"])
app.add_url_rule(
Expand Down Expand Up @@ -1447,6 +1463,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 @@ -1491,17 +1508,26 @@ def put(self, 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
8 changes: 7 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 @@ -2975,3 +2975,9 @@ class TelegramGroups(TelegramGroupsBase):

class TelegramGroupsTest(TelegramGroupsBase):
__tablename__ = "telegram_groups_test"

class TelegramForwardedMessages():
__tablename__ = 'telegram_forwarded_messages'
message_id = Column(String(), primary_key=True)
newsflash_id = Column(BigInteger(), nullable=False)
group_sent = Column(String(), nullable=False),
12 changes: 8 additions & 4 deletions anyway/request_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class RequestParams:
start_time: datetime.date
end_time: datetime.date
lang: str
news_flash_description: Optional[str]
news_flash_description: Optional[str] = None
news_flash_title: Optional[str] = None

def __str__(self):
return (
Expand All @@ -54,6 +55,11 @@ def get_request_params_from_request_values(vals: dict) -> Optional[RequestParams
if news_flash_obj is not None and news_flash_obj.description is not None
else None
)
news_flash_title = (
news_flash_obj.title
if news_flash_obj is not None and news_flash_obj.title is not None
else None
)
location = get_location_from_news_flash_or_request_values(news_flash_obj, vals)
if location is None:
return None
Expand All @@ -65,8 +71,6 @@ def get_request_params_from_request_values(vals: dict) -> Optional[RequestParams

if location_info is None:
return None
logging.debug("location_info:{}".format(location_info))
logging.debug("location_text:{}".format(location_text))
resolution = location_info.pop("resolution")
if resolution is None or resolution not in BE_CONST.SUPPORTED_RESOLUTIONS:
logging.error(f"Resolution empty or not supported: {resolution}.")
Expand Down Expand Up @@ -98,8 +102,8 @@ def get_request_params_from_request_values(vals: dict) -> Optional[RequestParams
end_time=end_time,
lang=lang,
news_flash_description=news_flash_description,
news_flash_title=news_flash_title,
)
logging.debug(f"Ending get_request_params. params: {request_params}")
return request_params


Expand Down
5 changes: 4 additions & 1 deletion anyway/widgets/all_locations_widgets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from . import (
accident_count_by_severity_widget,
injured_count_by_severity_widget,
most_severe_accidents_widget,
most_severe_accidents_table_widget,
seriously_injured_killed_in_bicycles_scooter_widget
seriously_injured_killed_in_bicycles_scooter_widget,
killed_and_injured_count_per_age_group_stacked_widget,
killed_and_injured_count_per_age_group_widget
)
Loading

0 comments on commit 6e59713

Please sign in to comment.