Exemplo n.º 1
0
 def test0(self):
     data, num_constellation = test_data[0]
     stars = parse(data)
     distance = manhattan_distance_all(stars)
     constellations = find_constellations(distance)
     print(constellations)
     self.assertEqual(len(constellations), num_constellation)
Exemplo n.º 2
0
def repl(prompt="> "):
    while True:
        program = ''
        try:
            program = input(prompt)
        except (KeyboardInterrupt, EOFError):
            print()
            return
        if len(program) > 0:
            val = None
            try:
                val = eval(parse(program))
            except NameError as e:
                print(e)
                continue
            if val is not None:
                print(sexpr(val))
Exemplo n.º 3
0
import reader
import params
import matplotlib.pyplot as plt

x = []
total = 0
min_price = 1000
max_price = 0
for k in reader.parse(params.metadata_path):
    if 'price' in k:
        x.append(k['price'])
        total += 1
        if k['price'] > max_price:
            max_price = k['price']
        if k['price'] < min_price:
            min_price = k['price']
        if total % 10000 == 0:
            print 'Read ', total

print 'Total items : ', total
print 'Min price : ', min_price
print 'Max price : ', max_price

print 'Plotting histogram'
num_bins = 1000
# the histogram of the data
n, bins, patches = plt.hist(x, num_bins, normed=0, facecolor='green')

plt.xlabel('Price range (USD)')
plt.ylabel('Number of products')
plt.title(r'Histogram of number of products vs price range')
Exemplo n.º 4
0
    plt.axis('off')


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("map", help="Path to map file", type=str)
    parser.add_argument("-s", "--solution",
                        help="File path to solution", type=str)
    parser.add_argument("--images", help="Background activation = 1, ant activation = 2 both = 3", action="store_true")
    args = parser.parse_args()
    if not os.path.exists(args.map):
        raise IOError("Map file not found")

    if args.solution and not os.path.exists(args.solution):
        raise IOError("Solution file not found")
    data = parse(args.map, args.solution)
    # Graph
    G = nx.Graph()
    G.add_edges_from(data['tunnels'])
    # Fruchterman-Reingold force-directed algorithm's to set rooms.
    pos = nx.spring_layout(G)
    # Ants speed
    speed_rate = 7
    # create an array of * on the ants object
    ants = make_ants(pos, speed_rate, data)
    # size of the graph
    fig = plt.figure(figsize = (15, 10))
    ant_img = read_png('./images/Fourmisse.png')
    ani = FuncAnimation(
    fig,
    re_init,
Exemplo n.º 5
0
 def test1(self):
     data, num_constellation = test_data[0]
     stars = parse(data)
     self.assertEqual(stars.shape, (8, 4))
Exemplo n.º 6
0
def readAST(s):
    ret = rdr.parse(s)
    if type(ret) == list and len(ret) == 1: ret = ret[0]
    return ret
Exemplo n.º 7
0
 def test_parser(self):
     for t in config.parse_tests:
         got = reader.parse(t['line'])
         self.assertEqual(got, t['want'])
Exemplo n.º 8
0
def evalString(str):
    ps = reader.parse(str)
    buf = buffer.BufferSexp(tn.TNode(ps))
    return eval(buf)
Exemplo n.º 9
0
#!/usr/bin/env python

from __future__ import print_function

from reader import parse
from utils import find_constellations
from utils import manhattan_distance_all

if __name__ == '__main__':
    with open('data.txt', 'r') as f:
        stars = parse(f)

    distances = manhattan_distance_all(stars)
    constellations = find_constellations(distances)

    print('Answer:', len(constellations))
    # 375
Exemplo n.º 10
0
from reader import init, parse, get_current_winners
import io, json

year = 2013
if year == 2015:
    tweets = '../data/goldenglobes2015.json'
else:
    tweets = '../data/gg2013.json'
init(tweets)
parse(tweets)
winners = get_current_winners()

result = {
    "metadata": {
        "year": year,
        "names": {
            "hosts": {
                "method": "hardcoded",
                "method_description": ""
            },
            "nominees": {
                "method": "scraped",
                "method_description": ""
            },
            "awards": {
                "method": "detected",
                "method_description": ""
            },
            "presenters": {
                "method": "detected",
                "method_description": ""
Exemplo n.º 11
0
        "--heuristic",
        default="manhattan",
        choices=HEURISTICS_TABLE.keys(),
    )
    parser.add_argument("-a",
                        "--algorithm",
                        default="a_star",
                        choices=ALGORITHM_TABLE.keys())
    parser.add_argument("-g", "--greedy", action="store_true")
    args = parser.parse_args()
    filename = args.file
    heuristic = HEURISTICS_TABLE[args.heuristic]
    algo = ALGORITHM_TABLE[args.algorithm]
    is_greedy = args.greedy
    try:
        with open(filename) as f:
            start = reader.parse(f)
        goal, time_comp, space_comp = algo(start, heuristic, greedy=is_greedy)
        if goal is None:
            print("Invalid puzzle")
        else:
            print("Length of path: {}".format(display_path(goal)))
        print("Time complexity: {}".format(time_comp))
        print("Space complexity: {}".format(space_comp))
    except (RecursionError, MemoryError):
        print(
            "Memory usage too high: consider using IDA* algorithm (python3 npuzzle.py -a ida FILE), may take more time than usual"
        )
    except Exception as e:
        print(e)