Beispiel #1
0
 // YDataSet constructor for the new datalogger
 public YDataSet(YFunction parent)
 {
     _parent     = parent;
     _startTime  = 0;
     _endTime    = 0;
     _hardwareId = "";
     _summary    = new YMeasure();
 }
Beispiel #2
0
        //--- (end of generated code: YDataSet definitions)

        // YDataSet constructor, when instantiated directly by a function
        public YDataSet(YFunction parent, string functionId, string unit, double startTime, double endTime)
        {
            _parent      = parent;
            _functionId  = functionId;
            _unit        = unit;
            _startTimeMs = startTime * 1000;
            _endTimeMs   = endTime * 1000;
            _progress    = -1;
            _hardwareId  = "";
            _summary     = new YMeasure();
        }
Beispiel #3
0
        //--- (end of generated code: YDataSet definitions)

        // YDataSet constructor, when instantiated directly by a function
        public YDataSet(YFunction parent, string functionId, string unit, long startTime, long endTime)
        {
            _parent     = parent;
            _functionId = functionId;
            _unit       = unit;
            _startTime  = startTime;
            _endTime    = endTime;
            _progress   = -1;
            _hardwareId = "";
            _summary    = new YMeasure();
        }
Beispiel #4
0
 public override async Task <int> _invokeTimedReportCallback(YMeasure value)
 {
     if (_timedReportCallbackPressure != null)
     {
         await _timedReportCallbackPressure(this, value);
     }
     else
     {
         await base._invokeTimedReportCallback(value);
     }
     return(0);
 }
            public virtual async Task invoke()
            {
                if (_value == null)
                {
                    YSensor  sensor = (YSensor)_fun;
                    YMeasure mesure = await sensor._decodeTimedReport(_timestamp, _report);

                    await sensor._invokeTimedReportCallback(mesure);
                }
                else
                {
                    // new value
                    await _fun._invokeValueCallback(_value);
                }
            }
Beispiel #6
0
        /**
         * <summary>
         *   Returns the detailed set of measures for the time interval corresponding
         *   to a given condensed measures previously returned by <c>get_preview()</c>.
         * <para>
         *   The result is provided as a list of <c>YMeasure</c> objects.
         * </para>
         * <para>
         * </para>
         * </summary>
         * <param name="measure">
         *   condensed measure from the list previously returned by
         *   <c>get_preview()</c>.
         * </param>
         * <returns>
         *   a table of records, where each record depicts the
         *   measured values during a time interval
         * </returns>
         * <para>
         *   On failure, throws an exception or returns an empty array.
         * </para>
         */
        public virtual async Task <List <YMeasure> > get_measuresAt(YMeasure measure)
        {
            double                startUtcMs;
            YDataStream           stream;
            List <List <double> > dataRows = new List <List <double> >();
            List <YMeasure>       measures = new List <YMeasure>();
            double                tim;
            double                itv;
            double                end_;
            int nCols;
            int minCol;
            int avgCol;
            int maxCol;

            startUtcMs = measure.get_startTimeUTC() * 1000;
            stream     = null;
            for (int ii = 0; ii < _streams.Count; ii++)
            {
                if (Math.Round(await _streams[ii].get_realStartTimeUTC() * 1000) == startUtcMs)
                {
                    stream = _streams[ii];
                }
            }
            if (stream == null)
            {
                return(measures);
            }
            dataRows = await stream.get_dataRows();

            if (dataRows.Count == 0)
            {
                return(measures);
            }
            tim = Math.Round(await stream.get_realStartTimeUTC() * 1000);
            itv = Math.Round(await stream.get_dataSamplesInterval() * 1000);
            if (tim < itv)
            {
                tim = itv;
            }
            nCols  = dataRows[0].Count;
            minCol = 0;
            if (nCols > 2)
            {
                avgCol = 1;
            }
            else
            {
                avgCol = 0;
            }
            if (nCols > 2)
            {
                maxCol = 2;
            }
            else
            {
                maxCol = 0;
            }

            for (int ii = 0; ii < dataRows.Count; ii++)
            {
                end_ = tim + itv;
                if ((end_ > _startTimeMs) && ((_endTimeMs == 0) || (tim < _endTimeMs)))
                {
                    measures.Add(new YMeasure(tim / 1000.0, end_ / 1000.0, dataRows[ii][minCol], dataRows[ii][avgCol], dataRows[ii][maxCol]));
                }
                tim = end_;
            }
            return(measures);
        }
