# -*- coding: utf-8 -*-
"""AEOPDay3.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1EBz2EcAFR7wNNt5BtgNLWoT9kxSkqfy3

# HackerRank Problems Continued

Task 11: Mean, Var, and STD
"""

import numpy as np

a = np.array([[1, 2], [3, 4]])
print(np.mean(a, axis = 1))
print(np.var(a, axis=0))
print(np.std(a, axis=None))

"""Task 12 Dot and Cross"""

## The dot tool returns the dot product of two arrays
## The cross tool returns the cross product of two arrays.
import numpy as np
A = np.array([[1, 2], [3, 4]])
B = np.array([[1, 2], [3, 4]])
print(np.dot(A, B))
#dot is just the matrix

"""Task 13 Inner and Outer"""

## The inner tool returns the inner product of two arrays.

import numpy

A = numpy.array([0, 1])
B = numpy.array([3, 4])

print(numpy.inner(A, B))   #Output : 4
## The outer tool returns the outer product of two arrays.
import numpy

A = numpy.array([0, 1])
B = numpy.array([3, 4])

print(numpy.outer(A, B))    #Output : [[0 0]
                            #          [3 4]]

import numpy as np
A = np.array([0,1])
B = np.array([2, 3])

print(np.inner(A, B))
print(np.outer(A, B))

"""Task 14 Polynomials"""

import numpy as np
poly = np.array([1.1, 2, 3])
np.polyval((poly), 0)

"""The poly tool returns the coefficients of a polynomial with the given sequence of roots.
 - The polyint tool returns an antiderivative (indefinite integral) of a polynomial.
 - The roots tool returns the roots of a polynomial with the given coefficients.
 - The polyder tool returns the derivative of the specified order of a polynomial.
 - The polyval tool evaluates the polynomial at specific value. (used above)
"""
#print numpy.poly([-1, 1, 1, 10])        
#Output : [  1 -11   9  11 -10]

#why are the outputs that way? are they different points of intersection

"""Task 15 Linear Algebra"""

import numpy as np

A = np.array([[1.1, 1.1], [1.1, 1.1]])
print(np.linalg.det(A))

"""# MatPlotLib

Video One: Creating + Customizing Plots
"""

import matplotlib

from matplotlib import pyplot as plt

# print(plt.style.available)
plt.style.use('fivethirtyeight')
# Median Developer Salaries by Age
ages_x = [25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35]

dev_y = [38496, 42000, 46752, 49320, 53200,
         56000, 62316, 64928, 67317, 68748, 73752]

plt.plot(ages_x, dev_y, color='k', linestyle = '--' ,label = 'All Devs')

# Median Python Developer Salaries by Age
## can remobe to keep axis py_dev_x = [25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35]
py_dev_y = [45372, 48876, 53850, 57287, 63016,
            65998, 70003, 70000, 71496, 75370, 83640]

plt.plot(ages_x, py_dev_y, color = '#009000', marker = '*', linewidth=3, label = 'Python')

# Median JavaScript Developer Salaries by Age
js_dev_y = [37810, 43515, 46823, 49293, 53437,
            56373, 62375, 66674, 68745, 68746, 74583]

plt.plot(ages_x, js_dev_y, color = '#adad3b', marker = '.', label = 'JavaScript')

plt.xlabel('Ages')
plt.ylabel('Salary')
plt.title('Median Salary (USD) by Age')

# If you know the order of which color is which, or just add as new parameter in plt.plot
# plt.legend(['All Devs','Python']), just legend better bc updates automatically
plt.legend()
# format string fmt = '[marker][line][color]'

#plt.grid(True)
plt.tight_layout()

plt.savefig('plot.png')

plt.show(ages_x, dev_y)

"""Video 2: Bar Charts and Analyzing Data from CSV"""

import matplotlib
import numpy as np
from matplotlib import pyplot as plt

ages_x = [25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35]

x_indexes = np.arange(len(ages_x))
width = 0.25

dev_y = [38496, 42000, 46752, 49320, 53200,
         56000, 62316, 64928, 67317, 68748, 73752]

