|
10 | 10 | },
|
11 | 11 | {
|
12 | 12 | "cell_type": "code",
|
13 |
| - "execution_count": 1, |
| 13 | + "execution_count": 10, |
14 | 14 | "id": "d3aa7606-0f50-4f05-b104-ad4521c80406",
|
15 | 15 | "metadata": {
|
16 | 16 | "editable": true,
|
|
24 | 24 | "outputs": [
|
25 | 25 | {
|
26 | 26 | "data": {
|
27 |
| - "text/markdown": [ |
28 |
| - "- Regression Analysis in R: Adapting to Varied Data Types: 13th January 2025 1-4pm (Online only) - [MS Form Sign-up](https://forms.office.com/e/QK4qbskQKe)\n", |
29 |
| - "- Introduction to Python: 17th/24th January 2025 10am-1pm (In-person only) - [MS Form Sign-up](https://forms.office.com/e/YAxvuE5dG5)\n", |
30 |
| - "- Computational Thinking: 28th January/4th February 2025 10am-1pm (In-person only) - [MS Form Sign-up](https://forms.office.com/e/HBxtMLxRZr)\n", |
31 |
| - "- Introduction to Unix: 5th/12th February 2025 1-4pm (Penryn Campus only) - [MS Form Sign-up](https://forms.office.com/e/6nrfXabJSH)\n", |
32 |
| - "- Python for Data Analysis: 6th/13th February 2025 1-4pm (Online only) - [MS Form Sign-up](https://forms.office.com/e/rJRBxYnxKA)\n", |
33 |
| - "- Introduction to R: 25th February/4th March/11th March 2025 10am-1pm (In-person only) - [MS Form Sign-up](https://forms.office.com/e/3BUKkXNELt)\n", |
34 |
| - "- Introduction to Version Control: 28th February/7th March 2025 10am-1pm (Online only) - [MS Form Sign-up](https://forms.office.com/e/YCB5kkGrws)\n", |
35 |
| - "- Introduction to Machine Learning: 14th/21st March 2025 10am-1pm (In-person only) - Registration Will Be Available Soon\n", |
36 |
| - "- Intermediate Version Control: 17th/24th March 2025 1-4pm (Online only) - Registration Will Be Available Soon\n", |
37 |
| - "- Introduction to HPC: 21st/28th March 2025 1.15-4.15pm (In-person only) - Registration Will Be Available Soon\n", |
38 |
| - "- Introduction to Regression with R: 28th March 2025 10am-1pm (In-person only) - Registration Will Be Available Soon" |
| 27 | + "text/html": [ |
| 28 | + "\n", |
| 29 | + "<table style=\"width:100%; text-align:center; border:1px solid black; border-collapse:collapse;\">\n", |
| 30 | + " <tr style=\"background:#f2f2f2;\">\n", |
| 31 | + " <th>Course Name</th>\n", |
| 32 | + " <th>Course Dates</th>\n", |
| 33 | + " <th>Location</th>\n", |
| 34 | + " <th>Registration Link</th>\n", |
| 35 | + " </tr>\n", |
| 36 | + "<tr><td style='padding:8px'><a href=\"../programme_information/intro_to_julia.ipynb\" target=\"_blank\">Introduction to Julia</a></td><td style='padding:8px'>2nd/9th/16th June 2025 1-4pm</td><td style='padding:8px'>Online only</td><td style='padding:8px'><a href=\"https://forms.office.com/e/QBS4nXp3Pz\" target=\"_blank\">Sign-Up</a></td></tr>\n", |
| 37 | + "<tr><td style='padding:8px'><a href=\"../programme_information/intro_to_hpc.ipynb\" target=\"_blank\">Introduction to HPC</a></td><td style='padding:8px'>4th/11th June 2025 1-4pm</td><td style='padding:8px'>In-person only</td><td style='padding:8px'><a href=\"https://forms.office.com/e/fKPjWbddYf\" target=\"_blank\">Sign-Up</a></td></tr>\n", |
| 38 | + "<tr><td style='padding:8px'><a href=\"../programme_information/Introduction_to_Markdown_in_R.ipynb\" target=\"_blank\">Introduction to Markdown in R</a></td><td style='padding:8px'>6th June 2025 10am-1pm</td><td style='padding:8px'>In-person only</td><td style='padding:8px'><a href=\"https://forms.office.com/e/8diVktHHzt\" target=\"_blank\">Sign-Up</a></td></tr>\n", |
| 39 | + "<tr><td style='padding:8px'>Using Markdown for Python</td><td style='padding:8px'>10th June 2025 10am-1pm</td><td style='padding:8px'>In-person only</td><td style='padding:8px'><a href=\"https://forms.office.com/e/5ixSXnxdHb\" target=\"_blank\">Sign-Up</a></td></tr>\n", |
| 40 | + "<tr><td style='padding:8px'><a href=\"../programme_information/parallel_computing.ipynb\" target=\"_blank\">Parallel Computing</a></td><td style='padding:8px'>12th/19th June 2025 10am-1pm</td><td style='padding:8px'>Online only</td><td style='padding:8px'><a href=\"https://forms.office.com/e/pEk26HmbAe\" target=\"_blank\">Sign-Up</a></td></tr>\n", |
| 41 | + "</table>" |
39 | 42 | ],
|
40 | 43 | "text/plain": [
|
41 |
| - "<IPython.core.display.Markdown object>" |
| 44 | + "<IPython.core.display.HTML object>" |
42 | 45 | ]
|
43 | 46 | },
|
44 | 47 | "metadata": {},
|
|
47 | 50 | ],
|
48 | 51 | "source": [
|
49 | 52 | "import pandas as pd\n",
|
50 |
| - "from IPython.display import Markdown, display\n", |
| 53 | + "from IPython.display import display, HTML\n", |
51 | 54 | "from datetime import datetime\n",
|
52 | 55 | "\n",
|
53 | 56 | "# Load the CSV file (adjust the file path as needed)\n",
|
|
57 | 60 | "# Strip any extra spaces in the column names\n",
|
58 | 61 | "courses_df.columns = courses_df.columns.str.strip()\n",
|
59 | 62 | "\n",
|
60 |
| - "# Convert the 'End Date' column to datetime (assuming the date format is day-first)\n", |
61 |
| - "courses_df['End Date'] = pd.to_datetime(courses_df['End Date'], dayfirst=True, errors='coerce')\n", |
| 63 | + "# Parse dates (assuming day-first)\n", |
| 64 | + "courses_df['End Date'] = pd.to_datetime(courses_df['End Date'], dayfirst=True, errors='coerce')\n", |
62 | 65 | "courses_df['Start Date'] = pd.to_datetime(courses_df['Start Date'], dayfirst=True, errors='coerce')\n",
|
63 | 66 | "\n",
|
64 |
| - "# Get today's date\n", |
65 | 67 | "today = datetime.now()\n",
|
66 | 68 | "\n",
|
67 |
| - "# Filter for rows that contain valid MS Form Signup links, Course Date information, and check if the 'End Date' is still valid\n", |
68 |
| - "filtered_courses_df = courses_df.dropna(subset=['Course Date'])\n", |
69 |
| - "filtered_courses_df = filtered_courses_df[filtered_courses_df['End Date'] > today]\n", |
70 |
| - "filtered_courses_df = filtered_courses_df[filtered_courses_df['Start Date'] <= today]\n", |
71 |
| - "filtered_courses_df = filtered_courses_df.sort_values(by=\"End Date\")\n", |
| 69 | + "# Filter to “in-progress or upcoming” courses with valid Course Date\n", |
| 70 | + "mask_dates = courses_df['Course Date'].notna()\n", |
| 71 | + "mask_started = courses_df['Start Date'] <= today\n", |
| 72 | + "mask_not_ended = courses_df['End Date'] > today\n", |
| 73 | + "\n", |
| 74 | + "upcoming = (\n", |
| 75 | + " courses_df[mask_dates & mask_started & mask_not_ended]\n", |
| 76 | + " .sort_values('End Date')\n", |
| 77 | + " .reset_index(drop=True)\n", |
| 78 | + ")\n", |
| 79 | + "\n", |
| 80 | + "# Build the HTML table header\n", |
| 81 | + "html_header = \"\"\"\n", |
| 82 | + "<table style=\"width:100%; text-align:center; border:1px solid black; border-collapse:collapse;\">\n", |
| 83 | + " <tr style=\"background:#f2f2f2;\">\n", |
| 84 | + " <th>Course Name</th>\n", |
| 85 | + " <th>Course Dates</th>\n", |
| 86 | + " <th>Location</th>\n", |
| 87 | + " <th>Registration Link</th>\n", |
| 88 | + " </tr>\n", |
| 89 | + "\"\"\"\n", |
| 90 | + "\n", |
| 91 | + "def generate_row(row):\n", |
| 92 | + " # Wrap Course Name in a link to the Homepage Filepath\n", |
| 93 | + " name = row['Course Name']\n", |
| 94 | + " page_url = row.get('Homepage Filepath', '')\n", |
| 95 | + " if pd.notna(page_url) and str(page_url).strip():\n", |
| 96 | + " name_html = f'<a href=\"{page_url}\" target=\"_blank\">{name}</a>'\n", |
| 97 | + " else:\n", |
| 98 | + " name_html = name\n", |
72 | 99 | "\n",
|
73 |
| - "# Function to generate markdown text based on course details\n", |
74 |
| - "def generate_markdown(row):\n", |
75 |
| - " if pd.isna(row['MS Form Signup']) or not row['MS Form Signup'].strip():\n", |
76 |
| - " return f\"- {row['Course Name']}: {row['Course Date']} - Registration Will Be Available Soon\"\n", |
| 100 | + " # Dates and location\n", |
| 101 | + " dates = row['Course Date']\n", |
| 102 | + " location = row.get('Location', '')\n", |
| 103 | + "\n", |
| 104 | + " # Registration link\n", |
| 105 | + " signup = row.get('MS Form Signup', '')\n", |
| 106 | + " if pd.isna(signup) or not str(signup).strip():\n", |
| 107 | + " link_html = \"Registration Will Be Available Soon\"\n", |
77 | 108 | " else:\n",
|
78 |
| - " return f\"- {row['Course Name']}: {row['Course Date']} - [MS Form Sign-up]({row['MS Form Signup']})\"\n", |
| 109 | + " link_html = f'<a href=\"{signup}\" target=\"_blank\">Sign-Up</a>'\n", |
| 110 | + "\n", |
| 111 | + " return (\n", |
| 112 | + " \"<tr>\"\n", |
| 113 | + " f\"<td style='padding:8px'>{name_html}</td>\"\n", |
| 114 | + " f\"<td style='padding:8px'>{dates}</td>\"\n", |
| 115 | + " f\"<td style='padding:8px'>{location}</td>\"\n", |
| 116 | + " f\"<td style='padding:8px'>{link_html}</td>\"\n", |
| 117 | + " \"</tr>\"\n", |
| 118 | + " )\n", |
79 | 119 | "\n",
|
80 | 120 | "\n",
|
81 |
| - "# Apply the function and create the markdown output\n", |
82 |
| - "markdown_output = filtered_courses_df.apply(generate_markdown, axis=1).tolist()\n", |
| 121 | + "# Generate all rows\n", |
| 122 | + "rows_html = \"\\n\".join(upcoming.apply(generate_row, axis=1).tolist())\n", |
83 | 123 | "\n",
|
84 |
| - "# Join the markdown lines into a single block\n", |
85 |
| - "markdown_text = \"\\n\".join(markdown_output)\n", |
| 124 | + "# Close the table\n", |
| 125 | + "html_table = html_header + rows_html + \"\\n</table>\"\n", |
86 | 126 | "\n",
|
87 |
| - "# Display the markdown text in rendered form\n", |
88 |
| - "display(Markdown(markdown_text))" |
| 127 | + "# Display it\n", |
| 128 | + "display(HTML(html_table))\n" |
89 | 129 | ]
|
90 | 130 | },
|
91 | 131 | {
|
|
0 commit comments