예제 #1
0
def OnGroupMsgs(message):
    ''' 监听群组消息'''

    tmp1 = message
    tmp2 = tmp1['CurrentPacket']
    tmp3 = tmp2['Data']
    a = GMess(tmp3)
    '''
    a.FrQQ 消息来源
    a.QQGName 来源QQ群昵称
    a.FromQQG 来源QQ群
    a.FromNickName 来源QQ昵称
    a.Content 消息内容
    a.MsgSeq 消息ID
    '''
    if 'GroupPic' in str(a.Content):
        Group.Group(msg=a.Content, QQ=a.FromQQID, GroupID=a.FromQQG)
    else:
        Jiance = Text.Check(msg=a.Content)
        if Jiance['Data']['DetailResult'] == None:
            Group.Group(msg=a.Content, QQ=a.FromQQID, GroupID=a.FromQQG)
        else:
            Group.Block(Jiance['Data']['DetailResult'][0]['EvilLabel'],
                        GroupID=a.FromQQG,
                        MsgSeq=a.MsgSeq,
                        MsgRandom=a.MsgRandom,
                        QQ=a.FromQQID)

    te = re.search(r'\#(.*)', str(a.Content))
    if te == None:
        return
예제 #2
0
    def create(self):

        self.setTitle("Space Rocks")
        self.fpsDisplay = True

        space = Sprite()
        space.setTexture(Texture.load("assets/space-rocks/space.png"))
        space.setPosition(400, 300)
        self.group.addEntity(space)

        self.spaceship = Sprite()
        self.spaceship.setTexture(
            Texture.load("assets/space-rocks/spaceship.png"))
        self.spaceship.setPosition(100, 300)
        # physics values
        self.spaceship.setPhysics(100, 200, 10)
        self.spaceship.addAction(ActionFactory.wrapToScreen(800, 600))
        self.group.addEntity(self.spaceship)

        rockTexture = Texture.load("assets/space-rocks/rock.png")
        self.rockGroup = Group()
        self.group.addEntity(self.rockGroup)

        for n in range(6):
            rock = Sprite()
            x = random() * 400 + 300
            y = random() * 600
            rock.setPosition(x, y)
            rock.setTexture(rockTexture)
            rock.setPhysics(0, 80, 0)
            rock.physics.setSpeed(80)
            angle = random() * 360
            rock.angle = angle
            rock.physics.setMotionAngle(angle)
            rock.addAction(ActionFactory.wrapToScreen(800, 600))
            self.rockGroup.addEntity(rock)

        self.laserTexture = Texture.load("assets/space-rocks/laser.png")
        self.laserGroup = Group()
        self.group.addEntity(self.laserGroup)

        self.explosionAnimation = Animation.load(
            "assets/space-rocks/explosion.png", 6, 6, 0.03, False)

        self.messageWin = Sprite()
        self.messageWin.setTexture(
            Texture.load("assets/space-rocks/message-win.png"))
        self.messageWin.setPosition(400, 300)
        self.messageWin.opacity = 0
        self.messageWin.visible = False
        self.group.addEntity(self.messageWin)
예제 #3
0
 def out_of_band_members(self):
     '''
     (MemberDatabase) -> list
     
     Returns a list of Members with out-of-band status.
     '''
     return Group.Group(self._directory, self._database,
                        "type-outofband").members()
예제 #4
0
def main():
  print('\n- Cost Splitter -')

  # Load save.
  groups = s.load_all_groups()
  if groups is None:
    groups = {}

  # Loop.
  user_in = ''
  while user_in != 'exit' and user_in != 'q':
    print_main_menu()
    user_in = input()
    print('')

    # Print groups.
    if user_in == '1':
      if len(groups) == 0:
        print('No stored groups')
        continue
      print('Stored Groups:')
      for group_name in groups:
        groups[group_name].print_group()
        print('')
    
    # Select group.
    if user_in == '2':
      print('Which group would you like to select?:')
      list_group_names(groups)
      group_name = input()
      if group_name not in groups:
        print('Group ' + group_name + ' does not exist\n')
        continue
      group_menu(groups[group_name])

    # Add new group.
    if user_in == '3':
      print('Enter name of group to add: ', end='')
      group_name = input()
      if group_name in groups:
        print('"' + group_name+ '" already exists in list of groups.')
        continue
      groups[group_name] = Group.Group(group_name)
      s.save_group(groups[group_name])
      # Select group automatically after creation.
      group_menu(groups[group_name])
    
    # Remove existing group.
    if user_in == '4':
      print('Enter name of group to remove:')
      list_group_names(groups)
      group_name = input()
      if group_name not in groups:
        print('"' + group_name+ '" cannot be found in list of groups.')
        continue
      deleted_group = groups.pop(group_name)
      s.delete_group(deleted_group)
예제 #5
0
def MatchContinueDress(who, s):
    ret = []
    pattern = MATCH_YB_CONTINUE_DRESS if who == YB else MATCH_PLAYER_CONTINUE_DRESS
    for i in re.finditer(pattern, s):
        group = Group(i.span()[0], i.span()[1] - 1)
        #		print(group)
        ret.append(group)
    ret.sort()
    return ret
