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 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()