Пример #1
0
        public async Task <IEnumerable <QueryIntervalValue <IDictionary <string, string> > > > MultiAnalysis(string collection, IEnumerable <MultiAnalysisParam> analysisParams, QueryTimeframe timeframe = null, QueryInterval interval = null, IEnumerable <QueryFilter> filters = null, string timezone = "")
        {
            var jObs      = analysisParams.Select(x => new JProperty(x.Label, JObject.FromObject(new { analysis_type = x.Analysis, target_property = x.TargetProperty })));
            var parmsJson = JsonConvert.SerializeObject(new JObject(jObs), Formatting.None, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            });

            var parms = new Dictionary <string, string>();

            parms.Add(KeenConstants.QueryParmEventCollection, collection);
            parms.Add(KeenConstants.QueryParmTimeframe, timeframe.ToSafeString());
            parms.Add(KeenConstants.QueryParmInterval, interval.ToSafeString());
            parms.Add(KeenConstants.QueryParmTimezone, timezone);
            parms.Add(KeenConstants.QueryParmFilters, filters == null ? "" : JArray.FromObject(filters).ToString());
            parms.Add(KeenConstants.QueryParmAnalyses, parmsJson);

            var reply = await KeenWebApiRequest(KeenConstants.QueryMultiAnalysis, parms);

            var result = new List <QueryIntervalValue <IDictionary <string, string> > >();

            foreach (JObject i in reply.Value <JArray>("result"))
            {
                var d = new Dictionary <string, string>();
                foreach (JProperty p in i.Value <JObject>("value").Values <JProperty>())
                {
                    d.Add(p.Name, (string)p.Value);
                }

                var t  = i.Value <JObject>("timeframe");
                var qv = new QueryIntervalValue <IDictionary <string, string> >(d, t.Value <DateTime>("start"), t.Value <DateTime>("end"));
                result.Add(qv);
            }

            return(result);
        }
Пример #2
0
        public async Task <IEnumerable <QueryIntervalValue <IDictionary <string, string> > > > MultiAnalysis(string collection, IEnumerable <MultiAnalysisParam> analysisParams, IQueryTimeframe timeframe = null, QueryInterval interval = null, IEnumerable <QueryFilter> filters = null, string timezone = "")
        {
            var parms = new Dictionary <string, string>();

            parms.Add(KeenConstants.QueryParmEventCollection, collection);
            parms.Add(KeenConstants.QueryParmTimeframe, timeframe.ToSafeString());
            parms.Add(KeenConstants.QueryParmInterval, interval.ToSafeString());
            parms.Add(KeenConstants.QueryParmTimezone, timezone);
            parms.Add(KeenConstants.QueryParmFilters, filters == null ? "" : JArray.FromObject(filters).ToString());
            parms.Add(KeenConstants.QueryParmAnalyses, SerializeMultiAnalysisQueryParameter(analysisParams));

            var reply = await KeenWebApiRequest(KeenConstants.QueryMultiAnalysis, parms).ConfigureAwait(false);

            var result = new List <QueryIntervalValue <IDictionary <string, string> > >();

            foreach (JObject i in reply.Value <JArray>("result"))
            {
                var d = new Dictionary <string, string>();
                foreach (JProperty p in i.Value <JObject>("value").Values <JProperty>())
                {
                    d.Add(p.Name, (string)p.Value);
                }

                var t  = i.Value <JObject>("timeframe");
                var qv = new QueryIntervalValue <IDictionary <string, string> >(d, t.Value <DateTime>("start"), t.Value <DateTime>("end"));
                result.Add(qv);
            }

            return(result);
        }