Exemple #1
0
def datafile(update, context):

    import io
    import pandas as pd

    choice = update.message['text']
    choice = choice if choice in ['json', 'csv'] else 'csv'

    chat_id = update.message['chat']['id']
    error, data = get_data(chat_id, 'a')

    if error:
        update.message.reply_text('Error: {0}'.format(error))
        return CHOOSING

    buffer = io.StringIO()
    df = pd.DataFrame(data=data)
    eval(f'df.to_{choice}(buffer)')
    buffer.seek(0)

    update.message.reply_text('Your data:', reply_markup=markup)

    context.bot.send_document(chat_id=chat_id,
                              document=io.BytesIO(
                                  buffer.read().encode('utf8')),
                              filename=f'data.{choice}')

    return CHOOSING
Exemple #2
0
def graph(update, context):

    chat_id = update.message['chat']['id']
    error, data = get_data(chat_id)

    if error:
        update.message.reply_text('Error: {0}'.format(error))
        return CHOOSING

    y1, y2, x, hand = zip(*data)

    if len(x) < 7:
        update.message.reply_text('You need more measurements (more than 7).',
                                  reply_markup=markup)
        return CHOOSING

    update.message.reply_text("Your graphs: ", reply_markup=markup)

    for name, func in list_graph.items():

        buffer = func(x, y1, y2, hand)

        update.message.reply_text(f"{name}: ", reply_markup=markup)

        context.bot.send_document(chat_id=chat_id, document=buffer)

    return CHOOSING
Exemple #3
0
 def get(self):
     timestamp = datetime.now(pytz.timezone('UTC'))
     logging.info("Retrieving data from GraphQL")
     data = get_data(timestamp=timestamp)
     logging.info("Processing..")
     return pipeline.process(
         data["buses"],
         timestamp.astimezone(pytz.timezone('America/Mexico_City')))
Exemple #4
0
def test_map_returns_correct_image_ID(index_number, expected_value):
    """
    Take JSON file with test_1 map and assert correct image ID.
    index_number: tiles list instance index
    expected value: "id" stored in tiles list
    If the test_1.json map is changed or removed, the test needs to be updated.
    """
    data = get_data("maps/test_1.json")
    assert data["tilesets"][0]["tiles"][index_number]["id"] == expected_value
Exemple #5
0
def test_tile_size(map_name):
    """
    Take size of tiles used in JSON files and assert correct tile size.
    This test has to be removed, when width and height of tile image are
    no longer constants used for tile drawing.
    """
    data = get_data("maps/" + map_name + ".json")
    assert data["tilewidth"] == 64
    assert data["tileheight"] == 64
Exemple #6
0
def test_robots_on_starting_coordinates():
    """
    Assert that the result of get_robots_to_start is a list which contains Robot objects with correct attribute coordinates.
    """
    data = get_data("maps/test_3.json")
    board = get_board(data)
    robots = get_robots_to_start(board)
    assert isinstance(robots, list)
    assert isinstance(robots[0], Robot)
def test_get_board_instance():
    """ Take JSON file with test_3 map and assert correct tilelist is returned.

    If the test_3.json map is changed or removed, the test needs to be updated."""

    data = get_data("maps/test_3.json")
    board = get_board(data)
    assert isinstance(board, dict)
    assert isinstance(board[1], dict)
Exemple #8
0
def test_starting_coordinates():
    """
    Take board (based on JSON test_3 map) and assert correct starting coordinates are returned.
    If the test_3.json map is changed or removed, the test needs to be updated.
    """
    data = get_data("maps/test_3.json")
    board = get_board(data)
    assert len(get_starting_coordinates(board)) == 8
    assert isinstance(get_starting_coordinates(board), list)
Exemple #9
0
def test_board_structure():
    """
    Take board (based on JSON test_3 map) and assert correct board structure is returned.
    If the test_3.json map is changed or removed, the test needs to be updated.
    """
    data = get_data("maps/test_3.json")
    board = get_board(data)
    example_tile = board[0, 0]
    assert example_tile[0].path == "./img/squares/png/ground.png"
    assert example_tile[0].direction == Direction.N
Exemple #10
0
def test_dict_paths_is_correct():
    """
    Assert that the result of get_paths() is a dictionary.
    Assert that the paths structure is valid: integer is tile ID, string is path to the picture.
    """
    data = get_data("maps/test_3.json")
    paths = get_paths(data)
    for key, value in paths.items():
        assert isinstance(key, int)
        assert isinstance(value, str)
    assert isinstance(paths, dict)
