update: add more example for sqlite3 cli in docs

This commit is contained in:
Wataru Otsubo 2024-09-14 18:05:48 +09:00
parent c5c57acb4b
commit 367ccf75fc
2 changed files with 98 additions and 3 deletions

View file

@ -2,6 +2,11 @@
このリポジトリは、PS BoardのQAQC結果を主に管理するデータベースを扱ってる。
```@contents
Pages = ["index.md"]
Depth = 4
```
## データベースの特徴
現時点(2024-09-13)でQAQC試験は[Google Sheetsで作成したデータベース](https://docs.google.com/spreadsheets/d/128qOseOy4QDotehYe4Wf2jj88tnwiXGVdR3NHrjcDYU/edit)でデータが管理されているが、主にデータを統合して参照するときに手作業が多く必要となり、エラーが発生する問題があった。
@ -17,7 +22,7 @@
以下に使いやすいであろうライブラリ/パッケージを列挙する。[^3]
- [sqlite3(コマンドラインプログラム)](https://www.sqlite.org/cli.html): 公式の提供するCLI。どこでも動く。CSVでのエクスポートもできる。
- [DB Browser for SQLite](https://sqlitebrowser.org): クロスプラットフォームプレイなデスクトップアプリケーション。最も簡単。
- [DB Browser for SQLite](https://sqlitebrowser.org): クロスプラットフォームなデスクトップアプリケーション。最も簡単。
- [Python sqlite3](https://docs.python.org/ja/3/library/sqlite3.html): Pythonの標準ライブラリ。すなわち(C)Pythonが入ってるならたいてい入っている。
- [SQLite Viewer Web App](https://sqliteviewer.app/), [beta版](https://beta.sqliteviewer.app/psboard_qaqc.db/table/qaqc_runs): ブラウザで動く。最も手軽。
- [SQLite.jl](https://github.com/JuliaDatabases/SQLite.jl/tree/master): Juliaのパッケージ。[Tables.jl](https://github.com/JuliaData/Tables.jl)準拠なため、[DataFrame](https://github.com/JuliaData/DataFrames.jl)やCSVに/から変換できる。 _この実装で用いられている。_
@ -110,7 +115,78 @@ LIMIT 10;
59|24|2024-07-24T04:18:46|hashimoto||1|1|1|1|1|0|1|hashimoto|PPconfig_doneが 立っていないが1回
sqlite>
```
より複雑なものがVIEW qaqc_single_run_resultsとして用意されているので、`select * from qaqc_single_run_results;`をすれば結果が見れる。
り複雑なものが`VIEW qaqc_single_run_results`として用意されているので、`select * from qaqc_single_run_results;`をすれば結果が見れる。
### 特定のrunでテストしたPSBoard IDをすべて表示
90以上93以下のrunidで試験したPSBoardのIDをrunidとpsboard_idの昇順で表示する。
出力はCSVで行う。
```fish
$ bat src/sql/get_psbids_for_run.sql
───────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ File: src/sql/get_psbids_for_run.sql
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ WITH
2 │ single AS (
3 │ SELECT
4 │ qaqc_single_run_results.psboard_id,
5 │ qaqc_single_run_results.runid
6 │ FROM
7 │ qaqc_single_run_results
8 │ UNION
9 │ SELECT
10 │ qaqc_extra_run_results.psboard_id,
11 │ qaqc_extra_run_results.runid
12 │ FROM
13 │ qaqc_extra_run_results
14 │ )
15 │ SELECT *
16 │ FROM single
17 │ WHERE single.runid BETWEEN 90 AND 93
18 │ ORDER BY runid, psboard_id
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
$ sqlite3 psboard_qaqc.db < (echo ".headers on
.mode csv
.once test.csv
.read src/sql/get_psbids_for_run.sql" | psub)
$ cat test.csv
psboard_id,runid
44,90
62,90
74,90
103,90
127,90
132,90
137,90
149,90
160,90
164,90
196,90
204,90
270,90
280,90
305,90
322,90
335,90
356,90
44,93
62,93
74,93
103,93
127,93
132,93
137,93
149,93
160,93
164,93
196,93
204,93
270,93
280,93
305,93
322,93
335,93
356,93
```
### Juliaでの例
Juliaで試してみる。
@ -184,7 +260,7 @@ julia> DBInterface.execute(
10 │ 59 24 2024-07-24T04:18:46 hashimoto 1 1 1 1 1 0 1
2 columns omitted
```
特定のpositionの結果だけをまとめ、shifterごとの数を数える。
#### 特定のpositionの結果だけをまとめ、shifterごとの数を数える。
まずはパラメーターを埋め込んだクエリを用意(コンパイル)する。
```julia
julia> stmt = DBInterface.prepare(
@ -346,6 +422,7 @@ julia> combine(gdf, nrow)
13 │ kmaki 1
14 │ muzuochi 1
```
#### 8月以降かつ試験をパスしなかったものを表示
8月以降の結果を取得(データフレームを上書き)。
```julia
julia> filter!(:run_timestamp => >(Date(2024, 8)), df)

View file

@ -0,0 +1,18 @@
WITH
single AS (
SELECT
qaqc_single_run_results.psboard_id,
qaqc_single_run_results.runid
FROM
qaqc_single_run_results
UNION
SELECT
qaqc_extra_run_results.psboard_id,
qaqc_extra_run_results.runid
FROM
qaqc_extra_run_results
)
SELECT *
FROM single
WHERE single.runid BETWEEN 90 AND 93
ORDER BY runid, psboard_id