Пример #1
0
    def append(self, head: CodePlan) -> None:
        """Append function of list object is overridden in order to add a check for the CodePlan

        :param head:
        """
        if isinstance(head, CodePlan):
            head.check_contents()
            super(TabHead, self).append(head)
        elif isinstance(head, TabHead):
            if self.is_subhead:
                raise TypeError("Nested TabHeads only for 1 level allowed!")
            else:
                head.is_subhead = True
                super(TabHead, self).append(head)
        else:
            raise TypeError("Wrong object added to TabHead ({}). Only CodePlan or TabHead allowed!".format(type(head)))
Пример #2
0
 def split_head(self, head, reportingColumnCount):
     if isinstance(head, CodePlan):  # TODO 2. Bedingung kaputt.
         head = TabHead(head)
     if isinstance(head[0], TabHead):
         return self.split_head(head[0])  # recursive
     elif isinstance(head[0], CodePlan):
         columns_count_max = 14  # TODO relocate!!
         code_count = 1  # Total
         for codeplan_head in head:
             code_count += len(codeplan_head.key_order)
         columns_count_original = code_count * reportingColumnCount
         if columns_count_original <= columns_count_max:  # # Nichts zu tun. Gesamtlänge der Codepläne unter maximumg
             return head
         else:
             newHeads = []
             if len(head) == 1:
                 head_new = TabHead()
                 newHeads.append(head_new)
                 i = 1
                 remainingColmuns = columns_count_max - reportingColumnCount
                 remainingCodes = len(head[0].key_order)
                 try:  # TODO: ausbessern!!
                     newCodePlan = CodePlan(title=head[0].title + " (%d)" % i, variables=head[0].variables)
                 except:
                     newCodePlan = CodePlan(title=head[0].title.encode('utf8') + " (%d)" % i,
                                            variables=head[0].variables)
                 for key in head[0].key_order:
                     remainingColmuns -= reportingColumnCount
                     newCodePlan.data = {}
                     newCodePlan.data[key] = head[0][key]
                     newCodePlan[key] = head[0][key]
                     newCodePlan.key_order.append(key)
                     remainingCodes -= 1
                     if remainingColmuns <= reportingColumnCount and remainingCodes > 0:
                         i += 1
                         remainingColmuns = columns_count_max - reportingColumnCount
                         head_new = TabHead()
                         newHeads.append(head_new)
                         head_new.append(newCodePlan)
                         newCodePlan = CodePlan(title=head[0].title + " (%d)" % i, variables=head[0].variables)
                 head_new.append(newCodePlan)
         return newHeads
Пример #3
0
    def calc_splits_sub(self, rs: ReportingSet, filter_string: str, variables_calculation):
        """calculation of dataset crossed with a codeplan, similar to a crosstable.

        :param rs:
        :param filter_string:
        :param variables_calculation:
        :return:
        """
        for result_split in self.result_subsplits:
            if isinstance(result_split, str):  # TODO check if functional
                """Einfache Kreuztabelle mit Nennung von Kreuzvariable als string. Codes werden aus Bestehendem abgeleitet."""
                filter_string = " WHERE " + filter_string if filter_string else ""
                result_split_new = CodePlan()
                result_split_new.data = self.db.query_list("SELECT " + result_split + " FROM " + self.database_table + filter + " GROUP BY " + result_split, echo=False)
                result_split_new.variables = [result_split, ]
                result_split = result_split_new
            elif isinstance(result_split, CodePlan) and len(result_split) > 0:
                for code in result_split:
                    filter_string_split = " ({})".format(' OR '.join(["{}='{}' ".format(var, code) for var in result_split.variables]))
                    if filter_string:
                        filter_string_split += " and ({}) ".format(filter_string)
                    rs['{}_{}'.format(result_split.variables[0], code)] = self._calc_frequencies(variables_calculation, filter_string_split)
                    rs.splits_sub[result_split.variables[0]] = copy.copy(result_split)