Example #1
0
def root():
    pages, requested_page = get_effective_page(request.args.get("page", 0))
    def s(x):
        return True
    items = get_items(s, g.db_file, requested_page)

    return render_template("index.html", items=items, pages=pages,
        current_page=request.args.get('page', 0))
Example #2
0
def draw_state_sentiments(state_sentiments):
    """Draw all U.S. states in colors corresponding to their sentiment value.

    Unknown state names are ignored; states without values are colored grey.

    state_sentiments -- A database from state strings to sentiment values
    """
    for name, shapes in get_items(us_states):
        if name in get_keys(state_sentiments):
            sentiment = get_value_from_key(state_sentiments, name)
        else:
            sentiment = None
        draw_state(shapes, sentiment)
    for name, shapes in get_items(us_states):
        center = find_state_center(shapes)
        if center is not None:
            draw_name(name, center)
Example #3
0
def introspect(domain):
    filter_func = lambda x: get_domain(loads(x[1])).lower() in domain.lower()
    pages, requested_page = get_effective_page(request.args.get("page", 0),
            filter_func)
    items = get_items(filter_func, g.db_file, requested_page)

    return render_template("index.html", items=items, pages=pages,
            requested_page=requested_page, current_page=request.args.get('page', 0))
Example #4
0
def draw_state_sentiments(state_sentiments):
    """Draw all U.S. states in colors corresponding to their sentiment value.

    Unknown state names are ignored; states without values are colored grey.

    state_sentiments -- A database from state strings to sentiment values
    """
    for name, shapes in get_items(us_states):
        if name in get_keys(state_sentiments):
            sentiment = get_value_from_key(state_sentiments, name)
        else:
            sentiment = None
        draw_state(shapes, sentiment)
    for name, shapes in get_items(us_states):
        center = find_state_center(shapes)
        if center is not None:
            draw_name(name, center)
Example #5
0
def interrogate(qstring):
    filter_func = lambda x: search_func(loads(x[1]), qstring)
    pages, requested_page = get_effective_page(request.args.get("page", 0),
            filter_func)
    items = get_items(filter_func, g.db_file, requested_page)

    return render_template("index.html", items=items, pages=pages,
            requested_page=requested_page, current_page=request.args.get('page', 0))
Example #6
0
def intrigue(user):
    filter_func = lambda x: loads(x[1])["person"].lower() == user.lower()
    pages, requested_page = get_effective_page(request.args.get("page", 0),
            filter_func)
    items = get_items(filter_func, g.db_file, requested_page)

    return render_template("index.html", items=items, pages=pages,
            requested_page=requested_page, current_page=request.args.get('page', 0))
Example #7
0
def introspect(domain):
    def filter_func(x):
        return get_domain(loads(x[1])).lower() in domain.lower()
    pages, requested_page = get_effective_page(request.args.get("page", 0),
            filter_func)
    items = get_items(filter_func, g.db_file, requested_page)

    return render_template("index.html", items=items, pages=pages,
            requested_page=requested_page, current_page=request.args.get('page', 0))
Example #8
0
def intrigue(user):
    def filter_func(x):
        return loads(x[1])["person"].lower() == user.lower()
    pages, requested_page = get_effective_page(request.args.get("page", 0),
            filter_func)
    items = get_items(filter_func, g.db_file, requested_page)

    return render_template("index.html", items=items, pages=pages,
            requested_page=requested_page, current_page=request.args.get('page', 0))
Example #9
0
def interrogate(qstring):
    def filter_func(x):
        return search_func(loads(x[1]), qstring)
    pages, requested_page = get_effective_page(request.args.get("page", 0),
            filter_func)
    items = get_items(filter_func, g.db_file, requested_page)

    return render_template("index.html", items=items, pages=pages,
            requested_page=requested_page, current_page=request.args.get('page', 0))
