# Family Tree Tool Guide

A Python tool to manage and visualize family trees from Excel spreadsheets.

## Features

✅ **Read Excel Family Trees** - Loads family data from structured Excel files  
✅ **Add New People** - Easily add new family members  
✅ **Manage Relationships** - Add parent-child and marriage relationships  
✅ **Visualize Family Tree** - Generate visual family tree diagrams  
✅ **Save to Excel** - Save all changes back to Excel format  

## Excel File Structure

The tool expects an Excel file with three sheets:

### 1. People Sheet
Contains person information:
- `Person ID` - Unique identifier (e.g., P001, P002)
- `First Name` - Person's first name
- `Middle Name` - Middle name (optional)
- `Last Name` - Last name
- `Birth Date` - Date of birth (format: DD/MM/YYYY)
- `Birth Place` - Place of birth
- `Notes` - Additional notes

### 2. ParentChild Sheet
Contains parent-child relationships:
- `Child ID` - Person ID of the child
- `Parent ID` - Person ID of the parent
- `Relationship` - Type of relationship (Father, Mother, etc.)

### 3. Marriages Sheet
Contains marriage relationships:
- `Partner 1 ID` - Person ID of first partner
- `Partner 2 ID` - Person ID of second partner
- `Marriage Date` - Date of marriage (format: DD/MM/YYYY)
- `Divorce Date` - Date of divorce if applicable (optional)

## Installation

### Required Libraries

Basic functionality (reading/writing Excel):
```bash
pip install pandas openpyxl
```

For visualization (optional):
```bash
pip install matplotlib networkx
```

## Usage Examples

### 1. View Family Tree Summary

```bash
python family_tree_tool.py --input job_descriptions/Kirk_Family_Tree.xlsx --summary
```

### 2. Add a New Person

```bash
python family_tree_tool.py \
  --input job_descriptions/Kirk_Family_Tree.xlsx \
  --add-person "John" "Smith" \
  --birth-date "15/06/1990" \
  --birth-place "London, England" \
  --middle-name "Michael" \
  --notes "Added from family records"
```

### 3. Add Parent-Child Relationship

```bash
python family_tree_tool.py \
  --input job_descriptions/Kirk_Family_Tree.xlsx \
  --add-child P005 P001
```

This makes P001 the parent of P005.

### 4. Add Marriage Relationship

```bash
python family_tree_tool.py \
  --input job_descriptions/Kirk_Family_Tree.xlsx \
  --add-marriage P001 P007 \
  --marriage-date "22/08/1982"
```

### 5. Generate Visualizations

**Network View** (connection diagram):
```bash
python family_tree_tool.py \
  --input job_descriptions/Kirk_Family_Tree.xlsx \
  --visualize
```

**Hierarchical Tree** (proper family tree with generations):
```bash
python family_tree_tool.py \
  --input job_descriptions/Kirk_Family_Tree.xlsx \
  --tree
```

This creates `family_tree_hierarchical.png` - a proper hierarchical family tree showing generations from top to bottom, with marriages shown as horizontal connections.

### 6. Export to GEDCOM Format

Export your family tree to GEDCOM format for use with professional genealogy software:

```bash
python family_tree_tool.py \
  --input job_descriptions/Kirk_Family_Tree.xlsx \
  --export-gedcom
```

This creates `family_tree.ged` which can be imported into:
- **Gramps** (free, open-source) - https://gramps-project.org
- **Family Tree Maker**
- **Ancestry.com**
- **MyHeritage**
- **RootsMagic**
- **GenoPro**
- And many other genealogy programs

You can specify a custom output file:
```bash
python family_tree_tool.py \
  --input job_descriptions/Kirk_Family_Tree.xlsx \
  --export-gedcom \
  --gedcom-output Kirk_Family.ged
```

### 6. Complete Workflow: Add Person and Relationships

```bash
# Step 1: Add a new person
python family_tree_tool.py \
  --input job_descriptions/Kirk_Family_Tree.xlsx \
  --add-person "Emma" "Kirk" \
  --birth-date "10/05/2020" \
  --birth-place "Oslo, Norway"

# Step 2: Add as child of existing person (use the Person ID from step 1 output)
python family_tree_tool.py \
  --input job_descriptions/Kirk_Family_Tree.xlsx \
  --add-child P035 P005
```

