import numpy as np
import matplotlib.pyplot as plt

#Example 3
def vending_machine():
    '''Data for Example 18.8, vending machine'''
    
    '''delivery time (minutes)'''
    y = np.array([[16.68, 11.50, 12.03, 14.88, 13.75, 18.11, 8.00, 
            17.83, 79.24, 21.50,40.33, 21.00, 13.50, 19.75, 24.00, 29.00, 
            15.35, 19.00, 9.50, 35.10,17.90, 52.32, 18.75, 19.83, 10.75]]).T
    
    '''number of refills (-)'''
    x1 = np.array([[7, 3, 3, 4, 6, 7, 2, 7, 30, 5, 16, 10, 4, 6,
                                9, 10, 6, 7, 3, 17, 10, 26, 9, 8, 4]]).T
    
    x2 = np.array([[560, 220, 340, 80, 150, 330, 110, 210, 1460, 
                                  605, 688, 215, 255, 462, 448, 776, 200, 
                                  132, 36, 770, 140, 810, 450, 635, 150]]).T
    
    return x1, x2, y

#Example 5
def buildings():
    '''Data for Exercise 18.5: stock of buildings in Austria 1869 - 2011'''
    
    '''year'''
    x = np.array([[1869, 1880, 1890, 1900, 1910, 1923, 1934, 
                                 1951, 1961, 1971, 1981, 1991, 2001, 2011]]).T
    '''number of existing buildings'''
    y = np.array([[562045, 590029, 614694, 648116, 690731, 717004,
                                805849, 896030, 1049953, 1259533, 1586841, 
                                1809060, 2046712, 2191280]]).T
    return x, y


#Example 6
def breweries():
    '''Data for Exercise 18.6 (share index of 4 breweries):
    share index for the groups Holsten, Carlsberg, Heineken und BBAG,
    November 1999 (= 100%) - November 2000, from the magazine "profil" 46/2000.
    '''

    '''time axis: 0 = 11/1999, ..., 12 = 11/2000'''
    x = np.array([list(range(13))]).T
    
    '''BBAG'''
    y1 = np.array([[100, 91, 89, 85, 89, 89, 95, 93, 102, 115, 
                                 110, 107, 100]]).T

    '''Heineken'''
    y2 = np.array([[100, 90, 97, 104, 104, 115, 123, 114, 123, 
                                 127, 116, 125, 126]]).T
    
    '''Carlsberg'''
    y3 = np.array([[100, 107, 103, 88, 88, 83, 89, 95, 85, 102, 
                                 105, 123, 142]]).T
    
    '''Holsten'''
    y4 = np.array([[100, 90, 90, 95, 97, 93, 101, 100, 134, 146, 
                                 145, 145, 150]]).T
    return x, y1, y2, y3, y4


#Example 8
def vehicles():
    '''Data for Exercise 18.8, gasoline mileage 

    The vehicles are: Apollo, Omega, Nova, Monarch, Duster, Jenson, Skyhawk, 
    Monza, Scirocco, Corolla SR-5, Camaro, Datsun B210, Capri II, Pacer, 
    Bobcat, Granada, Eldorado, Imperial, Nova LN, Valiant, Starfire, Cordoba, 
    Corolla E-5, Mark IV, Celica GT, Charger SE, Cougar, Elite, Matador,
    Corvette
    '''
    
    '''mileage per gallon (miles/gallon)'''         
    y = np.array([[18.9, 17, 20, 18.25, 20.07, 11.2, 22.12, 21.47, 34.7, 30.4, 
                   16.5, 36.5, 21.5, 19.7, 20.3, 17.8, 14.39, 14.89, 17.8, 
                   16.41, 23.54, 21.47, 31.9, 13.27, 23.9, 19.73, 13.9, 13.27, 
                   13.77, 16.5]]).T
    
    '''displacement(cubicinch)'''   
    x1 = np.array([[350, 350, 250, 351, 225, 440, 231, 262, 89.7, 96.9, 350, 
                    85.3, 171, 258, 140, 302, 500, 440, 350, 318, 231, 360, 
                    96.9, 460, 133.6, 318, 351, 351, 360, 350]]).T
    
    '''horsepower (ft-lb)'''  
    x2 = np.array([[165, 170, 105, 143, 95, 215, 110, 110, 70, 75, 155, 80, 
                    109, 110, 83, 129, 190, 215, 155, 145, 110, 180, 75, 223, 
                    96, 140, 148, 148, 195, 165]]).T
    
    '''overall length (inch)''' 
    x3 = np.array([[200.3, 199.6, 196.7, 199.9, 194.1, 184.5, 179.3, 179.3, 
                    155.7, 165.2, 195.4, 160.6, 170.4, 171.5, 168.8, 199.9, 
                    224.1, 231, 196.7, 197.6, 179.3, 214.2, 165.2, 228, 171.5, 
                    215.3, 215.5, 216.1, 209.3, 185.2]]).T
    
    '''weight (lb)'''
    x4 = np.array([[3910, 3860, 3510, 3890, 3365, 4215, 3020, 3180, 1905, 2320, 
                    3885, 2009, 2655, 3375, 2700, 3890, 5290, 5185, 3910, 3660, 
                    3050, 4250, 2275, 5430, 2535, 4370, 4540, 4715, 4215, 
                    3660]]).T
    
    return y, x1, x2, x3, x4


