QuantumChecker 0.2.1__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,20 +1,27 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: QuantumChecker
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: A package to evaluate homework submissions in Python, SQL, PowerBI, and SSIS.
5
- Author-email: Qobiljon <qobiljonkhayrullayev@gmail.com>
5
+ Author: Qobiljon
6
+ Author-email: qobiljonkhayrullayev@gmail.com
6
7
  Classifier: Programming Language :: Python :: 3
7
8
  Classifier: License :: OSI Approved :: MIT License
8
9
  Classifier: Operating System :: OS Independent
9
10
  Requires-Python: >=3.6
10
11
  Description-Content-Type: text/markdown
11
- License-File: LICENSE
12
12
  Requires-Dist: requests>=2.31.0
13
13
  Requires-Dist: tenacity>=8.2.3
14
14
  Requires-Dist: pdf2image>=1.16.3
15
15
  Requires-Dist: python-dotenv>=1.0.0
16
16
  Requires-Dist: Pillow>=10.0.0
17
- Dynamic: license-file
17
+ Dynamic: author
18
+ Dynamic: author-email
19
+ Dynamic: classifier
20
+ Dynamic: description
21
+ Dynamic: description-content-type
22
+ Dynamic: requires-dist
23
+ Dynamic: requires-python
24
+ Dynamic: summary
18
25
 
19
26
  # HomeworkEvaluator
20
27
 
@@ -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,20 +1,27 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: QuantumChecker
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: A package to evaluate homework submissions in Python, SQL, PowerBI, and SSIS.
5
- Author-email: Qobiljon <qobiljonkhayrullayev@gmail.com>
5
+ Author: Qobiljon
6
+ Author-email: qobiljonkhayrullayev@gmail.com
6
7
  Classifier: Programming Language :: Python :: 3
7
8
  Classifier: License :: OSI Approved :: MIT License
8
9
  Classifier: Operating System :: OS Independent
9
10
  Requires-Python: >=3.6
10
11
  Description-Content-Type: text/markdown
11
- License-File: LICENSE
12
12
  Requires-Dist: requests>=2.31.0
13
13
  Requires-Dist: tenacity>=8.2.3
14
14
  Requires-Dist: pdf2image>=1.16.3
15
15
  Requires-Dist: python-dotenv>=1.0.0
16
16
  Requires-Dist: Pillow>=10.0.0
17
- Dynamic: license-file
17
+ Dynamic: author
18
+ Dynamic: author-email
19
+ Dynamic: classifier
20
+ Dynamic: description
21
+ Dynamic: description-content-type
22
+ Dynamic: requires-dist
23
+ Dynamic: requires-python
24
+ Dynamic: summary
18
25
 
19
26
  # HomeworkEvaluator
20
27
 
@@ -1,6 +1,5 @@
1
- LICENSE
2
1
  README.md
3
- pyproject.toml
2
+ setup.py
4
3
  QuantumCheck/__init__.py
5
4
  QuantumCheck/main.py
6
5
  QuantumCheck/powerbi_evaluator.py
@@ -12,4 +11,5 @@ QuantumChecker.egg-info/PKG-INFO
12
11
  QuantumChecker.egg-info/SOURCES.txt
13
12
  QuantumChecker.egg-info/dependency_links.txt
14
13
  QuantumChecker.egg-info/requires.txt
15
- QuantumChecker.egg-info/top_level.txt
14
+ QuantumChecker.egg-info/top_level.txt
15
+ tests/test.py
@@ -0,0 +1,27 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="QuantumChecker",
5
+ version="0.2.3",
6
+ author="Qobiljon",
7
+ author_email="qobiljonkhayrullayev@gmail.com",
8
+ description="A package to evaluate homework submissions in Python, SQL, PowerBI, and SSIS.",
9
+ long_description=open("README.md", encoding="utf-8").read(),
10
+ long_description_content_type="text/markdown",
11
+ license_files=["LICENSE.txt"],
12
+ python_requires=">=3.6",
13
+ packages=find_packages(),
14
+ install_requires=[
15
+ "requests>=2.31.0",
16
+ "tenacity>=8.2.3",
17
+ "pdf2image>=1.16.3",
18
+ "python-dotenv>=1.0.0",
19
+ "Pillow>=10.0.0",
20
+ ],
21
+ classifiers=[
22
+ "Programming Language :: Python :: 3",
23
+ "License :: OSI Approved :: MIT License",
24
+ "Operating System :: OS Independent",
25
+ ],
26
+ include_package_data=True,
27
+ )
@@ -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,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Qobiljon Xayrullayev
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -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
-
@@ -1,27 +0,0 @@
1
- [build-system]
2
- requires = ["setuptools>=61.0", "wheel"]
3
- build-backend = "setuptools.build_meta"
4
-
5
- [project]
6
- name = "QuantumChecker"
7
- version = "0.2.1"
8
- authors = [
9
- { name = "Qobiljon", email = "qobiljonkhayrullayev@gmail.com" },
10
- ]
11
- description = "A package to evaluate homework submissions in Python, SQL, PowerBI, and SSIS."
12
- readme = "README.md"
13
- license = { file = "LICENSE.txt" }
14
- requires-python = ">=3.6"
15
- dependencies = [
16
- "requests>=2.31.0",
17
- "tenacity>=8.2.3",
18
- "pdf2image>=1.16.3",
19
- "python-dotenv>=1.0.0",
20
- "Pillow>=10.0.0",
21
- ]
22
- classifiers = [
23
- "Programming Language :: Python :: 3",
24
- "License :: OSI Approved :: MIT License",
25
- "Operating System :: OS Independent",
26
- ]
27
-
File without changes
File without changes