https://github.com/dataforgoodfr/12_pinkbombs
https://github.com/dataforgoodfr/12_pinkbombs
Last synced: 6 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/dataforgoodfr/12_pinkbombs
- Owner: dataforgoodfr
- License: mit
- Created: 2024-02-02T15:55:12.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-24T09:55:42.000Z (almost 2 years ago)
- Last Synced: 2024-04-24T10:06:55.547Z (almost 2 years ago)
- Language: HTML
- Size: 16.8 MB
- Stars: 1
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Pinkbombs
================
This repository contains the pyhton code needed to generate the figure for the [Pinkbombs website](https://www.pinkbombs.org).
# Contributing
## Use Poetry
[Install Poetry](https://python-poetry.org/docs/):
python3 -m pip install "poetry==1.4.0"
Install dependencies:
poetry install
Add a dependency:
poetry add pandas
Update dependencies:
poetry update
## Use a venv
python3 -m venv name-of-your-venv
source name-of-your-venv/bin/activate
## To launch pre-commits locally
[Install precommit](https://pre-commit.com/)
pre-commit run --all-files
## Test the code with Tox
tox -vv
# How to
## Generate the graphs and maps
Activate your virtual environment:
source name-of-your-venv/bin/activate
Run the generation script:
python pinkbombs/generate.py
The graphs and maps will be added to the `data` directory. They are separated by type (`graphs`and `maps`) and by language (`fr`and `en`):
data
├── graphs
│ ├── en
│ └── fr
└── maps
├── en
└── fr
Copy these to the [Pinkbombs webapp reppository](https://github.com/dataforgoodfr/12_pinkbombs_app) in the `public/dashboard/` directory.
**NOTE**: This is a temporary feature, when the images are moved to S3, a workflow will do this automatically upon merge.
## Adding a new visualization
To add a new graph or map, add a function that generates the visualization in the `pinkbombs/graphs/viz.py` or `pinkbombs/graphs/maps_viz.py` files respectively.
**The function NEEDS to return a Plotly Figure object for graphs or an html string for maps**
Make sure that the function is the import in the `__init__.py` file in the graphs directory:
from .viz import my_viz_function
from .maps_viz import my_map_viz_function
The maps needs to the be added to the `config.py` file in order to have it automatically generated. Add the function to the correct section:
MAPPING --> graphs/en
MAPPINGFR --> graphs/fr
MAPS --> maps/en
MAPSFR --> maps/fr
__Be sure to add to both the french and english section.__
The function needs to be added in the following dictionary entry format:
"visualisation-id": {
"filename": "source-data.csv",
"function": pb.my_viz_function,
"parser": pd.read_csv, # or pd.read_excel for example
"arguments": [ # add all the arguments in an ordered list
"arg1",
"arg2",
"arg3",
True,
0
],
},
Do not skip any argument to the function as these need to be in the correct order.
## Temporary Python scripts for testing locally
To run the plotly graphs locally and generate html files you can view in your browser, you can use the script:
python3 pinkbombs/graphs/test_graphs.py
Note that the changes to the html files in this folder won't be included in git as the folder `pinkbombs/graphs/test_html/` is included in `.gitignore`.
To translate the data and zip the csv files for download, run locally:
python3 pinkbombs/graphs/translate_data.py
python3 pinkbombs/graphs/zip_data.py
Note that this will regenerate all files and may not be adapted