def students():
    '''Data for Exercise 18.2
    x = height, y = weight 
    of 44 civil engineering students at the University of Innsbruck, 
    class of 1998.
    '''
    
    '''height'''
    x = np.array([186, 178, 199, 168, 187, 184, 176, 176, 176, 170, 176, 186, 
                  169, 178, 174, 178, 169, 190, 170, 167, 183, 176, 167, 189, 
                  173, 180, 186, 180, 176, 189, 178, 175, 184, 186, 185, 191, 
                  185, 193, 178, 187, 182, 179, 173, 183])
    
    '''weight'''
    y = np.array([73, 73, 93, 60, 83, 73, 74, 68, 71, 57, 68, 80, 55, 70, 60, 
                  78, 70, 92, 60, 70, 80, 68, 71, 85, 69, 73, 84, 70, 73, 69, 
                  66, 70, 80, 80, 69, 85, 95, 70, 72, 82, 66, 71, 63, 75])
    
    return x, y


def students2():
    '''Data for Fig. 8.7, Fig. 18.1 and Example 18.1:
    x = body height, y = body weight
    of 70 (male) students attending the course "Analysis for Computer Scientists"
    at the University of Innsbruck, summer term 2002
    
    Same data in python08_3'''

    '''height'''
    x = np.array([[185, 183, 183, 182, 193, 185, 180, 180, 176, 190, 183, 175, 
                   192, 190, 186, 180, 180, 191.5, 185, 180, 173, 196, 172, 186, 
                   183, 190, 178, 186, 175, 184, 180, 191, 179, 185, 183, 186, 
                   188, 178, 184, 185, 190, 174, 182, 192, 178, 190, 180, 182, 
                   175, 186, 196, 191, 178, 187, 189, 174, 180, 183, 178, 188, 
                   183, 174, 173, 186, 188, 184, 183, 174, 169, 170]]).T
    '''weight'''
    y = np.array([[100, 71, 75, 70, 77, 79, 76, 78, 75, 76, 132, 67, 71, 80, 
                   86, 70, 74, 83, 82, 71, 64, 102, 82, 82, 78, 83, 83, 64, 55,
                   90, 80, 81, 71, 72, 110, 75, 75, 78, 70, 73, 76, 61, 64, 86,
                   70, 76, 68, 65, 60, 69, 73, 77, 74, 79, 76.5, 54, 72, 70, 
                   78, 73, 87, 72, 70, 87, 84, 80, 77, 75, 61, 62]]).T
    
    return x, y

# Example 11
def consumer_price():
    '''Data for Exercise 18.11: housing price index in Austria 2010 - 2021'''
    
    '''year'''
    x = np.array([[2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 
                   2020, 2021]]).T
    
    '''price index'''
    y = np.array([[100.00, 106.25, 114.03, 119.32, 124.13, 130.21, 141.32, 
                   146.78, 156.70, 164.85, 177.50, 199.56]]).T
    return x, y