Spaces:
Runtime error
Runtime error
File size: 6,372 Bytes
5e5fbfc 6f93256 5e5fbfc 6f93256 5e5fbfc 6f93256 5e5fbfc 6f93256 5e5fbfc 6f93256 5e5fbfc 6f93256 5e5fbfc 6f93256 5e5fbfc 6f93256 5e5fbfc 6f93256 5e5fbfc 6f93256 5e5fbfc 6f93256 5e5fbfc 6f93256 5e5fbfc 88f3533 5e5fbfc 6f93256 5e5fbfc 88f3533 5e5fbfc 6f93256 5e5fbfc 88f3533 5e5fbfc 6f93256 5e5fbfc 88f3533 5e5fbfc 6f93256 5e5fbfc 88f3533 5e5fbfc 6f93256 5e5fbfc 88f3533 5e5fbfc 6f93256 5e5fbfc 88f3533 5e5fbfc 6f93256 88f3533 6f93256 5e5fbfc 6f93256 5e5fbfc 6f93256 5e5fbfc | 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | """Load and normalize thematic analysis CSV data."""
import os
import pandas as pd
# Base path: one level up from src/
BASE = os.path.join(os.path.dirname(__file__), "..")
KRIUKOWTA_DIR = os.path.join(BASE, "KriukowTA")
ZAMBRANOTA_DIR = os.path.join(BASE, "ZambranoTA")
BRAUNCLARKETA_DIR = os.path.join(BASE, "BraunClarkeTA")
GOOGLEFORM_DIR = os.path.join(BASE, "GoogleForm")
# Default encoding for CSV files (handles BOM and special characters)
CSV_ENCODING = "utf-8-sig"
def load_videota_initial_coding():
"""Load KriukowTA Initial Coding data."""
path = os.path.join(KRIUKOWTA_DIR, "VideoTA - InitialCoding.csv")
if not os.path.exists(path):
return pd.DataFrame()
try:
df = pd.read_csv(path, encoding=CSV_ENCODING)
return df.dropna(how="all")
except Exception:
return pd.DataFrame()
def load_videota_focused_coding():
"""Load KriukowTA Focused Coding (Axial Coding) data."""
path = os.path.join(KRIUKOWTA_DIR, "VideoTA - FocusedCoding(Axial Coding).csv")
if not os.path.exists(path):
return pd.DataFrame()
try:
df = pd.read_csv(path, encoding=CSV_ENCODING)
return df.dropna(how="all")
except Exception:
return pd.DataFrame()
def load_videota_mapping_evidence():
"""Load KriukowTA Mapping & Evidence data."""
path = os.path.join(KRIUKOWTA_DIR, "VideoTA - Mapping&Evidence.csv")
if not os.path.exists(path):
return pd.DataFrame()
try:
df = pd.read_csv(path, encoding=CSV_ENCODING)
return df.dropna(how="all")
except Exception:
return pd.DataFrame()
def load_videota_moscow():
"""Load KriukowTA MoSCoW prioritization data."""
path = os.path.join(KRIUKOWTA_DIR, "VideoTA - MoSCoW.csv")
if not os.path.exists(path):
return pd.DataFrame()
try:
df = pd.read_csv(path, encoding=CSV_ENCODING)
return df.dropna(how="all")
except Exception:
return pd.DataFrame()
def load_zambranota_coded_dataset():
"""Load ZambranoTA Coded Dataset."""
path = os.path.join(ZAMBRANOTA_DIR, "ZambranoTA - CodedDataset.csv")
if not os.path.exists(path):
return pd.DataFrame()
try:
df = pd.read_csv(path, encoding=CSV_ENCODING)
return df.dropna(how="all")
except Exception:
return pd.DataFrame()
def load_zambranota_initial_codebook():
"""Load ZambranoTA Initial Codebook."""
path = os.path.join(ZAMBRANOTA_DIR, "ZambranoTA - InitialCodeBook.csv")
if not os.path.exists(path):
return pd.DataFrame()
try:
df = pd.read_csv(path, encoding=CSV_ENCODING)
return df.dropna(how="all")
except Exception:
return pd.DataFrame()
def load_zambranota_refined_codebook():
"""Load ZambranoTA Refined Codebook."""
path = os.path.join(ZAMBRANOTA_DIR, "ZambranoTA - RefinedCodeBook.csv")
if not os.path.exists(path):
return pd.DataFrame()
try:
df = pd.read_csv(path, encoding=CSV_ENCODING)
return df.dropna(how="all")
except Exception:
return pd.DataFrame()
def load_zambranota_theme_frequency():
"""Load ZambranoTA Theme Frequency Distribution."""
path = os.path.join(ZAMBRANOTA_DIR, "ZambranoTA - ThemeFrequencyDistribution.csv")
if not os.path.exists(path):
return pd.DataFrame()
try:
df = pd.read_csv(path, encoding=CSV_ENCODING)
return df.dropna(how="all")
except Exception:
return pd.DataFrame()
def load_zambranota_moscow():
"""Load ZambranoTA MoSCoW prioritization data."""
path = os.path.join(ZAMBRANOTA_DIR, "ZambranoTA - MoSCoW.csv")
if not os.path.exists(path):
return pd.DataFrame()
try:
df = pd.read_csv(path, encoding=CSV_ENCODING)
return df.dropna(how="all")
except Exception:
return pd.DataFrame()
def load_zambranota_qualitative_analysis():
"""Load ZambranoTA Qualitative Analysis."""
path = os.path.join(ZAMBRANOTA_DIR, "ZambranoTA - QualitativeAnalysis.csv")
if not os.path.exists(path):
return pd.DataFrame()
try:
df = pd.read_csv(path, encoding=CSV_ENCODING)
return df.dropna(how="all")
except Exception:
return pd.DataFrame()
def load_braunclarke_ta():
"""Load Braun-Clarke Thematic Analysis."""
path = os.path.join(BRAUNCLARKETA_DIR, "BraunClarkeTA - Braun_Clarke.csv")
if not os.path.exists(path):
return pd.DataFrame()
try:
df = pd.read_csv(path, encoding=CSV_ENCODING)
return df.dropna(how="all")
except Exception:
return pd.DataFrame()
def load_braunclarke_moscow():
"""Load Braun-Clarke MoSCoW prioritization data."""
path = os.path.join(BRAUNCLARKETA_DIR, "BraunClarkeTA - Braun_ClarkeMoSCoW.csv")
if not os.path.exists(path):
return pd.DataFrame()
try:
df = pd.read_csv(path, encoding=CSV_ENCODING)
return df.dropna(how="all")
except Exception:
return pd.DataFrame()
def load_google_form():
"""Load Google Form responses CSV. Returns None if file not found (optional data)."""
import glob
if not os.path.exists(GOOGLEFORM_DIR):
return None
# Try multiple patterns to be more flexible
patterns = [
os.path.join(GOOGLEFORM_DIR, "*Form*Responses*.csv"),
os.path.join(GOOGLEFORM_DIR, "*responses*.csv"),
os.path.join(GOOGLEFORM_DIR, "*.csv"),
]
files = []
for pattern in patterns:
files = glob.glob(pattern, recursive=False)
if files:
break
if not files:
return None
path = files[0]
try:
df = pd.read_csv(path, encoding=CSV_ENCODING)
return df.dropna(how="all")
except Exception:
return None
def participant_count(s):
"""Parse 'P1, P4, P6' or 'P1/P14' or 'Participant 1, Participant 2' into count."""
if pd.isna(s) or not str(s).strip():
return 0
s = str(s).replace("/", ",").replace(" and ", ",")
# Handle both "P1" and "Participant 1" formats
parts = [x.strip() for x in s.split(",") if "P" in x or "participant" in x.lower() or x.strip().replace("#", "").isdigit()]
# Unique participant IDs
seen = set()
for p in parts:
# Extract numbers
n = "".join(c for c in p if c.isdigit())
if n:
seen.add(n)
return len(seen)
|