plt.bar(x_indexes - width, dev_y, width=width, color = "#444444", label = "All Devs") 

# Median Python Developer Salaries by Age
py_dev_y = [45372, 48876, 53850, 57287, 63016,
            65998, 70003, 70000, 71496, 75370, 83640]

plt.bar(x_indexes, py_dev_y, width=width, color = "#004400", label = "Python") 

# Median JavaScript Developer Salaries by Age
js_dev_y = [37810, 43515, 46823, 49293, 53437,
            56373, 62375, 66674, 68745, 68746, 74583]

plt.bar(x_indexes + width, js_dev_y, width=width, color = "#440000", label = "JavaScript") 

plt.xticks(ticks=x_indexes, labels = ages_x)

plt.legend()

import matplotlib
import csv
import pandas as pd #open files neater
import numpy as np
from collections import Counter
from matplotlib import pyplot as plt

'''with open('data.txt') as csv_file:
  csv_reader = csv.DictReader(csv_file)'''

data = pd.read_csv('data.txt')
ids = data['Responder_id']
lang_responses = data['LanguagesWorkedWith']

language_counter = Counter()

      #replace row with response after use of pandas and cvs_reader with lang_responses
for response in lang_responses:   #row also replaced
  language_counter.update(response.split(';'))
                      #and remove 'LanguagesWorkedWith idk why
languages =[]
popularity = []

for item in language_counter.most_common(15):
  languages.append(item[0])
  popularity.append(item[1])

#print(language_counter.most_common(15))
languages.reverse()
popularity.reverse()
plt.barh(languages, popularity)

"""Video 3 Pie Charts"""

import matplotlib 
from matplotlib import pyplot as plt 

# Language Popularity
slices = [59219, 55466, 47544, 36443, 35917]
labels = ['JavaScript', 'HTML/CSS', 'SQL', 'Python', 'Java']
explode = [0, 0, 0, 0.1, 0]
                                                                                      #ask to define percentages
plt.pie(slices, labels = labels, explode = explode, shadow = True, startangle = 90, autopct = '%1.1f%%',colors = colors, wedgeprops = {'edgecolor' : 'black'})

plt.title("My Awesome Pie Chart")
plt.show()

"""Video 4 Stack Plots"""

import matplotlib
from matplotlib import pyplot as plt

plt.style.use("fivethirtyeight")


minutes = [1, 2, 3, 4, 5, 6, 7, 8, 9]

player1 = [8, 6, 5, 5, 4, 2, 1, 1, 0]
player2 = [0, 1, 2, 2, 2, 4, 4, 4, 4]
player3 = [0, 1, 1, 1, 2, 2, 3, 3, 4]

labels = ('Player 1', 'Player 2', 'Player 3')
plt.stackplot(minutes, player1, player2, player3, labels= labels)

plt.legend(loc = (0.07, 0.05))  #google matplotlib legend to adjust coordinates

plt.title("My Awesome Stack Plot")
plt.tight_layout()
plt.show()

"""Filling Area on Line Plots"""

import pandas as pd
import matplotlib
from matplotlib import pyplot as plt

data = pd.read_csv('data.csv')
ages = data['Age']
dev_salaries = data['All_Devs']
py_salaries = data['Python']
js_salaries = data['JavaScript']

plt.plot(ages, dev_salaries, color='#444444',
         linestyle='--', label='All Devs')

plt.plot(ages, py_salaries, label='Python')

overall_median = 57287
                                    #to change intensity of fill
plt.fill_between(ages, py_salaries, overall_median, 
                 where = (py_salaries <= overall_median), 
                 interpolate = True, alpha = 0.25, )
plt.fill_between(ages, py_salaries, overall_median, 
                 where = (py_salaries > overall_median), 
                 color = "green",alpha = 0.25)

plt.legend()

plt.title('Median Salary (USD) by Age')
plt.xlabel('Ages')
plt.ylabel('Median Salary (USD)')

plt.tight_layout()

plt.show()

## TIMESTAMP: 11:30