예제 #6
0
def create_group(guestArray, guestIndices, groupList=[], useAll='True'):
    """
    Function takes in indices of guests to be grouped together. 
    The group that is created gets appended onto groupList. 
    If "useAll" parameter is True, then the remaining guests in the guestArray
    get grouped together into a second group (which then gets appended onto groupList). 
    Otherwise, the remaining guests are left in guestArray for future grouping.
    """
    guestListTemp = list()
    #the pointers to all of the objects needed to be removed
    listTorem = list()
    
    #add all the pointers of the objects needed to be removed to the holding arr
    for i in guestIndices:
        g = guestArray[i]
        listTorem.append(g)
    #run through each object needed to be removed and remove it from the GL
    
    print listTorem
    print guestIndices
    
    for i in range(len(listTorem)): 
        #pointer to object
        gRem = listTorem[i]
        #put that object into guest List temp
        guestListTemp.append(gRem)
        #If we are using everything
        if useAll: 
            #remove it from the guestArray
            guestArray.remove(gRem)
            
    print listTorem
    #create a group for this guest List
    group = Group(guestListTemp)
    #append it to our returning list
    groupList.append(group)
    #if we are using everything
    if useAll: 
        #make a group from the remnants
        group = Group(guestArray)
        #append it to our returning thingy
        groupList.append(group)
    #return our t
    return groupList, guestArray
예제 #7
0
 def __init__(self, directory, database, roleName):
     '''
     (Role, LdapConnection, SqlConnection, str) -> None
     
     Initialize the Role instance from the role name.
     '''
     self._directory = directory
     self._database = database
     self._name = roleName
     self._roleGroup = Group.Group(directory, database, roleName)
예제 #8
0
 def __init__(self, handtiles, ting_tile, iszimo, melds=[]):
     assert len(handtiles) + len(melds) * 3 == 14
     self.funList = [dandiao, wuzi, queyimen, erwubajiang, pengfeng, laoshaofu, yibangao, siguiyi, minggang, angang,
                     bianzhang, kanzhang, lianliu, xixiangfeng, pinghu, self.buqiuren, self.menqing, self.zimo]
     self.handtiles = handtiles
     self.ting_tile = ting_tile
     self.iszimo = iszimo
     self.melds = melds
     self.fan = 0
     self.group = Group(handtiles, melds)
     self.group.judge()
예제 #9
0
def decompose_addition_group(m: int):
    subgroups = []
    orders = []

    if get_euler(m) == m - 1:
        subgroups.append(Group.Group(1, [0], Group.OperationType.ADDITION))
        subgroups.append(Group.Group(2, list(range(m)), Group.OperationType.ADDITION))
        return subgroups

    for a in range(1, m + 1):
        for n in range(1, m + 1):
            if a * n % m == 0:
                if n in orders:
                    break
                subgroups.append(Group.Group(a,
                                             fill_subgroup(a, n, m, OperationType.ADDITION),
                                             Group.OperationType.ADDITION))
                orders.append(n)
                break

    return subgroups
    def build_account_object(self, received_list):
        """
        This functions builds an account object which can be written directly to the database. The function received a
        list containing the teacher, course, groups and students plus semester.

        Example list style: [{"teacher": ["Teachername"], {"course":["Coursename"]}...}]
        :param received_list:
        :type received_list:
        :return account:
        :rtype DbAccount:
        """
        account = DbAccount()
        teacher = Teacher()
        course = Course()
        group = Group()
        groupdict = {}
        for i in received_list:
            for key, value in i.iteritems():
                if "teacher" in key:
                    teacher.set_name(value[0])
                elif "semester" in key:
                    teacher.set_semester(value[0])
                elif "course" in key:
                    course.set_coursename(value[0])
                elif "group" in key:
                    for groupkey, memberlist in value.iteritems():
                        group = Group()
                        groupdict.update({groupkey: memberlist})
                        group.set_groupname(groupkey)
                        group.set_students(memberlist)
                        if any(x.get_groupname() == groupkey
                               for x in course.get_groups()):
                            logging.info(groupkey +
                                         " exists in the object from before")
                        else:
                            course.set_group_list(group)
        teacher.set_course(course)
        account.set_teacher(teacher)
        return account