### 7. Save to Different File

```bash
python family_tree_tool.py \
  --input job_descriptions/Kirk_Family_Tree.xlsx \
  --add-person "New Person" "LastName" \
  --output job_descriptions/Kirk_Family_Tree_updated.xlsx
```

## Command Line Options

```
--input, -i          Input Excel file path (default: job_descriptions/Kirk_Family_Tree.xlsx)
--output, -o         Output Excel file path (default: overwrites input file)
--visualize, -v      Generate network visualization of family tree
--tree, -t          Generate hierarchical family tree (proper tree layout)
--export-gedcom     Export family tree to GEDCOM format
--gedcom-output     Output file for GEDCOM export (default: family_tree.ged)
--summary, -s        Print summary of family tree

--add-person         Add a new person (provide: FirstName LastName)
--birth-date         Birth date for new person (format: DD/MM/YYYY)
--birth-place        Birth place for new person
--middle-name        Middle name for new person
--notes              Notes for new person

--add-child          Add parent-child relationship (CHILD_ID PARENT_ID)
--add-marriage       Add marriage relationship (PARTNER1_ID PARTNER2_ID)
--marriage-date      Marriage date (format: DD/MM/YYYY)
```

## Finding Person IDs

To find a person's ID, use the summary command:

```bash
python family_tree_tool.py --input job_descriptions/Kirk_Family_Tree.xlsx --summary
```

This will list all people with their Person IDs.

## Tips

1. **Backup First**: Always backup your Excel file before making changes
2. **Person IDs**: The tool automatically generates Person IDs (P001, P002, etc.)
3. **Relationships**: You can add multiple relationships for the same person
4. **Visualization Types**:
   - **Network View** (`--visualize`): Shows all connections as a network diagram
   - **Hierarchical Tree** (`--tree`): Creates a proper family tree with generations from top to bottom
     - Black lines: Parent-child relationships
     - Red dashed lines: Marriages connecting spouses
5. **GEDCOM Export**: Export to standard genealogy format for use with professional software
6. **Excel Format**: The tool preserves Excel formatting and adds headers

## Troubleshooting

### "File not found" error
- Check the file path is correct
- Use absolute paths if needed: `/full/path/to/file.xlsx`

### "Visualization libraries not available"
- Install with: `pip install matplotlib networkx`
- Visualization is optional - the tool works without it

### "Person ID not found" when adding relationships
- Make sure you're using the correct Person ID
- Check the summary to see all available Person IDs

## Example Workflow

```bash
# 1. View current family tree
python family_tree_tool.py -i Kirk_Family_Tree.xlsx -s

# 2. Add a new family member
python family_tree_tool.py -i Kirk_Family_Tree.xlsx \
  --add-person "Alice" "Kirk" \
  --birth-date "12/03/2021" \
  --birth-place "Oslo, Norway"

# 3. Note the Person ID from output (e.g., P035)

# 4. Add parent relationship
python family_tree_tool.py -i Kirk_Family_Tree.xlsx \
  --add-child P035 P005

# 5. Generate hierarchical family tree (recommended!)
python family_tree_tool.py -i Kirk_Family_Tree.xlsx --tree

# Or generate network visualization
python family_tree_tool.py -i Kirk_Family_Tree.xlsx -v

# 6. Export to GEDCOM for genealogy software
python family_tree_tool.py -i Kirk_Family_Tree.xlsx --export-gedcom

# 6. View updated summary
python family_tree_tool.py -i Kirk_Family_Tree.xlsx -s
```

## File Location

The tool is located at:
```
/var/www/html/wordpress6/wordpress/EP/family_tree_tool.py
```

Make it executable:
```bash
chmod +x family_tree_tool.py
```

Then you can run it directly:
```bash
./family_tree_tool.py --input job_descriptions/Kirk_Family_Tree.xlsx --summary
```

