Upload app.py
Browse files
app.py
CHANGED
|
@@ -180,9 +180,7 @@ def build_cleaned_from_indices(df: pd.DataFrame,
|
|
| 180 |
return cleaned
|
| 181 |
|
| 182 |
def random_assign(cleaned: pd.DataFrame,
|
| 183 |
-
capacities: Dict[str, int],
|
| 184 |
-
seed: Optional[int] = None) -> Tuple[pd.DataFrame, pd.DataFrame, Dict[str, int]]:
|
| 185 |
-
rng = np.random.default_rng(seed)
|
| 186 |
wards = [w for w in cleaned.columns if w not in ("NAME", "ID")]
|
| 187 |
cap = {w: int(capacities.get(w, 0)) for w in wards}
|
| 188 |
|
|
@@ -208,7 +206,7 @@ def random_assign(cleaned: pd.DataFrame,
|
|
| 208 |
if len(candidates) <= cap[w]:
|
| 209 |
pick = candidates
|
| 210 |
else:
|
| 211 |
-
pick = list(
|
| 212 |
assigned.loc[pick] = w
|
| 213 |
choice_no.loc[pick] = r
|
| 214 |
cap[w] -= len(pick)
|
|
|
|
| 180 |
return cleaned
|
| 181 |
|
| 182 |
def random_assign(cleaned: pd.DataFrame,
|
| 183 |
+
capacities: Dict[str, int]) -> Tuple[pd.DataFrame, pd.DataFrame, Dict[str, int]]:
|
|
|
|
|
|
|
| 184 |
wards = [w for w in cleaned.columns if w not in ("NAME", "ID")]
|
| 185 |
cap = {w: int(capacities.get(w, 0)) for w in wards}
|
| 186 |
|
|
|
|
| 206 |
if len(candidates) <= cap[w]:
|
| 207 |
pick = candidates
|
| 208 |
else:
|
| 209 |
+
pick = list(np.random.choice(candidates, size=cap[w], replace=False))
|
| 210 |
assigned.loc[pick] = w
|
| 211 |
choice_no.loc[pick] = r
|
| 212 |
cap[w] -= len(pick)
|