QuantumChecker 0.2.2__tar.gz → 0.2.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: QuantumChecker
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: A package to evaluate homework submissions in Python, SQL, PowerBI, and SSIS.
5
5
  Author: Qobiljon
6
6
  Author-email: qobiljonkhayrullayev@gmail.com
@@ -0,0 +1,125 @@
1
+ import logging
2
+ import os
3
+ from datetime import datetime
4
+ from typing import List, Dict, Optional
5
+ from .python_evaluator import PythonEvaluator
6
+ from .sql_evaluator import SQLEvaluator
7
+ from .powerbi_evaluator import PowerBIEvaluator
8
+ from .ssis_evaluator import SSISEvaluator
9
+
10
+
11
+ class HomeworkEvaluator:
12
+ EXTENSION_TO_TYPE = {
13
+ ".py": "python",
14
+ ".sql": "sql",
15
+ ".zip": "powerbi",
16
+ ".dtsx": "ssis",
17
+ ".DTSX": "ssis",
18
+ ".txt": "text",
19
+ ".md": "text"
20
+ }
21
+
22
+ def _setup_logger(self, file_type: str) -> logging.Logger:
23
+ base_log_dir = os.path.join(os.path.dirname(__file__), "logs")
24
+ type_log_dir = os.path.join(base_log_dir, file_type)
25
+ os.makedirs(type_log_dir, exist_ok=True)
26
+
27
+ timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
28
+ log_file_path = os.path.join(type_log_dir, f"evaluation_{timestamp}.log")
29
+
30
+ logger = logging.getLogger(f"{file_type}_{timestamp}")
31
+ logger.setLevel(logging.INFO)
32
+
33
+ if not logger.handlers:
34
+ file_handler = logging.FileHandler(log_file_path, encoding="utf-8")
35
+ formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
36
+ file_handler.setFormatter(formatter)
37
+ logger.addHandler(file_handler)
38
+
39
+ return logger
40
+
41
+ @staticmethod
42
+ def parse_questions(md_content: str) -> List[str]:
43
+ questions = [q.strip() for q in md_content.strip().split("\n\n") if q.strip()]
44
+ if not questions:
45
+ raise ValueError("No valid questions found in the question content")
46
+ return questions
47
+
48
+ def evaluate_from_content(
49
+ self,
50
+ question_content: str,
51
+ answer_path: str,
52
+ api_key: str,
53
+ backup_api_keys: Optional[List[str]] = None,
54
+ ) -> Dict[str, any]:
55
+ if backup_api_keys is None:
56
+ backup_api_keys = []
57
+
58
+ try:
59
+ questions = self.parse_questions(question_content)
60
+ except Exception as e:
61
+ base_logger = logging.getLogger("base")
62
+ base_logger.error("Failed to parse question content: %s", str(e))
63
+ raise ValueError(f"Failed to parse question content: {str(e)}")
64
+
65
+ answer_path = answer_path.strip()
66
+ _, ext = os.path.splitext(answer_path)
67
+ ext = ext.lower()
68
+ file_type = self.EXTENSION_TO_TYPE.get(ext, "text")
69
+
70
+ logger = self._setup_logger(file_type)
71
+ logger.info("Processing answer_path: %s", answer_path)
72
+ logger.info("Extracted extension: %s", ext)
73
+ logger.info("Detected file type: %s for file: %s", file_type, answer_path)
74
+
75
+ if not os.path.exists(answer_path):
76
+ logger.error("Answer file not found: %s", answer_path)
77
+ raise FileNotFoundError(f"Answer file not found: {answer_path}")
78
+
79
+ def create_evaluator(ftype, key):
80
+ if ftype == "python":
81
+ return PythonEvaluator(key)
82
+ elif ftype == "sql":
83
+ return SQLEvaluator(key)
84
+ elif ftype == "powerbi":
85
+ return PowerBIEvaluator(key)
86
+ elif ftype == "ssis":
87
+ return SSISEvaluator(key)
88
+ else:
89
+ return PythonEvaluator(key) # default fallback
90
+
91
+ keys_to_try = [api_key] + backup_api_keys[:5] # max 5 backups
92
+
93
+ last_exception = None
94
+ for i, key in enumerate(keys_to_try):
95
+ evaluator = create_evaluator(file_type, key)
96
+ try:
97
+ evaluation = evaluator.evaluate(questions, answer_path)
98
+ logger.info(f"Evaluation complete with API key #{i + 1}: Score = {evaluation.get('score')}")
99
+ break
100
+ except Exception as e:
101
+ error_msg = str(e).lower()
102
+ if (
103
+ "429" in error_msg
104
+ or "rate limit" in error_msg
105
+ or "quota exceeded" in error_msg
106
+ or "daily limit exceeded" in error_msg
107
+ or "quota" in error_msg
108
+ ):
109
+ logger.warning(f"API key #{i + 1} limited or quota exceeded. Trying next key if available.")
110
+ last_exception = e
111
+ continue
112
+ else:
113
+ logger.error(f"Evaluation failed with API key #{i + 1}: {str(e)}")
114
+ raise
115
+ else:
116
+ logger.error("All API keys exhausted and evaluation failed.")
117
+ if last_exception:
118
+ raise last_exception
119
+ else:
120
+ raise RuntimeError("Evaluation failed for unknown reasons.")
121
+
122
+ return {
123
+ "mark": evaluation["score"],
124
+ "feedback": evaluation["feedback"]
125
+ }
@@ -14,7 +14,7 @@ from PIL import Image
14
14
  import io
