Skip to content

Commit

Permalink
Merge ed86730 into 8511c4f
Browse files Browse the repository at this point in the history
  • Loading branch information
adelavega committed Sep 28, 2021
2 parents 8511c4f + ed86730 commit 90a9f18
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions neuroscout/models/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,22 @@ def mean_age(self):
try:
val = GroupPredictorValue.query.join(GroupPredictor).filter_by(
dataset_id=self.id, name='age').values('value')
# Translating age ranges to
age_map = {'20-25': 22.5, '25-30': 27.5, '30-35': 32.5, '35-40': 37.5}
# Translating age ranges to numeric
age_map = {
'20-25': 22.5, '25-30': 27.5, '30-35': 32.5, '35-40': 37.5}
vals = []
for v in val:
if v[0] in age_map:
vals.append(age_map[v[0]])
else:
vals += [float(v) for v in v.split(",")]
v = v[0]
if v in age_map:
vals.append(age_map[v])
elif "," in v:
# If age is comma separated
new_val = [float(v) for v in v.split(",") if v != "n/a"]
if new_val:
mv = statistics.mean(new_val)
vals.append(statistics.mean(new_val))
elif v != 'nan':
vals.append(float(v))
except ValueError:
return None

Expand Down

0 comments on commit 90a9f18

Please sign in to comment.