Example #10
0
def draw_centered_map(center_state='TX', n=10):
    """Draw the n states closest to center_state."""
    us_centers = make_database()
    for state, s in get_items(us_states):
        us_centers = add_value(us_centers, state, find_state_center(s))
    center = get_value_from_key(us_centers, center_state.upper()) 
    dist_from_center = lambda name: geo_distance(center, get_value_from_key(us_centers, name))
    for name in sorted(get_keys(us_centers), key=dist_from_center)[:int(n)]:
        draw_state(get_value_from_key(us_states, name))
        draw_name(name, get_value_from_key(us_centers, name))
    draw_dot(center, 1, 10)  # Mark the center state with a red dot
    wait()
Example #11
0
def starred():
    user = get_user()["user"]
    if not user:
        return redirect(url_for('merveilles.login'))

    filter_func = lambda x: int(loads(x[1])["created_at"]) in user["starred"]
    pages, requested_page = get_effective_page(request.args.get("page", 0),
            filter_func)
    items = get_items(filter_func, g.db_file, requested_page)

    return render_template("index.html", items=items, pages=pages,
            requested_page=requested_page, current_page=request.args.get('page', 0))
Example #12
0
def draw_centered_map(center_state='TX', n=10):
    """Draw the n states closest to center_state."""
    us_centers = make_database()
    for state, s in get_items(us_states):
        us_centers = add_value(us_centers, state, find_state_center(s))
    center = get_value_from_key(us_centers, center_state.upper())
    dist_from_center = lambda name: geo_distance(
        center, get_value_from_key(us_centers, name))
    for name in sorted(get_keys(us_centers), key=dist_from_center)[:int(n)]:
        draw_state(get_value_from_key(us_states, name))
        draw_name(name, get_value_from_key(us_centers, name))
    draw_dot(center, 1, 10)  # Mark the center state with a red dot
    wait()
Example #13
0
def starred():
    user = get_user()["user"]
    if not user:
        return redirect(url_for('merveilles.login'))

    def filter_func(x):
        return int(loads(x[1])["created_at"]) in user["starred"]
    pages, requested_page = get_effective_page(request.args.get("page", 0),
            filter_func)
    items = get_items(filter_func, g.db_file, requested_page)

    return render_template("index.html", items=items, pages=pages,
            requested_page=requested_page, current_page=request.args.get('page', 0))
Example #14
0
def send_inventory(key):
  db_key = database.get_db_key()
  if db_key != None and key != None and key == db_key:
    phone_sock.send(json.dumps({"type" : "inventory",
                                "inventory" : {"key" : db_key}})+"\n")
  else:
    categories = list()
    for item in database.get_items(order_by = "category"):
      cat_name = sanitize(item[4])
      if len(categories) == 0 or categories[-1]['name'] != cat_name:
        categories.append({"name" : cat_name, "items" : list()})
      categories[-1]['items'].append(make_item(*item[0:4]))
    phone_sock.send(json.dumps({"type" : "inventory",
                                "inventory" : {"key" : db_key,
                                               "categories" : categories}})+"\n")
Example #15
0
def load_states():
    """Load the coordinates of all the state outlines and return them
    in a database, from names to shapes lists.

    >>> len(get_value_from_key(load_states(), 'HI'))  # Hawaii has 5 islands
    5
    """
    json_data_file = open(DATA_PATH + 'states.json', encoding='utf8')
    states = JSONDecoder().decode(json_data_file.read())
    states_database = make_database()
    for state, shapes in states.items():
        states_database = add_value(states_database, state, shapes)
    for state, shapes in get_items(states_database):
        for index, shape in enumerate(shapes):
            if type(shape[0][0]) == list:  # the shape is a single polygon
                assert len(shape) == 1, 'Multi-polygon shape'
                shape = shape[0]
            shapes[index] = [make_position(*reversed(pos)) for pos in shape]
    return states_database
