Groups a list of scheduled documents by their class.
8586
private function getClassesForCommitAction(array $documents, bool $includeEmbedded = false) : array
    {
        if (empty($documents)) {
            return [];
        }
        $divided = [];
        $embeds  = [];
        foreach ($documents as $oid => $d) {
            $className = get_class($d);
            if (isset($embeds[$className])) {
                continue;
            }
            if (isset($divided[$className])) {
                $divided[$className][1][$oid] = $d;
                continue;
            }
            $class = $this->dm->getClassMetadata($className);
            if ($class->isEmbeddedDocument && ! $includeEmbedded) {
                $embeds[$className] = true;
                continue;
            }
            if (empty($divided[$class->name])) {
                $divided[$class->name] = [$class, [$oid => $d]];
            } else {
                $divided[$class->name][1][$oid] = $d;
            }
        }
        return $divided;
    }
177080
def _group(self, taxslice):
        ''''''
        res = []
        while taxslice:
            taxref, lident = taxslice.pop()
            if lident == '':
                res.append(([taxref], lident))
            else:
                # identify idents in the same group and pop from taxslice
                i = 0
                group = []
                while i < len(taxslice):
                    if taxslice[i][1] == lident:
                        group.append(taxslice.pop(i)[0])
                    else:
                        i += 1
                group.append(taxref)
                res.append((group, lident))
        return res
677872
def create_form_groupings(self,
                              vocabularies,
                              solr_response,
                              element_group_dict,
                              sort_order):
        """"""
        element_list = []
        # Loop through the group dictionary.
        for group_name, group_list in element_group_dict.items():
            # Create the element group.
            element_group = UNTL_GROUP_DISPATCH[group_name](
                vocabularies=vocabularies,
                solr_response=solr_response,
                group_name=group_name,
                group_list=group_list,
            )
            # Loop through the adjustable forms of the group if they exist.
            if element_group.adjustable_form is not None:
                for adj_name, form_dict in element_group.adjustable_form.items():
                    # If an item has an adjustable form,
                    # append it to the adjustable list.
                    if form_dict['value_py'] is not None:
                        self.adjustable_items.append(adj_name)
            # Append the group to the element group list.
            element_list.append(element_group)
        # Sort the elements by the index of sort_order pre-ordered list.
        element_list.sort(key=lambda obj: sort_order.index(obj.group_name))
        return element_list
782779
def list_assignment_groups(self, course_id, exclude_assignment_submission_types=None, grading_period_id=None, include=None, override_assignment_dates=None, scope_assignments_to_student=None):
        
        path = {}
        data = {}
        params = {}

        # REQUIRED - PATH - course_id
        """ID"""
        path["course_id"] = course_id

        # OPTIONAL - include
        """Associations to include with the group. "discussion_topic", "all_dates"
        "assignment_visibility" & "submission" are only valid are only valid if "assignments" is also included.
        The "assignment_visibility" option additionally requires that the Differentiated Assignments course feature be turned on."""
        if include is not None:
            self._validate_enum(include, ["assignments", "discussion_topic", "all_dates", "assignment_visibility", "overrides", "submission"])
            params["include"] = include

        # OPTIONAL - exclude_assignment_submission_types
        """If "assignments" are included, those with the specified submission types
        will be excluded from the assignment groups."""
        if exclude_assignment_submission_types is not None:
            self._validate_enum(exclude_assignment_submission_types, ["online_quiz", "discussion_topic", "wiki_page", "external_tool"])
            params["exclude_assignment_submission_types"] = exclude_assignment_submission_types

        # OPTIONAL - override_assignment_dates
        """Apply assignment overrides for each assignment, defaults to true."""
        if override_assignment_dates is not None:
            params["override_assignment_dates"] = override_assignment_dates

        # OPTIONAL - grading_period_id
        """The id of the grading period in which assignment groups are being requested
        (Requires the Multiple Grading Periods feature turned on.)"""
        if grading_period_id is not None:
            params["grading_period_id"] = grading_period_id

        # OPTIONAL - scope_assignments_to_student
        """If true, all assignments returned will apply to the current user in the
        specified grading period. If assignments apply to other students in the
        specified grading period, but not the current user, they will not be
        returned. (Requires the grading_period_id argument and the Multiple Grading
        Periods feature turned on. In addition, the current user must be a student.)"""
        if scope_assignments_to_student is not None:
            params["scope_assignments_to_student"] = scope_assignments_to_student

        self.logger.debug("GET /api/v1/courses/{course_id}/assignment_groups with query params: {params} and form data: {data}".format(params=params, data=data, **path))
        return self.generic_request("GET", "/api/v1/courses/{course_id}/assignment_groups".format(**path), data=data, params=params, all_pages=True)
1349348
def documents(cls, filter=None, **kwargs):
        
        documents = [cls(document) for document in cls.find(filter, **kwargs)]
        return [document for document in documents if document.document]
