Exemple #1
0
            def _fetchSubs(container, parent=None, level=-1):
                # If no subelements in container, return
                if len(container) == 0:
                    return (0, None)
                # Adding titles
                GValues = []
                selected_items = 0
                for item in container:
                    if item.tag.lower() != 'item':
                        continue
                    indicator_name = item.attrib['indicator']
                    #if items and not indicator_name in items: continue
                    if not items or indicator_name in items:
                        data_dict['titles'].append(indent_str * level + ' ' + _T("templates", item.attrib['title']))
                        selected_items += 1
                    # temp list to do arithmetic operations
                    values = []
                    for i in xrange(len(period)):
                        date = period[i]
                        # Creating a timestamp range for the specified date
                        ts_min = int(time.mktime(datetime.strptime(date, "%Y-%m-%d").timetuple()))
                        ts_max = ts_min + 86400   # max = min + 1day (sec)
                        #
                        value = ReportDatabase().get_indicator_value_at_time(indicator_name, ts_min, ts_max, entities)
                        values.append(value)
                        # if item is not selected, don't add value to the Data Dict
                        if not items or indicator_name in items:
                            data_dict['values'][i].append(value)
                    # If item is not selected don't add values to arithmetic table list
                    #
                    if items and not indicator_name in items:
                        (subCount, childGValues) = _fetchSubs(item, container, level + 1)
                    else:
                        (subCount, childGValues) = (0, None)
                        GValues.append(values)

                    # Calcating "other" line if indicator type is numeric
                    if ReportDatabase().get_indicator_datatype(indicator_name) == 0 and subCount != 0:
                        #and (not items or indicator_name in items):
                        data_dict['titles'].append(indent_str * (level + 1) +
                                                   ' %s (%s)' %
                                                   (_T("templates",
                                                       item.attrib['title']),
                                                    locale['STR_OTHER']))
                        for i in xrange(len(period)):
                            child_sum = _sum_None([l[i] for l in childGValues])
                            other_value = (values[i] - child_sum) if child_sum is not None and values[i] else None
                            #print other_value
                            data_dict['values'][i].append(other_value)

                return (selected_items, GValues)
Exemple #2
0
        def _localization(loc_tag):
            for entry in loc_tag:
                if entry.tag.lower() != 'entry':
                    continue
                locale[entry.attrib['name']] = _T("templates", entry.attrib['value'])

            # Setting Period start and period end PDF var
            pdf_vars['__PERIOD_START__'] = datetime.strptime(period[0], "%Y-%m-%d").strftime(locale['DATE_FORMAT'])
            pdf_vars['__PERIOD_END__'] = datetime.strptime(period[-1], "%Y-%m-%d").strftime(locale['DATE_FORMAT'])
            pdf_vars['__NOW_DATE__'] = datetime.now().strftime(locale['DATE_FORMAT'])
            pdf_vars['__NOW_HOUR__'] = datetime.now().strftime('%H:%M:%S')
Exemple #3
0
            def _fetchSubs(container, parent=None, level=-1, parent_value=0):
                values = []
                for item in container:
                    if item.tag.lower() != 'item':
                        continue
                    indicator_name = item.attrib['indicator']
                    indicator_label = _T("templates", item.attrib['title'])
                    indicator_value = ReportDatabase().get_indicator_current_value(indicator_name, entities)
                    # indicator_value is a list of dict {'entity_id' : .., 'value' .. }
                    # ==============================================================
                    # ==> Generate one entry for each entity [disabled]
                    #for entry in indicator_value:
                    #    if entry['entity_id'] in entity_names:
                    #        entity_name = entity_names[entry['entity_id']]
                    #    else:
                    #        entity_name = entry['entity_id']
                    #    if not items or indicator_name in items:
                    #        data_dict['values'].append([ indent_str * level + indicator_label + (' (%s)' % entity_name ), entry['value']])
                    # =================================================================
                    # Calculating sum value for entities
                    value = _sum_None([x['value'] for x in indicator_value])
                    values.append(value)
                    if not items or indicator_name in items:
                        data_dict['values'].append([indent_str * level + indicator_label, value])

                    # TODO: Calculate other cols
                    # Fetch this item subitems
                    _fetchSubs(item, container, level + 1, value)
                # Generating others value
                if parent and values:
                    others_value = parent_value - _sum_None(values)
                    data_dict['values'].append([indent_str * level +
                                                ' %s (%s)' %
                                                (parent.attrib['title'],
                                                 locale['STR_OTHER']),
                                                others_value])
Exemple #4
0
def translate_attrs(attrs):
    for key, value in attrs.items():
        if key in TRANSLATE_ATTRS:
            attrs[key] = _T("templates", value)
    return attrs
Exemple #5
0
 def _homepage(text):
     pdf.pushHomePageHTML(_replace_pdf_vars(_T("templates", text)))
Exemple #6
0
 def _h3(text):
     pdf.h3(_T("templates", text))
Exemple #7
0
 def _h2(text):
     pdf.h2(_T("templates", text))
Exemple #8
0
 def _h1(text):
     pdf.h1(_T("templates", text))