Example #1
0
    def __init__(self, user_id=None, user=None):
        assert user_id is not None or user is not None, "either the user object or user id must be provided"

        if user_id:
            self.user = session.query(Users).get(user_id)
        else:
            self.user = user
Example #2
0
def main():
    today = datetime.date.today()
    users = [
        {
            "name": '田中太郎',
            "enable": True,
            "dotodays": [[datetime.date(2020, 1, 1), False], [today, True]]
        },
        {
            "name": '鈴木次郎',
            "enable": True,
            "dotodays": [[datetime.date(2020, 1, 1), False]]
        },
    ]

    for user in users:
        user_a = User(name=user['name'], enable=user['enable'])
        session.add(user_a)
        session.flush()
        for dotoday in user["dotodays"]:
            dotoday_a = DoToday(date=dotoday[0],
                                id=user_a.id,
                                dotoday=dotoday[1])
            session.add(dotoday_a)

    session.commit()
    users = session.query(User,
                          DoToday).outerjoin(DoToday,
                                             User.id == DoToday.id).all()
    pp(users)
Example #3
0
def main():
    today = datetime.date.today()
    users = session.query(User.id, User.name, DoToday.dotoday).outerjoin(
        DoToday, and_(User.id == DoToday.id, DoToday.date == today)).all()
    [dict(zip(("id", "name", "dotoday"), user)) for user in users]
    usernames = '、'.join([user[1] for user in users])
    message = ("本日は残業します\n" "メンバー:" + usernames)
    print(message)
Example #4
0
    def login(username, password):
        try:
            user = session.query(Users).filter(Users.username == username).one()
        except NoResultFound:
            raise UserNotFoundException

        if bcrypt.checkpw(password.encode(), user.password.encode()):
            return UserController(user=user)
        else:
            raise UserNotFoundException
Example #5
0
async def getMembers():
    today = datetime.date.today()
    users = session.query(User.id, User.name, DoToday.dotoday).outerjoin(
        DoToday, and_(User.id == DoToday.id, DoToday.date == today)).all()
    result = {
        "today": today,
        "users":
        [dict(zip(("id", "name", "dotoday"), user)) for user in users]
    }
    pp(result)
    return result
Example #6
0
async def putMembers(id, item: PutMembersItem):
    success = True
    message = ""
    pp(item)
    today = datetime.date.today()
    user = session.query(User.id).filter(User.id == id).first()
    if user == None:
        success = False
        message = "ユーザーが見つかりません"
    else:
        dotoday = session.query(DoToday).filter(
            DoToday.id == id, DoToday.date == today).with_for_update().first()
        if dotoday == None:
            dotoday = DoToday(id=id, date=today)
            session.add(dotoday)
        dotoday.dotoday = item.dotoday
        session.commit()

        users = session.query(User,
                              DoToday).outerjoin(DoToday,
                                                 User.id == DoToday.id).all()
        pp(users)

    return {"success": success, "message": message}
Example #7
0
    def find_trips_matching_line(cls, line, user_id):
        '''Find trips which completely contain the given line.

        Eventually, this method could also check to make sure that
        the given line is also heading in the same direction. This
        can be accomplished by finding the nearest point on a given
        route to each vertex on the input line (ST_LineLocatePoint). 
        There is a function
        called ST_OrderingEquals which will find if lines are moving
        in the same direction. So those derived points could be compared
        to the route to check that the original input line is moving in the
        correct direction.

        Another interesting addition would be to relax the contraint that
        every point of the given line needs to be inside of the target
        route buffer. Instead, maybe only 90% of points from a sufficiently
        large sample size would be sufficient.
        '''
        proj_line = cls.points_to_projected_line(line)
        s = session.query(Trip).filter_by(user_id=user_id).filter(func.ST_Within(proj_line, Trip.geom))
        return s
Example #8
0
def query_phton_and_first_hit():
    return (session.query(
        Photon, Hit).filter(Hit.photon_id == Photon.id).filter(Hit.index == 0))