CodeYourFuture / CodeYourFuture/trainee-tracker
Migrate sheets reading to use serde
- 主要言語
- Rust
- スター
- 0
- フォーク
- 0
- 平均マージ
- 20分
- マージ済み PR(30日)
- 2
説明
We have a bunch of structs which we fill from Google Sheets, one per row, e.g.
https://github.com/CodeYourFuture/trainee-tracker/blob/aa0d5787598ab8191f6429b6858f3b62dd2a6f9f/src/prs.rs#L217-L224
We currently do this in an annoyingly manual and inflexible way.
For this particular struct, we populate it here:
https://github.com/CodeYourFuture/trainee-tracker/blob/aa0d5787598ab8191f6429b6858f3b62dd2a6f9f/src/reviewer_staff_info.rs#L48-L79
We ignore the headings completely, so if someone changed the sheet, we would start reading incorrect values. Then we hard-code the field order and types of each cell.
In other places, we manually check headings, and just error if they're wrong: https://github.com/CodeYourFuture/trainee-tracker/blob/aa0d5787598ab8191f6429b6858f3b62dd2a6f9f/src/register.rs#L105-L160
We also handle partial rows poorly.
I would love instead for us to just use `serde`. We could derive `Deserialize` for each struct we populate, and use a `serde` adaptor to read the sheet into a `Vec`.
There is an existing [`serde_sheets` crate](https://crates.io/crates/serde_sheets) for doing this, but it has some issues. If it runs into issues with a row, it just prints an error to stdout and continues (https://docs.rs/serde_sheets/latest/src/serde_sheets/lib.rs.html#200).
Ideally we would either improve this crate, or write our own one. I'm imagining supporting a function along the lines of:
```rust
pub async fn read_all(
sheets: &mut Sheets,
document_id: &str,
tab_name: &str,
) -> SheetReadResult;
enum SheetReadResult {
AllOk(Vec),
SomeOk {
ok: Vec,
partial_records: Vec,
deserialization_error_records: Vec<(Record, serde::Error)>,
},
Err(SheetsError),
}
struct Record {
row_number: usize,
cells: Vec,
}
```
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
調査の方向性
まず src/prs.rs、src/reviewer_staff_info.rs、src/register.rs のシート読み取りパスを比較し、次に issue でリンクされている serde_sheets の動作を調査します。serde_sheets を改善するのか、アダプターを構築するのかを、ヘッダー、部分的な行、デシリアライズエラーをどのように表現するかも含めて決定します。関連する struct を現在の手動フィールド処理なしでシートから読み取ることができ、エラーが出力されて無視されるのではなく返されることを完了条件とします。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- rust
- 領域
- data-engineering
- issue の種類
- リファクタリング
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100