CodeYourFuture / CodeYourFuture/trainee-tracker

Migrate sheets reading to use serde

Abierto
#39 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Rust
Estrellas
0
Forks
0
Merge medio
20 min
PR fusionados (30 d)
2

Descripción

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

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Empieza comparando las rutas de lectura de hojas en src/prs.rs, src/reviewer_staff_info.rs y src/register.rs, y luego inspecciona el comportamiento de serde_sheets enlazado en el issue. Define si se debe mejorar serde_sheets o crear un adaptador, incluyendo cómo se representan los encabezados, las filas parciales y los errores de deserialización. Se considera terminado cuando los structs relevantes se pueden leer de las hojas sin el manejo manual actual de los campos y los errores se devuelven en lugar de imprimirse e ignorarse.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
rust
Área
data-engineering
Tipo de issue
Refactorización
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.