예제 #1
0
        def insert_pregen_data(self, indicator):
            """ Find all rows for the indicator, and insert each """
            count = 0
            for pregen_part in indicator.indicatorpregenpart_set.all():
                file_path = self.find_file(pregen_part)
                if not file_path:
                    print "WARNING: Couldn't find a file for %s (searched for %s)" % (
                        indicator.name, pregen_part.file_name)
                    return

                reader = csv.DictReader(open(file_path, 'rU'))
                found_column = False
                key_field = self.get_key_field(pregen_part)
                for row in reader:
                    if row.has_key(pregen_part.column_name):
                        found_column = True
                        data_type = pregen_part.indicator.data_type
                        if not data_type or data_type == '':
                            # this will trigger auto-detection
                            data_type = None
                        indicator_data = generate_indicator_data(
                            indicator,
                            pregen_part.key_type,
                            row[key_field],
                            pregen_part.time_type,
                            str(pregen_part.time_value).split('.')[0],
                            row[pregen_part.column_name],
                            data_type=indicator.data_type)
                        indicator_data.save(force_insert=True)
                        count += 1
                if not found_column:
                    print "WARNING: Couldn't find a column for %s in one or more rows" % indicator.name
            print "Inserted %d values for %s" % (count, indicator)
            return count
예제 #2
0
 def insert_pregen_data(self, indicator):
     """ Find all rows for the indicator, and insert each """
     count = 0
     for pregen_part in indicator.indicatorpregenpart_set.all():
         file_path = self.find_file(pregen_part)
         if not file_path:
             print "WARNING: Couldn't find a file for %s (searched for %s)" % (
                 indicator.name, pregen_part.file_name)
             return
         
         reader = csv.DictReader(open(file_path, 'rU'))
         found_column = False
         key_field = self.get_key_field(pregen_part)
         for row in reader:
             if row.has_key(pregen_part.column_name):
                 found_column = True
                 data_type = pregen_part.indicator.data_type
                 if not data_type or data_type == '':
                     # this will trigger auto-detection
                     data_type = None
                 indicator_data = generate_indicator_data(
                     indicator,
                     pregen_part.key_type,
                     row[key_field],
                     pregen_part.time_type,
                     str(pregen_part.time_value).split('.')[0],
                     row[pregen_part.column_name],
                     data_type=indicator.data_type
                 )
                 indicator_data.save(force_insert=True)
                 count += 1
         if not found_column:
             print "WARNING: Couldn't find a column for %s in one or more rows" % indicator.name
     print "Inserted %d values for %s" % (count, indicator)
     return count
예제 #3
0
def move_to_portal(indicator_defs, portal_name):
    if portal_name not in settings.DATABASES:
        raise Exception('%s is not a configured database' % portal_name)

    try:
        from core.models import IndicatorResult
    except ImportError:
        return

    for i_def in indicator_defs:
        indicator = Indicator.objects.get_for_def(i_def, using=portal_name)
        if indicator.indicatorpregenpart_set.count() > 0:
            # skip indicators that aren't "dynamic" indicators
            continue
        results = IndicatorResult.objects.filter(class_name=i_def.__name__)
        IndicatorData.objects.using(portal_name).filter(indicator=indicator).delete()
        for result in results:
            indicator_data = generate_indicator_data(
                indicator,
                result.key_unit_type,
                result.key_value,
                result.time_type,
                result.time_key,
                result.value,
                data_type='numeric'
            )
            indicator_data.save(force_insert=True,using=portal_name) 
예제 #4
0
def move_to_portal(indicator_defs, portal_name):
    if portal_name not in settings.DATABASES:
        raise Exception('%s is not a configured database' % portal_name)

    for i_def in indicator_defs:
        indicator = Indicator.objects.get_for_def(i_def, using=portal_name)
        if indicator.indicatorpregenpart_set.count() > 0:
            # skip indicators that aren't "dynamic" indicators
            continue
        results = IndicatorResult.objects.filter(class_name=i_def.__name__)
        IndicatorData.objects.using(portal_name).filter(
            indicator=indicator).delete()
        for result in results:
            indicator_data = generate_indicator_data(indicator,
                                                     result.key_unit_type,
                                                     result.key_value,
                                                     result.time_type,
                                                     result.time_key,
                                                     result.value,
                                                     data_type='numeric')
            indicator_data.save(force_insert=True, using=portal_name)