示例#1
0
 def coerce_value(value):
     try:
         value = float(value)
     except Exception as errmsg:
         dialog('Found non-number in values column: {}'.format(value))
         raise ValueError('All cells in teh values column must be numbers')
     else:
         return round(value, round_decimals)
示例#2
0
 def coerce_value(value):
     try:
         value = float(value)
     except Exception as errmsg:
         dialog('Found non-number in values column: {}'.format(value))
         raise ValueError('All cells in teh values column must be numbers')
     else:
         return round(value, round_decimals)
示例#3
0
def get_schedule_values(view, round_decimals=2):
    """Gets list of values from first column.
    Move Data parsing here
    """
    HEADER_VALUES = 'values'

    def coerce_value(value):
        try:
            value = float(value)
        except Exception as errmsg:
            dialog('Found non-number in values column: {}'.format(value))
            raise ValueError('All cells in teh values column must be numbers')
        else:
            return round(value, round_decimals)

    def validate_schedule(schedule_dict):
        if HEADER_VALUES in schedule_dict.keys():
            return schedule_dict
        else:
            dialog('You must have a numeric column labeled: values')


    if not isinstance(view, ViewSchedule):
        dialog('View must be a schedule')
    else:
        schedule = view
        body = schedule.GetTableData().GetSectionData(SectionType.Body)
        header = schedule.GetTableData().GetSectionData(SectionType.Body)
        first_row = body.FirstRowNumber
        schedule_name = schedule.Title

        qty_rows = body.NumberOfRows
        qty_cols = body.NumberOfColumns
        schedule_dict = {}
        schedule_dict['title'] = schedule_name
        for col in range(0, qty_cols):
            col_header = schedule.GetCellText(SectionType.Body, 0, col)
            schedule_dict[col_header] = []
            for row in range(2, qty_rows):
                cells = []
                cell = schedule.GetCellText(SectionType.Body, row, col)
                print('Cell:', cell)

                if col_header == 'values':
                    cell = coerce_value(cell)
                schedule_dict[col_header].append(cell)

        return validate_schedule(schedule_dict)
示例#4
0
    def __init__(self, values, fregion_ids, **options):
        """BarChart: Creates a Bar Chart.
        bar_chart = BarChart(values:list, fregion_ids:list,
                             labels:list, value_labels:list,
                             bar_height=1,spacing=0.25,)
        bar_chart.draw(view_id)

        fregion_ids = [list of field_region_type ids]
        OPTIONS: [DEFAULT]
        bar_height: 1
        spacing: 0.25
        labels: defaults to None: Does not Print
        value_labels: defaults str() of values
        label_padding: spacing / 2
        """

        # Hard coded settings
        self.start_x = 0
        self.start_y = 0

        # Required Arguments
        if not values:
            dialog('Invalid Values: [{}]'.format(values))
            raise ValueError('values column is a valid sequence')
        self.values = values
        self.fregion_ids = fregion_ids

        # Optional Configutarions
        self.title = options.get('title')
        self.bar_height = options.get('bar_height', 1)
        self.spacing = options.get('spacing', 0.25)
        self.max_width = options.get('max_width', 1)

        self.value_labels = options.get('value_labels') or [
            str(v) for v in values
        ]
        self.labels = options.get('labels') or ['' for v in values]

        self.label_padding = options.get('label_padding', self.spacing / 2)

        scale_factor = self.max_width / max(self.values)
        if self.max_width is None:
            self.scaled_values = values
        else:
            self.scaled_values = [value * scale_factor for value in values]

        self.make_bars()
示例#5
0
def get_schedule_values(view, round_decimals=2):
    """Gets list of values from first column.
    Move Data parsing here
    """
    HEADER_VALUES = 'values'

    def coerce_value(value):
        try:
            value = float(value)
        except Exception as errmsg:
            dialog('Found non-number in values column: {}'.format(value))
            raise ValueError('All cells in teh values column must be numbers')
        else:
            return round(value, round_decimals)

    def validate_schedule(schedule_dict):
        if HEADER_VALUES in schedule_dict.keys():
            return schedule_dict
        else:
            dialog('You must have a numeric column labeled: values')

    if not isinstance(view, ViewSchedule):
        dialog('View must be a schedule')
    else:
        schedule = view
        body = schedule.GetTableData().GetSectionData(SectionType.Body)
        header = schedule.GetTableData().GetSectionData(SectionType.Body)
        first_row = body.FirstRowNumber
        schedule_name = schedule.Title

        qty_rows = body.NumberOfRows
        qty_cols = body.NumberOfColumns
        schedule_dict = {}
        schedule_dict['title'] = schedule_name
        for col in range(0, qty_cols):
            col_header = schedule.GetCellText(SectionType.Body, 0, col)
            schedule_dict[col_header] = []
            for row in range(2, qty_rows):
                cells = []
                cell = schedule.GetCellText(SectionType.Body, row, col)
                print('Cell:', cell)

                if col_header == 'values':
                    cell = coerce_value(cell)
                schedule_dict[col_header].append(cell)

        return validate_schedule(schedule_dict)
