Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warnings for duplicate report rows #61

Merged
merged 8 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/rred_reports/reports/interface.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
from typing import Optional
from typing import Annotated, Optional

import typer
from loguru import logger
Expand Down Expand Up @@ -133,7 +133,7 @@ def create(level: ReportType, year: int, config_file: Path = "src/rred_reports/r
@app.command()
def send_school(
year: int,
manual_id: Optional[list[str]] = typer.Option(None), # noqa: B008
manual_id: Annotated[Optional[list[str]], typer.Option([])] = (),
attachment_name: str = "RRED_report.pdf",
config_file: Path = "src/rred_reports/reports/report_config.toml",
top_level_dir: Optional[Path] = None,
Expand All @@ -157,16 +157,15 @@ def send_school(
top_level_dir = TOP_LEVEL_DIR

dispatch_list = top_level_dir / dispatch_path

school_ids = list(manual_id)
if not manual_id:
manual_id = []
report_directory = top_level_dir / "output" / "reports" / str(year) / "schools"
for report_path in sorted(report_directory.glob("report_*.pdf")):
manual_id.append(report_path.stem.split("_")[-1])
school_ids.append(report_path.stem.split("_")[-1])

email_details = []
logger.info("Getting dispatch list details for each school report pdf found")
for school_id in tqdm(manual_id):
for school_id in tqdm(school_ids):
email_info = get_mailing_info(school_id, dispatch_list, override_mailto)
email_details.append({"school_id": school_id, "mail_info": email_info})

Expand All @@ -177,7 +176,7 @@ def send_school(
school_mailer(email_detail["school_id"], year, email_detail["mail_info"], report_name=attachment_name)
emailed_ids.add(email_detail["school_id"])
except Exception as error:
all_schools = set(manual_id)
all_schools = set(school_ids)
schools_to_send = sorted(all_schools.difference(emailed_ids))
school_command = f"--manual-id {' --manual-id '.join(schools_to_send)}"
logger.error(
Expand All @@ -198,8 +197,13 @@ def main():


if __name__ == "__main__":
create(ReportType.SCHOOL, 2022, TOP_LEVEL_DIR / "src/rred_reports/reports/report_config.toml")
# create(ReportType.SCHOOL, 2022, TOP_LEVEL_DIR / "src/rred_reports/reports/report_config.toml")
## test sending reports to specific UCL user
# send_school(2021, config_file=TOP_LEVEL_DIR / "src/rred_reports/reports/report_config.toml", top_level_dir=TOP_LEVEL_DIR, override_mailto="[email protected]")
send_school(
2022,
config_file=TOP_LEVEL_DIR / "src/rred_reports/reports/report_config.toml",
top_level_dir=TOP_LEVEL_DIR,
override_mailto="[email protected]",
)
## test sending reports to RRED email for UAT
# send_school(2021, config_file=TOP_LEVEL_DIR / "src/rred_reports/reports/report_config.toml", top_level_dir=TOP_LEVEL_DIR, override_mailto="[email protected]")
10 changes: 8 additions & 2 deletions src/rred_reports/reports/schools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path

import pandas as pd
from loguru import logger

from rred_reports.reports.filler import TemplateFiller

Expand Down Expand Up @@ -186,7 +187,7 @@ def get_outcome_from_summary(outcome_df: pd.DataFrame, outcome_type: str) -> int
return 0

filtered = filter_by_entry_and_exit(school_df, report_year)
filtered_summary_table = filtered[columns_used].copy()
filtered_summary_table = filtered[columns_used].drop_duplicates().copy()
# let's try and reduce the pain with exit outcome labels
filtered_summary_table["exit_outcome"] = filtered_summary_table["exit_outcome"].str.lower().str.strip()

Expand Down Expand Up @@ -239,7 +240,12 @@ def populate_school_tables(school_df: pd.DataFrame, template_path: Path, report_
columns, filter_function = column_and_filter
filtered = filter_function(school_df, report_year)
table_to_write = filtered[columns]
template_filler.populate_table(index + 1, table_to_write)
if index == 0 and (table_to_write.shape[0] != table_to_write.drop_duplicates().shape[0]):
logger.warning(
"Table 1 has duplicate values that will be removed, suggests an issue with the masterfile school or teacher data:\n{school_data}",
school_data=table_to_write.to_markdown(),
)
template_filler.populate_table(index + 1, table_to_write.drop_duplicates())

return template_filler

Expand Down