Exemplo n.º 1
0
        public GenericObject GetTimeSeries(
            [GraphQLNonNullType] TimeSeriesRequestInput input,
            [Service] ITimeSeriesRepository repo
            )
        {
            List <(int, string)> sensorNameIdPairs = repo.GetSensorTablePair(input.Sensors);
            DateTime             from;
            DateTime             to;

            if (input.SpecifiedTimePeriod)
            {
                if (input.From == null || input.To == null || input.From >= input.To)
                {
                    throw new QueryException(ErrorBuilder.New().SetMessage("There is an error with the given to and from times.").Build());
                }
                from = input.From ?? DateTime.Now;
                to   = input.To ?? DateTime.Now;
            }
            else
            {
                if (input.TicksBackwards == null || input.TicksBackwards <= 0)
                {
                    throw new QueryException(ErrorBuilder.New().SetMessage("Please specify ticks backwards.").Build());
                }
                from = new DateTime(DateTime.Now.Ticks - input.TicksBackwards ?? 1);
                to   = DateTime.Now;
            }
            var queryString = "";

            foreach (var sensorNameIdPair in sensorNameIdPairs)
            {
                queryString = queryString + TimeSeriesQueryBuilder.CreateTimeSeriesQueryString(sensorNameIdPair.Item1, sensorNameIdPair.Item2, from, to);
            }
            return(repo.GetTimeSeries("", queryString).Result);
        }
        public GenericObject OnData(
            int sensorId,
            IEventMessage message,
            //[Service] IUploadDataRepository _repository
            [Service] ITimeSeriesRepository _repository
            )
        {
            var data = (CreatedDataValues)message.Payload;
            List <(int, string)> sensorNameIdPairs = _repository.GetSensorTablePair(new List <int>()
            {
                data.sensorId
            });
            var queryString = "";

            foreach (var sensorNameIdPair in sensorNameIdPairs)
            {
                queryString = queryString + TimeSeriesQueryBuilder.CreateTimeSeriesQueryString(
                    sensorNameIdPair.Item1,
                    sensorNameIdPair.Item2,
                    data.fromDate,
                    data.toDate
                    );
            }
            return(_repository.GetTimeSeries("", queryString).Result);
        }
Exemplo n.º 3
0
        public List <SensorType> GetSensors(
            [Service] ITimeSeriesRepository repo
            )
        {
            var queryString = TimeSeriesQueryBuilder.CreateSensorsQueryString();

            return(repo.GetSensorsData(queryString).Result);
        }
Exemplo n.º 4
0
        public GenericTimeType GetTimeSeriesPeriode(
            TimeSeriesPeriodeInput input,
            [Service] ITimeSeriesRepository repo
            )
        {
            var queryString = TimeSeriesQueryBuilder.CreateTimeSeriesPeriodeQueryString(input.SensorId, input.TableName);

            return(repo.GetTimeSeriesPeriode(queryString).Result);
        }