CouncilDataProject / CouncilDataProject/cdp-data
Add a `dump_to_sqlite` function to the library
- Lenguaje dominante
- Jupyter Notebook
- Estrellas
- 5
- Forks
- 4
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
### Feature Description
Add a function to dump all data stored in a CDP Firestore database to a local `sqlite` file.
### Use Case
A lot more people know how to use SQL than our weird combination of Firestore + ORM in Python. And for tabular data (related to voting, legislation, people info, etc.), SQL is likely the best choice for quick and easy processing. There are also visualization engines that can read sqlite I believe??
### Solution
Add a function to the library (prototype fine for now) that takes in the CDP Instance name the user wants to create a CDP sqlite file for and the filepath / filename for where to dump the data to something like:
```python
def dump_to_sqlite(instance: str, path: Union[str, Path]):
```
That takes iteratively goes through each collection and requests data in batches from Firestore and writes in batches to the sqlite file.
### Notes
I assume the database models themselves should stay the same: [schema-diagram](https://councildataproject.org/cdp-backend/database_schema.html) & [model-docs](https://councildataproject.org/cdp-backend/cdp_backend.database.html#module-cdp_backend.database.models)
Since we use `FireO` for our "Firestore ORM" -- their docs on querying data (including batched) are likely important: https://octabyte.io/FireO/querying-data
An example of using the FireO models can be seen in [this notebook](https://github.com/CouncilDataProject/cdp-data/blob/main/notebooks/historical_vote_proportions.ipynb) or in our [source code](https://github.com/CouncilDataProject/cdp-data/blob/main/cdp_data/datasets.py#L338)
I say just use the [sqlite3](https://docs.python.org/3/library/sqlite3.html) library that ships with Python?
Guía de contribución
Línea de trabajo
Empieza con cdp_data/datasets.py y el ejemplo historical_vote_proportions.ipynb; después, revisa la documentación de consultas de FireO y la documentación enlazada del modelo de base de datos. Define cómo se asigna cada Collection a los modelos existentes y, a continuación, implementa dump_to_sqlite(instance, path) con lecturas y escrituras por lotes; se considera terminado cuando todos los datos de la instancia de CDP seleccionada estén presentes en el archivo SQLite local.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python, sqlite
- Área
- data, databases
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100