Exemple #11
0
def check_squares(map_name):
    data = get_data("maps/" + map_name + ".json")
    board = get_board(data)
    """
    Change the list of types squares to the letters.
    A, B and C type can be only once in type list.
    """
    for coordinate, type in board.items():
        square_type_letter = []
        square_type_and_direction = []
        for i in type:
            square_type_letter.append(get_order_squares(i.type))

            """
            Squares with the same type and direction mustn't be in list of types
            """
            if (i.type, i.direction) in square_type_and_direction:
                return coordinate, i.type # (8, 9), 'wall'
            else:
                square_type_and_direction.append((i.type, i.direction))

        a = 0
        b = 0
        c = 0

        for letter in square_type_letter:
            if letter[0] == 'A':
                a += 1
            if letter[0] == 'B':
                b += 1
            if letter[0] == 'C':
                c += 1
        if a > 1 or b > 1 or c > 1:
            return coordinate, a, b, c # ((1, 9), 1, 2, 0)

        """
        Squares types must be in the correct order.
        ["A","B","D"] is correct ["D", "A"] is not
        A < B < C < D
        """
        letters_count = len(square_type_letter)
        for i in range(letters_count-1):
            if square_type_letter[i][0] > square_type_letter[i+1][0]:
                return coordinate, square_type_letter[i] # ((7, 9), 'D')

        """
        "Flag" mustn't be over the "Hole" or "Starting square"
        """
        for i in range(len(square_type_letter)-1):
            if square_type_letter[i] == "B_hole" and  square_type_letter[i+1] == "C_flag" or square_type_letter[i] == "B_starting_square" and  square_type_letter[i+1] == "C_flag":
                return coordinate, square_type_letter[i]


    return True
Exemple #12
0
def test_map_returns_correct_data_list():
    '''Test that takes JSON file with test_1 map and asserts correct data list.
    
    If the test_1.json map is changed or removed, the test needs to be updated.'''
    data = get_data('maps/test_1.json')
    assert data['layers'][0]['data'] == [
        2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1,
        2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1,
        2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1,
        2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1,
        2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1,
        2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
    ]
def test_map_returns_correct_data_list():
    """Take JSON file with test_1 map and assert correct data list.

    If the test_1.json map is changed or removed, the test needs to be updated."""
    data = get_data("maps/test_1.json")
    assert data["layers"][0]["data"] == [
        2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1,
        2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1,
        2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1,
        2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1,
        2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1,
        2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
    ]
Exemple #14
0
def graph():
	print request.form

	# cp = None
	# acp = None
	# op = None
	# aop = None

	cp = request.form.get('cp')
	acp = request.form.get('acp')
	op = request.form.get('op')
	aop = request.form.get('aop')
	Checkboxes = namedtuple('Checkboxes', 'cp acp op aop')
	cb = Checkboxes(cp=cp, acp=acp, op=op, aop=aop)
	ticker_name = request.form.get('tckr')
	script, div = get_graph(get_data(ticker_name), cb, ticker_name)
	return render_template('graph.html', graph_div=div, graph_script=script, ticker=ticker_name.upper())
Exemple #15
0
def main(wait_time):
    pipeline = Pipeline(os.environ.get("MODEL_LOCATION", MODEL_LOCATION),
                        os.environ.get("OUTBOUND_LOCATION", OUTBOUND_LOCATION),
                        os.environ.get("INBOUND_LOCATION", INBOUND_LOCATION),
                        os.environ.get("STOPS_LOCATION", STOPS_LOCATION))

    while True:
        try:
            ts = datetime.now(pytz.timezone('UTC')).replace(
                second=0, microsecond=0) + timedelta(minutes=1)
            logging.info("Waiting until {}".format(ts.astimezone(tz)))
            wait_until(ts, 1000000000)
            logging.info("Getting data")
            data = get_data(GRAPHQL_URL, ts)
            logging.info("Processing")
            results = pipeline.process(data)
            post_results(GRAPHQL_URL, results, ts.astimezone(tz))
        except Exception as e:
            logging.error(e)
            logging.error(traceback.format_exc(limit=100))
