示例#1
0
    def _initialize(self, needs_only):
        if len(self.stream_keys) == 0:
            abort(400)

        # no duplicates allowed
        handled = []
        for key in self.stream_keys:
            if key in handled:
                abort(400)
            self.streams.append(self._create_data_stream(key))
            handled.append(key)

        # populate self.parameters if empty or None
        if self.parameters is None or len(self.parameters) == 0:
            self.parameters = set()
            for each in self.stream_keys:
                self.parameters = self.parameters.union(each.stream.parameters)

        # sort parameters by name for particle output
        params = [(p.name, p) for p in self.parameters]
        params.sort()
        self.parameters = [p[1] for p in params]

        # determine if any other parameters are needed
        distinct_sensors = get_distinct_sensors()
        needs = set()
        for each in self.parameters:
            if each.parameter_type == FUNCTION:
                needs = needs.union([p for p in each.needs if p not in self.parameters])

        # available in the specified streams?
        provided = []
        for stream_key in self.stream_keys:
            provided.extend([p.id for p in stream_key.stream.parameters])

        needs = needs.difference(provided)

        # find the available streams which provide any needed parameters
        found = set()
        for each in needs:
            each = CachedParameter.from_id(each)
            if each in found:
                continue
            streams = [CachedStream.from_id(sid) for sid in each.streams]
            sensor1, stream1 = find_stream(self.stream_keys[0], streams, distinct_sensors)
            if not any([sensor1 is None, stream1 is None]):
                new_stream_key = StreamKey.from_stream_key(self.stream_keys[0], sensor1, stream1.name)
                self.stream_keys.append(new_stream_key)
                self.streams.append(self._create_data_stream(new_stream_key))
                found = found.union(stream1.parameters)
        found = [p.id for p in found]

        self.needs_params = needs.difference(found)

        needs_cc = set()
        for stream in self.streams:
            needs_cc = needs_cc.union(stream.needs_cc)

        self.needs_cc = needs_cc.difference(self.coefficients.keys())
示例#2
0
 def test_find_stream(self):
     target_parameter = CachedParameter.from_id(163)  # coefficient C1 needed for PRESWAT
     distinct = get_distinct_sensors()
     stream_key = StreamKey(self.subsite, self.node, self.sensor, self.method, self.stream)
     streams = [CachedStream.from_id(i) for i in target_parameter.streams]
     sensor, stream = find_stream(stream_key, streams, distinct)
     self.assertEqual(sensor, self.sensor)
     self.assertEqual(stream.name, u'ctdbp_no_calibration_coefficients')
示例#3
0
 def test_distinct_sensors(self):
     distinct = get_distinct_sensors()
     self.assertListEqual(distinct,
                          [(u'RS00ENGC', u'XX001', u'00-CTDPFA001'),
                           (u'XX00XXXX', u'XX00X', u'00-CTDPFW100'),
                           (u'RS00ENGC', u'XX00X', u'00-CTDBPA002')])
示例#4
0
    def _initialize(self, needs_only):
        if len(self.stream_keys) == 0:
            abort(400)

        # no duplicates allowed
        handled = []
        for key in self.stream_keys:
            if key in handled:
                abort(400)
            self.streams.append(self._create_data_stream(key))
            handled.append(key)

        # populate self.parameters if empty or None
        if self.parameters is None or len(self.parameters) == 0:
            self.parameters = set()
            for each in self.stream_keys:
                self.parameters = self.parameters.union(each.stream.parameters)

        # sort parameters by name for particle output
        params = [(p.name, p) for p in self.parameters]
        params.sort()
        self.parameters = [p[1] for p in params]

        # determine if any other parameters are needed
        distinct_sensors = get_distinct_sensors()
        needs = set()
        for each in self.parameters:
            if each.parameter_type == FUNCTION:
                needs = needs.union(
                    [p for p in each.needs if p not in self.parameters])

        # available in the specified streams?
        provided = []
        for stream_key in self.stream_keys:
            provided.extend([p.id for p in stream_key.stream.parameters])

        needs = needs.difference(provided)

        # find the available streams which provide any needed parameters
        found = set()
        for each in needs:
            each = CachedParameter.from_id(each)
            if each in found:
                continue
            streams = [CachedStream.from_id(sid) for sid in each.streams]
            sensor1, stream1 = find_stream(self.stream_keys[0], streams,
                                           distinct_sensors)
            if not any([sensor1 is None, stream1 is None]):
                new_stream_key = StreamKey.from_stream_key(
                    self.stream_keys[0], sensor1, stream1.name)
                self.stream_keys.append(new_stream_key)
                self.streams.append(self._create_data_stream(new_stream_key))
                found = found.union(stream1.parameters)
        found = [p.id for p in found]

        self.needs_params = needs.difference(found)

        needs_cc = set()
        for stream in self.streams:
            needs_cc = needs_cc.union(stream.needs_cc)

        self.needs_cc = needs_cc.difference(self.coefficients.keys())