Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

startup tweaks and README additions #512

Merged
merged 27 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5a51fae
adds packages needed on installation
slhudson Oct 13, 2024
1ca2bf2
create package-lock.json
slhudson Oct 13, 2024
60f4f2c
moves the template .env file out of the README and into infra/
slhudson Oct 13, 2024
85934d3
rearranges README
slhudson Oct 13, 2024
1e74f17
relabel README sections
slhudson Oct 13, 2024
0481654
creates script to get API key and store it in .env
slhudson Oct 14, 2024
4220e6e
adds some whitespace to README for readability
slhudson Oct 14, 2024
2a46568
validates token based on length
slhudson Oct 14, 2024
a99ef81
removes package-lock.json
slhudson Oct 15, 2024
f9dacb9
adds .DS_store to .gitignore
slhudson Oct 15, 2024
98162f4
adds a script to create a user for local, offline use
slhudson Oct 15, 2024
8836bca
adds a script to create a user for local, offline use
slhudson Oct 15, 2024
61e81b1
README typo fixes
slhudson Oct 15, 2024
57ee579
removes get-api-key.sh from this branch
slhudson Oct 15, 2024
043f7cd
Merge branch 'chore/readme' of https://github.com/slhudson/rcvis into…
slhudson Oct 15, 2024
4527891
Merge branch 'chore/readme' of https://github.com/slhudson/rcvis into…
slhudson Oct 15, 2024
0dde313
Revert "Merge branch 'chore/readme' of https://github.com/slhudson/rc…
slhudson Oct 15, 2024
03d08b0
Update README.md
slhudson Oct 15, 2024
2d90495
Update infra/.env.template
slhudson Oct 15, 2024
98f4a1f
Update infra/.env.template
slhudson Oct 15, 2024
2e04f0c
remove HTML line breaks from README
slhudson Oct 15, 2024
364bb84
remove API parameters from .env.template
slhudson Oct 15, 2024
f9541e6
Update requirements-core.txt
slhudson Oct 15, 2024
f7b9f38
Remove recommendation to install postgresql
artoonie Oct 17, 2024
51e93ef
prompts the creation of an admin user in serve.sh
slhudson Oct 21, 2024
3ed9dec
improves serve.sh comments
slhudson Oct 21, 2024
d1da381
Update scripts/serve.sh
artoonie Nov 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ media/
static/CACHE/
node_modules/
staticfiles/
.DS_Store

# Elastic Beanstalk Files
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml

111 changes: 41 additions & 70 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ It has been published in the [Washington Post](https://www.washingtonpost.com/dc

While you may fork and run this code to run it locally, almost all users find it sufficient to upload data directly to RCVis.com.

<br>
slhudson marked this conversation as resolved.
Show resolved Hide resolved

# Ranked Choice Voting Visualization
Visualize the results of ranked-choice voting elections.

Expand All @@ -21,65 +23,35 @@ Visualize the results of ranked-choice voting elections.

Learn more on our Medium post: [An Illustrated Guide to Ranked-Choice Voting](https://medium.com/@armin.samii/an-illustrated-guide-to-ranked-choice-voting-4ce3c5fe73f9).

## Installation
Install `python3`, `virtualenv`, and `npm` with your favorite package manager, then run `./scripts/install.sh`.

Create a .env file with your secrets and configuration options:

```bash
export RCVIS_SECRET_KEY=''
export RCVIS_DEBUG=True
export RCVIS_HOST=localhost

# Either have OFFLINE_MODE=True
export OFFLINE_MODE=True

# The following fields are optional, though you will
# have limited functionality without them.
## Examples
Check out [rcvis.com](https://www.rcvis.com) for live examples, including:

# Or set up an AWS bucket and enter your credentials
# export OFFLINE_MODE=False
# export AWS_STORAGE_BUCKET_NAME=''
# export AWS_S3_REGION_NAME=''
# export AWS_ACCESS_KEY_ID=''
# export AWS_SECRET_ACCESS_KEY=''
| Barchart | Round-by-Round |
| --- | --- |
| ![Barchart](static/visualizer/icon_interactivebar.gif "Interactive Barchart") | ![Round-by-Round](static/visualizer/icon_interactiveroundbyround.gif "Round-by-Round") |

# To send registration emails when OFFLINE_MODE is False:
# export SENDGRID_USERNAME=''
# export SENDGRID_PASSWORD=''
| Sankey | Tabular Summary |
| --- | --- |
| ![Sankey](static/visualizer/icon_sankey.jpg "Sankey") | ![Tabular Summaries](static/visualizer/icon_singletable.png "Tabular Summaries") |

# To clear cloudflare cache when models update:
# export CLOUDFLARE_ZONE_ID=''
# export CLOUDFLARE_AUTH_TOKEN=''
## Embedding
RCVis implements the [oembed protocol](http://www.oembed.com) with discoverability, allowing you to embed files into your website with an iframe.

# To run the SauceLabs integration tests, you will need
export SAUCE_USERNAME=''
export SAUCE_ACCESS_KEY=''
<br>
slhudson marked this conversation as resolved.
Show resolved Hide resolved

# To generate videos (and to run movie tests), you will need:
export IMAGEIO_FFMPEG_EXE='/usr/bin/ffmpeg'
export SQS_QUEUE_NAME='default-queue'
# export MOVIE_FONT_NAME="Roboto"
# export AWS_POLLY_STORAGE_BUCKET_NAME="bucket-name-on-s3"
# Running RCVis Locally

# To subscribe users to mailchimp upon registration, you need:
# export MAILCHIMP_API_KEY=''
# export MAILCHIMP_LIST_ID=''
# export MAILCHIMP_DC=''
## Installation
Install `python3`, `virtualenv`, `npm`, and `postgresql` with your favorite package manager, then run `./scripts/install.sh`. This script will initalize a `.env` file in the root directory for your secrets and configuration. You will need to supply a secret key and local host IP address before proceeding.
artoonie marked this conversation as resolved.
Show resolved Hide resolved

# If you are updating a template, you'll need to clear the cache every time or set:
# export DISABLE_CACHE=True

```
## Running

To get moviepy working for Ubuntu 16.04 LTS users, comment out the following statement in `/etc/ImageMagick-6/policy.xml`:
```xml
<policy domain="path" rights="none" pattern="@*"/>
To upload data and generate visuals, you will need to create a local user with credentials from your `.env` file using:
artoonie marked this conversation as resolved.
Show resolved Hide resolved
```bash
./scripts/create-user.sh
```
or, simply run `sudo ./scripts/fix-moviepy-on-ubuntu-1604.sh`

## Running
To begin serving the website at localhost:8000:
You can then begin serving the website at localhost:8000:
```bash
./scripts/serve.sh
```
Expand All @@ -93,24 +65,8 @@ npm install # this works for me
python3 manage.py npminstall # this is purported to work but doesn't
```

To run workers to generate movies (optional - only needed to use the movie generation flow):
```bash
source .env
source venv/bin/activate
export DISPLAY=":0" # if not already set
celery -A rcvis worker --loglevel info
```

## Examples
Check out [rcvis.com](https://www.rcvis.com) for live examples, including:

| Barchart | Round-by-Round |
| --- | --- |
| ![Barchart](static/visualizer/icon_interactivebar.gif "Interactive Barchart") | ![Round-by-Round](static/visualizer/icon_interactiveroundbyround.gif "Round-by-Round") |

| Sankey | Tabular Summary |
| --- | --- |
| ![Sankey](static/visualizer/icon_sankey.jpg "Sankey") | ![Tabular Summaries](static/visualizer/icon_singletable.png "Tabular Summaries") |
## Test Data
Test data with election can be found in the `testData` directory.
slhudson marked this conversation as resolved.
Show resolved Hide resolved

## REST API
The primary API documentation is in the form of [example code](visualizer/tests/testRestApiExampleCode.py), which is documented line-by-line.
Expand All @@ -120,7 +76,7 @@ Addition documentation is available at [rcvis.com/api/](https://www.rcvis.com/ap
To get started with programmatic access to rcvis:

1. Create an account on RCVis
2. Email [email protected] to enable API access
2. Email [email protected] to request API access
3. Submit a POST request to [https://www.rcvis.com/api/auth/get-token](https://www.rcvis.com/api/auth/get-token) to obtain an API Key, e.g. `curl -X POST https://www.rcvis.com/api/auth/get-token -d username=yourUserName -d password=yourAmazingPassword`

With your API key, you may access two endpoints:
Expand All @@ -129,5 +85,20 @@ With your API key, you may access two endpoints:

For both endpoints, upload with POST and modify with PUT or PATCH. Authenticated users are limited to 1000 requests per hour.

## oembed
RCVis implements the [oembed protocol](http://www.oembed.com) with discoverability, allowing you to embed files into your website with an iframe.
<br>
slhudson marked this conversation as resolved.
Show resolved Hide resolved

## Movies

To get moviepy working for Ubuntu 16.04 LTS users, comment out the following statement in `/etc/ImageMagick-6/policy.xml`:
```xml
<policy domain="path" rights="none" pattern="@*"/>
```
or, simply run `sudo ./scripts/fix-moviepy-on-ubuntu-1604.sh`

To run workers to generate movies (optional - only needed to use the movie generation flow):
```bash
source .env
source venv/bin/activate
export DISPLAY=":0" # if not already set
celery -A rcvis worker --loglevel info
```
60 changes: 60 additions & 0 deletions infra/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
### The following fields must be provided to run RCVis locally and visualize results.

# a user-generated string
export RCVIS_SECRET_KEY=''

# set to True to enable debug mode
export RCVIS_DEBUG=True

# host IP address
export RCVIS_HOST=localhost

# toggle offline mode
export OFFLINE_MODE=True

# credentials for local user in offline mode
export OFFLINE_USERNAME=''
export OFFLINE_PASSWORD=''
artoonie marked this conversation as resolved.
Show resolved Hide resolved

### The following fields are optional, though you will have limited functionality without them.
### We should add some explanation here about what "limited functionality" means.
slhudson marked this conversation as resolved.
Show resolved Hide resolved

# authentication credentials for obtaining API key
export USERNAME='your_username'
export PASSWORD='your_password'
artoonie marked this conversation as resolved.
Show resolved Hide resolved

# API key
export API_KEY=''
artoonie marked this conversation as resolved.
Show resolved Hide resolved

# set up an AWS bucket when OFFLINE_MODE is False:
slhudson marked this conversation as resolved.
Show resolved Hide resolved
# export OFFLINE_MODE=False
# export AWS_STORAGE_BUCKET_NAME=''
# export AWS_S3_REGION_NAME=''
# export AWS_ACCESS_KEY_ID=''
# export AWS_SECRET_ACCESS_KEY=''

# To send registration emails when OFFLINE_MODE is False:
# export SENDGRID_USERNAME=''
# export SENDGRID_PASSWORD=''

# To clear cloudflare cache when models update:
# export CLOUDFLARE_ZONE_ID=''
# export CLOUDFLARE_AUTH_TOKEN=''

# To run the SauceLabs integration tests:
export SAUCE_USERNAME=''
export SAUCE_ACCESS_KEY=''

# To generate videos (and to run movie tests):
export IMAGEIO_FFMPEG_EXE='/usr/bin/ffmpeg'
export SQS_QUEUE_NAME='default-queue'
# export MOVIE_FONT_NAME="Roboto"
# export AWS_POLLY_STORAGE_BUCKET_NAME="bucket-name-on-s3"

# To subscribe users to mailchimp upon registration:
# export MAILCHIMP_API_KEY=''
# export MAILCHIMP_LIST_ID=''
# export MAILCHIMP_DC=''

# If you are updating a template, you'll need to clear the cache every time or set:
# export DISABLE_CACHE=True
3 changes: 2 additions & 1 deletion infra/requirements-core.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
boto3==1.17.100
boto3==1.26.0
botocore==1.29.0
artoonie marked this conversation as resolved.
Show resolved Hide resolved
csscompressor==0.9.5
django-admin-cursor-paginator==0.1.3
django-compressor==4.3.1
Expand Down
29 changes: 29 additions & 0 deletions scripts/create-user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
# Create or update a local server user using credentials from .env file

# Source the .env file to get the environment variables
source .env

# Activate the virtual environment
source venv/bin/activate

# Run the Django shell to create or update the user
python manage.py shell <<EOF
from django.contrib.auth.models import User

# Get the username and password from environment variables
username = '$OFFLINE_USERNAME'
password = '$OFFLINE_PASSWORD'

# Check if the user already exists
user, created = User.objects.get_or_create(username=username)
if created:
user.set_password(password)
user.email = username
user.save()
print(f"User {username} created successfully.")
else:
user.set_password(password)
user.save()
print(f"User {username} password updated successfully.")
EOF
14 changes: 14 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ pip3 install -r requirements.txt
# Install npm deps
npm i

# initialize .env
if [ -f .env ]; then
echo ""
echo ".env file already exists."
echo ""
else
# Copy the template to .env
cp infra/.env.template .env
echo ""
echo ".env file has been initialized from the template."
echo "Please modify the .env file to include the necessary values."
echo ""
fi

# Run migrations to set up db
source .env
python3 manage.py migrate