15
15
  import base64
16
16
 
17
- from prompts import prompt_text_powerbi
17
+ from .prompts import prompt_text_powerbi
18
18
 
19
19
  load_dotenv()
20
20
  logger = logging.getLogger(__name__)
@@ -1,6 +1,6 @@
1
1
  import logging
2
2
  import requests
3
- from prompts import prompt_text_python
3
+ from .prompts import prompt_text_python
4
4
  from typing import List, Dict
5
5
  from tenacity import retry, stop_after_attempt, wait_exponential, retry_if_exception_type
6
6
 
@@ -3,7 +3,7 @@ import requests
3
3
  from typing import List, Dict
4
4
  from tenacity import retry, stop_after_attempt, wait_exponential, retry_if_exception_type
5
5
 
6
- from prompts import prompt_text_sql
6
+ from .prompts import prompt_text_sql
7
7
 
8
8
  logger = logging.getLogger(__name__)
9
9
 
@@ -4,7 +4,7 @@ import xml.etree.ElementTree as ET
4
4
  from typing import List, Dict
5
5
  from tenacity import retry, stop_after_attempt, wait_exponential, retry_if_exception_type
6
6
 
7
- from prompts import prompt_text_ssis
7
+ from .prompts import prompt_text_ssis
8
8
 
9
9
  logger = logging.getLogger(__name__)
10
10
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: QuantumChecker
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: A package to evaluate homework submissions in Python, SQL, PowerBI, and SSIS.
5
5
  Author: Qobiljon
6
6
  Author-email: qobiljonkhayrullayev@gmail.com
@@ -11,4 +11,5 @@ QuantumChecker.egg-info/PKG-INFO
11
11
  QuantumChecker.egg-info/SOURCES.txt
12
12
  QuantumChecker.egg-info/dependency_links.txt
13
13
  QuantumChecker.egg-info/requires.txt
14
- QuantumChecker.egg-info/top_level.txt
14
+ QuantumChecker.egg-info/top_level.txt
15
+ tests/test.py
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="QuantumChecker",
5
- version="0.2.2",
5
+ version="0.2.3",
6
6
  author="Qobiljon",
7
7
  author_email="qobiljonkhayrullayev@gmail.com",
8
8
  description="A package to evaluate homework submissions in Python, SQL, PowerBI, and SSIS.",