예제 #11
0
def load(graph):
    with open('users_data.json') as f:
        data = json.load(f)

    graph.numUsers = 0
    graph.maxUsers = int(data["maxUsers"])
    graph.num_posts = int(data["num_posts"])
    for one in data["Users"]:
        graph.AddUser(
            person.Person(one["name"], one["email"], one["password"],
                          one["age"], one["location"], one["gender"]))
        graph.Users[-1].groups = [int(i) for i in one["groups"]]
        graph.Users[-1].posts = [int(i) for i in one["posts"]]
        graph.Users[-1].admin = [int(i) for i in one["admin"]]
        for x in one["requests_sent"]:
            graph.Users[-1].requests_sent[int(x)] = int(
                one["requests_sent"][x])

        for x in one["requests_received"]:
            graph.Users[-1].requests_received[int(x)] = int(
                one["requests_received"][x])

    graph.edges = []
    for row in range(0, len(data["edges"])):
        graph.edges.append([])
        for col in range(0, len(data["edges"][row])):
            graph.edges[row].append([
                int(data["edges"][row][col][0]),
                int(data["edges"][row][col][1])
            ])

    for i in data["Posts"]:
        graph.Posts.append(post.Post(i["text"], int(i["user_id"])))
        graph.Posts[-1].post_id = int(i["post_id"])
        graph.Posts[-1].time = i["time"]
        for j in i["Comments"]:
            graph.Posts[-1].Comments.append(
                post.Comment(j["text"], int(j["user_id"]), int(j["post_id"])))
            graph.Posts[-1].Comments[-1].time = j["time"]
            graph.Posts[-1].Comments[-1].comment_id = int(j["comment_id"])

    for g in data["Groups"]:
        graph.Groups.append(
            group.Group(0, g["group_name"], g["group_description"]))
        graph.Groups[-1].admin_id = [int(i) for i in g["admin_id"]]
        graph.Groups[-1].group_id = int(g["group_id"])
        graph.Groups[-1].group_members = [int(i) for i in g["group_members"]]
        graph.Groups[-1].group_posts = [int(i) for i in g["group_posts"]]
        graph.Groups[-1].group_count = int(g["group_count"])
예제 #12
0
 def __init__(self):
     pygame.display.init()
     pygame.font.init()
     self.windowSize = (800, 600)
     self.windowMode = pygame.locals.DOUBLEBUF  # much better than default (0)
     self.displaySurface = pygame.display.set_mode(self.windowSize,
                                                   self.windowMode)
     self.running = True
     self.input = Input()
     self.group = Group()
     self.clearColor = (255, 255, 255)
     self.deltaTime = 0
     # display FPS
     self.fpsDisplay = False
     self.fps = 60
     self.fpsClock = pygame.time.Clock()
예제 #13
0
    def login_user(self, user: User):
        """ Logs the user in and gets the group name. A new group is created
            if the group requested does not exist already.

        Args:
            user (User): The user who is supposed to be logged in
        """
        user_name = self.get(user)
        user.user_name = user_name
        self.send(user, '/sendgroup')
        group_name = self.get(user)
        user.group_name = group_name
        if group_name in self.groups.keys():
            self.groups[group_name].connect(user)
        else:
            self.groups[group_name] = Group.Group(group_name)
            self.groups[group_name].connect(user)
예제 #14
0
def decompose_multiple_group(m: int):
    subgroups = []
    orders = []

    for a in range(1, m):
        eul = get_euler(m)
        n = 1
        while n <= eul:
            if a ** n % m == 1:
                if n in orders:
                    break
                subgroups.append(Group.Group(a,
                                             fill_subgroup(a, n, m, OperationType.MULTIPLE),
                                             Group.OperationType.MULTIPLE))
                orders.append(n)
                break
            n += 1

    return subgroups
예제 #15
0
 def addGroupToContainer():
     newGroup = Group(groupE.get())
     errorCode = checkNewGroup(newGroup.getName(), groupContainer)
     if errorCode == 0:
         groupContainer.getGroupList().append(newGroup)
         grpWindow.destroy()
     elif errorCode == 1:
         errorL = makeLabel(grpWindow, "Group Name Empty", "Red")
         errorL.grid(row=3,
                     column=0,
                     sticky="nsew",
                     padx=(15, 15),
                     pady=(0, 10))
     elif errorCode == 2:
         errorL = makeLabel(grpWindow, "Group Already Exists", "Red")
         errorL.grid(row=3,
                     column=0,
                     sticky="ew",
                     padx=(15, 15),
                     pady=(0, 10))
예제 #16
0
    def __init__(self, parent, username):
        self._user = username
        self._group_model = Group()
        self._user_group_model = UserGroup()
        self._custom_goal = CustomGoal()

        self.data = self.read_data()
        self.proxyModel = SortFilterProxyModel()  # make a proxy model object
        self.model = CustomTableModel(self.data)
        self.proxyModel.setSourceModel(self.model)

        self.ui = Ui_group(parent, self.proxyModel, self.data)
        #self.ui.group_table.setModel(self.proxyModel)  # At initialisation, the proxyModel is the model itself
        self.checkGroupSearch()  # method for searching the database
        self.ui.group_table.clicked.connect(
            partial(self.displayInQlineEdit
                    ))  # method for displaying text when row is clicked

        #self.ui.group_name_output.textEdited.connect(partial(self.addNewGroup))  # method for editing calorific value when portion changes
        self.ui.create_group_button.clicked.connect(partial(
            self.addNewGroup))  # method to add new food to database
        self.ui.join_group_button.clicked.connect(partial(
            self.joinNewGroup))  # method to add new food to database
