Example #1
0
    def parse_with_groupings(self, grouping_col, headers, header_row):
        # grouping_col is an integer
        # header_row is an integer
        # Puts group at end
        header_map = self.construct_header_map(headers, header_row)
        row_range = self.get_row_range()

        cur_group = ""
        result = []
        for i in row_range:
            line = self.lines[i]
            fields = line.split("\t")

            # Update group if necessary
            if fields[grouping_col] != "":
                cur_group = input_conditioner.condition_user_input(fields[grouping_col])

            item = []
            for h in headers:
                item.append(self.get_field_value(fields, header_map[h]))

            # Add grouping to the end of the result
            item.append(cur_group)
            result.append(item)
        return result
Example #2
0
    def parse(self):
        """
        Parses staff data.

            Tries to figure out where the start and end rows are. This will
            always be a little delicate.
        """
        # Figure out spreadsheet area
        start_row = self.get_start_row()
        end_row = self.get_end_row()
        header_row = start_row - 1

        track_headers = filter(is_not_empty,
                self.staff_lines[header_row].split("\t"))

        area = SpreadsheetArea(self.staff_lines,
                               start_row=start_row, end_row=end_row)
        grouping_column = 0
        staff = area.parse_with_groupings(grouping_column,
                                           track_headers, header_row)

        # Construct assignments by track
        result = []

        for row in staff:
            skill = row[-1]

            # Iterate across track columns
            for i in range(len(track_headers)):
                track = input_conditioner.condition_user_input(track_headers[i])
                if not self.skip_cell(row[i]):
                    result.append({
                        'name': input_conditioner.condition_user_input(row[i]),
                        'skill': skill,
                        'track': track
                    })
        return result
Example #3
0
    def parse(self):
        """
        Parses data from work stream.
        """
        area = SpreadsheetArea(self.work_lines, start_row=self.start_row)
        parsed_work = area.parse(self.headers + self.skill_headers,
                                                         self.header_row)
        # Gathers tags from columns that have headings like "Tag",
        # "Tag:Product", etc.
        tags = area.parse_tags(self.header_row)

        # Rearrange data in work records
        num_headers = len(self.headers)
        num_skill_headers = len(self.skill_headers)
        result = []
        cur_rank = 1

        for rec_index in range(len(parsed_work)):
            record = parsed_work[rec_index]
            rank = str(cur_rank)
            cur_rank += 1
            item = []
            estimates = []

            if self.skip_record(record):
                print("Skipping %d" % cur_rank)
                continue

            # The first part of the record will be our normal headers
            for i in range(0, num_headers):
                value = input_conditioner.condition_user_input(record[i])
                item.append(value)

            # After the normal headers we'll augment with the rank
            item.append(rank)

            # The last part of the record is the estimate. We'll gather them
            # here and then pack them here.
            for i in range(num_headers, num_headers + num_skill_headers):
                estimates.append(self.condition_manweeks(record[i]))
            print(record, estimates)
            item.append(sectionize.pack_string(self.skill_headers, estimates))

            # Condition work record fields
            conditioned_record = self.condition_work_record(item, tags[rec_index])
            if conditioned_record:
                result.append(conditioned_record)

        return result