Exemple #16
0
def graph():
    print request.form

    # cp = None
    # acp = None
    # op = None
    # aop = None

    cp = request.form.get('cp')
    acp = request.form.get('acp')
    op = request.form.get('op')
    aop = request.form.get('aop')
    Checkboxes = namedtuple('Checkboxes', 'cp acp op aop')
    cb = Checkboxes(cp=cp, acp=acp, op=op, aop=aop)
    ticker_name = request.form.get('tckr')
    script, div = get_graph(get_data(ticker_name), cb, ticker_name)
    return render_template('graph.html',
                           graph_div=div,
                           graph_script=script,
                           ticker=ticker_name.upper())
	def __init__(self, username):

		keys = ['Name','Lastname','Sex', 'Age', 'Social Sites']
		response = get_data(username)
		data = response['data']

		self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
		self.window.set_title("Fascinating Trip")
		self.window.connect("delete_event", lambda w,e: gtk.main_quit())
		self.window.set_size_request(300, 300)

		box = gtk.VBox(False, 0)
		self.window.add(box)
		box.show()

		for i in xrange(5):
			label = gtk.Label(keys[i]+': '+str(data[i]))
			box.pack_start(label, False, False, 5)
			label.show()

		self.window.show()
Exemple #18
0
def test_get_coordinates_returns_list(map_name):
    data = get_data('maps/' + map_name + '.json')
    coordinates = get_coordinates(data)
    assert isinstance(coordinates, list)
Exemple #19
0
 def GET(self):
     return render.index(data=backend.get_data())
Exemple #20
0
def get_data():
    return flask.jsonify(backend.get_data(db_str))
Exemple #21
0
    - draws the game map and runs pyglet
"""

import backend
import frontend
import pyglet

# definition of game board tiles and their size:
TILE_WIDTH = 64
TILE_HEIGHT = 64
WINDOW_WIDTH = 12 * TILE_WIDTH
WINDOW_HEIGHT = 12 * TILE_HEIGHT

# loading JSON map data from the backend module
map_name = "./maps/test_3.json"
data = backend.get_data(map_name)

# loading pyglet graphic window from the frontend module
window = frontend.init_window(WINDOW_WIDTH, WINDOW_HEIGHT)

# calling functions from the backend module to draw the game board
coordinates = backend.get_coordinates(data)
tilelist = backend.get_tiles(data)
state = backend.get_coordinate_dict(coordinates, tilelist)

# loading pyglet sprites by the frontend module
images = frontend.load_images(data, state, TILE_WIDTH, TILE_HEIGHT)


@window.event
def on_draw():
def test_map_returns_correct_image_path(id_number, expected_value):
    """Take JSON file with test_1 map and assert correct image path.

    If the test_1.json map is changed or removed, the test needs to be updated."""
    data = get_data("maps/test_1.json")
    assert data["tilesets"][0]["tiles"][id_number]["image"] == expected_value
Exemple #23
0
def test_get_coordinates_returns_list(map_name):
    """Test that get_coordinates() returns a list for each map."""
    data = get_data("maps/" + map_name + ".json")
    coordinates = get_coordinates(data)
    assert isinstance(coordinates, list)
Exemple #24
0
def test_map_returns_correct_data_list_type():
    '''Test that takes JSON file with test_1 map and asserts data type is list.
    
    If the test_1.json map is changed or removed, the test needs to be updated.'''
    data = get_data('maps/test_1.json')
    assert isinstance(data['layers'][0]['data'], list)
Exemple #25
0
def test_map_returns_correct_image_path(id_number, expected_value):
    '''Test that takes JSON file with test_1 map and asserts correct image path.
    
    If the test_1.json map is changed or removed, the test needs to be updated.'''
    data = get_data('maps/test_1.json')
    assert data['tilesets'][0]['tiles'][id_number]['image'] == expected_value
Exemple #26
0
def test_get_coordinates_returns_list(map_name):
    '''Test that get_coordinates() returns a list for each map.'''
    data = get_data('maps/' + map_name + '.json')
    coordinates = get_coordinates(data)
    assert isinstance(coordinates, list)
Exemple #27
0
def test_map_returns_correct_firstgid():
    '''Test that takes JSON file with test_1 map and asserts correct firstgid (tileset ID) value.
    
    If the test_1.json map is changed or removed, the test needs to be updated.'''
    data = get_data('maps/test_1.json')
    assert data['tilesets'][0]['firstgid'] == 1