Browse Source

Added Vim folds to models.py and utils.py

master
Kevin Mok 7 years ago
parent
commit
e07fd0965a
  1. 13
      spotifyvis/models.py
  2. 22
      spotifyvis/utils.py
  3. 4
      spotifyvis/views.py

13
spotifyvis/models.py

@ -1,5 +1,7 @@
from django.db import models
# Artist {{{ #
class Artist(models.Model):
class Meta:
@ -14,6 +16,9 @@ class Artist(models.Model):
def __str__(self):
return self.name
# }}} Artist #
# User {{{ #
class User(models.Model):
@ -27,6 +32,9 @@ class User(models.Model):
def __str__(self):
return self.username
# }}} User #
# Track {{{ #
class Track(models.Model):
@ -46,6 +54,9 @@ class Track(models.Model):
def __str__(self):
return self.name
# }}} Track #
# AudioFeatures {{{ #
class AudioFeatures(models.Model):
@ -66,4 +77,4 @@ class AudioFeatures(models.Model):
def __str__(self):
return super(AudioFeatures, self).__str__()
# }}} AudioFeatures #

22
spotifyvis/utils.py

@ -1,6 +1,11 @@
# imports {{{ #
import requests
import math
import pprint
from models import *
# }}} imports #
# parse_library {{{ #
@ -44,6 +49,8 @@ def parse_library(headers, tracks, library_stats):
# }}} parse_library #
# get_audio_features {{{ #
def get_audio_features(headers, track_id):
"""Returns the audio features of a soundtrack
@ -71,6 +78,9 @@ def get_audio_features(headers, track_id):
return features_dict
# }}} get_audio_features #
# update_std_dev {{{ #
def update_std_dev(cur_mean, cur_std_dev, new_data_point, sample_size):
"""Calculates the standard deviation for a sample without storing all data points
@ -94,6 +104,9 @@ def update_std_dev(cur_mean, cur_std_dev, new_data_point, sample_size):
))
return new_mean, new_std_dev
# }}} update_std_dev #
# update_audio_feature_stats {{{ #
def update_audio_feature_stats(feature, new_data_point, sample_size, library_stats):
"""Updates the audio feature statistics in library_stats
@ -124,6 +137,7 @@ def update_audio_feature_stats(feature, new_data_point, sample_size, library_sta
"std_dev": new_std_dev
}
# }}} update_audio_feature_stats #
# increase_nested_key {{{ #
@ -167,6 +181,8 @@ def increase_artist_count(headers, artist_name, artist_id, library_stats):
# }}} increase_artist_count #
# update_popularity_stats {{{ #
def update_popularity_stats(new_data_point, library_stats, sample_size):
"""Updates the popularity statistics in library_stats
@ -193,6 +209,8 @@ def update_popularity_stats(new_data_point, library_stats, sample_size):
"std_dev": new_std_dev,
}
# }}} update_popularity_stats #
# get_track_info {{{ #
def get_track_info(track_dict, library_stats, sample_size):
@ -241,6 +259,8 @@ def calculate_genres_from_artists(headers, library_stats):
# }}} calculate_genres_from_artists #
# process_library_stats {{{ #
def process_library_stats(library_stats):
"""Processes library_stats into format more suitable for D3 consumption
@ -291,3 +311,5 @@ def process_library_stats(library_stats):
processed_library_stats[key] = library_stats[key]
return processed_library_stats
# }}} process_library_stats #

4
spotifyvis/views.py

@ -1,3 +1,5 @@
# imports {{{ #
from django.shortcuts import render, redirect
from django.http import HttpResponse, HttpResponseBadRequest
import math
@ -10,6 +12,8 @@ import pprint
from datetime import datetime
from .utils import parse_library, process_library_stats
# }}} imports #
TIME_FORMAT = '%Y-%m-%d-%H-%M-%S'
library_stats = {"audio_features":{}, "genres":{}, "year_released":{}, "artists":{}, "num_songs":0, "popularity":[], "total_runtime":0}

Loading…
Cancel
Save