def NonCompliance(data): return Column(width='50%').add( Text( text=boil('recon_&_retrofit_non-compliances_title'), color=Color.ACCENT, font_family="Roboto Condensed", font_size=9, font_weight=Text.BOLD, margin=Rect([3.2, 0, 5, 0]), ), Text(markup='<b>{}:</b> {}'.format( boil('recon_&_retrofit_registered_(both)'), fmt_num(data['registered']), ), font_family="Roboto Condensed", font_size=7.5, margin=Rect([0, 0, 3, 0])), Text( markup='<b>{}:</b> {}'.format( boil('recon_&_retrofit_addressed_(both)'), fmt_num(data['addressed']), ), font_family="Roboto Condensed", font_size=7.5, ), )
def Houses(data): return Column(width='100%').add( Text(text=boil('recon_&_retrofit_houses_title'), font_family="Roboto Condensed", font_size=9, font_weight=Text.BOLD, color=Color.ACCENT, margin=Rect([0, 0, 2, 0])), Row( width='100%', justify='space-between', margin=Rect([0, 0, 3, 0]), ).add( Text( markup='<b>{}</b>: {}'.format( boil('recon_&_retrofit_under_construction'), fmt_num(data['under_construction'], )), font_family="Roboto Condensed", font_size=7.5, ), Text( markup='<b>{}</b>: {}'.format( boil('recon_&_retrofit_completed'), fmt_num(data['completed'], )), font_family="Roboto Condensed", font_size=7.5, )), )
def Contact(it, title, contact): for k, v in contact.items(): # TODO: fix 'none' if not v or v == 'None': contact[k] = '-' return Column(width='33%', padding=Rect([0, 8, 0, 8])).add( Text( text=title, font_family="Roboto Condensed", font_size=9, font_weight=Text.BOLD, ), Text( text=contact['name'] if contact['name'] != ZERO_DEFAULT else '', font_family="Roboto Condensed", font_size=7, ), Text( text=contact['title'] if contact['title'] != ZERO_DEFAULT else '', font_family="Roboto Condensed", font_size=7, ), Text( text=get_lang_num(contact['contact']) if contact['contact'] != ZERO_DEFAULT else '', font_family="Roboto Condensed", font_size=7, ))
def FurtherInfoNotes(data, **kwargs): # TODO: check nans before entering return Row(**kwargs, width='100%', height=16).add( Text( text=boil('page_2_futher_information'), font_family='Roboto Condensed', font_size=7, font_weight=Pango.Weight.BOLD, padding=Rect([12.5, 0, 0, 5]), ), *[ Column(padding=Rect(8)).add( Text( text='{}. {} ({})'.format( get_lang_num(i + 1), contact['name'] if contact['name'] and contact['name'] != 'None' else '', contact['title'] if contact['title'] and contact['title'] != 'None' else '', ), font_family='Roboto Condensed', font_size=7, padding=Rect([5, 0, 0, 0]), ), Text( text=' {}'.format( get_lang_num(contact['phone']) if contact['phone'] and contact['phone'] != 'None' else ''), font_family='Roboto Condensed', font_size=7, ), ) for i, contact in enumerate(data) if not all([is_nan(v) for v in contact.values()]) ])
def Sector(label, items, icon): return Column( width='50%', height='100%', justify='center', align='center', ).add( Canvas( width=56, height=56, renderer=IconRenderer(filename=icon), ), Text( text=label, color=Color.ACCENT, margin=Rect(4), font_family='Roboto Condensed', font_size=8, font_weight=Pango.Weight.BOLD, ), *[ Row().add( Text( text='{}: '.format(key), font_family='Roboto Condensed', font_size=8, font_weight=Pango.Weight.BOLD, ), Text( text=value, font_family='Roboto Condensed', font_size=8, )) for key, value in items.items() ])
def Header(data): nm_text = '{} | {}'.format( data['rep_data']['dist_nm'], data['rep_data']['palika_nm'], ) return Column( width='100%', margin=Rect([0, 5, 8, 5]), ).add( Row(height=52, width='10%').add( Text( text=boil('header_title'), font_family='Roboto Condensed', font_size=24, font_weight=Pango.Weight.BOLD, color=Color.PRIMARY, height='100%', vertical_alignment=Text.BOTTOM, ), Vr( width=2, height='100%', color=Color.PRIMARY, margin=Rect([0, 16, 0, 16]), padding=Rect([24, 0, 0, 0]), ), Column(height='100%', justify='end').add( Text( text='{} {}'.format( boil('header_month'), boil('header_year') if isinstance( boil('header_year'), str) else get_lang_num( str(boil('header_year'))), ), font='Roboto Light', font_size=10, color=Color.PRIMARY, ), Text( text=nm_text, font='Roboto Light', font_size=calc_nm_len(nm_text), color=Color.PRIMARY, ))), Hr( width='100%', height=1, color=Color.PRIMARY, margin=Rect([8, 0, 0, 0]), ), Hr( width='100%', height=1.8, color=Color.PRIMARY, margin=Rect([2, 0, 0, 0]), ), )
def RetrofitStatus(data): rows = [ TwoValueLineChart(datum, bar_color=Color.ACCENT2) for datum in data ] return Column(width='100%').add( Text( text=boil('recon_&_retrofit_retrofitting_status_title'), font_family="Roboto Condensed", font_size=9, font_weight=Text.BOLD, color=Color.ACCENT, ), Hr( width='100%', height=1, margin=Rect([3, 0, 3, 0]), dash=[3], color=Color.PRIMARY, ), *rows, Hr( width='100%', height=1, margin=Rect([3, 0, 3, 0]), dash=[3], color=Color.PRIMARY, ), )
def TwoValueLineChart(data, bar_color): row_margin = [4, 0, 0, 0] # if get_lang() == 'en': # row_margin = [4, 0, 0, 0] # elif get_lang() == 'np': # row_margin = [6, 0, 0, 0] label = boil(data['label']) if (label == 'Ist Tranche received'): label = 'I<sup>st</sup> Tranche received' if (label == 'IInd Tranche received'): label = 'II<sup>nd</sup> Tranche received' if (label == 'IIIrd Tranche received'): label = 'III<sup>rd</sup> Tranche received' return Row( width='100%', height=16, margin=Rect(row_margin), ).add( Text( width='40%', markup=label, font_family="Roboto Condensed", font_size=9, font_weight=Text.BOLD, ), # Row(width='60%', height='70%').add(add Row(width='60%', height='70%').add( Canvas( width='100%', height='100%', renderer=Bars(data, bar_color), )))
def TrainingsFooter(**kwargs): return Text( **kwargs, text=boil('training_footer'), font_family='Roboto Condensed Light', font_size=6, )
def TR(widths, items): return Row(width='100%').add(*[ Row( width=widths[i], height='100%', border=Border( width=0.5, color=Color.BLACK, ), padding=Rect([3, 6, 3, 0]) if i in (2, 4) else Rect([3, 0, 3, 0]), ).add( Image( filename=get_resource_abspath('images/{}'.format(item['icon'] ), ), height=8, margin=Rect([2, 4, 4, 4]), ) if item.get('icon') else None, Text( markup=xstr(item.get('text')), font_family='Roboto Condensed', font_size=7, width=("100%" if i != 0 else None), height="100%", alignment=Text.RIGHT if i in (2, 4) else Text.CENTER, vertical_alignment=Text.MIDDLE, )) for i, item in enumerate(items) ])
def Label(text): return Text( text=text, font='RobotoCondensed', font_size=6, padding=Rect(2), )
def TechnicalStaffFooter(**kwargs): return Text( **kwargs, text=boil('tech_staff_footer'), font_family='Roboto Condensed Light', font_size=6, )
def PoGroup(h, pos): #TODO: set global val for what blank is label = pos[0] pos_list = pos[1] return Column( width='98%', height='{}%'.format(h + 4), border=Border( width=0.5, color=Color.BLACK, ), ).add( Text( width='98%', height='{}%'.format(h + 4), # markup='{}'.format('hello '*60), markup='<b>{}:</b> {}'.format(boil(label), pos_list), color=Color.BLACK, font_family="Roboto Condensed", font_size=7, #TODO: fix bug where row cuts off early auto_scale_height=False, padding=Rect([1, 0, 5, 3]), ), )
def Item(index, **kwargs): if index == 0: return Text( font_family="Roboto Condensed", font_size=8, font_weight=Text.BOLD, alignment=Text.LEFT, **kwargs, ) else: return Text( font="Roboto light", font_size=8, alignment=Text.RIGHT, **kwargs, )
def LeftFootNotes(**kwargs): return Text( **kwargs, text=boil('page_1_sources_footer'), font='RobotoCondensed', font_size=5, )
def RightFootNotes(**kwargs): return Text( **kwargs, text=boil('page_1_no_info_footer'), font='RobotoCondensed', font_size=5, )
def ReconstructionAndRetrofitFooter(**kwargs): return Text(**kwargs, text='{} {}'.format(boil('recon_&_retrofit_panel_footer'), kwargs['data']), font_family="Roboto Light", font_size=6, color=Color.DARK_GRAY, padding=Rect([0, 5, 2, 0]))
def sand(): t = Text( width='100%', height='50%', text='x', color=Color.DARK_GREEN, font_family="Roboto Condensed", font_size=5, auto_scale=True, ), b = Text( width='100%', height='50%', text='' * 300, color=Color.DARK_GREEN, font_family="Roboto Condensed", font_size=5, auto_scale=True, ),
def BottomBox(data): return Row( width='100%', margin=Rect([8, 0, 6, 0]), border=Border( width=0.5, color=Color.BLACK, ), padding=Rect([2, 8, 4, 8]), ).add( Column(width='50%').add( Text( text=boil('status_of_cm_types_of_workers'), font_family='Roboto Condensed', font_size=8, font_weight=Pango.Weight.BOLD, ), Text(text='{} {}'.format( boil('status_of_cm_list_1'), boil('status_of_cm_skilled_mason'), ), font_family='Roboto Condensed', font_size=8, padding=Rect([2, 0, 2, 0])), Text( text='{} {}'.format( boil('status_of_cm_list_2'), boil('status_of_cm_labourer'), ), font_family='Roboto Condensed', font_size=8, ), ), Column(width='60%').add( Text( text=boil('status_of_cm_avg._daily_wage_(nrs.)'), width='100%', alignment=Text.CENTER, font_family='Roboto Condensed', font_size=8, font_weight=Pango.Weight.BOLD, ), Text( text='%s %s' % (fmt_num(data['avg_wage_1']), '/-'), width='65%', alignment=Text.RIGHT, font_family='Roboto Condensed', font_size=8, padding=Rect([2, 0, 2, 0]), ), Text( text='%s %s' % (fmt_num(data['avg_wage_2']), '/-'), width='65%', alignment=Text.RIGHT, font_family='Roboto Condensed', font_size=8, padding=Rect([0, 0, 1, 0]), )), )
def Numeral( value=None, prefix='', separator=True, suffix='', **kwargs ): text = '{}{}{}'.format(prefix, value, suffix) return Text( markup=text, **kwargs, )
def Footer(data): faq_blocks = [] for it, item in enumerate(data): question = Text( width='100%', text='{}: {}'.format(boil('faq_q'), item['q']), font_family='Roboto Condensed', font_size=8.5, font_weight=Pango.Weight.BOLD, ) answer = Text( width='100%', text='{}: {}'.format(boil('faq_a'), item['a']), font_family='Roboto Condensed', font_size=8, padding=Rect([0, 0, 8, 0]) if it == 0 else Rect(0), ) faq_blocks.append(question) faq_blocks.append(answer) return Column( width='100%', padding=Rect([10, 16, 6, 16]), ).add(*faq_blocks, )
def Label(label, color): return Row( margin=Rect([8, 0, 0, 0]), ).add( Node( width=10, height=10, bg_color=color, margin=Rect([2, 4, 0, 0]), ), Text( text=label, font='Roboto Light', font_size=8, padding=Rect([2.5, 0, 0, 0]) ) )
def Label(label, color): return Row( margin=Rect([0, 10, 0, 10]), padding=Rect([8, 10, 5, 10]), ).add( Node( width=7, height=7, bg_color=color, margin=Rect([0, 4, 0, 0]), ), Text( text=label, font='Roboto Light', font_size=6, ) )
def Panel(**kwargs): title = kwargs.pop('title', None) left_footer = kwargs.pop('left_footer', empty) right_footer = kwargs.pop('right_footer', empty) footer_data = kwargs.pop('footer_data', empty) return Row( border=Border( color=Color.BLUE, radius=16, width=1, ), relative=True, margin=Rect([10, 5, 10, 5]), **kwargs, ).add( Text( text=title, absolute=True, font_family='Roboto Condensed', font_size=13, font_weight=Pango.Weight.BOLD, color=Color.BLUE, top=-6, left=10, bg_color=Color.WHITE, padding=Rect([0, 6, 0, 6]), ), left_footer( absolute=True, bottom=-12, left=0, data=footer_data, ), right_footer( absolute=True, bottom=-12, right=2, data=footer_data, ), )
def TR_Text(widths, items): return Row(width='100%').add(*[ Row( width=widths[i], height='100%', border=Border( width=0.5, color=Color.BLACK, ), padding=Rect(5), ).add( Text( markup=xstr(item), font_family='Roboto Condensed', font_size=7, width=("100%" if i != 0 else None), height="100%", alignment=Text.CENTER, vertical_alignment=Text.MIDDLE, )) for i, item in enumerate(items) ])
def HH(data): """for showing the HH bar. logic: if 0 values: show message that there are no reported issues if 1 value: do something #TODO else: show bar """ # info f.e type items = [ { 'key': 'landless', 'label': boil('land_issues_landless'), 'color': hx('#ff6117'), }, { 'key': 'no_land_certificates', 'label': boil('land_issues_no_land_certificates'), 'color': hx('#bf053d'), }, { 'key': 'right_of_way', 'label': boil('land_issues_right_of_way'), 'color': hx('#7d0547'), }, { 'key': 'affected_by_hep', 'label': boil('land_issues_affected_by_hep'), 'color': hx('#1e7a8c'), }, { 'key': 'smallplots', 'label': boil('land_issues_small_plots'), 'color': hx('#abd1b5'), }, { 'key': 'guthi_land', 'label': boil('land_issues_guthi_land'), 'color': hx('#ffc202'), }, ] # add val and drop item if it's zero or invalid items = _filter_items(items, data) wdz = _get_widths(items) bars = [] labels = [] if wdz: for item in wdz: color = item['color'] bar = Text( bg_color=color, height=20, width='{}%'.format(item['w']), alignment=Text.CENTER, vertical_alignment=Text.MIDDLE, text=fmt_num(item['val']), color=Color.WHITE, font_family='Roboto Condensed', font_size=11, font_weight=Pango.Weight.BOLD, ) bars.append(bar) label = Label( label=item['label'], color=color, ) labels.append(label) return Column( width='100%', padding=Rect([16, 16, 8, 16]), ).add( Row(width='100%').add(*bars), Row( width='100%', justify='space-between' if len(labels) > 1 else None, ).add(*labels) ) else: return Column(width='100%', height='100%').add( Text( height='100%', width='100%', alignment=Text.CENTER, vertical_alignment=Text.MIDDLE, text=boil('land_issues_no_information'), color=Color.GRAY, font_family='Roboto Condensed', font_size=18, font_weight=Pango.Weight.BOLD, margin=Rect([0, 0, 43, 0]), ) )
def Typologies(data): widths = ['60%', '20%', '20%'] headers = [ boil('typologies_typology'), boil('typologies_municipal'), boil('typologies_district') ] if get_lang() == 'np': row_seperator_padding = [3.5, 0, 4.5, 0] else: row_seperator_padding = [4.5, 0, 4.5, 0] # flatten and add dict # TODO: assert that we don't have duplicate keys? (exclude blanks)) rows = get_list_typo(OrderedDict((boil(k), v) for k, v in data.items()), 5) return Column( width='100%', padding=Rect(12), ).add( Row(width='100%').add(*[ Text( width=widths[i], text=header, font_family="Roboto Condensed", font_size=9, font_weight=Text.BOLD, color=Color.ACCENT, alignment=Text.LEFT if i == 0 else Text.RIGHT, ) for i, header in enumerate(headers) ]), Hr( width='100%', height=1, color=Color.PRIMARY, dash=[3], margin=Rect([3, 0, 3, 0]), ), *[ Row(width='100%').add(*[ Item( width=widths[i], text=k if i == 0 else fmt_pct( list(d_v.items())[i - 1][1], pts=2, ), index=i, padding=Rect(row_seperator_padding), ) for i in range(NUM_COLS) ]) for k, d_v in rows.items() ], *[ Row(width='100%').add(*[ Item( width=widths[i], text=' ', index=i, padding=Rect(row_seperator_padding), ) for i in range(NUM_COLS) ]) for v in range(NUM_ROWS - len(rows)) ], Text(width='100%', text=boil('typologies_cbs_footer'), font_family="Roboto Light", font_size=6, alignment=Text.RIGHT, color=Color.DARK_GRAY, padding=Rect([0, 0, 10, 0])), )
def Trainings(data): short = data['short'] vocational = data['vocational'] short_training = [ {'value': short['reached'], 'color': Color.ACCENT}, {'value': _calc_reached(short['reqd'], short['reached']), 'color': Color.GRAY}, ] vocational_training = [ {'value': vocational['reached'], 'color': Color.ACCENT}, {'value': _calc_reached(vocational['reqd'], vocational['reached']), 'color': Color.GRAY}, ] items = [ {'label': boil('training_reached'), 'color': Color.ACCENT}, {'label': boil('training_remaining'), 'color': Color.GRAY}, ] return Column( width='100%', height='100%', padding=Rect([10, 10, 4, 10]), ).add( Text( height=13, text=boil('training_sub_title'), color=Color.PRIMARY, font_family='Roboto Condensed', font_size=8, font_weight=Pango.Weight.BOLD, ), Row(width='100%', height='100% - 32', padding=Rect(4)).add( Canvas( width='50%', height='100%', renderer=PieChart( items=short_training, label=boil('training_short_training'), ) ), Canvas( width='50%', height='100%', renderer=PieChart( items=vocational_training, label=boil('training_vocational_training'), ) ), ), Row( width='100%', height=16, justify='center', align='center', ).add( *[ Label( label=item['label'], color=item['color'], ) for item in items ] ), )
def TechnicalStaff(tech_data, mason_data): widths = ['35%', '30%', '35%'] headers = [ boil('tech_staff_staff_title'), boil('tech_staff_available_title'), boil('tech_staff_addl_req_title') ] tech_data = [[ boil(item['lookup']), fmt_num(item['available']), fmt_num(item['additional']) ] for item in tech_data] mason_data = [ boil(mason_data['lookup']), mason_data['available'], mason_data['additional'] ] # mason_data = [mason_data['label'], 100, 300] header_row = Row(width='100%').add(*[ Text( border=Border(width=0.5, color=Color.BLACK), text=item, width=widths[i], font_family='Roboto Condensed', font_size=7, font_weight=Pango.Weight.BOLD, padding=Rect(4), alignment=(Text.LEFT if i == 0 else Text.CENTER), ) for i, item in enumerate(headers) ]) # add non masons data_rows = [ Row(width='100%').add( *[ Text( border=Border(width=0.5, color=Color.BLACK), text=item, width=widths[i], height='15', font_family='Roboto Condensed', font_size=7 if i == 0 else 9, font_weight=Pango.Weight.BOLD if i == 0 else None, padding=Rect([3, 0, 0, 4]), alignment=(Text.LEFT if i == 0 else Text.CENTER), ) for i, item in enumerate(row) ], ) for row in tech_data ] # add masons data_rows.append( Row(width='100%').add(*[ Text( border=Border(width=0.5, color=Color.BLACK), text=mason_data[0], width=widths[0], font_family='Roboto Condensed', font_weight=Pango.Weight.BOLD, font_size=7, padding=Rect(4), alignment=Text.LEFT, ), Column( border=Border(width=0.5, color=Color.BLACK), height='100%', width=widths[1], ).add( Text( text='{} ({} {})'.format(fmt_num(mason_data[1][0]), fmt_num(7), boil( 'tech_staff_days')), font_family='Roboto Condensed', font_size=6, width='100%', alignment=Text.CENTER, padding=Rect([2, 0, 0, 0]), )).add( Text( text='{} ({} {})'.format(fmt_num(mason_data[1][1]), fmt_num(50), boil('tech_staff_days')), font_family='Roboto Condensed', font_size=6, width='100%', alignment=Text.CENTER, )), Column(border=Border(width=0.5, color=Color.BLACK), height='100%', width=widths[2]).add( Text( text='{} ({} {})'.format(fmt_num(mason_data[2][0]), fmt_num(7), boil('tech_staff_days')), font_family='Roboto Condensed', font_size=6, width='100%', alignment=Text.CENTER, padding=Rect([2, 0, 0, 0]), )).add( Text( text='{} ({} {})'.format( fmt_num(mason_data[2][1]), fmt_num(50), boil('tech_staff_days')), font_family='Roboto Condensed', font_size=6, width='100%', alignment=Text.CENTER, )), ])) # # Row(width=widths[1], # border=Border(width=0.5, color=Color.BLACK), # height='100%').add( # Row(border=Border(width=0.5, color=Color.BLACK)).add( # Text( # text='xx22', # font='RobotoCondensed bold 6', # font_size='RobotoCondensed bold', # alignment=Text.CENTER, # ), # ).add(Row(border=Border(width=0.5, color=Color.BLACK)).add( # Text( # text='yy', # font='RobotoCondensed 6', # ), # ), # ), return Column( width='100%', padding=Rect(16), ).add( header_row, *data_rows, )