Beispiel #7
0
        public virtual async Task <int> loadSummary(byte[] data)
        {
            List <List <double> > dataRows = new List <List <double> >();
            double        tim;
            double        mitv;
            double        itv;
            double        fitv;
            double        end_;
            int           nCols;
            int           minCol;
            int           avgCol;
            int           maxCol;
            int           res;
            int           m_pos;
            double        previewTotalTime;
            double        previewTotalAvg;
            double        previewMinVal;
            double        previewMaxVal;
            double        previewAvgVal;
            double        previewStartMs;
            double        previewStopMs;
            double        previewDuration;
            double        streamStartTimeMs;
            double        streamDuration;
            double        streamEndTimeMs;
            double        minVal;
            double        avgVal;
            double        maxVal;
            double        summaryStartMs;
            double        summaryStopMs;
            double        summaryTotalTime;
            double        summaryTotalAvg;
            double        summaryMinVal;
            double        summaryMaxVal;
            string        url;
            string        strdata;
            List <double> measure_data = new List <double>();

            if (_progress < 0)
            {
                strdata = YAPI.DefaultEncoding.GetString(data);
                if (strdata == "{}")
                {
                    _parent._throw(YAPI.VERSION_MISMATCH, "device firmware is too old");
                    return(YAPI.VERSION_MISMATCH);
                }
                res = await this._parse(strdata);

                if (res < 0)
                {
                    return(res);
                }
            }
            summaryTotalTime = 0;
            summaryTotalAvg  = 0;
            summaryMinVal    = YAPI.MAX_DOUBLE;
            summaryMaxVal    = YAPI.MIN_DOUBLE;
            summaryStartMs   = YAPI.MAX_DOUBLE;
            summaryStopMs    = YAPI.MIN_DOUBLE;

            // Parse complete streams
            for (int ii = 0; ii < _streams.Count; ii++)
            {
                streamStartTimeMs = Math.Round(await _streams[ii].get_realStartTimeUTC() * 1000);
                streamDuration    = await _streams[ii].get_realDuration();
                streamEndTimeMs   = streamStartTimeMs + Math.Round(streamDuration * 1000);
                if ((streamStartTimeMs >= _startTimeMs) && ((_endTimeMs == 0) || (streamEndTimeMs <= _endTimeMs)))
                {
                    // stream that are completely inside the dataset
                    previewMinVal   = await _streams[ii].get_minValue();
                    previewAvgVal   = await _streams[ii].get_averageValue();
                    previewMaxVal   = await _streams[ii].get_maxValue();
                    previewStartMs  = streamStartTimeMs;
                    previewStopMs   = streamEndTimeMs;
                    previewDuration = streamDuration;
                }
                else
                {
                    // stream that are partially in the dataset
                    // we need to parse data to filter value outside the dataset
                    url  = _streams[ii].imm_get_url();
                    data = await _parent._download(url);

                    _streams[ii].imm_parseStream(data);
                    dataRows = await _streams[ii].get_dataRows();
                    if (dataRows.Count == 0)
                    {
                        return(await this.get_progress());
                    }
                    tim    = streamStartTimeMs;
                    fitv   = Math.Round(await _streams[ii].get_firstDataSamplesInterval() * 1000);
                    itv    = Math.Round(await _streams[ii].get_dataSamplesInterval() * 1000);
                    nCols  = dataRows[0].Count;
                    minCol = 0;
                    if (nCols > 2)
                    {
                        avgCol = 1;
                    }
                    else
                    {
                        avgCol = 0;
                    }
                    if (nCols > 2)
                    {
                        maxCol = 2;
                    }
                    else
                    {
                        maxCol = 0;
                    }
                    previewTotalTime = 0;
                    previewTotalAvg  = 0;
                    previewStartMs   = streamEndTimeMs;
                    previewStopMs    = streamStartTimeMs;
                    previewMinVal    = YAPI.MAX_DOUBLE;
                    previewMaxVal    = YAPI.MIN_DOUBLE;
                    m_pos            = 0;
                    while (m_pos < dataRows.Count)
                    {
                        measure_data = dataRows[m_pos];
                        if (m_pos == 0)
                        {
                            mitv = fitv;
                        }
                        else
                        {
                            mitv = itv;
                        }
                        end_ = tim + mitv;
                        if ((end_ > _startTimeMs) && ((_endTimeMs == 0) || (tim < _endTimeMs)))
                        {
                            minVal = measure_data[minCol];
                            avgVal = measure_data[avgCol];
                            maxVal = measure_data[maxCol];
                            if (previewStartMs > tim)
                            {
                                previewStartMs = tim;
                            }
                            if (previewStopMs < end_)
                            {
                                previewStopMs = end_;
                            }
                            if (previewMinVal > minVal)
                            {
                                previewMinVal = minVal;
                            }
                            if (previewMaxVal < maxVal)
                            {
                                previewMaxVal = maxVal;
                            }
                            previewTotalAvg  = previewTotalAvg + (avgVal * mitv);
                            previewTotalTime = previewTotalTime + mitv;
                        }
                        tim   = end_;
                        m_pos = m_pos + 1;
                    }
                    if (previewTotalTime > 0)
                    {
                        previewAvgVal   = previewTotalAvg / previewTotalTime;
                        previewDuration = (previewStopMs - previewStartMs) / 1000.0;
                    }
                    else
                    {
                        previewAvgVal   = 0.0;
                        previewDuration = 0.0;
                    }
                }
                _preview.Add(new YMeasure(previewStartMs / 1000.0, previewStopMs / 1000.0, previewMinVal, previewAvgVal, previewMaxVal));
                if (summaryMinVal > previewMinVal)
                {
                    summaryMinVal = previewMinVal;
                }
                if (summaryMaxVal < previewMaxVal)
                {
                    summaryMaxVal = previewMaxVal;
                }
                if (summaryStartMs > previewStartMs)
                {
                    summaryStartMs = previewStartMs;
                }
                if (summaryStopMs < previewStopMs)
                {
                    summaryStopMs = previewStopMs;
                }
                summaryTotalAvg  = summaryTotalAvg + (previewAvgVal * previewDuration);
                summaryTotalTime = summaryTotalTime + previewDuration;
            }
            if ((_startTimeMs == 0) || (_startTimeMs > summaryStartMs))
            {
                _startTimeMs = summaryStartMs;
            }
            if ((_endTimeMs == 0) || (_endTimeMs < summaryStopMs))
            {
                _endTimeMs = summaryStopMs;
            }
            if (summaryTotalTime > 0)
            {
                _summary = new YMeasure(summaryStartMs / 1000.0, summaryStopMs / 1000.0, summaryMinVal, summaryTotalAvg / summaryTotalTime, summaryMaxVal);
            }
            else
            {
                _summary = new YMeasure(0.0, 0.0, YAPI.INVALID_DOUBLE, YAPI.INVALID_DOUBLE, YAPI.INVALID_DOUBLE);
            }
            return(await this.get_progress());
        }