@@ -0,0 +1,29 @@
1
+ from QuantumCheck import HomeworkEvaluator
2
+
3
+ if __name__ == "__main__":
4
+ evaluator = HomeworkEvaluator()
5
+
6
+ primary_api_key = "AIzaSyD0ptgEixhLLjCWjkyxhqDsUzO16ytQq2c"
7
+ question = "How to write print in python"
8
+
9
+ backup_keys = [
10
+ "BACKUP_KEY_1",
11
+ "BACKUP_KEY_2",
12
+ "BACKUP_KEY_3",
13
+ "BACKUP_KEY_4",
14
+ "BACKUP_KEY_5",
15
+ ]
16
+
17
+ result = evaluator.evaluate_from_content(
18
+ question_content="How to write print in python",
19
+ answer_path="../tests/answer/answer.py",
20
+ api_key=primary_api_key,
21
+ backup_api_keys=backup_keys
22
+ )
23
+
24
+ print(result)
25
+
26
+
27
+
28
+
29
+
@@ -1,72 +0,0 @@
1
- import logging
2
- import os
3
- from typing import List, Dict
4
- from python_evaluator import PythonEvaluator
5
- from sql_evaluator import SQLEvaluator
6
- from powerbi_evaluator import PowerBIEvaluator
7
- from ssis_evaluator import SSISEvaluator
8
-
9
- logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
10
- logger = logging.getLogger(__name__)
11
-
12
-
13
- class HomeworkEvaluator:
14
- EXTENSION_TO_TYPE = {
15
- ".py": "python",
16
- ".sql": "sql",
17
- ".zip": "powerbi",
18
- ".dtsx": "ssis",
19
- ".DTSX": "ssis",
20
- ".txt": "text",
21
- ".md": "text"
22
- }
23
-
24
- @staticmethod
25
- def parse_questions(md_content: str) -> List[str]:
26
- questions = [q.strip() for q in md_content.strip().split("\n\n") if q.strip()]
27
- if not questions:
28
- raise ValueError("No valid questions found in the question content")
29
- return questions
30
-
31
- def evaluate_from_content(self, question_content: str, answer_path: str, api_key: str) -> Dict[str, any]:
32
- try:
33
- questions = self.parse_questions(question_content)
34
- except Exception as e:
35
- logger.error("Failed to parse question content: %s", str(e))
36
- raise ValueError(f"Failed to parse question content: {str(e)}")
37
-
38
- answer_path = answer_path.strip()
39
- logger.info("Processing answer_path: %s", answer_path)
40
- _, ext = os.path.splitext(answer_path)
41
- ext = ext.lower()
42
- logger.info("Extracted extension: %s", ext)
43
- file_type = self.EXTENSION_TO_TYPE.get(ext, "text")
44
- logger.info("Detected file type: %s for file: %s", file_type, answer_path)
45
-
46
- if not os.path.exists(answer_path):
47
- logger.error("Answer file not found: %s", answer_path)
48
- raise FileNotFoundError(f"Answer file not found: {answer_path}")
49
-
50
- if file_type == "python":
51
- evaluator = PythonEvaluator(api_key)
52
- evaluation = evaluator.evaluate(questions, answer_path)
53
- elif file_type == "sql":
54
- evaluator = SQLEvaluator(api_key)
55
- evaluation = evaluator.evaluate(questions, answer_path)
56
- elif file_type == "powerbi":
57
- evaluator = PowerBIEvaluator(api_key)
58
- evaluation = evaluator.evaluate(questions, answer_path)
59
- elif file_type == "ssis":
60
- evaluator = SSISEvaluator(api_key)
61
- evaluation = evaluator.evaluate(questions, answer_path)
62
- else:
63
- logger.warning("Unrecognized file type '%s', defaulting to text (Python parser)", file_type)
64
- evaluator = PythonEvaluator(api_key)
65
- evaluation = evaluator.evaluate(questions, answer_path)
66
-
67
- return {
68
- "mark": evaluation["score"],
69
- "feedback": evaluation["feedback"]
70
- }
71
-
72
-
File without changes
File without changes