Update docs/tech_docs/python/economics_presentation_sample.md

This commit is contained in:
2024-03-29 01:59:22 +00:00
parent 0d1117883f
commit 8ef272b826

View File

@@ -1,22 +1,19 @@
Below is a template for a modified README.md that you can use for your project, with placeholders for embedding your Python code. This README is structured to provide comprehensive information about setting up and running your project, including the virtual environment setup and execution of the script.
# Economics 101 Presentation Generator
This project automates the creation of PowerPoint presentations for Economics 101, covering both macro and microeconomics topics. Utilizing the `python-pptx` library, this script generates a presentation with predefined slides tailored to advanced economic studies.
This project automates the creation of PowerPoint presentations for Economics 101, focusing on both macro and microeconomics topics. Utilizing the `python-pptx` library, this script generates presentations with predefined slides tailored for advanced economic studies.
## Getting Started
These instructions will guide you through setting up your project environment and running the presentation generation script.
Follow these instructions to set up your project environment and run the presentation generation script.
### Prerequisites
- Python 3.6 or higher
- pip and venv (usually come with Python installation)
- pip and venv
### Setting Up a Virtual Environment
A virtual environment is crucial for managing project-specific dependencies. Follow these steps to set up your environment:
Creating a virtual environment is essential for managing project-specific dependencies.
1. **Navigate to Your Project Directory:**
@@ -38,27 +35,27 @@ A virtual environment is crucial for managing project-specific dependencies. Fol
### Installing Dependencies
With the virtual environment activated, install the required packages specified in `requirements.txt`.
After activating the virtual environment, install the required packages specified in `requirements.txt`.
```bash
pip install -r requirements.txt
```
The `requirements.txt` file should contain:
Example `requirements.txt` content:
```
python-pptx==x.x.x
# Add any additional dependencies here
```
### Running the Script
Ensure your script is executable by updating its permissions (only required once):
Make the script executable:
```bash
chmod u+x Economics_101_Presentation.py
```
Run the script with:
Run the script:
```bash
./Economics_101_Presentation.py
@@ -72,7 +69,7 @@ python3 Economics_101_Presentation.py
### Presentation Structure
The script generates a PowerPoint presentation with the following slides:
The script generates a PowerPoint presentation including slides on:
- Introduction to Economics
- Macroeconomics Overview
- Microeconomics Overview
@@ -86,29 +83,143 @@ The script generates a PowerPoint presentation with the following slides:
### Customizing the Presentation
The script allows for customization of slide content and layout. To modify the presentation structure, adjust the following code block in your script:
To customize slide content and layout, modify the `PresentationCreator` class in your script:
```python
# Placeholder for the presentation structure code
from pptx import Presentation
from pptx.util import Inches, Pt
from pptx.enum.shapes import MSO_SHAPE
from pptx.enum.chart import XL_CHART_TYPE
from pptx.chart.data import CategoryChartData
from pptx.dml.color import RGBColor
class PresentationCreator:
"""
A class to create PowerPoint presentations with predefined slide templates.
Attributes:
prs (Presentation): A python-pptx Presentation object.
title (str): The title of the presentation.
"""
def __init__(self, title="Presentation"):
"""
Initializes the PresentationCreator with a title for the presentation.
Args:
title (str): The title of the presentation.
"""
self.prs = Presentation()
self.title = title
def add_section_header_slide(self, title):
"""
Adds a section header slide with a given title.
Args:
title (str): The title of the section.
"""
layout = self.prs.slide_layouts[1] # Use Title and Content layout
slide = self.prs.slides.add_slide(layout)
slide.shapes.title.text = title
# Set a subtitle or a short description in the content placeholder if needed
def add_two_content_slide(self, title, left_content, right_content):
"""
Adds a slide with a title and two content sections side by side.
Args:
title (str): The title of the slide.
left_content (str): The content for the left section.
right_content (str): The content for the right section.
"""
layout = self.prs.slide_layouts[1] # Reuse Title and Content layout
slide = self.prs.slides.add_slide(layout)
slide.shapes.title.text = title
slide.placeholders[1].text = left_content # Placeholder for left content
# Note: For a true side-by-side layout, consider adding a textbox or customizing the layout
def add_comparison_slide(self, title, content):
"""
Adds a slide designed for comparisons.
Note: This example simplifies to a single content area for demonstration.
Args:
title (str): The title of the slide.
content (str): The content for comparison.
"""
layout = self.prs.slide_layouts[1] # Simplified use of Title and Content layout
slide = self.prs.slides.add_slide(layout)
slide.shapes.title.text = title
slide.placeholders[1].text = content # Placeholder for comparison content
def add_chart_slide(self, title, data):
"""
Adds a slide with a chart based on provided data.
Args:
title (str): The title of the slide.
data (dict): The data for the chart, including categories and series.
"""
slide_layout = self.prs.slide_layouts[5] # Use Title Only layout for more chart space
slide = self.prs.slides.add_slide(slide_layout)
slide.shapes.title.text = title
chart_data = CategoryChartData()
chart_data.categories = data["categories"]
for name, values in data["series"].items():
chart_data.add_series(name, values)
x, y, cx, cy = Inches(2), Inches(1.5), Inches(6), Inches(4.5)
chart = slide.shapes.add_chart(
XL_CHART_TYPE.COLUMN_CLUSTERED, x, y, cx, cy, chart_data
).chart
# Chart style and colors can be customized further
def save_presentation(self, filename="presentation.pptx"):
"""
Saves the presentation to a file.
Args:
filename (str): The filename or path to save the presentation.
"""
self.prs.save(filename)
# Example usage
if __name__ == "__main__":
creator = PresentationCreator("Economics 101 Presentation")
# Adding slides
creator.add_section_header_slide("Introduction to Economic Theories")
creator.add_two_content_slide("Supply and Demand", "Supply Side Analysis", "Demand Side Analysis")
creator.add_comparison_slide("Economic Models", "Comparative Analysis")
# Chart data example for economic indicators
chart_data_example = {
"categories": ['2015', '2016', '2017', '2018', '2019'],
"series": {
"GDP Growth": (2.5, 2.9, 2.3, 3.1, 2.2),
"Inflation Rate": (1.5, 1.8, 2.1, 1.9, 1.6),
}
}
creator.add_chart_slide("Economic Indicators Over Time", chart_data_example)
# Saving the presentation
creator.save_presentation("./Economics_101_Presentation.pptx")
```
## Project Structure
This project follows a standard directory structure for clarity and organization:
- `src/`: Source code files
- `docs/`: Documentation files
- `src/`: Source code
- `docs/`: Documentation
- `tests/`: Test scripts and data
- `data/`: Data files
- `env/`: Virtual environment (not version-controlled)
- `env/`: Virtual environment (excluded from version control)
## Deactivating the Virtual Environment
To exit the virtual environment when you're done working:
```bash
deactivate
```
## Notes
Replace `path/to/your/project` with the actual path where your project is located, and adjust the `requirements.txt` content according to the actual dependencies and their versions used in your project. This README provides a comprehensive guide for users and contributors to set up, run, and understand the purpose and structure of your project.
Ensure to replace `path/to/your/project` with your actual project path and adjust the `requirements.txt` as necessary for your dependencies.