plotting work

This commit is contained in:
Xevion
2019-10-27 15:28:22 -05:00
parent 050ca81fc9
commit cff38fbaa9

View File

@@ -1,8 +1,11 @@
import os import os
import sys import sys
import json import json
import dateutil.parser
import logging import logging
import collections
import numpy as np
import dateutil.parser
import matplotlib.pyplot as plt
def get_files(): def get_files():
folder = os.path.join(sys.path[0], 'tracks') folder = os.path.join(sys.path[0], 'tracks')
@@ -20,18 +23,35 @@ def combine_files(files):
items.extend(file['items']) items.extend(file['items'])
return items return items
def process(data): def print_data(data):
for i, item in enumerate(data): for i, item in enumerate(data):
date = dateutil.parser.parse(item['added_at']) date = dateutil.parser.parse(item['added_at'])
explicit = '!' if item['track']['explicit'] else ' ' explicit = '!' if item['track']['explicit'] else ' '
track_name = item['track']['name'] track_name = item['track']['name']
artists = ' & '.join(artist['name'] for artist in item['track']['artists']) artists = ' & '.join(artist['name'] for artist in item['track']['artists'])
print('[{}] {} "{}" by {}'.format( print('[{}] {} "{}" by {}'.format(date, explicit, track_name, artists))
date,
explicit, def process_data(data):
track_name, explicit = collections.defaultdict(int)
artists 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(): def main():
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
@@ -41,6 +61,6 @@ def main():
logging.info("Combining into single track file for ease of access") logging.info("Combining into single track file for ease of access")
data = combine_files(files) data = combine_files(files)
logging.info(f'File combined with {len(data)} items') logging.info(f'File combined with {len(data)} items')
logging.info('Prcessing file...') logging.info('Processing file...')
process(data) process_data(data)
main() main()