Пример #1
0
def species_from_csv(filename, section):
    curdata = load_species_refval()
    with open(filename, 'rb') as f:
        reader = UnicodeDictReader(f)
        for row in reader:
            key = row['code'] + '-' + row['region']
            for k, v in curdata[key][section].iteritems():
                if k in row:
                    curdata[key][section][k] = row[k]
    save_species_refval(curdata)
Пример #2
0
def species_from_csv(filename, section):
    curdata = load_species_refval()
    with open(filename, 'rb') as f:
        reader = UnicodeDictReader(f)
        for row in reader:
            key = row['code'] + '-' + row['region']
            for k, v in curdata[key][section].iteritems():
                if k in row:
                    curdata[key][section][k] = row[k]
    save_species_refval(curdata)
Пример #3
0
def species_methods_from_csv(filename):
    curdata = load_species_refval()
    with open(filename, 'rb') as f:
        reader = UnicodeDictReader(f)
        for row in reader:
            code = row.pop('code')
            for region in REGIONS:
                key = code + '-' + region
                if not key in curdata:
                    continue
                for k, v in row.iteritems():
                    section, field = k.split('-')
                    curdata[key][section][field] = v
    save_species_refval(curdata)
Пример #4
0
def species_methods_from_csv(filename):
    curdata = load_species_refval()
    with open(filename, 'rb') as f:
        reader = UnicodeDictReader(f)
        for row in reader:
            code = row.pop('code')
            for region in REGIONS:
                key = code + '-' + region
                if not key in curdata:
                    continue
                for k, v in row.iteritems():
                    section, field = k.split('-')
                    curdata[key][section][field] = v
    save_species_refval(curdata)
Пример #5
0
def species_from_dataset(dataset_id=1):
    """
        Import the reference values from a previous dataset - not reference,
        but actual values.

        range:
            'Areal favorabil referinta' - r.range_surface_area
        habitat:
            u'Suprafața adecvata' - r.habitat_surface_area
        population_range:
            'Populatia favorabila de referinta' - population_alt_minimum_size
    """
    from art17.scripts.export_refval import generic_species_exporter

    def format_row(sp, sr):
        key = '{}-{}'.format(sp.code, sr.region)
        population_size = (sr.population_minimum_size
                           or sr.population_alt_minimum_size
                           or sr.population_alt_maximum_size)
        data = {
            'range': {
                'Areal favorabil referinta':
                unicode(sr.range_surface_area)
                if sr.range_surface_area else None,
            },
            'habitat': {
                u'Suprafața adecvata':
                unicode(sr.habitat_surface_area)
                if sr.habitat_surface_area else None,
            },
            'population_range': {
                'Populatia favorabila de referinta':
                unicode(population_size) if population_size else None
            }
        }
        print key, data
        return (key, data)

    newdata = dict(generic_species_exporter(format_row, dataset_id=dataset_id))
    curdata = load_species_refval()
    data = smart_update(curdata, newdata)
    save_species_refval(data)
    print "Done."
Пример #6
0
def species_from_dataset(dataset_id=1):
    """
        Import the reference values from a previous dataset - not reference,
        but actual values.

        range:
            'Areal favorabil referinta' - r.range_surface_area
        habitat:
            u'Suprafața adecvata' - r.habitat_surface_area
        population_range:
            'Populatia favorabila de referinta' - population_alt_minimum_size
    """
    from art17.scripts.export_refval import generic_species_exporter

    def format_row(sp, sr):
        key = '{}-{}'.format(sp.code, sr.region)
        population_size = (sr.population_minimum_size or
                           sr.population_alt_minimum_size or
                           sr.population_alt_maximum_size)
        data = {
            'range': {
                'Areal favorabil referinta': unicode(
                    sr.range_surface_area) if sr.range_surface_area else None,
            },
            'habitat': {
                u'Suprafața adecvata': unicode(sr.habitat_surface_area)
                if sr.habitat_surface_area else None,
            },
            'population_range': {
                'Populatia favorabila de referinta': unicode(population_size)
                if population_size else None
            }
        }
        print key, data
        return (key, data)

    newdata = dict(generic_species_exporter(format_row, dataset_id=dataset_id))
    curdata = load_species_refval()
    data = smart_update(curdata, newdata)
    save_species_refval(data)
    print "Done."
Пример #7
0
 def post(self, **kwargs):
     context = self.get_context(**kwargs)
     form = context['form']
     subject = context['subject']
     if form.validate():
         required_struct = get_struct(get_refvals(context['subject']))
         wb = load_workbook(form.excel_doc.data)
         struct = {sheet: [r.value for r in wb[sheet].rows[0] if r.value]
                   for sheet in wb.get_sheet_names()}
         if required_struct == struct:
             d = process_xls(wb, struct)
             if subject == 'species':
                 save_species_refval(d)
             elif subject == 'habitat':
                 save_habitat_refval(d)
             else:
                 raise NotImplementedError
             flash(u'Noile valori de referință au fost salvate.', 'success')
         else:
             flash(u'Documentul Excel nu este în formatul acceptat.',
                   'danger')
     return render_template(self.template_name, **context)
Пример #8
0
def refactor_species_refval():
    data = refactor_refval('species.json', 'species')
    save_species_refval(data)
Пример #9
0
def refactor_species_refval():
    data = refactor_refval('species.json', 'species')
    save_species_refval(data)