Example #16
0
def load_states():
    """Load the coordinates of all the state outlines and return them
    in a database, from names to shapes lists.

    >>> len(get_value_from_key(load_states(), 'HI'))  # Hawaii has 5 islands
    5
    """
    json_data_file = open(DATA_PATH + 'states.json', encoding='utf8')
    states = JSONDecoder().decode(json_data_file.read())
    states_database = make_database()
    for state, shapes in states.items():
        states_database = add_value(states_database, state, shapes)
    for state, shapes in get_items(states_database):
        for index, shape in enumerate(shapes):
            if type(shape[0][0]) == list:  # the shape is a single polygon
                assert len(shape) == 1, 'Multi-polygon shape'
                shape = shape[0]
            shapes[index] = [make_position(*reversed(pos)) for pos in shape]
    return states_database
Example #17
0
def plot_generic(datelist):
    dfs = {}
    for d in datelist:
        items = database.get_items(d)
        dfs[d] = pd.DataFrame.from_records(items, index='Date', columns=['Description', 'Date', 'Category', 'Price'])

    df = pd.DataFrame.from_records(items, index='Date', columns=['Description', 'Date', 'Category', 'Price'])

    fig, axes = plt.subplots(nrows=2, ncols=1)
    df[df.Price < 500].hist(ax=axes[0], color='k', alpha=0.5, bins=100)
    axes[0].set_title('All prices')

    for d in datelist:
        if not dfs[d].empty:
            temp_ser = dfs[d].index.time
            print(temp_ser)
            pd.to_datetime(dfs[d].set_index(temp_ser, inplace=True))
            print(dfs[d])
            print(temp_ser)
            dfs[d].Description.resample('10T').count().plot.line(ax=axes[1], color='k', alpha=0.5)

    axes[1].set_title('Items / 10 min')
Example #18
0
def plot_categories():
    items = database.get_items(date)
    df = pd.DataFrame.from_records(items, index='Date', columns=['Description', 'Date', 'Category', 'Price'])

    gb = df.groupby(['Category'])

    # for cat in df.Category.unique():
    # does the same thing: data[data.Category == cat]
    # print(gb.get_group(cat))

    print(gb.count())

    plot_price_hist = False
    plot_date_hist = False

    cats = df.Category.unique()[:8]
    cols = 4
    rows = math.ceil(len(cats) / cols)

    if plot_price_hist:
        fig, axes = plt.subplots(nrows=rows, ncols=cols)
        plt.tight_layout(pad=0.4, w_pad=0.5, h_pad=1.0)
        for ind, cat in enumerate(cats):
            ax = axes[ind // cols, ind % cols]
            cat_items = gb.get_group(cat)
            cat_items[cat_items.Price < 1000].hist(ax=ax, color='k', alpha=0.5, bins=100)
            ax.set_title(cat)
            ax.set_xlim(0, 1000)

    if plot_date_hist:
        fig, axes = plt.subplots(nrows=rows, ncols=cols)
        plt.tight_layout(pad=0.4, w_pad=0.5, h_pad=1.0)
        for ind, cat in enumerate(cats):
            ax = axes[ind // cols, ind % cols]
            cat_items = gb.get_group(cat)
            items = cat_items.Description.resample('10T').count()
            items.hist(ax=ax, color='k', alpha=0.5, bins=100)
            ax.set_title(cat)
Example #19
0
def item():
    if request.method == "POST":
        item = json.loads(request.data)
        db_item = db.add_item(name=item["ItemName"],
                              room=item["Room"],
                              owner=item["Owner"],
                              value=item["Value"],
                              quant=item["Quantity"],
                              size=item["Size"],
                              priority=item["Priority"],
                              fragile=item["Fragile"],
                              owned=item["Owned"],
                              moved=item["Moved"],
                              keeping=item["Keeping"],
                              notes=item["Notes"])
        return json.dumps(db_item), 201, json_content
    elif request.method == "GET":
        items = db.get_items()
        return json.dumps(items), 200, json_content
    elif request.methos == "DELETE":
        item = json.loads(request.data)
        db_item = db.delete_item(item["ItemName"])
        return json.dumps(db_item), json_content
Example #20
0
def printItem(vendId):
  printQuery(database.get_items(where = ('vendId', vendId)))