File size: 1,415 Bytes
9d242f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# modules/storage.py - Storage management functions
import os
import shutil
from pathlib import Path
import json
from datetime import datetime
import pandas as pd

# Storage paths
STORAGE_DIR = Path(os.environ.get('STORAGE_DIR', './data'))
DB_PATH = STORAGE_DIR / 'empower.db'
BACKUP_DIR = STORAGE_DIR / 'backups'
UPLOADS_DIR = STORAGE_DIR / 'uploads'

# Ensure directories exist
for directory in [STORAGE_DIR, BACKUP_DIR, UPLOADS_DIR]:
    directory.mkdir(exist_ok=True)

def backup_database():
    """Create a backup of database"""
    try:
        timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
        backup_path = BACKUP_DIR / f"empower_backup_{timestamp}.db"
        shutil.copy2(DB_PATH, backup_path)
        return True, f"Backup created: {backup_path}"
    except Exception as e:
        return False, f"Backup failed: {str(e)}"

def get_grade(avg):
    """Calculate grade from average"""
    if avg is None or pd.isna(avg):
        return "U"
    avg = float(avg)
    if avg >= 90: return "A*"
    elif avg >= 80: return "A"
    elif avg >= 70: return "B"
    elif avg >= 60: return "C"
    elif avg >= 50: return "D"
    elif avg >= 40: return "E"
    else: return "U"

def show_storage_status():
    """Display storage status in sidebar"""
    if os.environ.get('SPACE_ID'):
        st.sidebar.success("🟒 Persistent Storage Active")
    else:
        st.sidebar.info("πŸ”΅ Local Storage Mode")