예제 #17
0
    def json_to_data(self, data, conn):
        self.conn = conn

        # init data
        self.plan = []
        self.constraints = []
        self.groups = []

        width = data["width"]
        height = data["height"]
        forbidden_seats = data["forbidden_seats"]
        for line in range(height - 1):
            self.plan.append([])
            for cell in range(width - 1):
                forbid = any(fseat["line"] == line and fseat["cell"] == cell
                             for fseat in forbidden_seats)
                self.plan[line].append(0 if forbid else 1)

        groups = data["groups"]
        for group in groups:
            self.groups.append(Group(group["name"], group["number"], None, 0))

        self.lets_go()
예제 #18
0
    def create(self):

        self.setTitle("Rectangle Destroyer")
        self.fpsDisplay = True

        background = Sprite()
        background.setTexture(
            Texture.load("assets/rectangle-destroyer/background.jpg"))
        background.setPosition(400, 300)
        self.group.addEntity(background)

        self.paddle = Sprite()
        self.paddle.setTexture(
            Texture.load("assets/rectangle-destroyer/paddle.png"))
        self.paddle.setPosition(400, 550)
        self.group.addEntity(self.paddle)

        self.ball = Sprite()
        self.ball.setTexture(
            Texture.load("assets/rectangle-destroyer/ball.png"))
        self.ball.setPosition(400, 525)
        self.ball.setPhysics(0, 1000, 0)
        self.group.addEntity(self.ball)

        self.wallGroup = Group()
        self.group.addEntity(self.wallGroup)
        wallSideTexture = Texture.load(
            "assets/rectangle-destroyer/wall-side.jpg")  # 20 x 600
        wallTopTexture = Texture.load(
            "assets/rectangle-destroyer/wall-top.jpg")  # 800 x 60
        leftWall = Sprite()
        leftWall.setTexture(wallSideTexture)
        leftWall.setPosition(10, 300)
        rightWall = Sprite()
        rightWall.setTexture(wallSideTexture)
        rightWall.setPosition(790, 300)
        topWall = Sprite()
        topWall.setTexture(wallTopTexture)
        topWall.setPosition(400, 30)
        self.wallGroup.addEntity(leftWall)
        self.wallGroup.addEntity(rightWall)
        self.wallGroup.addEntity(topWall)

        self.brickGroup = Group()
        self.group.addEntity(self.brickGroup)

        brickTexture = Texture.load("assets/rectangle-destroyer/brick.jpg")

        for col in range(0, 11):
            for row in range(0, 8):
                brick = Sprite()
                brick.setTexture(brickTexture)
                brick.setPosition(80 + 64 * col, 120 + row * 32)
                self.brickGroup.addEntity(brick)

        self.messageLabel = Label()
        self.messageLabel.loadFont("assets/starfish-collector/OpenSans.ttf",
                                   48)
        self.messageLabel.fontColor = (128, 128, 128)
        self.messageLabel.text = "click to start"
        self.messageLabel.setPosition(400, 400)
        self.messageLabel.alignment = "CENTER"
        self.group.addEntity(self.messageLabel)

        self.score = 0
        self.scoreLabel = Label()
        self.scoreLabel.loadFont("assets/starfish-collector/OpenSans.ttf", 36)
        self.scoreLabel.fontColor = (255, 255, 0)
        self.scoreLabel.text = "Score: " + str(self.score)
        self.scoreLabel.setPosition(400, 0)
        self.scoreLabel.alignment = "CENTER"
        self.group.addEntity(self.scoreLabel)
예제 #19
0
from Group import *
from Person import *

formAnswers = open("form-answers.txt", "r").read().splitlines()

setOfAnswers = set()
listOfPersons = list()
listOfGroups = list()
for line in formAnswers:
    if (len(line) != 0):
        for answer in line:
            setOfAnswers.add(answer)
        listOfPersons.append(Person(setOfAnswers.copy()))
        setOfAnswers.clear()
    else:
        listOfGroups.append(Group(listOfPersons.copy()))
        listOfPersons.clear()

# Part 1: For each group, count the number of questions to which anyone answered "yes"
yesCounter = 0
for group in listOfGroups:
    yesCounter += len(group.getUnionAnswers())

print(
    "Day 6 - part one: For each group, the total number count of questions to which ANYONE answered 'yes' is",
    yesCounter)

# Part 2: For each group, count the number of questions to which anyone answered "yes"
yesCounter = 0
for group in listOfGroups:
    yesCounter += len(group.getIntersectionAnswers())
예제 #20
0
 def groups(self):
     return [Group.Group(group["_id"]) for group in self.__groups]
