Skip to content

[feat][doc] Add JavaScript analysis tutorial & add some extensions to be installed when in codespaces #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
{
"image": "ghcr.io/lonrun/codefuse-query-tutorial:0.5",
"hostRequirements": {
"cpus": 4
"cpus": 4
},
"customizations": {
"codespaces": {
"openFiles": ["tutorial/README.md"]
}
"codespaces": {
"openFiles": [
"tutorial/README.md"
]
},
// Configure properties specific to VS Code.
"vscode": {
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-toolsai.jupyter",
"MS-CEINTL.vscode-language-pack-zh-hans",
"CodeFuse-Query.codefuse-query-extension"
]
}
}
}
}
82 changes: 77 additions & 5 deletions tutorial/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,85 @@
## CodeQuery使用教程
## CodeFuse-Query使用教程

### 使用Github Codespaces 来体验CodeQuery分析能力
### 使用Github Codespaces 来体验CodeFuse-Query分析能力

### Jupyter kernel for CodeFuse-query 介绍

Jupyter kernel for CodeFuse-query 是 Jupyter 的一个特定内核,它为 Jupyter 环境提供了与 CodeFuse-query 相关的交互式功能。该内核允许用户在 Jupyter Notebook 中编写和执行 Godel 脚本,用于抽取、查询代码数据。此外,它还支持编写 Python 代码,以便对查询到的数据进行更深入的数据可视化和数据后处理操作。这里我们使用这个内核编写 Jupyter Notebook,用来进行 CodeFuse-Query 教程的学习和实践。

#### 步骤

- 在项目主页切换到目标分支
- 创建 Codespaces,依次点击 Code -> Codespaces,在当前分支创建一个 Codespaces
- 创建后,打开该 Codespaces,加载完成后,切换至项目 tutorial/notebook 目录下
- 选择示例下的 jupyter notebook 分析教程,即可开始体验
- 选择示例下的 Jupyter Notebook 分析教程,即可开始体验

#### 注意
- 打开jupyter页面之后,如果是第一次加载容器,你还需要配置教程所使用的内核,在右上角 “选择内核”弹出框中,依次选择 “Juypter Kernel...” -> “Godel Kernel” 即可。

在打开 Jupyter 页面之后,如果是第一次加载容器,你还需要配置教程所使用的 `Jupyter kernel for CodeFuse-query`。在右上角的 "选择内核" 弹出框中,依次选择 "Jupyter Kernel..." -> "Godel Kernel"。

#### Kernel 用法
##### 设置要查询的 COREF database

使用 `%db /path/to/db` 魔法命令来设置COREF db路径,内核会读取这个值来进行query查询,比如:

```bash
%db ./db
```

> tips: 还可以用`!`来运行一些有用的bash命令,比如查看Sparrow CLI是否存在:

```rust
!which sparrow
```

##### Godel 查询

设置好db路径后可以直接写Godel脚本,Jupyter kernel会创建临时文件来保存当前运行的Godel脚本并调用`sparrow query run`命令来进行查询,结果返回以HTML格式显示:


```rust
// Write your query and run in the notebook
// ...
```


`%db` 魔法命令可以写在 Godel 脚本的第一行:


```rust
%db ./db
// Write your query and run in the notebook
// ...
```


可以通过 `%%save_to` cell魔法命令保存**上一次运行成功**的 query 结果到一个JSON文件,具体用法:
```bash
%%save_to PATH - save the query result to a JSON file.

This cell magic will save the Sparrow query result to a file.

Example:
%%save_to /path/to/file.json
```

比如:
```bash
%%save_to ./query.json
```

##### 运行 Python 代码

可以通过 `%%python` 或者 `%python` 来运行 Python 代码,比如:

```python
%%python
import pandas as pd
data = pd.read_json('./query.json')
data.sort_values('cmplx', ascending=False, inplace=True)
top_10 = data.head(10)
print(top_10)
```

```python
%python print('hello')
```
Loading