Example #1
0
def test_API_overload():
    test_list = [5000] * 20  # Create test array
    test_list[2] = 323  # Create two points which contain the critical value
    test_list[15] = 323
    with patch.object(Greengraph, 'green_between') as mock:
        mock.return_value = test_list
        test_map = Greengraph(sample_start, sample_end, sample_delay)
        assert (test_map.api_overload(sample_steps)) == True
Example #2
0
def test_API_overload():
    test_list = [5000]*20 # Create test array
    test_list[2] = 323 # Create two points which contain the critical value
    test_list[15] = 323
    with patch.object(Greengraph, 'green_between') as mock:
        mock.return_value = test_list
        test_map = Greengraph(sample_start, sample_end, sample_delay)
        assert (test_map.api_overload(sample_steps))==True
Example #3
0
    parser.add_argument('filename', type=str, help ='image filename with extension')
    parser.add_argument('--steps', '-s', type=int, help = 'Number of steps, default = 20')
    parser.add_argument('--plot', '-p', action ='store_true', help ='Display plot')
    parser.add_argument('--delay', '-d', type=int, help = 'API request delay in seconds')

    arguments = parser.parse_args()



    mygraph = Greengraph(arguments.start, arguments.end, arguments.delay) # Create Greengraph object
    data = mygraph.green_between(arguments.steps)

    # Catch API overload error
    # Google sends error picture with 325 green pixels.
    # This method should be in one of the classes
    if mygraph.api_overload(arguments.steps):
        print 'Warning: API overload'


    # Saving and plotting data
    fig = plt.figure()
    plt.plot(data)
    fig.suptitle('Greengraph - %s to %s' %(arguments.start, arguments.end), fontsize=14, fontweight='bold')
    ax = fig.add_subplot(111)
    ax.set_xlabel('steps')
    ax.set_ylabel('green pixel count')
    plt.savefig(arguments.filename) # Save plot

    if arguments.plot: # Show plot if arguments.plot = TRUE
        plt.show()
Example #4
0
                        help='Display plot')
    parser.add_argument('--delay',
                        '-d',
                        type=int,
                        help='API request delay in seconds')

    arguments = parser.parse_args()

    mygraph = Greengraph(arguments.start, arguments.end,
                         arguments.delay)  # Create Greengraph object
    data = mygraph.green_between(arguments.steps)

    # Catch API overload error
    # Google sends error picture with 325 green pixels.
    # This method should be in one of the classes
    if mygraph.api_overload(arguments.steps):
        print 'Warning: API overload'

    # Saving and plotting data
    fig = plt.figure()
    plt.plot(data)
    fig.suptitle('Greengraph - %s to %s' % (arguments.start, arguments.end),
                 fontsize=14,
                 fontweight='bold')
    ax = fig.add_subplot(111)
    ax.set_xlabel('steps')
    ax.set_ylabel('green pixel count')
    plt.savefig(arguments.filename)  # Save plot

    if arguments.plot:  # Show plot if arguments.plot = TRUE
        plt.show()