Beispiel #8
0
        /**
         * <summary>
         *   Returns the detailed set of measures for the time interval corresponding
         *   to a given condensed measures previously returned by <c>get_preview()</c>.
         * <para>
         *   The result is provided as a list of YMeasure objects.
         * </para>
         * <para>
         * </para>
         * </summary>
         * <param name="measure">
         *   condensed measure from the list previously returned by
         *   <c>get_preview()</c>.
         * </param>
         * <returns>
         *   a table of records, where each record depicts the
         *   measured values during a time interval
         * </returns>
         * <para>
         *   On failure, throws an exception or returns an empty array.
         * </para>
         */
        public virtual async Task <List <YMeasure> > get_measuresAt(YMeasure measure)
        {
            long                  startUtc;
            YDataStream           stream;
            List <List <double> > dataRows = new List <List <double> >();
            List <YMeasure>       measures = new List <YMeasure>();
            double                tim;
            double                itv;
            int nCols;
            int minCol;
            int avgCol;
            int maxCol;

            startUtc = (long)Math.Round(measure.get_startTimeUTC());
            stream   = null;
            for (int ii = 0; ii < _streams.Count; ii++)
            {
                if (await _streams[ii].get_startTimeUTC() == startUtc)
                {
                    stream = _streams[ii];
                }
            }
            if (stream == null)
            {
                return(measures);
            }
            dataRows = await stream.get_dataRows();

            if (dataRows.Count == 0)
            {
                return(measures);
            }
            tim = (double)await stream.get_startTimeUTC();

            itv = await stream.get_dataSamplesInterval();

            if (tim < itv)
            {
                tim = itv;
            }
            nCols  = dataRows[0].Count;
            minCol = 0;
            if (nCols > 2)
            {
                avgCol = 1;
            }
            else
            {
                avgCol = 0;
            }
            if (nCols > 2)
            {
                maxCol = 2;
            }
            else
            {
                maxCol = 0;
            }

            for (int ii = 0; ii < dataRows.Count; ii++)
            {
                if ((tim >= _startTime) && ((_endTime == 0) || (tim <= _endTime)))
                {
                    measures.Add(new YMeasure(tim - itv, tim, dataRows[ii][minCol], dataRows[ii][avgCol], dataRows[ii][maxCol]));
                }
                tim = tim + itv;
            }
            return(measures);
        }