535628
function grouped(array, groups, order) {
  if (!groups) { groups = [returnFalse]; }
  var sorted = [];
  var ordered = [];
  var remaining = array.slice();
  var unmatchedPosition = groups.indexOf('unmatched');
  groups.forEach(function(criteria, index) {
    if (index === unmatchedPosition) { return; }
    var tieBreakers = [];
    if (index !== groups.length - 1) {
      tieBreakers = groups.slice(index + 1);
      if (index < unmatchedPosition) {
        tieBreakers.splice(unmatchedPosition - index - 1, 1);
      }
    }
    var spliced = splice(remaining, criteria, tieBreakers);
    var matched = spliced.matched;
    var unmatched = spliced.unmatched;
    sorted[index] = matched;
    remaining = unmatched;
  });
  if (unmatchedPosition === -1) { unmatchedPosition = sorted.length; }
  sorted[unmatchedPosition] = remaining;
  if (Array.isArray(order)) {
    order.forEach(function(position, index) {
      ordered[index] = sorted[position];
    });
  } else {
    ordered = sorted;
  }
  return ordered.reduce(function(flat, group) {
    return flat.concat(group);
  }, []);
}
696270
def groups_archive(self, room_id, **kwargs):
        """"""
        return self.__call_api_post('groups.archive', roomId=room_id, kwargs=kwargs)
262792
def group_list(items):
    
    groups = defaultdict(list)
    for key, value in items:
        groups[key].append(value)
    return groups
415665
def _group_range(records, method):
    

    start_date = records[0].datetime
    end_date = records[-1].datetime
    _fun = DATE_GROUPERS[method]

    d = start_date

    # Day and week use timedelta
    if method not in ["month", "year"]:
        def increment(i):
            return i + timedelta(**{method + 's': 1})

    elif method == "month":
        def increment(i):
            year, month = divmod(i.month + 1, 12)
            if month == 0:
                month = 12
                year = year - 1
            return d.replace(year=d.year + year, month=month)

    elif method == "year":
        def increment(i):
            return d.replace(year=d.year + 1)

    while _fun(d) <= _fun(end_date):
        yield d
        d = increment(d)
1289767
def _expand_scheduledict(scheduledict):
    """"""
    result = []
    def f(d):
        nonlocal result
        #print(d)
        d2 = {}
        for k,v in d.items():
            if isinstance(v, str) and _cronslash(v, k) is not None:
                d[k] = _cronslash(v, k)

        for k,v in d.items():
            if isinstance(v, Iterable):
                continue
            else:
                d2[k] = v

        if len(d2.keys()) == len(d.keys()):
            result.append(d2)
            return

        for k,v in d.items():
            if isinstance(v, Iterable):
                for i in v:
                    dprime = dict(**d)
                    dprime[k] = i
                    f(dprime)
                break
    f(scheduledict)
    return result
644237
def _findSingleMemberGroups(classDictionaries):
    
    toRemove = {}
    for classDictionaryGroup in classDictionaries:
        for classDictionary in classDictionaryGroup:
            for name, members in list(classDictionary.items()):
                if len(members) == 1:
                    toRemove[name] = list(members)[0]
                    del classDictionary[name]
    return toRemove
474107
def _grouped(iterable, n):
        
        args = [iter(iterable)] * n
        return [[e for e in t if not e is None] for t in zip_longest(*args, fillvalue=None)]
538327
def tokenize_documents(docs):
    """"""
    sep = '\n\n'
    texts = []
    for doc in docs:
        text = '\n\n'.join(['\n'.join(para[SENTENCES]) for para in doc[PARAGRAPHS]])
        doc[TEXT] = text
        del doc[PARAGRAPHS]
        texts.append(Text(doc))
    return texts
214558
def getGroupUpcomingEvents(request, group):
    
    # Get events that are a child of a group page, or a postponement or extra
    # info a child of the recurring event child of the group
    rrEvents = RecurringEventPage.events(request).exclude(group_page=group) \
                                        .upcoming().child_of(group).this()
    qrys = [SimpleEventPage.events(request).exclude(group_page=group)
                                        .upcoming().child_of(group).this(),
            MultidayEventPage.events(request).exclude(group_page=group)
                                        .upcoming().child_of(group).this(),
            rrEvents]
    for rrEvent in rrEvents:
        qrys += [PostponementPage.events(request).child_of(rrEvent.page)
                                         .upcoming().this(),
                 ExtraInfoPage.events(request).exclude(extra_title="")
                                 .child_of(rrEvent.page).upcoming().this()]

    # Get events that are linked to a group page, or a postponement or extra
    # info a child of the recurring event linked to a group
    rrEvents = group.recurringeventpage_set(manager='events').auth(request)  \
                                                        .upcoming().this()
    qrys += [group.simpleeventpage_set(manager='events').auth(request)
                                                        .upcoming().this(),
             group.multidayeventpage_set(manager='events').auth(request)
                                                        .upcoming().this(),
             rrEvents]
    for rrEvent in rrEvents:
        qrys += [PostponementPage.events(request).child_of(rrEvent.page)
                                                       .upcoming().this(),
                 ExtraInfoPage.events(request).exclude(extra_title="")
                                 .child_of(rrEvent.page).upcoming().this()]
    events = sorted(chain.from_iterable(qrys),
                    key=attrgetter('page._upcoming_datetime_from'))
    return events
758061
def group(requestContext, *seriesLists):
    
    seriesGroup = []
    for s in seriesLists:
        seriesGroup.extend(s)

    return seriesGroup
647629
def _iter_grouped(self):
        """"""
        for indices in self._group_indices:
            yield self._obj.isel(**{self._group_dim: indices})
1259960
def groups_with_resources(cls, instance):
        
        return instance.groups_dynamic.options(
            sa.orm.eagerload(cls.models_proxy.Group.resources)
        )