LovnishVerma commited on
Commit
0113cbc
·
verified ·
1 Parent(s): cf93ac5

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +21 -6
main.py CHANGED
@@ -124,18 +124,33 @@ def resultbt():
124
 
125
  @app.route('/dbresults')
126
  def dbresults():
127
- """Fetch all results from MongoDB and render them in a template."""
128
- # Fetch all documents from the MongoDB collection
129
- all_results = collection.find() # Returns a cursor
130
-
131
  # Convert cursor to a list of dictionaries
132
  results_list = []
 
 
 
133
  for result in all_results:
134
  result['_id'] = str(result['_id']) # Convert ObjectId to string for JSON serialization
135
  results_list.append(result)
136
 
137
- # Pass the results to the HTML template
138
- return render_template('dbresults.html', results=results_list)
 
 
 
 
 
 
 
 
 
 
 
 
139
 
140
 
141
  if __name__ == '__main__':
 
124
 
125
  @app.route('/dbresults')
126
  def dbresults():
127
+ """Fetch all results from MongoDB, show aggregated data, and render in a template."""
128
+ # Fetch all documents from MongoDB, sorted by timestamp in descending order
129
+ all_results = collection.find().sort("timestamp", -1) # Sort by timestamp, latest first
130
+
131
  # Convert cursor to a list of dictionaries
132
  results_list = []
133
+ tumor_count = 0
134
+ no_tumor_count = 0
135
+
136
  for result in all_results:
137
  result['_id'] = str(result['_id']) # Convert ObjectId to string for JSON serialization
138
  results_list.append(result)
139
 
140
+ # Count total patients with tumor and without tumor
141
+ if result['prediction'] == 'Tumor Detected':
142
+ tumor_count += 1
143
+ else:
144
+ no_tumor_count += 1
145
+
146
+ total_patients = len(results_list) # Total number of patients
147
+
148
+ # Pass the results and aggregated counts to the HTML template
149
+ return render_template('dbresults.html',
150
+ results=results_list,
151
+ total_patients=total_patients,
152
+ tumor_count=tumor_count,
153
+ no_tumor_count=no_tumor_count)
154
 
155
 
156
  if __name__ == '__main__':