示例#6
0
    def __init__(self, values, fregion_ids, **options):
        """BarChart: Creates a Bar Chart.
        bar_chart = BarChart(values:list, fregion_ids:list,
                             labels:list, value_labels:list,
                             bar_height=1,spacing=0.25,)
        bar_chart.draw(view_id)

        fregion_ids = [list of field_region_type ids]
        OPTIONS: [DEFAULT]
        bar_height: 1
        spacing: 0.25
        labels: defaults to None: Does not Print
        value_labels: defaults str() of values
        label_padding: spacing / 2
        """

        # Hard coded settings
        self.start_x = 0
        self.start_y = 0

        # Required Arguments
        if not values:
            dialog('Invalid Values: [{}]'.format(values))
            raise ValueError('values column is a valid sequence')
        self.values = values
        self.fregion_ids = fregion_ids

        # Optional Configutarions
        self.title = options.get('title')
        self.bar_height = options.get('bar_height', 1)
        self.spacing = options.get('spacing', 0.25)
        self.max_width = options.get('max_width', 1)

        self.value_labels = options.get('value_labels') or [str(v) for
                                                            v in values]
        self.labels = options.get('labels') or ['' for v in values]

        self.label_padding = options.get('label_padding', self.spacing / 2)

        scale_factor = self.max_width / max(self.values)
        if self.max_width is None:
            self.scaled_values = values
        else:
            self.scaled_values = [value * scale_factor for value in values]

        self.make_bars()
示例#7
0
    def make_loops(self):
        start_x = self.start_x
        start_y = self.start_y
        end_x = start_x + self.width
        end_y = start_y + self.height
        p1 = XYZ(start_x, start_y, 0.0)
        p2 = XYZ(end_x, start_y, 0.0)
        p3 = XYZ(end_x, end_y, 0.0)
        p4 = XYZ(start_x, end_y, 0.0)
        p5 = XYZ(start_x, start_y, 0.0)
        points = [p1, p2, p3, p4, p5]

        profileloop = CurveLoop()
        profileloops = List[CurveLoop]()

        for n, p in enumerate(points):
            try:
                line = Line.CreateBound(points[n], points[n + 1])
            except:
                continue
            else:
                profileloop.Append(line)
        try:
            profileloops.Add(profileloop)
        except Exception as errmsg:
            dialog('Something wrong processing points: {}'.format(self.points))
            # ADD LOGGER
            logger.error('width: {}'.format(self.width))
            logger.error('height: {}'.format(self.height))
            logger.error('start_x: {}'.format(start_x))
            logger.error('start_y: {}'.format(start_y))
            for n, point in enumerate(points):
                logger.error('Point {}:{}'.format(n, point))

        # Defines Location for Label and Value Label
        label_x = start_x - self.label_padding
        label_y = start_y + (self.height / 2)
        value_label_x = start_x + self.width + self.label_padding
        value_label_y = label_y
        self.label_pt = XYZ(label_x, label_y, 0)
        self.value_label_pt = XYZ(value_label_x, value_label_y, 0)

        return profileloops
示例#8
0
    def make_loops(self):
        start_x = self.start_x
        start_y = self.start_y
        end_x = start_x + self.width
        end_y = start_y + self.height
        p1 = XYZ(start_x, start_y, 0.0)
        p2 = XYZ(end_x, start_y, 0.0)
        p3 = XYZ(end_x, end_y, 0.0)
        p4 = XYZ(start_x, end_y, 0.0)
        p5 = XYZ(start_x, start_y, 0.0)
        points = [p1, p2, p3, p4, p5]

        profileloop = CurveLoop()
        profileloops = List[CurveLoop]()

        for n, p in enumerate(points):
            try:
                line = Line.CreateBound(points[n], points[n + 1])
            except:
                continue
            else:
                profileloop.Append(line)
        try:
            profileloops.Add(profileloop)
        except Exception as errmsg:
            dialog('Something wrong processing points: {}'.format(self.points))
            # ADD LOGGER
            logger.error('width: {}'.format(self.width))
            logger.error('height: {}'.format(self.height))
            logger.error('start_x: {}'.format(start_x))
            logger.error('start_y: {}'.format(start_y))
            for n, point in enumerate(points):
                logger.error('Point {}:{}'.format(n, point))

        # Defines Location for Label and Value Label
        label_x = start_x - self.label_padding
        label_y = start_y + (self.height / 2)
        value_label_x = start_x + self.width + self.label_padding
        value_label_y = label_y
        self.label_pt = XYZ(label_x, label_y, 0)
        self.value_label_pt = XYZ(value_label_x, value_label_y, 0)

        return profileloops
示例#9
0
 def validate_schedule(schedule_dict):
     if HEADER_VALUES in schedule_dict.keys():
         return schedule_dict
     else:
         dialog('You must have a numeric column labeled: values')
示例#10
0
 def validate_schedule(schedule_dict):
     if HEADER_VALUES in schedule_dict.keys():
         return schedule_dict
     else:
         dialog('You must have a numeric column labeled: values')