예제 #21
0
    def handle(self, msg_list):
        assert isinstance(msg_list, list), "msg_list is NOT a LIST"
        for msg in msg_list:
            # 仅处理程序管理层面上的操作 Only do the operation of the program management

            if not isinstance(msg, (Msg, Notify)):
                logging.error(
                    "Handler received a not a Msg or Notify instance.")
                raise TypeError(
                    "Handler received a not a Msg or Notify instance.")

            elif isinstance(msg, MsgWithContent):
                logging.info(
                    str(self.__operator.get_account(msg)) + ":" + msg.content)

            if isinstance(msg, GroupMsg):
                # 判断群对象是否存在,info_seq实际上为群号
                if msg.info_seq not in self.__group_list:
                    self.__group_list[msg.info_seq] = Group(
                        self.__operator, msg)
                    self.process_threads[msg.info_seq] = MsgHandleQueue(
                        self.__group_list[msg.info_seq])
                    self.process_threads[msg.info_seq].start()
                    logging.debug("Now group list:  " + str(self.__group_list))

                tgt_group = self.__group_list[msg.info_seq]
                if len(tgt_group.msg_list
                       ) >= 1 and msg.seq == tgt_group.msg_list[-1].seq:
                    # 若如上一条seq重复则抛弃此条信息不处理
                    logging.info("消息重复,抛弃")
                    return

                tgt_group.msg_id = msg.msg_id

                self.process_threads[msg.info_seq].append(msg)

            elif isinstance(msg, PmMsg):
                tid = self.__operator.get_account(msg)
                if tid not in self.__pm_list:
                    self.__pm_list[tid] = Pm(self.__operator, msg)
                    self.process_threads[tid] = MsgHandleQueue(
                        self.__pm_list[tid])
                    self.process_threads[tid].start()
                    logging.debug("Now pm thread list:  " +
                                  str(self.__pm_list))

                tgt_pm = self.__pm_list[tid]
                if len(tgt_pm.msg_list) >= 1 and msg.time == tgt_pm.msg_list[-1].time \
                        and msg.from_uin == tgt_pm.msg_list[-1].from_uin \
                        and msg.content == tgt_pm.msg_list[-1].content:
                    # 私聊没有seq可用于判断重复,只能抛弃同一个人在同一时间戳发出的内容相同的消息。
                    logging.info("消息重复,抛弃")
                    return

                tgt_pm.msg_id = msg.msg_id

                self.process_threads[tid].append(msg)

            elif isinstance(msg, SessMsg):
                tid = self.__operator.get_account(msg)
                if tid not in self.__sess_list:
                    self.__sess_list[tid] = Sess(self.__operator, msg)
                    self.process_threads[tid] = MsgHandleQueue(
                        self.__sess_list[tid])
                    self.process_threads[tid].start()
                    logging.debug("Now sess thread list:  " +
                                  str(self.__sess_list))

                tgt_sess = self.__sess_list[tid]
                if len(tgt_sess.msg_list) >= 1 and msg.time == tgt_sess.msg_list[-1].time \
                        and msg.from_uin == tgt_sess.msg_list[-1].from_uin \
                        and msg.content == tgt_sess.msg_list[-1].content:
                    # 私聊没有seq可用于判断重复,只能抛弃同一个人在同一时间戳发出的同一内容的消息。
                    logging.info("消息重复,抛弃")
                    return
                tgt_sess.msg_id = msg.msg_id
                self.process_threads[tid].append(msg)

            elif isinstance(msg, InputNotify):
                self.__input_notify_handler(msg)

            elif isinstance(msg, BuddiesStatusChange):
                self.__buddies_status_change_handler(msg)

            elif isinstance(msg, KickMessage):
                self.__kick_message(msg)

            else:
                logging.warning("Unsolved Msg type :" + str(msg.poll_type))
                raise TypeError("Unsolved Msg type :" + str(msg.poll_type))
