mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-22 22:07:10 +00:00
+41
-1
@@ -1 +1,41 @@
|
|||||||
# DataRush Docs
|
# Website
|
||||||
|
|
||||||
|
This website is built using [Docusaurus](https://docusaurus.io/), a modern static website generator.
|
||||||
|
|
||||||
|
### Installation
|
||||||
|
|
||||||
|
```
|
||||||
|
$ yarn
|
||||||
|
```
|
||||||
|
|
||||||
|
### Local Development
|
||||||
|
|
||||||
|
```
|
||||||
|
$ yarn start
|
||||||
|
```
|
||||||
|
|
||||||
|
This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.
|
||||||
|
|
||||||
|
### Build
|
||||||
|
|
||||||
|
```
|
||||||
|
$ yarn build
|
||||||
|
```
|
||||||
|
|
||||||
|
This command generates static content into the `build` directory and can be served using any static contents hosting service.
|
||||||
|
|
||||||
|
### Deployment
|
||||||
|
|
||||||
|
Using SSH:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ USE_SSH=true yarn deploy
|
||||||
|
```
|
||||||
|
|
||||||
|
Not using SSH:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ GIT_USER=<Your GitHub username> yarn deploy
|
||||||
|
```
|
||||||
|
|
||||||
|
If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.
|
||||||
|
|||||||
@@ -47,9 +47,6 @@ class Competition(BaseModel):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
@property
|
|
||||||
def
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = "соревнование"
|
verbose_name = "соревнование"
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ ALLOWED_MODULES = {
|
|||||||
"csv",
|
"csv",
|
||||||
"math",
|
"math",
|
||||||
"statistics",
|
"statistics",
|
||||||
"statsmodels",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -64,28 +63,18 @@ def validate_code(code_str):
|
|||||||
raise SecurityException(f"Security check failed: {e!s}")
|
raise SecurityException(f"Security check failed: {e!s}")
|
||||||
|
|
||||||
|
|
||||||
def secure_exec(code_str, result_path, input_files=None):
|
def secure_exec(code_str, result_path):
|
||||||
original_dir = os.getcwd()
|
original_dir = os.getcwd()
|
||||||
original_stdout = sys.stdout
|
original_stdout = sys.stdout
|
||||||
sys.stdout = captured_stdout = StringIO()
|
sys.stdout = captured_stdout = StringIO()
|
||||||
result_content = None
|
result_content = None
|
||||||
|
|
||||||
if input_files is None:
|
|
||||||
input_files = []
|
|
||||||
|
|
||||||
with tempfile.TemporaryDirectory() as temp_dir:
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
try:
|
try:
|
||||||
os.chdir(temp_dir)
|
os.chdir(temp_dir)
|
||||||
|
|
||||||
for file in input_files:
|
|
||||||
file_path = os.path.join(temp_dir, file["bind_at"])
|
|
||||||
os.makedirs(os.path.dirname(file_path), exist_ok=True)
|
|
||||||
with open(file_path, "wb") as f:
|
|
||||||
f.write(file["content"])
|
|
||||||
|
|
||||||
restricted_globals = {
|
restricted_globals = {
|
||||||
"__builtins__": {
|
"__builtins__": {
|
||||||
"open": open,
|
"open": lambda f, *a, **kw: open(f, *a, **kw),
|
||||||
"print": print,
|
"print": print,
|
||||||
"str": str,
|
"str": str,
|
||||||
"int": int,
|
"int": int,
|
||||||
@@ -116,15 +105,11 @@ def secure_exec(code_str, result_path, input_files=None):
|
|||||||
|
|
||||||
|
|
||||||
@app.task(bind=True)
|
@app.task(bind=True)
|
||||||
def analyze_data_task(
|
def analyze_data_task(self, code_str, result_path, expected_bytes):
|
||||||
self, code_str, result_path, expected_bytes, input_files=[]
|
|
||||||
):
|
|
||||||
try:
|
try:
|
||||||
validate_code(code_str)
|
validate_code(code_str)
|
||||||
|
|
||||||
result_content = secure_exec(code_str, result_path, input_files)
|
result_content = secure_exec(code_str, result_path)
|
||||||
|
|
||||||
print(result_content * 1024)
|
|
||||||
|
|
||||||
result_hash = hashlib.sha256(result_content).hexdigest()
|
result_hash = hashlib.sha256(result_content).hexdigest()
|
||||||
expected_hash = hashlib.sha256(expected_bytes).hexdigest()
|
expected_hash = hashlib.sha256(expected_bytes).hexdigest()
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
import unittest
|
|
||||||
|
|
||||||
from apps.task.tasks import analyze_data_task
|
|
||||||
|
|
||||||
|
|
||||||
class TestAnalyzeDataTask(unittest.TestCase):
|
|
||||||
def test_task_execution_basic(self):
|
|
||||||
code_str = 'print("Hello, World!")'
|
|
||||||
result_path = "stdout"
|
|
||||||
expected_bytes = b"Hello, World!\n"
|
|
||||||
result = analyze_data_task(code_str, result_path, expected_bytes)
|
|
||||||
self.assertTrue(result["success"])
|
|
||||||
self.assertTrue(result["match"])
|
|
||||||
|
|
||||||
def test_task_execution_with_files(self):
|
|
||||||
code_str = """
|
|
||||||
with open("file.txt") as f:
|
|
||||||
print(f.read())
|
|
||||||
"""
|
|
||||||
result_path = "stdout"
|
|
||||||
expected_bytes = b"some_content\n"
|
|
||||||
result = analyze_data_task(
|
|
||||||
code_str,
|
|
||||||
result_path,
|
|
||||||
expected_bytes,
|
|
||||||
input_files=[{"bind_at": "file.txt", "content": b"some_content"}],
|
|
||||||
)
|
|
||||||
print(result)
|
|
||||||
self.assertTrue(result["success"])
|
|
||||||
self.assertTrue(result["match"])
|
|
||||||
Reference in New Issue
Block a user