From cff38fbaa90196b7c8d1ffb4445f0c88558a6f9a Mon Sep 17 00:00:00 2001 From: Xevion Date: Sun, 27 Oct 2019 15:28:22 -0500 Subject: [PATCH] plotting work --- process.py | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/process.py b/process.py index 08903af..2e78e30 100644 --- a/process.py +++ b/process.py @@ -1,8 +1,11 @@ import os import sys import json -import dateutil.parser import logging +import collections +import numpy as np +import dateutil.parser +import matplotlib.pyplot as plt def get_files(): folder = os.path.join(sys.path[0], 'tracks') @@ -20,18 +23,35 @@ def combine_files(files): items.extend(file['items']) return items -def process(data): +def print_data(data): for i, item in enumerate(data): date = dateutil.parser.parse(item['added_at']) explicit = '!' if item['track']['explicit'] else ' ' track_name = item['track']['name'] artists = ' & '.join(artist['name'] for artist in item['track']['artists']) - print('[{}] {} "{}" by {}'.format( - date, - explicit, - track_name, - artists - )) + print('[{}] {} "{}" by {}'.format(date, explicit, track_name, artists)) + +def process_data(data): + explicit = collections.defaultdict(int) + safe = collections.defaultdict(int) + for item in data: + date = dateutil.parser.parse(item['added_at']) + date = date.strftime('%b %Y') + if item['track']['explicit']: + explicit[date] += 1 + else: + safe[date] += 1 + times = [dateutil.parser.parse(item['added_at']) for item in data] + sort_func = lambda x : dateutil.parser.parse(x[0]).epoch + + + n = len(data) + ind = np.arange(n) + width = 0.35 + plt.ylabel('Month') + plt.xlabel('Song by Type') + plt.xticks(ind, ) + # plt.show() def main(): logging.basicConfig(level=logging.INFO) @@ -41,6 +61,6 @@ def main(): logging.info("Combining into single track file for ease of access") data = combine_files(files) logging.info(f'File combined with {len(data)} items') - logging.info('Prcessing file...') - process(data) + logging.info('Processing file...') + process_data(data) main() \ No newline at end of file