Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
68 changes: 68 additions & 0 deletions database/README.MD
Original file line number Diff line number Diff line change
@@ -1 +1,69 @@
# Mock Data Generation

## Purpose

This module generates realistic synthetic mock data for Saayam database tables.

The generated data is useful for:

- Testing
- Development
- ETL validation
- Dashboard demos
- Non-production environments

No real user data is used.

---

## Input Files

Schema reference files:

- `database/Saayam_Table.column.names_data.xlsx`
- `database/mock-data-generation/db_info.json`

Lookup/reference tables:

- `database/lookup_tables/`

---

## Generated Tables

### users

References:

- state_id → state
- country_id → country
- user_status_id → user_status
- user_category_id → user_category

### request

References:

- req_user_id → users
- req_for_id → request_for
- req_islead_id → request_isleadvol
- req_cat_id → help_categories
- req_type_id → request_type
- req_priority_id → request_priority
- req_status_id → request_status

---

## Technologies Used

- Python
- Pandas
- Faker

---

## Install Dependencies

```bash
pip install pandas faker openpyxl

49 changes: 49 additions & 0 deletions database/mock-data-generation/common_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import os
import random
from datetime import datetime, timedelta

import pandas as pd
from faker import Faker

fake = Faker()

random.seed(42)
Faker.seed(42)


def load_lookup(lookup_dir, file_name):
path = os.path.join(lookup_dir, file_name)

if not os.path.exists(path):
print(f"Missing lookup file: {file_name}")
return pd.DataFrame()

return pd.read_csv(path)


def get_id_values(df):
if df.empty:
return [1]

id_cols = [
col for col in df.columns
if col.lower() == "id"
or col.lower().endswith("_id")
]

if id_cols:
return df[id_cols[0]].dropna().tolist()

return df.iloc[:, 0].dropna().tolist()


def random_datetime(start_year=2022, end_year=2026):
start_date = datetime(start_year, 1, 1)
end_date = datetime(end_year, 12, 31)

diff = end_date - start_date

return start_date + timedelta(
days=random.randint(0, diff.days),
seconds=random.randint(0, 86400)
)
Loading