def findNextPoint(self, current): print("moving in simple direction: " + str(current.direction + 180)) new_latlng = self.mover.destination(current.geo, bearing=current.direction + 180) new_point = Point(new_latlng.latitude, new_latlng.longitude) if not new_point.is_in_bounds(): print("point " + str(new_point) + " is out of bounds") return current if not new_point.is_better_than(current): self.move_dist *= .9 self.makeMover() return new_point
def findNextPoint(self, current): new_dir = current.find_weighted_direction() print("moving in weighted direction: " + str(new_dir)) new_latlng = self.mover.destination(current.geo, bearing=new_dir) new_point = Point(new_latlng.latitude, new_latlng.longitude) if not new_point.is_in_bounds(): print("point " + str(new_point) + " is out of bounds") return current if not new_point.is_better_than(current): self.move_dist *= .9 self.makeMover() # if new_point.is_better_than(current): return new_point
def create(self, db: Session, *, curve_in: schemas.CurveCreate) -> Curve: curve = self.model(name=curve_in.name, kind=curve_in.kind, offset=curve_in.offset, default=False) # type: ignore Point(x=0, y=200, first=True, curve=curve) Point(x=1440, y=200, last=True, curve=curve) for index in range(1, curve_in.count - 1): Point(x=1440 / (curve_in.count - 1) * index, y=200, curve=curve) db.add(curve) db.commit() db.refresh(curve) return curve
def point_create(): form = PointForm() if request.method == 'POST' and form.validate_on_submit(): point = Point(area=form.area.data, number=form.number.data, type=form.type.data, installdate=form.installdate.data, startdate=form.startdate.data, enddate=form.enddate.data, locate=form.locate.data, active=form.active.data, cst01=form.cst01.data, cst02=form.cst02.data, cst03=form.cst03.data, cst04=form.cst04.data, cst05=form.cst05.data, cst06=form.cst06.data, cst07=form.cst07.data, cst08=form.cst08.data, cst09=form.cst09.data, cst10=form.cst10.data, cst11=form.cst11.data, cst12=form.cst12.data, cst13=form.cst13.data, cst14=form.cst14.data, cst15=form.cst15.data) db.session.add(point) db.session.commit() return redirect(url_for('point.point_list')) return render_template('point/point_form.html', form=form)
def add_points(user, grade): """Give the user points based on their multiplier""" value = grade * 2 point = Point(user=user, value=value) db.session.add(point) return value
def _is_peak(xs: np.ndarray, ts: np.ndarray, checker: callable) -> List[Point]: """ Looks for peaks in vector of prices xs: Parameters ---------- xs - price array ts - time array checker - function used for checking if point is a peak Returns ------- list of peaks """ lines = [] radius = 7 # For each strength level for i, (y, t) in enumerate(zip(xs, ts)): if i > xs.size - radius: continue if i < radius: continue ys = xs[i - radius:i + radius] is_peak = reduce(lambda a, b: a and b, checker(ys, np.array([y] * ys.size))) if is_peak: lines.append(Point(t, float(y))) return lines
def setUp(self): super().setUp() # add a user self.mitch = AppUser(phone_number=self.inviter_number, username='******', timezone=US_TIMEZONES['b']) self.db.session.add(self.mitch) # self.db.session.add(self.blair) # add a notif self.notif = Notification(router=RouterNames.DID_YOU_DO_IT, hour=21, minute=0, active=True, user=self.mitch) self.db.session.add(self.notif) # add exchange self.exchange = Exchange(router=RouterNames.DID_YOU_DO_IT, outbound='Did you do it?', user=self.mitch, created=dt.datetime.now() - dt.timedelta(days=10)) self.db.session.add(self.exchange) # add point self.point = Point(value=10, user=self.mitch) # add task self.task = Task(description='Win today', due_date=dt.datetime.now(), active=True, exchange=self.exchange, user=self.mitch) self.db.session.add(self.task) self.inteam = Team(id=TEST_TEAM_ID, founder=self.mitch, name='inteam') self.db.session.add(self.inteam) self.pendingteam = Team(founder=self.mitch, name='pendingteam') self.db.session.add(self.pendingteam) self.mitch_member = TeamMember(user=self.mitch, team=self.inteam, inviter=self.mitch, status=Statuses.ACTIVE) self.db.session.add(self.mitch_member) self.mitch_member2 = TeamMember(user=self.mitch, team=self.pendingteam, inviter=self.mitch, status=Statuses.PENDING) self.db.session.add(self.mitch_member2)
def findNextPoint(self, current): best_point = current new_points = [ self.mover.destination(current.geo, bearing=current.direction + 90), self.mover.destination(current.geo, bearing=current.direction + 135), self.mover.destination(current.geo, bearing=current.direction + 180), self.mover.destination(current.geo, bearing=current.direction + 225), self.mover.destination(current.geo, bearing=current.direction + 270) ] for p in new_points: new_point = Point(p.latitude, p.longitude) if not new_point.is_in_bounds(): print("point " + str(new_point) + " is out of bounds") continue if new_point.is_better_than(best_point): best_point = new_point return best_point
def job2(): with scheduler.app.app_context(): # Get data from our db list = Coin.query.order_by(Coin.market_cap_rank.asc()).all() coins = list # keep track at index of coin count = 0 for coin in coins[0:100]: print(coin.name) # Get data from request historical_data = cg.get_coin_market_chart_by_id(id=coin.coin_id, vs_currency='usd', days=7, interval='daily') # Now filter data into x and y lists x = [t[0] for t in historical_data.get('prices')] y = [p[1] for p in historical_data.get('prices')] data = coin.data.all() for k in range(len(x)): if len(data) == 0: p = Point(x=x[k], y=y[k], parent=coin) db.session.add(p) # If Coin already has existing data else: if len(data) == len(x): # If this "time" is not in our db if x[k] not in data and len(x) >= 168: setattr(data[k], 'x', str(x[k - 1])) setattr(data[k], 'y', str(y[k - 1])) count += 1 db.session.commit() print('{} data was added'.format(coin.name)) print("Coin # : ", count) print("NOW SLEEPING") time.sleep(3) print("JOB2 All done :) ")
def add(urlname=''): if urlname: Bbs_node.query.filter_by(urlname=urlname).first_or_404() form = BbsAddForm() nodelist = Bbs_node.get_all_list() choices = [] _c = {} for node in nodelist: choices.append((node.urlname, node.name)) _c[node.urlname] = node.name form.node.choices = choices if urlname and 'GET' == request.method: form.node.data = urlname if form.title.data: form.title.data = form.title.data.strip() if form.validate_on_submit(): node = Bbs_node.query.filter_by(urlname=form.node.data).first() if node is None: abort(404) else: node.n_post += 1 db.session.add(node) content = editor_filter(form.content.data) post = Bbs_post(title=form.title.data, content=content, author=g.user, node=node, is_anony=form.is_anony.data) db.session.add(post) db.session.commit() point = Point.add_bbs_post(g.user, post).get_point() flash(u'成功添加新主题,获得%d个积分' % point, 'message') return redirect(url_for('bbs.detail', post_id=post.id)) X = {'form': form} if urlname: X['node'] = {'urlname':urlname, 'name':_c.get(urlname)} return render_template('bbs/add.html', X=X)
def f_cmt(obj): cmt_form = CmtForm() type = Cmt.get_type(obj) content = cmt_form.content.data pid = cmt_form.pid.data if cmt_form.validate_on_submit(): content = editor_filter(content) is_anony = cmt_form.is_anony.data cmt = Cmt(content = content, pid = pid, is_anony = is_anony, author = g.user, type=type, sid = obj.id) db.session.add(cmt) obj.n_cmt += 1 obj.date_last_mod = datetime.utcnow() obj.user_last_mod = g.user.name(is_anony) db.session.add(obj) db.session.commit() # msg if pid > 0 and cmt.reply(obj): pass elif obj.author != g.user: Msg(uid = obj.author.id, content=u'有人回复了您的主题 %s,快去瞅瞅吧' % obj.get_link(cmt.id)).send() point = Point.add_cmt(g.user, cmt).get_point() flash(u'成功添加评论,获得%d个积分' % point, 'message') return cmt.id # redirect cmts = Cmt.query.filter_by(type=type, sid=obj.id, seen = 1) return {'form': cmt_form, 'list': cmts}
def f_cmt(obj): cmt_form = CmtForm() type = Cmt.get_type(obj) content = cmt_form.content.data pid = cmt_form.pid.data if cmt_form.validate_on_submit(): content = editor_filter(content) is_anony = cmt_form.is_anony.data cmt = Cmt(content=content, pid=pid, is_anony=is_anony, author=g.user, type=type, sid=obj.id) db.session.add(cmt) obj.n_cmt += 1 obj.date_last_mod = datetime.utcnow() obj.user_last_mod = g.user.name(is_anony) db.session.add(obj) db.session.commit() # msg if pid > 0 and cmt.reply(obj): pass elif obj.author != g.user: Msg(uid=obj.author.id, content=u'有人回复了您的主题 %s,快去瞅瞅吧' % obj.get_link(cmt.id)).send() point = Point.add_cmt(g.user, cmt).get_point() flash(u'成功添加评论,获得%d个积分' % point, 'message') return cmt.id # redirect cmts = Cmt.query.filter_by(type=type, sid=obj.id, seen=1) return {'form': cmt_form, 'list': cmts}
def create_point(self, db: Session, *, curve: Curve, point_index: int, point_in: schemas.PointCreate) -> Curve: points = self.get_multiple_points(db, curve=curve) point = points[point_index] if point_in.position == 'after': if point.last: raise HTTPException( status_code=422, detail='Can not create Point after last Point') new_x = self.new_point_location(before=points[point_index], after=points[point_index + 1]) else: if point.first: raise HTTPException( status_code=422, detail='Can not create Point before first Point') new_x = self.new_point_location(before=points[point_index - 1], after=points[point_index]) Point(x=new_x, y=self.calc_value(db, curve, new_x), curve=curve) db.commit() db.refresh(curve) return curve
def putData(): """ putData. putData catch GET or POST requests and put paramaterers from it to db. The name of point must match pattern 'LoRa', otherwise it will be ignored. If name have not in database(db), will be create new point. """ content = request.get_json(silent=True) # print("*******************************************") # print("Incoming Request") # print("datetime now {}".format(datetime.utcnow())) # print("headers {}".format(request.headers)) # print("MIME type {}".format(request.accept_mimetypes)) # print("Date is {}".format(request.date)) # print("Request method: {}".format(request.method)) # print("Content-Type: {}".format(request.content_type)) # print("Data as JSON: {}".format(content)) # print("Raw data: {}".format(request.data)) # print("********************************************") if request.content_type is None: return (jsonify({"content_type": "None"}), "200") if content is None: return (jsonify({"Content": "invalid"}), "200") # method GET not used if request.method == "GET": param = request.args match = re.search("LoRa", param["pointname"]) # name match LoRa or not if match: point = Point.query.filter_by( pointname=content["pointname"]).first() reply = {"Method": "GET"} return (jsonify(reply), "200") if request.method == "POST": match = re.search("LoRa", content["pointname"]) # name match LoRa or not # for item in Point.query.all(): # print("Item in db: {}".format(item)) if match: point = Point.query.filter_by( pointname=content["pointname"]).first() if point is None: # create new instance print("Point is None") point = Point(content["pointname"], content["V1"], content["V2"], content["T"], content["load1"], content["load2"], content["load3"], content["A"], content["B"], content["C"], content["D"]) db.session.add(point) db.session.commit() return ("your first query, ok", "200") compareData(content, point, ignorKeys=('id', 'pointname', 'date', 'modulName', 'data', 'load1', 'load2', 'load3')) point.date = str(datetime.now().isoformat(timespec='seconds')) point.modulName = str(request.user_agent) db.session.add(point) db.session.commit() # print(point) reply = { "load1": point.load1, "load2": point.load2, "load3": point.load3 } return (jsonify(reply), "200") return (jsonify({"Name": "invalid"}), "200")
def insert_points(user, inbound, **kwargs): '''insert arbitrary number of points for user. assume that inbound is an integer''' point = Point(value=inbound, user_id=user['id']) db.session.add(point) db.session.commit()