CodeYourFuture / CodeYourFuture/trainee-tracker

Migrate sheets reading to use serde

Aperta
#39 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Rust
Stelle
0
Fork
0
Merge medio
20m
PR unite (30g)
2

Descrizione

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,
}
```

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia confrontando i percorsi di lettura dei fogli in src/prs.rs, src/reviewer_staff_info.rs e src/register.rs, quindi esamina il comportamento di serde_sheets collegato nell’issue. Definisci se migliorare serde_sheets o creare un adattatore, includendo il modo in cui vengono rappresentati le intestazioni, le righe parziali e gli errori di deserializzazione. Il lavoro è completato quando le struct rilevanti possono essere lette dai fogli senza l’attuale gestione manuale dei campi e gli errori vengono restituiti invece di essere stampati e ignorati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
rust
Ambito
data-engineering
Tipo di issue
Refactoring
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.