|
270 | 270 | " c.corp_type_cd AS \"{COLUMN_NAMES['corp_type']}\",\n", |
271 | 271 | " CASE\n", |
272 | 272 | " WHEN cp.processed_status = 'COMPLETED' THEN 'Migrated'\n", |
| 273 | + " WHEN cp.processed_status = 'FAILED' THEN 'Failed'\n", |
273 | 274 | " WHEN cp.processed_status IS NULL THEN 'Pending'\n", |
| 275 | + " ELSE 'Pending'\n", |
274 | 276 | " END AS \"{COLUMN_NAMES['status']}\",\n", |
275 | 277 | " cp.create_date::date AS \"{COLUMN_NAMES['date']}\"\n", |
276 | 278 | "FROM\n", |
|
291 | 293 | " g.id IN ({mig_group_ids})\n", |
292 | 294 | " AND (\n", |
293 | 295 | " (cp.processed_status = 'COMPLETED' AND cp.environment = 'prod')\n", |
| 296 | + " OR (cp.processed_status = 'FAILED' AND cp.environment = 'prod')\n", |
294 | 297 | " OR cp.processed_status IS NULL\n", |
295 | 298 | " )\n", |
296 | 299 | "ORDER BY\n", |
297 | 300 | " g.display_name, \n", |
298 | 301 | " b.display_name,\n", |
299 | 302 | " CASE\n", |
300 | 303 | " WHEN cp.processed_status = 'COMPLETED' THEN 0\n", |
301 | | - " ELSE 1\n", |
| 304 | + " WHEN cp.processed_status = 'FAILED' THEN 1\n", |
| 305 | + " ELSE 2\n", |
302 | 306 | " END, \n", |
303 | 307 | " cp.create_date DESC,\n", |
304 | 308 | " cn.corp_name;\n", |
|
319 | 323 | "\n", |
320 | 324 | "# Display results\n", |
321 | 325 | "with pd.option_context('display.max_rows', None):\n", |
322 | | - " display(colin_extract_df)\n" |
| 326 | + " display(colin_extract_df)" |
323 | 327 | ] |
324 | 328 | }, |
325 | 329 | { |
|
431 | 435 | "\n", |
432 | 436 | "# Display results\n", |
433 | 437 | "with pd.option_context('display.max_rows', None):\n", |
434 | | - " display(lear_combined_df)\n" |
| 438 | + " display(lear_combined_df)" |
435 | 439 | ] |
436 | 440 | }, |
437 | 441 | { |
|
548 | 552 | "\n", |
549 | 553 | "# Display results\n", |
550 | 554 | "with pd.option_context('display.max_rows', None):\n", |
551 | | - " display(colin_oracle_combined_df)\n" |
| 555 | + " display(colin_oracle_combined_df)" |
552 | 556 | ] |
553 | 557 | }, |
554 | 558 | { |
|
660 | 664 | " raise\n", |
661 | 665 | "\n", |
662 | 666 | "with pd.option_context('display.max_rows', None):\n", |
663 | | - " display(batch_summary_df)\n" |
| 667 | + " display(batch_summary_df)" |
664 | 668 | ] |
665 | 669 | }, |
666 | 670 | { |
|
672 | 676 | "Generate formatted Excel file with the merged migration tracking data." |
673 | 677 | ] |
674 | 678 | }, |
| 679 | + { |
| 680 | + "cell_type": "code", |
| 681 | + "execution_count": null, |
| 682 | + "metadata": {}, |
| 683 | + "outputs": [], |
| 684 | + "source": [ |
| 685 | + "# Define highlighting rules\n", |
| 686 | + "HIGHLIGHTING_RULES = [\n", |
| 687 | + " {\n", |
| 688 | + " 'column_name': COLUMN_NAMES['affiliated'],\n", |
| 689 | + " 'condition_value': 'N',\n", |
| 690 | + " 'fill_color': CONFIG['excel_export']['filled_color']\n", |
| 691 | + " },\n", |
| 692 | + " {\n", |
| 693 | + " 'column_name': COLUMN_NAMES['banner_updated_in_colin'], \n", |
| 694 | + " 'condition_value': 'N',\n", |
| 695 | + " 'fill_color': CONFIG['excel_export']['filled_color']\n", |
| 696 | + " },\n", |
| 697 | + " {\n", |
| 698 | + " 'column_name': COLUMN_NAMES['status'],\n", |
| 699 | + " 'condition_value': 'Failed', \n", |
| 700 | + " 'fill_color': CONFIG['excel_export']['filled_color']\n", |
| 701 | + " },\n", |
| 702 | + " {\n", |
| 703 | + " 'column_name': COLUMN_NAMES['frozen_in_colin'],\n", |
| 704 | + " 'condition_value': 'N',\n", |
| 705 | + " 'fill_color': CONFIG['excel_export']['filled_color']\n", |
| 706 | + " }\n", |
| 707 | + "]" |
| 708 | + ] |
| 709 | + }, |
675 | 710 | { |
676 | 711 | "cell_type": "code", |
677 | 712 | "execution_count": null, |
|
680 | 715 | "source": [ |
681 | 716 | "from openpyxl.styles import Font, PatternFill, Alignment\n", |
682 | 717 | "\n", |
| 718 | + "def apply_cell_highlighting(worksheet, highlighting_rules):\n", |
| 719 | + " \"\"\"\n", |
| 720 | + " Apply conditional highlighting to worksheet cells based on rules.\n", |
| 721 | + " \n", |
| 722 | + " Args:\n", |
| 723 | + " worksheet: The openpyxl worksheet\n", |
| 724 | + " highlighting_rules: List of dicts with column_name, condition_value, fill_color\n", |
| 725 | + " \n", |
| 726 | + " Returns:\n", |
| 727 | + " int: Total number of cells highlighted\n", |
| 728 | + " \"\"\"\n", |
| 729 | + " highlighted_count = 0\n", |
| 730 | + " \n", |
| 731 | + " # Find column indices for all highlighting rules\n", |
| 732 | + " column_indices = {}\n", |
| 733 | + " for col_idx, cell in enumerate(worksheet[1], 1):\n", |
| 734 | + " for rule in highlighting_rules:\n", |
| 735 | + " if cell.value == rule['column_name']:\n", |
| 736 | + " column_indices[rule['column_name']] = col_idx\n", |
| 737 | + " break\n", |
| 738 | + " \n", |
| 739 | + " # Apply highlighting based on rules\n", |
| 740 | + " for row_num, row in enumerate(worksheet.iter_rows(), 1):\n", |
| 741 | + " if row_num == 1: # Skip header row\n", |
| 742 | + " continue\n", |
| 743 | + " \n", |
| 744 | + " for col_idx, cell in enumerate(row, 1):\n", |
| 745 | + " # Check each highlighting rule\n", |
| 746 | + " for rule in highlighting_rules:\n", |
| 747 | + " if col_idx == column_indices.get(rule['column_name']) and cell.value == rule['condition_value']:\n", |
| 748 | + " fill = PatternFill(start_color=rule['fill_color'], end_color=rule['fill_color'], fill_type='solid')\n", |
| 749 | + " cell.fill = fill\n", |
| 750 | + " highlighted_count += 1\n", |
| 751 | + " \n", |
| 752 | + " return highlighted_count\n", |
| 753 | + "\n", |
| 754 | + "\n", |
683 | 755 | "def format_worksheet(worksheet) -> None:\n", |
684 | 756 | " \"\"\"Format the given worksheet.\"\"\"\n", |
| 757 | + " \n", |
685 | 758 | " # Define display styles\n", |
686 | 759 | " header_font = Font(size=CONFIG['excel_export']['font_size'], bold=True)\n", |
687 | 760 | " normal_font = Font(size=CONFIG['excel_export']['font_size'])\n", |
688 | | - " red_fill = PatternFill(start_color=CONFIG['excel_export']['filled_color'], end_color=CONFIG['excel_export']['filled_color'], fill_type='solid')\n", |
689 | 761 | "\n", |
690 | | - " # Find the Affiliated column index\n", |
691 | | - " affiliated_col_idx = None\n", |
692 | | - " for col_idx, cell in enumerate(worksheet[1], 1):\n", |
693 | | - " if cell.value == COLUMN_NAMES['affiliated']:\n", |
694 | | - " affiliated_col_idx = col_idx\n", |
695 | | - " break\n", |
| 762 | + " # Apply cell highlighting\n", |
| 763 | + " highlighted_count = apply_cell_highlighting(worksheet, HIGHLIGHTING_RULES)\n", |
696 | 764 | "\n", |
697 | | - " # Format and highlight rows\n", |
698 | | - " highlighted_count = 0\n", |
| 765 | + " # Format rows (excluding highlighting which is now handled separately)\n", |
699 | 766 | " for row_num, row in enumerate(worksheet.iter_rows(), 1):\n", |
700 | 767 | " for col_idx, cell in enumerate(row, 1):\n", |
701 | 768 | " if row_num == 1:\n", |
|
705 | 772 | " # Data rows\n", |
706 | 773 | " cell.font = normal_font\n", |
707 | 774 | " cell.alignment = Alignment(horizontal='left')\n", |
708 | | - " \n", |
709 | | - " # Highlight Affiliated column if value is 'N'\n", |
710 | | - " if col_idx == affiliated_col_idx and cell.value == 'N':\n", |
711 | | - " cell.fill = red_fill\n", |
712 | | - " highlighted_count += 1\n", |
713 | 775 | " \n", |
714 | 776 | " # Freeze header row\n", |
715 | 777 | " worksheet.freeze_panes = 'A2'\n", |
|
737 | 799 | " adjusted_width = min(max_length + 10, CONFIG['excel_export']['max_column_width'])\n", |
738 | 800 | " worksheet.column_dimensions[column_letter].width = adjusted_width\n", |
739 | 801 | "\n", |
740 | | - " print(f\"Red highlighting applied to {highlighted_count} cells in '{COLUMN_NAMES['affiliated']}' column with 'N'\")" |
| 802 | + " # Print highlighting summary\n", |
| 803 | + " rule_names = [rule['column_name'] for rule in HIGHLIGHTING_RULES]\n", |
| 804 | + " print(f\"In {worksheet.title} tab:\\n Red highlighting applied to {highlighted_count} cells across columns: {', '.join(rule_names)}\")" |
741 | 805 | ] |
742 | 806 | }, |
743 | 807 | { |
|
798 | 862 | ], |
799 | 863 | "metadata": { |
800 | 864 | "kernelspec": { |
801 | | - "display_name": "3.8.17", |
| 865 | + "display_name": "Python 3", |
802 | 866 | "language": "python", |
803 | 867 | "name": "python3" |
804 | 868 | }, |
|
812 | 876 | "name": "python", |
813 | 877 | "nbconvert_exporter": "python", |
814 | 878 | "pygments_lexer": "ipython3", |
815 | | - "version": "3.8.17" |
| 879 | + "version": "3.10.12" |
816 | 880 | } |
817 | 881 | }, |
818 | 882 | "nbformat": 4, |
|
0 commit comments