From 2fb9a1ed56b9e180054051bd178624a3bbe6a6ba Mon Sep 17 00:00:00 2001 From: Atalya Alon <20992625+atalyaalon@users.noreply.github.com> Date: Sun, 20 Oct 2024 13:42:00 +0300 Subject: [PATCH 1/3] Update DOCKER.md Update common errors --- docs/DOCKER.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/DOCKER.md b/docs/DOCKER.md index f5a12efb..a6088f57 100644 --- a/docs/DOCKER.md +++ b/docs/DOCKER.md @@ -251,6 +251,17 @@ services: This loads the ./anyway dir (relative to the docker-compose file) as /anyway/anyway in the docker overriding the inner volume and allowing you to run your own code inside the docker. + +Common Errors +----------------------- +Q: When working in Windows environment you might encounter in this error during the build proccess. +``` +anyway_1 | standard_init_linux.go:211: exec user process caused "no such file or directory" +``` +A: The solution is very simple. You need to go to the docker-entrypoint.sh file and save it as CRLF (encoding of new line in Windows) instead of LF (encoding of new line in Linux). +In VS code just open the file and choose CLRF at the button right of the screen, for other IDEs check online for instructions. + + Questions and ideas ----------------- Talk to Atalya on ANYWAY's Slack (atalya) or email us [anyway@anyway.co.il](mailto:anyway@anyway.co.il). From eb450ba4cd27150dda3b8c0f0634ca4520da08eb Mon Sep 17 00:00:00 2001 From: Gil Michalovich <105370127+GilMich@users.noreply.github.com> Date: Sun, 20 Oct 2024 15:25:02 +0300 Subject: [PATCH 2/3] Update DOCKER.md (#2559) * Update DOCKER.md added a little refinement to the installation guide as requested * Update DOCKER.md * Update DOCKER.md --------- Co-authored-by: Atalya Alon <20992625+atalyaalon@users.noreply.github.com> --- docs/DOCKER.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/DOCKER.md b/docs/DOCKER.md index a6088f57..c79b816d 100644 --- a/docs/DOCKER.md +++ b/docs/DOCKER.md @@ -25,7 +25,7 @@ Instructions **1.** [Get the code](https://github.com/data-for-change/anyway#getting-the-code) -**2.** [Install Docker](https://docs.docker.com/install/) and [Install Docker Compose](https://docs.docker.com/compose/install/) +**2.** [Install Docker](https://docs.docker.com/install/) and [Install Docker Compose](https://docs.docker.com/compose/install/). (Install Docker for Windows, also when using WSL2) **3.** Get the `.env` file with the required secret values and place in the project **root directory** - can be downloaded [from here](https://drive.google.com/file/d/1bgMyKlHoAAIixlk8qqmZaXPdmqCxldLu/view?usp=sharing). Note that this file **needs to be saved as `.env`** - with the `.` at the beginning of the name of the file. **Continue with your OS, See below** From 018599d4774a8c6b48acccf8ece168e2629fd6b3 Mon Sep 17 00:00:00 2001 From: ziv Date: Sun, 20 Oct 2024 13:04:45 +0300 Subject: [PATCH 3/3] Add street numeric indexes to involved_markers_hebrew and two additional small imrovements --- ...add_street_numeric_indexes_to_involved_.py | 28 ++++++++++ .../infographics_data_cache_updater.py | 51 +++++++++---------- anyway/widgets/widget.py | 6 +-- 3 files changed, 56 insertions(+), 29 deletions(-) create mode 100644 alembic/versions/e962054e4422_add_street_numeric_indexes_to_involved_.py diff --git a/alembic/versions/e962054e4422_add_street_numeric_indexes_to_involved_.py b/alembic/versions/e962054e4422_add_street_numeric_indexes_to_involved_.py new file mode 100644 index 00000000..13611f96 --- /dev/null +++ b/alembic/versions/e962054e4422_add_street_numeric_indexes_to_involved_.py @@ -0,0 +1,28 @@ +"""add street numeric indexes to involved heberw + +Revision ID: e962054e4422 +Revises: mn9px8cacn24 +Create Date: 2024-10-20 08:24:08.746964 + +""" + +# revision identifiers, used by Alembic. +revision = 'e962054e4422' +down_revision = 'mn9px8cacn24' +branch_labels = None +depends_on = None + +from alembic import op +# import sqlalchemy as sa + + +def upgrade(): + op.create_index('ix_involved_markers_hebrew_street1', + 'involved_markers_hebrew', ['street1'], unique=False) + op.create_index('ix_involved_markers_hebrew_street2', + 'involved_markers_hebrew', ['street2'], unique=False) + + +def downgrade(): + op.drop_index('ix_involved_markers_hebrew_street1', 'involved_markers_hebrew') + op.drop_index('ix_involved_markers_hebrew_street2', 'involved_markers_hebrew') diff --git a/anyway/parsers/infographics_data_cache_updater.py b/anyway/parsers/infographics_data_cache_updater.py index de067ff4..03f05208 100755 --- a/anyway/parsers/infographics_data_cache_updater.py +++ b/anyway/parsers/infographics_data_cache_updater.py @@ -179,46 +179,45 @@ def get_streets() -> Iterable[Streets]: def get_street_infographic_keys() -> Iterable[Dict[str, int]]: for street in get_streets(): - for y in CONST.INFOGRAPHICS_CACHE_YEARS_AGO: - yield { - "yishuv_symbol": street.yishuv_symbol, - "street1": street.street, - "years_ago": y, - "lang": "en", - } + if street_has_accidents(street.yishuv_symbol, street.street): + for y in CONST.INFOGRAPHICS_CACHE_YEARS_AGO: + yield { + "yishuv_symbol": street.yishuv_symbol, + "street1": street.street, + "years_ago": y, + "lang": "en", + } def build_street_cache_into_temp(): start = datetime.now() db.session.query(InfographicsStreetDataCacheTemp).delete() db.session.commit() - for n, chunk in enumerate(chunked_generator(get_street_infographic_keys(), 4960)): - cache_chunk = [ - { - "yishuv_symbol": d["yishuv_symbol"], - "street": d["street1"], - "years_ago": d["years_ago"], - "data": anyway.infographics_utils.create_infographics_data_for_location(d), - } - for d in chunk - if street_has_accidents(d["yishuv_symbol"], d["street1"]) - ] - if cache_chunk: - logging.debug(f"Adding chunk num {n}, {len(chunk)} entries.") - # pylint: disable=no-member - db.get_engine().execute(InfographicsStreetDataCacheTemp.__table__.insert(), cache_chunk) + for chunk in chunked_generator(get_street_infographic_keys(), 4960): + db.get_engine().execute( + InfographicsStreetDataCacheTemp.__table__.insert(), + [ + { + "yishuv_symbol": d["yishuv_symbol"], + "street": d["street1"], + "years_ago": d["years_ago"], + "data": anyway.infographics_utils.create_infographics_data_for_location(d), + } + for d in chunk + ], + ) db.session.commit() logging.info(f"cache rebuild took:{str(datetime.now() - start)}") def street_has_accidents(yishuv_symbol: int, street: int) -> bool: - return ( + res = db.session.query( db.session.query(AccidentMarker) .filter(AccidentMarker.yishuv_symbol == yishuv_symbol) .filter(or_(AccidentMarker.street1 == street, AccidentMarker.street2 == street)) - .count() - > 0 - ) + .exists() + ).scalar() + return res def get_road_segments() -> Iterable[RoadSegments]: diff --git a/anyway/widgets/widget.py b/anyway/widgets/widget.py index b06d6072..c27faf25 100644 --- a/anyway/widgets/widget.py +++ b/anyway/widgets/widget.py @@ -30,7 +30,7 @@ class Widget: def __init__(self, request_params: RequestParams): self.request_params = copy.deepcopy(request_params) self.rank = -1 - self.items = {} + self.items = None self.text = {} self.meta = {"widget_digest": self.widget_digest} self.information = "" @@ -53,7 +53,7 @@ def is_included(self) -> bool: def generate_items(self) -> None: """Generates the data of the widget and set it to self.items""" - pass + self.items = {} @staticmethod def is_relevant(request_params: RequestParams) -> bool: @@ -104,7 +104,7 @@ def generate_widget_data(cls, request_params: RequestParams): return {} def serialize(self): - if not self.items: + if self.items is None: self.generate_items() output = {"name": self.name, "data": {}} output["data"]["items"] = self.items if self.is_included() else {}