|
|
@ -36,15 +36,15 @@ module JupyterService
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _open_game_jupyter(game)
|
|
|
|
def _open_game_jupyter(myshixun)
|
|
|
|
## 打开tpi
|
|
|
|
## 打开tpi
|
|
|
|
shixun = game.myshixun.shixun
|
|
|
|
shixun = myshixun.shixun
|
|
|
|
|
|
|
|
|
|
|
|
if shixun.is_jupyter?
|
|
|
|
if shixun.is_jupyter?
|
|
|
|
shixun_tomcat = edu_setting('cloud_bridge')
|
|
|
|
shixun_tomcat = edu_setting('cloud_bridge')
|
|
|
|
uri = "#{shixun_tomcat}/bridge/jupyter/get"
|
|
|
|
uri = "#{shixun_tomcat}/bridge/jupyter/get"
|
|
|
|
|
|
|
|
|
|
|
|
tpiID = game.myshixun.id
|
|
|
|
tpiID = myshixun.id
|
|
|
|
params = {tpiID: tpiID, :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(shixun))}"}
|
|
|
|
params = {tpiID: tpiID, :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(shixun))}"}
|
|
|
|
res = uri_post uri, params
|
|
|
|
res = uri_post uri, params
|
|
|
|
|
|
|
|
|
|
|
@ -56,20 +56,20 @@ module JupyterService
|
|
|
|
|
|
|
|
|
|
|
|
@game_jupyter_port = res['port']
|
|
|
|
@game_jupyter_port = res['port']
|
|
|
|
|
|
|
|
|
|
|
|
repo_save_path = game.myshixun.repo_save_path
|
|
|
|
repo_save_path = myshixun.repo_save_path
|
|
|
|
|
|
|
|
|
|
|
|
"https://#{res['port']}.jupyter.educoder.net/notebooks/data/workspace/myshixun_#{tpiID}/#{repo_save_path}/01.ipynb"
|
|
|
|
"https://#{res['port']}.jupyter.educoder.net/notebooks/data/workspace/myshixun_#{tpiID}/#{repo_save_path}/01.ipynb"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def jupyter_url_with_game(game)
|
|
|
|
def jupyter_url_with_game(myshixun)
|
|
|
|
_open_game_jupyter(game)
|
|
|
|
_open_game_jupyter(myshixun)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def jupyter_port_with_game(game)
|
|
|
|
def jupyter_port_with_game(myshixun)
|
|
|
|
if @game_jupyter_port.to_i <=0
|
|
|
|
if @game_jupyter_port.to_i <=0
|
|
|
|
_open_game_jupyter(shixun)
|
|
|
|
_open_game_jupyter(myshixun)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@game_jupyter_port
|
|
|
|
@game_jupyter_port
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -82,11 +82,11 @@ module JupyterService
|
|
|
|
tpiID = "tpm#{shixun.id}"
|
|
|
|
tpiID = "tpm#{shixun.id}"
|
|
|
|
|
|
|
|
|
|
|
|
#https://47526.jupyter.educoder.net/nbconvert/notebook/data/workspace/myshixun_570461/f2ef5p798r20191210163135/01.ipynb?download=true
|
|
|
|
#https://47526.jupyter.educoder.net/nbconvert/notebook/data/workspace/myshixun_570461/f2ef5p798r20191210163135/01.ipynb?download=true
|
|
|
|
src_url = URI("https://#{jupyter_port}.jupyter.educoder.net/nbconvert/notebook/data/workspace/myshixun_#{tpiID}/01.ipynb?download=true")
|
|
|
|
src_url = "https://#{jupyter_port}.jupyter.educoder.net/nbconvert/notebook/data/workspace/myshixun_#{tpiID}/01.ipynb?download=true"
|
|
|
|
response = Net::HTTP.get_response(src_url)
|
|
|
|
response = Faraday.get(src_url)
|
|
|
|
|
|
|
|
|
|
|
|
if response.code.to_i != 200
|
|
|
|
if response.status.to_i != 200
|
|
|
|
raise("获取文件内容失败:#{response.code}")
|
|
|
|
raise("获取文件内容失败:#{response.status}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
content = response.body
|
|
|
|
content = response.body
|
|
|
@ -101,25 +101,25 @@ module JupyterService
|
|
|
|
return c.size
|
|
|
|
return c.size
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def jupyter_save_with_game(game,jupyter_port)
|
|
|
|
def jupyter_save_with_game(myshixun,jupyter_port)
|
|
|
|
author_name = current_user.real_name
|
|
|
|
author_name = current_user.real_name
|
|
|
|
author_email = current_user.git_mail
|
|
|
|
author_email = current_user.git_mail
|
|
|
|
message = "User submitted"
|
|
|
|
message = "User submitted"
|
|
|
|
|
|
|
|
|
|
|
|
tpiID = game.myshixun.id
|
|
|
|
tpiID = myshixun.id
|
|
|
|
|
|
|
|
|
|
|
|
repo_save_path = game.myshixun.repo_save_path
|
|
|
|
repo_save_path = myshixun.repo_save_path
|
|
|
|
|
|
|
|
|
|
|
|
src_url = URI("https://#{jupyter_port}.jupyter.educoder.net/nbconvert/notebook/data/workspace/myshixun_#{tpiID}/#{repo_save_path}/01.ipynb?download=true")
|
|
|
|
src_url = "https://#{jupyter_port}.jupyter.educoder.net/nbconvert/notebook/data/workspace/myshixun_#{tpiID}/#{repo_save_path}/01.ipynb?download=true"
|
|
|
|
response = Net::HTTP.get_response(src_url)
|
|
|
|
response = Faraday.get(src_url)
|
|
|
|
|
|
|
|
|
|
|
|
if response.code.to_i != 200
|
|
|
|
if response.status.to_i != 200
|
|
|
|
raise("获取文件内容失败:#{response.code}")
|
|
|
|
raise("获取文件内容失败:#{response.status}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
content = response.body
|
|
|
|
content = response.body
|
|
|
|
|
|
|
|
|
|
|
|
c = GitService.update_file(repo_path: game.myshixun.repo_path,
|
|
|
|
c = GitService.update_file(repo_path: myshixun.repo_path,
|
|
|
|
file_path: "01.ipynb",
|
|
|
|
file_path: "01.ipynb",
|
|
|
|
message: message,
|
|
|
|
message: message,
|
|
|
|
content: content,
|
|
|
|
content: content,
|
|
|
|