Skip to content

Commit

Permalink
Feat/ Program grid can change (#253)
Browse files Browse the repository at this point in the history
* wip: program grid evolution

* fix: test

* wip test

* chores: update some programs

* chores: alembic

* chores: default values for columns

* alembic: new columns for program metadata

* fix: use timezone for comparing start date

* chores: update programs evolution

* fix: tesdt

* fix: right column type for date

* fix: default time for empty date
  • Loading branch information
polomarcus authored Oct 4, 2024
1 parent 51b82ee commit 43b6668
Show file tree
Hide file tree
Showing 15 changed files with 2,308 additions and 187 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,10 @@ Using [Alembic](https://alembic.sqlalchemy.org/en/latest/autogenerate.html) Auto
# If changes have already been applied (on your feature vranch) and you have to recreate your alembic file by doing :
# 1. change to your main branch
git switch main
# 2. start test container and run "pytest -vv -k api" to rebuild the state of the DB (or drop table the table you want)
# 2. start test container (docker compose up testconsole -d / docker compose exec testconsole bash) and run "pytest -vv -k api" to rebuild the state of the DB (or drop table the table you want) - just let it run a few seconds.
# 3. rechange to your WIP branch
git switch -
# 4. connect to the test container : docker compose up test -d / docker compose exec test bash
# 4. connect to the test container : docker compose up testconsole -d / docker compose exec testconsole bash
# 5. reapply the latest saved state :
poetry run alembic stamp head
# 6. Save the new columns
Expand Down Expand Up @@ -372,6 +372,8 @@ poetry run python3 quotaclimat/transform_excel_to_json.py
## Program Metadata table
The media perimeter is defined here : "quotaclimat/data_processing/mediatree/channel_program.json"

To evolve the media perimeter, we use `program_grid_start` and `program_grid_end` columns to version all evolutions.

To calculate the right total duration for each channel, after updating "quotaclimat/data_processing/mediatree/channel_program.json" you need to execute this command to update `postgres/program_metadata.json`
```
poetry run python3 transform_program.py
Expand Down
32 changes: 32 additions & 0 deletions alembic/versions/30abfd828007_program_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""program metadata
Revision ID: 30abfd828007
Revises: 43103d5b49c9
Create Date: 2024-10-03 14:18:09.874225
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '30abfd828007'
down_revision: Union[str, None] = '43103d5b49c9'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('program_metadata', sa.Column('program_grid_start', sa.DateTime(), nullable=True))
op.add_column('program_metadata', sa.Column('program_grid_end', sa.DateTime(), nullable=True))
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('program_metadata', 'program_grid_end')
op.drop_column('program_metadata', 'program_grid_start')
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""program: add start/end date for grid evolution
Revision ID: 43103d5b49c9
Revises: af956a85658f
Create Date: 2024-10-02 13:18:56.251135
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '43103d5b49c9'
down_revision: Union[str, None] = 'af956a85658f'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ services:
#START_DATE_UPDATE: "2024-02-01" # to batch update PG from a date
#END_DATE: "2024-02-29" # optional - otherwise end of the month
BATCH_SIZE: 100 # number of records to update in one batch
# START_DATE: 1717227223 # to test batch import
CHANNEL : france-info # to reimport only one channel
# START_DATE: 1727610071 # to test batch import
CHANNEL : fr3-idf # to reimport only one channel
MEDIATREE_USER : /run/secrets/username_api
MEDIATREE_PASSWORD: /run/secrets/pwd_api
MEDIATREE_AUTH_URL: https://keywords.mediatree.fr/api/auth/token/
Expand Down
2 changes: 1 addition & 1 deletion docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ poetry run alembic upgrade head


echo "update program metadata file"
python transform_program.py
poetry run python3 transform_program.py
if [[ $? -eq 0 ]]; then
echo "Command succeeded"
else
Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

1 comment on commit 43b6668

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
postgres
   insert_data.py43784%36–38, 56–58, 63
   insert_existing_data_example.py19384%25–27
postgres/schemas
   models.py1551094%126–133, 145–146, 211–212, 226–227
quotaclimat/data_ingestion
   scrap_sitemap.py1341787%27–28, 33–34, 66–71, 95–97, 138–140, 202, 223–228
quotaclimat/data_ingestion/ingest_db
   ingest_sitemap_in_db.py553733%21–42, 45–58, 62–73
quotaclimat/data_ingestion/scrap_html
   scrap_description_article.py36392%19–20, 32
quotaclimat/data_processing/mediatree
   api_import.py21113337%44–48, 53–74, 78–81, 87, 90–132, 138–153, 158, 171–183, 187–193, 206–218, 221–225, 231, 266–267, 270–301, 304–306
   channel_program.py1655765%25–27, 38–40, 57–58, 61–63, 102–103, 112, 128, 179–220
   config.py15287%7, 16
   detect_keywords.py209896%220, 278–285
   update_pg_keywords.py674927%15–108, 132, 135, 142–157, 180–206, 213
   utils.py792568%29–53, 56, 65, 86–87, 117–120
quotaclimat/utils
   healthcheck_config.py291452%22–24, 27–38
   logger.py241154%22–24, 28–37
   sentry.py11282%22–23
TOTAL127837870% 

Tests Skipped Failures Errors Time
93 0 💤 0 ❌ 0 🔥 1m 47s ⏱️

Please sign in to comment.