Beispiel #9
0
        // YDataSet parser for stream list
        protected internal virtual async Task <int> _parse(string json_str)
        {
            YJSONObject json;
            YJSONArray  jstreams;
            double      summaryMinVal    = double.MaxValue;
            double      summaryMaxVal    = double.Epsilon;
            double      summaryTotalTime = 0;
            double      summaryTotalAvg  = 0;
            long        streamStartTime;
            long        streamEndTime;
            long        startTime = 0x7fffffff;
            long        endTime   = 0;

            json = new YJSONObject(json_str);
            json.parse();
            _functionId = json.getString("id");
            _unit       = json.getString("unit");
            if (json.has("calib"))
            {
                _calib    = YAPIContext.imm_decodeFloats(json.getString("calib"));
                _calib[0] = _calib[0] / 1000;
            }
            else
            {
                _calib = YAPIContext.imm_decodeWords(json.getString("cal"));
            }
            _streams  = new List <YDataStream>();
            _preview  = new List <YMeasure>();
            _measures = new List <YMeasure>();
            jstreams  = json.getYJSONArray("streams");
            for (int i = 0; i < jstreams.Length; i++)
            {
                YDataStream stream = _parent.imm_findDataStream(this, jstreams.getString(i));
                streamStartTime = await stream.get_startTimeUTC() - await stream.get_dataSamplesIntervalMs() / 1000;

                streamEndTime = await stream.get_startTimeUTC() + await stream.get_duration();

                if (_startTime > 0 && streamEndTime <= _startTime)
                {
                    // this stream is too early, drop it
                }
                else if (_endTime > 0 && await stream.get_startTimeUTC() > _endTime)
                {
                    // this stream is too late, drop it
                }
                else
                {
                    _streams.Add(stream);
                    if (startTime > streamStartTime)
                    {
                        startTime = streamStartTime;
                    }
                    if (endTime < streamEndTime)
                    {
                        endTime = streamEndTime;
                    }

                    if (await stream.isClosed() && await stream.get_startTimeUTC() >= _startTime && (_endTime == 0 || streamEndTime <= _endTime))
                    {
                        if (summaryMinVal > await stream.get_minValue())
                        {
                            summaryMinVal = await stream.get_minValue();
                        }
                        if (summaryMaxVal < await stream.get_maxValue())
                        {
                            summaryMaxVal = await stream.get_maxValue();
                        }
                        summaryTotalAvg += await stream.get_averageValue() * await stream.get_duration();

                        summaryTotalTime += await stream.get_duration();

                        YMeasure rec = new YMeasure(await stream.get_startTimeUTC(), streamEndTime, await stream.get_minValue(), await stream.get_averageValue(), await stream.get_maxValue());
                        _preview.Add(rec);
                    }
                }
            }
            if ((_streams.Count > 0) && (summaryTotalTime > 0))
            {
                // update time boundaries with actual data
                if (_startTime < startTime)
                {
                    _startTime = startTime;
                }
                if (_endTime == 0 || _endTime > endTime)
                {
                    _endTime = endTime;
                }
                _summary = new YMeasure(_startTime, _endTime, summaryMinVal, summaryTotalAvg / summaryTotalTime, summaryMaxVal);
            }
            _progress = 0;
            return(await this.get_progress());
        }