Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -30,6 +30,7 @@ from io import BytesIO
|
|
30 |
from typing import List
|
31 |
import re
|
32 |
import importlib.metadata
|
|
|
33 |
|
34 |
|
35 |
set_global_handler("simple") # imposta un handler semplice per il logging
|
@@ -535,15 +536,47 @@ def create_mock_questions():
|
|
535 |
|
536 |
|
537 |
return [
|
538 |
-
|
539 |
-
"task_id":"
|
540 |
-
"question":"
|
541 |
"Level":"1",
|
542 |
-
"file_name":"
|
543 |
}
|
544 |
]
|
545 |
|
546 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
547 |
|
548 |
|
549 |
#Tools
|
|
|
30 |
from typing import List
|
31 |
import re
|
32 |
import importlib.metadata
|
33 |
+
import random
|
34 |
|
35 |
|
36 |
set_global_handler("simple") # imposta un handler semplice per il logging
|
|
|
536 |
|
537 |
|
538 |
return [
|
539 |
+
{
|
540 |
+
"task_id":"4fc2f1ae-8625-45b5-ab34-ad4433bc21f8",
|
541 |
+
"question":"Who nominated the only Featured Article on English Wikipedia about a dinosaur that was promoted in November 2016?",
|
542 |
"Level":"1",
|
543 |
+
"file_name":""
|
544 |
}
|
545 |
]
|
546 |
|
547 |
+
def process_questions(serviceList, whiteList, blackList):
|
548 |
+
# 1. Rimuovi dalla serviceList tutte le domande i cui task_id sono in blackList
|
549 |
+
initial_len = len(serviceList)
|
550 |
+
serviceList = [q for q in serviceList if q["task_id"] not in blackList]
|
551 |
+
removed_blacklisted = initial_len - len(serviceList)
|
552 |
+
|
553 |
+
# 2. Calcola la somma con whiteList
|
554 |
+
total_after_merge = len(serviceList) + len(whiteList)
|
555 |
+
|
556 |
+
# 3. Se somma > 20, rimuovi a caso da serviceList
|
557 |
+
removed_random = []
|
558 |
+
if total_after_merge > 20:
|
559 |
+
to_remove = total_after_merge - 20
|
560 |
+
removed_random = random.sample(serviceList, to_remove)
|
561 |
+
serviceList = [q for q in serviceList if q not in removed_random]
|
562 |
+
|
563 |
+
# 4. Stampa le domande eliminate
|
564 |
+
print("=== Domande rimosse per blacklist ===")
|
565 |
+
print(removed_blacklisted)
|
566 |
+
print("=== Domande rimosse random ===")
|
567 |
+
for q in removed_random:
|
568 |
+
print(q)
|
569 |
+
|
570 |
+
# 5. Stampa la nuova serviceList
|
571 |
+
print("=== Nuova serviceList ===")
|
572 |
+
for q in serviceList:
|
573 |
+
print(q)
|
574 |
+
|
575 |
+
# 6. Aggiungi le domande della whiteList
|
576 |
+
serviceList.extend(whiteList)
|
577 |
+
|
578 |
+
# 7. Ritorna la lista risultante
|
579 |
+
return serviceList
|
580 |
|
581 |
|
582 |
#Tools
|