Spaces:
Sleeping
Sleeping
Commit
·
899dcbd
1
Parent(s):
4c15e27
Allowing preds update
Browse files- app.py +29 -6
- leaders/users.json +1 -1
- users.json +1 -1
app.py
CHANGED
|
@@ -169,7 +169,7 @@ def submit_prediction(
|
|
| 169 |
return
|
| 170 |
|
| 171 |
prediction_id = uuid.uuid4().hex
|
| 172 |
-
|
| 173 |
|
| 174 |
prediction_data = {
|
| 175 |
'prediction_id': prediction_id,
|
|
@@ -178,17 +178,40 @@ def submit_prediction(
|
|
| 178 |
'predicted_winner': predicted_winner,
|
| 179 |
'predicted_motm': predicted_motm,
|
| 180 |
'bid_points': bid_points,
|
| 181 |
-
'prediction_date':
|
| 182 |
}
|
| 183 |
|
| 184 |
# Construct the filename to include match_id for easier retrieval
|
| 185 |
-
prediction_file_name = f"prediction_{match_id}_{
|
| 186 |
prediction_file = PREDICTIONS_FOLDER / prediction_file_name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
|
|
|
|
| 188 |
with scheduler.lock:
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
st.success("Prediction submitted successfully!")
|
| 194 |
|
|
|
|
| 169 |
return
|
| 170 |
|
| 171 |
prediction_id = uuid.uuid4().hex
|
| 172 |
+
prediction_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
| 173 |
|
| 174 |
prediction_data = {
|
| 175 |
'prediction_id': prediction_id,
|
|
|
|
| 178 |
'predicted_winner': predicted_winner,
|
| 179 |
'predicted_motm': predicted_motm,
|
| 180 |
'bid_points': bid_points,
|
| 181 |
+
'prediction_date': prediction_time # Include the prediction time
|
| 182 |
}
|
| 183 |
|
| 184 |
# Construct the filename to include match_id for easier retrieval
|
| 185 |
+
prediction_file_name = f"prediction_{match_id}_{user_name}.json"
|
| 186 |
prediction_file = PREDICTIONS_FOLDER / prediction_file_name
|
| 187 |
+
|
| 188 |
+
# Load existing predictions for the user and match, if any
|
| 189 |
+
existing_predictions = []
|
| 190 |
+
if prediction_file.exists():
|
| 191 |
+
with prediction_file.open("r") as file:
|
| 192 |
+
for line in file:
|
| 193 |
+
existing_predictions.append(json.loads(line.strip()))
|
| 194 |
+
|
| 195 |
+
# Update existing prediction if it exists for the same user and match
|
| 196 |
+
prediction_updated = False
|
| 197 |
+
for existing_prediction in existing_predictions:
|
| 198 |
+
if existing_prediction['user_name'] == user_name and existing_prediction['match_id'] == match_id:
|
| 199 |
+
existing_prediction.update(prediction_data)
|
| 200 |
+
prediction_updated = True
|
| 201 |
+
break
|
| 202 |
|
| 203 |
+
# Save the updated predictions back to the file
|
| 204 |
with scheduler.lock:
|
| 205 |
+
if not prediction_updated:
|
| 206 |
+
# Append the new prediction if it doesn't already exist
|
| 207 |
+
with prediction_file.open("a") as file:
|
| 208 |
+
file.write(json.dumps(prediction_data))
|
| 209 |
+
file.write("\n")
|
| 210 |
+
else:
|
| 211 |
+
with prediction_file.open("w") as file:
|
| 212 |
+
for prediction in existing_predictions:
|
| 213 |
+
file.write(json.dumps(prediction))
|
| 214 |
+
file.write("\n")
|
| 215 |
|
| 216 |
st.success("Prediction submitted successfully!")
|
| 217 |
|
leaders/users.json
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
{"Arpit":{"0":
|
|
|
|
| 1 |
+
{"Arpit":{"0":36218},"Ganesh":{"0":10251},"Haaris":{"0":11200},"Jay":{"0":5972},"Kishore":{"0":8620},"Megha":{"0":19150},"Naveein":{"0":15800},"Neha":{"0":7500},"Praveen":{"0":23616},"Rakesh":{"0":4520},"Sai":{"0":30984},"Sahil":{"0":16704},"Sunil":{"0":4818},"Vaibhav":{"0":6301},"Vinay":{"0":22720}}
|
users.json
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
{"Arpit":{"0":
|
|
|
|
| 1 |
+
{"Arpit":{"0":36218},"Ganesh":{"0":10251},"Haaris":{"0":11200},"Jay":{"0":5972},"Kishore":{"0":8620},"Megha":{"0":19150},"Naveein":{"0":15800},"Neha":{"0":7500},"Praveen":{"0":23616},"Rakesh":{"0":4520},"Sai":{"0":30984},"Sahil":{"0":16704},"Sunil":{"0":4818},"Vaibhav":{"0":6301},"Vinay":{"0":22720}}
|