ouhenio commited on
Commit
23f111d
·
verified ·
1 Parent(s): 0cdbf95

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -119,24 +119,28 @@ def count_answers_per_space(country: str):
119
 
120
  answered_questions = 0
121
  total_answers = 0
122
- answers_per_user = {}
123
 
124
  for record in records:
125
- responses = record.responses.to_dict()
 
 
 
 
126
  if "answer_1" in responses:
127
- answered_questions += 1
128
- total_answers += len(responses)
129
 
130
- for response in responses:
131
- user_id = str(response.user_id)
132
- answers_per_user[user_id] = answers_per_user.get(user_id, 0) + 1
133
 
134
- percentage_complete = (answered_questions / total_questions * 100) if total_questions > 0 else 0
135
 
136
  return {
137
  "name": country,
138
  "total_questions": total_questions,
139
- "answered_questions": answered_questions,
140
  "total_answers": total_answers,
141
  "percent": round(percentage_complete, 2),
142
  "documents": total_answers * 10
 
119
 
120
  answered_questions = 0
121
  total_answers = 0
122
+ # answers_per_user = {}
123
 
124
  for record in records:
125
+ record = record.to_dict()
126
+ responses = record["responses"]
127
+ if record["status"] == "completed":
128
+ # +1 completed questions
129
+ completed_questions += 1
130
  if "answer_1" in responses:
131
+ answers = responses["answer_1"]
132
+ total_answers += len(answers)
133
 
134
+ # for answer in answers:
135
+ # user_id = answer["user_id"]
136
+ # answers_per_user[user_id] = answers_per_user.get(user_id, 0) + 1
137
 
138
+ percentage_complete = (completed_questions / total_questions * 100) if total_questions > 0 else 0
139
 
140
  return {
141
  "name": country,
142
  "total_questions": total_questions,
143
+ "answered_questions": completed_questions,
144
  "total_answers": total_answers,
145
  "percent": round(percentage_complete, 2),
146
  "documents": total_answers * 10