예제 #22
0
    def test_mode(self):
        # le plan
        self.plan = [
            [
                1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                1, 1, 1
            ],
            [
                1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1,
                1, 1, 1
            ],
            [
                1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1,
                1, 1, 1
            ],
            [
                1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1,
                1, 1, 1
            ],
            [
                1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1,
                1, 1, 1
            ],
            [
                1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1,
                1, 1, 1
            ],
            [
                1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1,
                1, 1, 1
            ],
            [
                1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1,
                1, 1, 1
            ],
            [
                1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1,
                1, 1, 1
            ],
        ]
        # Les contraintes
        ct_p_rang = Constraint("p_rang")
        ct_p_rang.set_concerned_seats([
            [8, 0],
            [8, 1],
            [8, 2],
            [8, 3],
            [8, 4],
            [8, 5],
            [8, 6],
            [8, 7],
            [8, 8],
            [8, 9],
            [8, 10],
            [8, 12],
            [8, 12],
            [8, 13],
            [8, 14],
            [8, 15],
            [8, 16],
            [8, 17],
            [8, 18],
            [8, 19],
            [8, 20],
            [8, 21],
            [8, 22],
            [8, 23],
        ])
        ct_milieu = Constraint("milieu")
        ct_milieu.set_concerned_seats([
            [3, 0],
            [3, 1],
            [3, 2],
        ])
        self.constraints = [
            ct_p_rang,
            ct_milieu,
        ]

        # les groupes de personnes
        self.groups = [
            Group("Madi.L", 5, ct_p_rang, "*"),
            Group("Leco.A", 6, None, 0),
            Group("Maingu", 2, None, 0),
            Group("Bour.R", 2, None, 0),
            Group("Coll.J", 8, None, 0),
            Group("Meun.V", 16, None, 0),
            Group("Leme.H", 3, None, 0),
            Group("Vall.M", 2, None, 0),
            Group("Lero.E", 2, None, 0),
            Group("Laur.T", 8, None, 0),
            # Group("Jupin", 2, None, 0),
            # Group("Pean.A", 2, None, 0),
            # Group("Bett.A", 9, None, 0),
            # Group("Les vi  ", 33, None, 0),
            # Group("Pins.V  ", 10, None, 0),
            # Group("Pott.N", 2, None, 0),
            # Group("Remi p", 3, None, 0),
            # Group("Epro.I", 6, None, 0),
            # Group("Doue.K", 1, None, 0),
            # Group("Dilis", 3, None, 0),
            # Group("Delcou", 4, None, 0),
            # Group("Epro.M", 5, None, 0),
            # Group("Gibon", 6, None, 0),
            # Group("Lang.P  ", 19, None, 0),
            # Group("Rondea", 1, None, 0),
            # Group("Jarr.V", 2, None, 0),
            # Group("Dane.D", 2, None, 0),
            # Group("Techer", 4, None, 0),
            # Group("Pier.J", 5, None, 0),
            # Group("Pillai", 7, None, 0),
            # Group("Less.B", 1, None, 0),
            # Group("Yver.M", 3, None, 0),
        ]

        return self.lets_go()
예제 #23
0
import Group as gp  # 使用 as 可以避免过长的前缀
import sys

sys.path.append("../base")
import Temo as note

mygroup = gp.Group("GD dd", "ddd lab", "ddd")
mygroup.show()
예제 #24
0
 def create_group(self, name, description):
     group = Group(name=name, description=description)
     self.session.add(group)
     self.session.flush()
     return group
예제 #25
0
 def add_group(self,admin_id, group_name,description = None):
     self.Groups.append(group.Group(admin_id,group_name,description))
예제 #26
0
 def __init__(self):
     self.__groupList = []
     self.__groupNameList = []
     generalGroup = Group("General")
     self.addGroup(generalGroup)
예제 #27
0
def full_cover_V1(res, genes_lst, size_of_input):
    '''find the candidates group that maximize the objective'''
    groups_DS = []
    #make the singletones
    for i in range(len(res)):
        groups_DS.append(Group(res[i].genes_score_dict, set([i])))
