A Flask-based web application for conducting a data literacy study with contextualized visualizations and sentiment analysis.
- Python 3.11 or higher
- PostgreSQL database (local or remote, e.g., Supabase)
- Azure OpenAI API key (for contextualization features)
- pip (Python package manager)
-
Clone the repository (if applicable):
git clone <repository-url> cd quiz-platform
-
Create a virtual environment (recommended):
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
Create a .env file in the project root directory with the following variables:
# Flask Configuration
SECRET_KEY=your-secret-key-here
# PostgreSQL Database
POSTGRES_URL=postgresql://user:password@host:port/database
# Example for Supabase:
# POSTGRES_URL=postgresql://postgres:[YOUR-PASSWORD]@db.[PROJECT-REF].supabase.co:5432/postgres?sslmode=require
# Azure OpenAI API
AZURE_OPENAI_API_KEY=your-azure-openai-api-key-here-
SECRET_KEY: A random secret key for Flask session management. Generate one using:
import secrets print(secrets.token_hex(32))
-
POSTGRES_URL: Connection string for your PostgreSQL database. The application uses this to store logs and survey responses.
-
AZURE_OPENAI_API_KEY: API key for Azure OpenAI service, used for generating contextualized graph titles and axis labels.
SECRET_KEY=a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6
POSTGRES_URL=postgresql://postgres:mypassword@localhost:5432/quizdb
AZURE_OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-
Activate your virtual environment (if using one):
source venv/bin/activate # On Windows: venv\Scripts\activate
-
Initialize the database (first time only):
python3 -c "from app import init_db; init_db()" -
Run the Flask application:
python3 app.py
Or using Flask's development server:
export FLASK_APP=app.py export FLASK_ENV=development flask run
-
Access the application:
- Open your browser and navigate to
http://localhost:5000(or the port shown in the terminal)
- Open your browser and navigate to
The project includes Jupyter notebooks for data analysis and sentiment analysis.
-
Install Jupyter (if not already installed):
pip install jupyter
-
Start Jupyter Notebook:
jupyter notebook
-
Open
data_analysis.ipynb:- The notebook contains comprehensive data analysis including:
- Performance metrics (Phase 1, Phase 2, Phase 3)
- Survey analysis
- Sentiment analysis using RoBERTa model
- Make sure the data files are in the
data/directory:study_logs.csvsurvey_responses.csv
- The notebook contains comprehensive data analysis including:
The analysis notebook requires additional packages that are included in requirements.txt:
transformers(for RoBERTa sentiment analysis)torch(PyTorch for the ML model)scipy,seaborn,matplotlib(for statistical analysis and visualization)tqdm(for progress bars)
quiz-platform/
├── app.py # Main Flask application
├── viz_functions.py # Visualization helper functions
├── requirements.txt # Python dependencies
├── .env # Environment variables (create this)
├── README.md # This file
├── appendix.pdf # Supplementary material
│
├── data/ # Data files
│ ├── study_logs.csv # Study logs from database
│ ├── survey_responses.csv # Survey responses
│ ├── user_ids.csv # User identifiers
│ ├── open_responses_improved_users.csv # Generated for sentiment analysis
│ └── open_responses_no_improvement_users.csv # Generated for sentiment analysis
│
├── templates/ # HTML templates
│ ├── index.html
│ ├── consent.html
│ ├── question.html
│ ├── phase2_question.html
│ ├── survey_part1.html
│ ├── survey_part2.html
│ ├── survey_part3.html
│ └── ...
│
├── static/ # Static files
│ ├── style.css
│ └── screenshots/
│
├── output/ # Generated analysis plots
│ ├── transfer_4groups.png
│ ├── survey_cognitive_load.png
│ ├── avg_sentiment_scores.png
│ └── ...
│
└── data_analysis.ipynb # Main analysis notebook
- Multi-phase study design: Pretest (Phase 1), Learning phase (Phase 2), Posttest (Phase 3)
- Contextualization: AI-generated contextualized visualizations based on user interests
- Hints system: Optional hints during the learning phase
- Comprehensive logging: All user interactions are logged to PostgreSQL
- Survey integration: Multi-part survey with Likert scales and open-ended questions
- Data analysis: Statistical analysis and sentiment analysis of survey responses
The application uses two main tables:
-
logs: Stores all user actions and interactions
id,user_id,timestamp,action,details
-
survey_responses: Stores survey responses
id,user_id,timestamp,question_key,question_text,response,response_type
To export data from PostgreSQL to CSV for analysis:
-- Export logs
COPY (SELECT * FROM logs ORDER BY timestamp) TO '/path/to/data/study_logs.csv' WITH CSV HEADER;
-- Export survey responses
COPY (SELECT * FROM survey_responses ORDER BY timestamp) TO '/path/to/data/survey_responses.csv' WITH CSV HEADER;Or use a database client like pgAdmin or DBeaver to export the tables.
Supplementary material and additional details can be found in the Appendix.
- The application uses Flask sessions for user state management
- All timestamps are stored in UTC
- The sentiment analysis uses the
cardiffnlp/twitter-roberta-base-sentiment-latestmodel - Generated plots are saved in the
output/directory