Пример #1
0
def process_bin_sizes(sheet):
    print 'Processing bin sizes'
    for row in sheet:
        if 'stream' in row:
            stream = Stream().query.filter(Stream.name == row.get('stream')).first()
            if stream is None:
                print 'Can not find stream %s in preload' % row.get('stream')
            else:
                bin_size_text = row.get('binsize')
                bin_size = config.DEFAULT_BIN_SIZE_MINUTES
                if bin_size_text is not None:
                    bin_size = int(bin_size_text)
                else:
                    print 'Using default bin size for stream %s with blank row in sheet' % stream.name
                stream.binsize_minutes = bin_size
    database.Session.commit()
Пример #2
0
def process_streams(sheet):
    print 'Processing streams'
    common_fields = [7, 10, 11, 12, 16, 863]
    for row in sheet:
        if validate_stream_row(row):
            stream = Stream()
            stream.id = int(row.get('id')[4:])
            stream.name = row.get('name')
            params = row.get('parameterids').split(',')
            params = common_fields + [int(p.strip()[2:]) for p in params if p.startswith('PD')]
            params = sorted(list(set(params)))
            for each in params:
                parameter = get_parameter(each)
                if parameter is not None:
                    stream.parameters.append(parameter)
            if len(stream.parameters) > 0:
                db.session.add(stream)

    db.session.commit()
Пример #3
0
def process_streams(sheet):
    print 'Processing streams'
    common_fields = [7, 10, 11, 12, 16, 863]
    for row in sheet:
        if validate_stream_row(row):
            stream = Stream()
            stream.id = int(row.get('id')[4:])
            stream.name = row.get('name')
            params = row.get('parameterids').split(',')
            params = common_fields + [
                int(p.strip()[2:]) for p in params if p.startswith('PD')
            ]
            params = sorted(list(set(params)))
            for each in params:
                parameter = get_parameter(each)
                if parameter is not None:
                    stream.parameters.append(parameter)
            if len(stream.parameters) > 0:
                db.session.add(stream)

    db.session.commit()
Пример #4
0
def process_streams(sheet):
    print 'Processing streams'
    common_fields = [7, 10, 11, 12, 16, 863]
    for row in sheet:
        if validate_stream_row(row):
            stream = Stream()
            stream.binsize_minutes = config.DEFAULT_BIN_SIZE_MINUTES
            stream.id = int(row.get('id')[4:])
            stream.name = row.get('name')
            time_param = row.get('temporalparameter')
            if time_param and time_param.startswith('PD'):
                time_param = int(time_param.strip()[2:])
            else:
                time_param = 7
            stream.time_parameter = time_param

            # for geolocation
            stream.lat_param_id = row.get('latparam')
            stream.lon_param_id = row.get('lonparam')
            stream.depth_param_id = row.get('depthparam')

            stream.lat_stream_id = row.get('latstream')
            if stream.lat_stream_id is None:
                stream.lat_stream_id = stream.id

            stream.lon_stream_id = row.get('lonstream')
            if stream.lon_stream_id is None:
                stream.lon_stream_id = stream.id

            stream.depth_stream_id = row.get('depthstream')
            if stream.depth_stream_id is None:
                stream.depth_stream_id = stream.id
                stream.uses_ctd = True
            # ---

            dependencies = row.get("streamdependency")
            params = row.get('parameterids').split(',')
            # temp fix until spreadsheet is fixed:
            if dependencies is not None:
                params = [int(p.strip()[2:]) for p in params if p.startswith('PD')]
                for i in dependencies.split(','):
                    if i.startswith("DICT"):
                        source = int(i[4:])
                        sd = StreamDependency()
                        sd.source_stream_id = source
                        sd.product_stream_id = stream.id
                        database.Session.add(sd)
                    else:
                        print "ACK! Stream dependency is not in the correct format"

            else:
                params = common_fields + [int(p.strip()[2:]) for p in params if p.startswith('PD')]
            params = sorted(list(set(params)))
            for each in params:
                parameter = get_parameter(each)
                if parameter is not None:
                    stream.parameters.append(parameter)
                else:
                    print "ACK! missing parameter: %d for stream: %s" % (each, stream.name)
            if len(stream.parameters) > 0:
                database.Session.add(stream)
    database.Session.commit()