예제 #28
0
    def generate_school_timetable(self, profs, courses, class_list, break_time,
                                  settings):
        def arrange_regular():
            pass

        # Step 1: initialization & checking
        wait = og.show_waiting_message()
        conflicts = []
        for pid in profs.keys():
            profs[pid].schedule = []  # Clear all schedule
            for i in range(self.week_num):
                profs[pid].schedule.append(
                    tt.Timetable(title=profs[pid].name +
                                 l.timetable_of_week[settings.language] +
                                 str(i)))
                # in Prof.schedule, for Timetable[i][j],
                # 0: not occupied;
                # not possible: the prof required not to teach in this period(set in Prof info page;
                # break time: the period is in break time, thus not allocated with any courses;
                # [course_id, [classId]]: teach Course with course_id to Class(es) with classId(s)in this period

        for cid in class_list.keys():
            class_list[cid].schedule = []  # Clear all schedule
            for i in range(self.week_num):
                class_list[cid].schedule.append(
                    tt.Timetable(title=class_list[cid].classId +
                                 l.timetable_of_week[settings.language] +
                                 str(i)))
                # in Class.schedule, for Timetable[i][j],
                # 0: not occupied;
                # break time: the period is in break time, thus not allocated with any courses;
                # [course_id, [prof_id]]: be taught Course with course_id by Prof(s) with prof_id(s) in this period

        # Step 2: negate all break time in schedule, so that it can't be used
        for pid in profs.keys():  # set break time in profs' info
            cur = profs[pid].schedule
            for w in range(self.week_num):
                err = cur[w].update_based_on(break_time, ['0'], ['0', '1'],
                                             '1', 'break time')
                if err: print(err)

        for cid in class_list.keys():  # set break time in classes' info
            cur = class_list[cid].schedule
            for w in range(self.week_num):
                err = cur[w].update_based_on(break_time, ['0'], ['0', '1'],
                                             '1', 'break time')
                if err: print(err)

        # Step 3: negate all time not possible in profs' schedule
        for pid in profs.keys():
            tnp = profs[pid].time_not_possible
            for w in range(self.week_num):
                err = profs[pid].schedule[w].update_based_on(
                    tnp, ['0', 'break time'], ['0', '1'], '1',
                    'time not possible')
                if err: print(err)

        # Step 4: take all Courses that should be scheduled
        courses_to_be_allocated = {}
        courses_manually = []
        for cid in courses.keys():
            if courses[cid].should_be_scheduled and not courses[
                    cid].scheduled_manually:
                courses_to_be_allocated[cid] = courses[cid]
        for cid in courses.keys():
            if courses[cid].should_be_scheduled and courses[
                    cid].scheduled_manually:
                courses_manually.append(courses[cid])

        # Step 5: check Courses
        for c in courses_manually:
            if not c.groups:
                err.append(c.title +
                           " hasn't been assigned with any classes or profs")
            if c.period_required.all_zeros():
                err.append(
                    c.title +
                    ' is set to manually distributed, but no periods are given'
                )
            if not ('1' in c.weeks):
                err.append(c.title + ': no weeks are set')
        for cid in courses_to_be_allocated.keys():
            c = courses_to_be_allocated[cid]
            if not c.groups:
                err.append(c.title +
                           " hasn't been assigned with any classes or profs")
            if not ('1' in c.weeks):
                err.append(c.title + ': no weeks are set')
        if err: print(err)

        # Step 6: pre-distribute courses that are set manually
        for c in courses_manually:
            print('allocating ', c.title)
            for w in range(30):
                if c.weeks[w] == 0 or c.weeks[w] == '0':
                    continue
                for g in c.groups:
                    for cl in g[0]:
                        err = class_list[cl].schedule[w].check(
                            c.period_required, '0', '1')
                        class_list[cl].schedule[w].change(
                            c.period_required,
                            [c.course_id, [i for i in g[1]]], '1')
                        if err:
                            print(err)

                    for p in g[1]:
                        err = profs[p].schedule[w].check(
                            c.period_required, '0', '1')
                        profs[p].schedule[w].change(
                            c.period_required,
                            [c.course_id, [i for i in g[0]]], '1')
                        if err:
                            print(err)

        # Step 7: allocate courses

        # Courses to groups
        groups = []
        for cid in courses_to_be_allocated.keys():
            c = courses_to_be_allocated[cid]
            for g in c.groups:
                cur_group = Group.Group(c.course_id, g[1], g[0])
                groups.append(cur_group)

        # i)Select courses that have profs with time preference (first group of Courses)

        # to be implemented

        # ii)Select courses that have profs with time not possible (second group of Courses)
        second = []
        for i in range(len(groups))[::-1]:
            cur_prof_id_list = groups[i].prof_id_list
            for cur_prof_id in cur_prof_id_list:
                if profs[cur_prof_id].get_time_impossible_as_list():
                    second.append(groups[i])
                    groups.pop(i)

        err = []
        if settings.arranging_rule == 0:  # if set to priority to periods that are most empty
            print(
                'Allocating courses with priority to periods that are most empty in a week'
            )
        elif settings.arranging_rule == 1:  # if set to closely pack
            print('Allocating courses: closely pack everything')
            for i in range(len(second)):
                cur_prof_id_list = second[i].prof_id_list
                cur_class_id_list = second[i].class_id_list
                weeks = courses[second[i].course_id].weeks
                first_period_is_chosen, second_period_is_chosen = False, False

                for date in range(7):
                    for period in range(12):
                        if not op.profs_are_available(profs, cur_prof_id_list,
                                                      weeks, period, date):
                            continue
                        elif not oc.classes_are_available(
                                class_list, cur_class_id_list, weeks, period,
                                date):
                            continue
                        else:
                            first_period_is_chosen = True
                            first_period = (period, date)
                            for d in range(date + 2, 7):
                                for p in range(12):
                                    if not op.profs_are_available(
                                            profs, cur_prof_id_list, weeks, p,
                                            d):
                                        continue
                                    elif not oc.classes_are_available(
                                            class_list, cur_class_id_list,
                                            weeks, p, d):
                                        continue
                                    else:
                                        second_period_is_chosen = True
                                        second_period = (p, d)
                                        break
                                if second_period_is_chosen:
                                    break

                        if first_period_is_chosen and second_period_is_chosen:
                            break
                    if first_period_is_chosen and second_period_is_chosen:
                        break

                if not (first_period_is_chosen and second_period_is_chosen):
                    err.append(courses[second[i].course_id].title +
                               'cannot be arranged')
                else:
                    for pid in cur_prof_id_list:
                        op.change(profs, pid, weeks, first_period[0],
                                  first_period[1],
                                  [second[i].course_id, cur_class_id_list])
                        op.change(profs, pid, weeks, first_period[0] + 1,
                                  first_period[1],
                                  [second[i].course_id, cur_class_id_list])
                        op.change(profs, pid, weeks, second_period[0],
                                  second_period[1],
                                  [second[i].course_id, cur_class_id_list])
                        op.change(profs, pid, weeks, second_period[0] + 1,
                                  second_period[1],
                                  [second[i].course_id, cur_class_id_list])

                    for cid in cur_class_id_list:
                        oc.change(class_list, cid, weeks, first_period[0],
                                  first_period[1],
                                  [second[i].course_id, cur_prof_id_list])
                        oc.change(class_list, cid, weeks, first_period[0] + 1,
                                  first_period[1],
                                  [second[i].course_id, cur_prof_id_list])
                        oc.change(class_list, cid, weeks, second_period[0],
                                  second_period[1],
                                  [second[i].course_id, cur_prof_id_list])
                        oc.change(class_list, cid, weeks, second_period[0] + 1,
                                  second_period[1],
                                  [second[i].course_id, cur_prof_id_list])

        # iii)Allocate the remaining courses according to rules
        err = []
        if settings.arranging_rule == 0:  # if set to priority to periods that are most empty
            print(
                'Allocating courses with priority to periods that are most empty in a week'
            )
        elif settings.arranging_rule == 1:  # if set to closely pack
            print('Allocating courses: closely pack everything')
            for i in range(len(groups)):
                cur_prof_id_list = groups[i].prof_id_list
                cur_class_id_list = groups[i].class_id_list
                weeks = courses[groups[i].course_id].weeks
                first_period_is_chosen, second_period_is_chosen = False, False

                for date in range(7):
                    for period in range(12):
                        if not op.profs_are_available(profs, cur_prof_id_list,
                                                      weeks, period, date):
                            continue
                        elif not oc.classes_are_available(
                                class_list, cur_class_id_list, weeks, period,
                                date):
                            continue
                        else:
                            first_period_is_chosen = True
                            first_period = (period, date)
                            for d in range(date + 2, 7):
                                for p in range(12):
                                    if not op.profs_are_available(
                                            profs, cur_prof_id_list, weeks, p,
                                            d):
                                        continue
                                    elif not oc.classes_are_available(
                                            class_list, cur_class_id_list,
                                            weeks, p, d):
                                        continue
                                    else:
                                        second_period_is_chosen = True
                                        second_period = (p, d)
                                        break
                                if second_period_is_chosen:
                                    break

                        if first_period_is_chosen and second_period_is_chosen:
                            break
                    if first_period_is_chosen and second_period_is_chosen:
                        break

                if not (first_period_is_chosen and second_period_is_chosen):
                    err.append(courses[groups[i].course_id].title +
                               'cannot be arranged')
                else:
                    for pid in cur_prof_id_list:
                        op.change(profs, pid, weeks, first_period[0],
                                  first_period[1],
                                  [groups[i].course_id, cur_class_id_list])
                        op.change(profs, pid, weeks, first_period[0] + 1,
                                  first_period[1],
                                  [groups[i].course_id, cur_class_id_list])
                        op.change(profs, pid, weeks, second_period[0],
                                  second_period[1],
                                  [groups[i].course_id, cur_class_id_list])
                        op.change(profs, pid, weeks, second_period[0] + 1,
                                  second_period[1],
                                  [groups[i].course_id, cur_class_id_list])

                    for cid in cur_class_id_list:
                        oc.change(class_list, cid, weeks, first_period[0],
                                  first_period[1],
                                  [groups[i].course_id, cur_prof_id_list])
                        oc.change(class_list, cid, weeks, first_period[0] + 1,
                                  first_period[1],
                                  [groups[i].course_id, cur_prof_id_list])
                        oc.change(class_list, cid, weeks, second_period[0],
                                  second_period[1],
                                  [groups[i].course_id, cur_prof_id_list])
                        oc.change(class_list, cid, weeks, second_period[0] + 1,
                                  second_period[1],
                                  [groups[i].course_id, cur_prof_id_list])

        else:
            og.show_error_message('Bad arranging rule parameter: mode ' +
                                  str(settings.arranging_rule) + ' not define')
        if err:
            print(err)

        self.is_generated = True
        wait.destroy()
        og.show_succeed_message()
        parser.error("I require five arguments")
    memberId = str(args[0])
    fullName = str(args[1])
    email = str(args[2])
    department = str(args[3])
    username = str(args[4])

    # Check validity of arguments
    if not Member.is_valid_lidnummer(memberId):
        parser.error("Not a valid member ID. Aborting...")
    if not Member.is_valid_full_name(fullName):
        parser.error("Not a valid full name. Aborting...")
    if not Member.is_valid_mail(email):
        parser.error("Not a valid email address. Aborting...")
    if not Member.is_valid_afdeling(department):
        parser.error("Not a valid department. Aborting...")
    if not Member.is_valid_username(username):
        parser.error("Not a valid username. Aborting...")
    newMember = Member.Member(l, s, int(memberId))
    if newMember.exists():
        helper.logger.error("Member %s already exists. Aborting..." % memberId)
        sys.exit()

    # Create out-of-band member
    newMember.create(fullName, email, department)
    newMember.make_user(username, 3)
    group = Group.Group(l, s, "type-outofband")
    group.add(newMember)
    helper.logger.info("Created out-of-band member %s (%s)." %
                       (fullName, memberId))
예제 #30
0
def extractGroupAtt(line, device):
    group = Group.Group()
    start = line.rfind('id="') + 4
    end = line.rfind('">')
    group.set_id(line[start:end])
    device.add_group(group)