Currently, Topics are managed via the Rails Console and some Rake tasks. Below are steps for setting up a new Topic and preparing data for analysis. If not running locally, the following assumes you have SSH access to the server and your public SSH key is appropriately installed on the server.
- If running locally: run
rails console
from project directory. - If setup for local development, but running on remote server:
cap rails:console
. - If NOT setup locally, but running on remote server:
- SSH into server
- Navigate into current within project directory. Example:
cd /var/www/impact-visualizer/current
RAILS_ENV=production bundle exec rails console
Topic.create(
name: 'Topic Name',
slug: 'topic_name',
description: 'Brief description of topic',
editor_label: 'participant',
start_date: Date.new(2022, 1, 1),
end_date: Date.new(2022, 12, 31),
timepoint_day_interval: 365,
wiki_id: 1,
display: true
)
name
: The topic's name. Spaces OK. Should be title cased.slug
: A URL-safe version of the Topic's name.description
: A description of the Topic and participant group.editor_label
: A lowercase word to describe the users whose activity will be visualized. "participant" is the default.start_date
: a Ruby Date object representing the start of the analysis period.end_date
: a Ruby Date object representing the end of the analysis period.timepoint_day_interval
: the number of days between analysis timepoints (between the start and end dates). An interval of 30, for example, would roughly lead to monthly analysis snapshots. Typically, the longer the topic's timeframe, the higher this number should be (for both visualization and analysis speed reasons).wiki_id
: The ID of the associated Wiki version. RunWiki.all
to see all available options.display
: a boolean switch to determine whether or not the Topic will be displayed on homepage of visualizer. Should be left asfalse
until topic's data is ready to be displayed.
You can edit the topic in the Rails console like so:
topic = Topic.find_by(slug: 'topic_name')
topic.update(editor_label: 'editor')
Two CSV files are required for the importing of Topic data, one for Articles and another for Users. They should be prepared as follows. See csv/topic-articles-example.csv and csv/topic-users-example.csv for example files.
- CSV files should be named using the following pattern:
topic-articles-topic_slug.csv
where "topic_slug" is the Topic's slug.topic-users-topic_slug.csv
where "topic_slug" is the Topic's slug.
- CSV files should contain Article titles (example: "California red-legged frog" OR User screen names (example: "MattFordham"). Each entry should be on its own line/row. Only the 1 column should be present. If User names or Article titles contain commas, the name/title must be wrapped in double quotes. There should be no commas outside of quoted text.
- If running locally, the CSV files should be placed within the db/csv/ directory, alongside the aforementioned example files. If running on server, the files should be placed in the project's "shared/db/csv" directory, which will likely be somewhere like /var/www/impact-visualizer/shared/db/csv.
With the CSV files in place, you can now run the import script.
rake import_topic topic_slug
where "topic_slug" is the Topic's slug.
As this import script will fetch information about each Article and User it can take a long time. Given this, it is recommended that the script be run within a tool like tmux, which will allow you to disconnect from the server and leave the script running. You can log back in a later time to check progress or results.
- SSH into server
- Run
tmux
to start a new tmux session ORtmux a
to attach to an existing tmux session. - Within a tmux session, navigate into current within project directory. Example: cd /var/www/impact-visualizer/current
- Run
RAILS_ENV=production rake import_topic topic_slug
- Optional: while the above command is running, detach from the tmux session using the key command Ctrl+B then D. You can now safely close the SSH connection to the server and return (and reattach to tmux session) at a later time.
After you have both created a Topic via rails console
and imported associated articles and users via rake import_topic topic_slug
, you are now ready to "generate timepoints" which is the process of preparing and analyzing the data needed for visualization. To do this, there is another Rake task/script.
rake generate_timepoints topic_slug
where "topic_slug" is the Topic's slug.
The note above about the usage of tmux also applies here, perhaps even more so, depending on the specifics of your Topic. Use tmux!
- SSH into server
- Run
tmux
to start a new tmux session ORtmux a
to attach to an existing tmux session. - Within a tmux session, navigate into current within project directory. Example: cd /var/www/impact-visualizer/current
- Run
RAILS_ENV=production rake generate_timepoints topic_slug
- Optional: while the above command is running, detach from the tmux session using the key command Ctrl+B then D. You can now safely close the SSH connection to the server and return (and reattach to tmux session) at a later time.
After the initial timepoint generation for a Topic has taken place, you may safely run the same generate_timepoints
script again to capture additional data (perhaps because the timeframe has changed or new articles have been added). Running the script again, as specified above, will generally NOT cause analysis of existing articles to take place again. Because of this, subsequent runs will be much faster.
If you would like to force existing analysis to be recomputed, you may force updates by adding "true" to the end of the command, such as this:
rake generate_timepoints topic_slug true
- Ruby 3.2.2
- Node 18.17.1
- Postgres
- Ruby Gems and Bundler for managing Ruby dependencies
- Yarn for managing Node dependencies
bundle install
yarn install
- Create the following Postgres databases:
- impact-visualizer-development
- impact-visualizer-test
rake db:create
rake db:migrate
rails server
vite dev
(in a 2nd terminal window/pane)- The project http://localhost:3000
rspec
(tests are located in /spec directory)
In the project's root directory, create a .env.local
file following the format of the .env.example
file
In the project's root directory, create a .env.production
file following the format of the .env.example
file
- Ensure server has your public SSH key
- Server will pull from production branch, so:
git push production
cap production deploy
In addition to deploying the latest code, the above deploy command will run any pending Rails migrations and will also compile front-end resources. To learn more about other, more granular, Capistrano commands see their documentation.
- Setup new Debian server
- Add SSH key to server
- Install Ruby and Bundler using RVM
- Install Node
- Install Git and add server key to Github
- Install Postgres and create db: impact-visualizer-production
- Create project directory at
/var/www/impact-visualizer
- Install and configure NGINX and Passenger
- Locally, run
cap production deploy
to deploy code