This script analyzes the performance of your photos on Unsplash. It fetches your photos, calculates performance scores, identifies outliers, filters them, normalizes the scores, and generates a visualization.
- Fetch Photos from Unsplash: Retrieves your photos using the Unsplash API.
- Calculate Performance Scores: Computes raw performance scores based on views per day and downloads per view.
- Identify Upper Bound Outliers: Uses the Interquartile Range (IQR) method to calculate the upper bound for outliers.
- Filter Upper Bound Outliers: Removes photos identified as upper bound outliers.
- Recalculate Min and Max Scores: Recalculates the minimum and maximum raw scores after removing outliers.
- Normalize Scores: Normalizes the scores of the remaining photos to a scale of 0 to 100.
- Output Results: Prints the normalized scores, generates a bar chart, and optionally saves the results to a JSON file.
- Python 3.x
requests
librarynumpy
librarymatplotlib
library
You can install the required libraries using pip:
pip install requests numpy matplotlib
-
Unsplash API Access Key: You need an Unsplash API access key. You can get it by registering as a developer on the Unsplash website.
-
Environment Variables: Set the
UNSPLASH_ACCESS_KEY
andUNSPLASH_USERNAME
environment variables with your Unsplash access key and username.
Add the following lines to your .bashrc
or .bash_profile
:
export UNSPLASH_ACCESS_KEY='your_unsplash_access_key'
export UNSPLASH_USERNAME='your_unsplash_username'
Then, source the file to apply the changes:
source ~/.bashrc # or source ~/.bash_profile
Set the environment variables using the command line or through the System Properties dialog:
setx UNSPLASH_ACCESS_KEY "your_unsplash_access_key"
setx UNSPLASH_USERNAME "your_unsplash_username"
Run the script using Python:
python uppa.py
The script will:
- Check if
photos.json
exists. If it does, it will load photos from the file. - If
photos.json
does not exist, it will fetch photos from Unsplash, save them tophotos.json
, and proceed. - Calculate raw performance scores for each photo.
- Filter out photos with fewer than 30 days online.
- Identify and filter out upper bound outliers.
- Recalculate min and max scores and normalize the scores to a range of 0 to 100.
- Sort the photos by their normalized scores and print the results.
- Generate a bar chart showing the normalized scores of the photos.
Photo URL: https://unsplash.com/photos/abc123, Days Online: 45, Views: 1200, Downloads: 150, Normalized Score: 92.50
Photo URL: https://unsplash.com/photos/def456, Days Online: 60, Views: 1500, Downloads: 180, Normalized Score: 85.30
...
A bar chart will also be displayed, visualizing the normalized scores of your photos.