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 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).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); }
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); }
public async Task <IEnumerable <QueryIntervalValue <string> > > Metric(QueryType queryType, string collection, string targetProperty, IQueryTimeframe timeframe, QueryInterval interval, IEnumerable <QueryFilter> filters = null, string timezone = "") { if (queryType == null) { throw new ArgumentNullException("queryType"); } if (string.IsNullOrWhiteSpace(collection)) { throw new ArgumentNullException("collection"); } if (string.IsNullOrWhiteSpace(targetProperty) && (queryType != QueryType.Count())) { throw new ArgumentNullException("targetProperty"); } if (null == timeframe) { throw new ArgumentException("timeframe", "Timeframe must be specified for a series query."); } if (null == interval) { throw new ArgumentNullException("interval", "interval must be specified for a series query"); } var parms = new Dictionary <string, string>(); parms.Add(KeenConstants.QueryParmEventCollection, collection); parms.Add(KeenConstants.QueryParmTargetProperty, targetProperty); 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()); var reply = await KeenWebApiRequest(queryType.ToString(), parms).ConfigureAwait(false); IEnumerable <QueryIntervalValue <string> > result; if (queryType == QueryType.SelectUnique()) { // This is to support SelectUnique which is the only query type with a list-type result. result = from i in reply.Value <JArray>("result") let v = string.Join(",", i.Value <JArray>("value").Values <string>()) let t = i.Value <JObject>("timeframe") select new QueryIntervalValue <string>(v, t.Value <DateTime>("start"), t.Value <DateTime>("end")); } else { result = from i in reply.Value <JArray>("result") let v = i.Value <string>("value") let t = i.Value <JObject>("timeframe") select new QueryIntervalValue <string>(v, t.Value <DateTime>("start"), t.Value <DateTime>("end")); } return(result); }
public async Task <IEnumerable <dynamic> > Extract(string collection, IQueryTimeframe timeframe = null, IEnumerable <QueryFilter> filters = null, int latest = 0, string email = "") { var parms = new Dictionary <string, string>(); parms.Add(KeenConstants.QueryParmEventCollection, collection); parms.Add(KeenConstants.QueryParmTimeframe, timeframe.ToSafeString()); parms.Add(KeenConstants.QueryParmFilters, filters == null ? "" : JArray.FromObject(filters).ToString()); parms.Add(KeenConstants.QueryParmEmail, email); parms.Add(KeenConstants.QueryParmLatest, latest > 0 ? latest.ToString() : ""); var reply = await KeenWebApiRequest(KeenConstants.QueryExtraction, parms).ConfigureAwait(false); return(from i in reply.Value <JArray>("result") select(dynamic) i); }
public async Task <IEnumerable <QueryGroupValue <string> > > Metric(QueryType queryType, string collection, string targetProperty, string groupby, IQueryTimeframe timeframe = null, IEnumerable <QueryFilter> filters = null, string timezone = "") { if (queryType == null) { throw new ArgumentNullException("queryType"); } if (string.IsNullOrWhiteSpace(collection)) { throw new ArgumentNullException("collection"); } if (string.IsNullOrWhiteSpace(targetProperty) && (queryType != QueryType.Count())) { throw new ArgumentNullException("targetProperty"); } if (string.IsNullOrWhiteSpace(groupby)) { throw new ArgumentNullException("groupby", "groupby field name must be specified for a groupby query"); } var parms = new Dictionary <string, string>(); parms.Add(KeenConstants.QueryParmEventCollection, collection); parms.Add(KeenConstants.QueryParmTargetProperty, targetProperty); parms.Add(KeenConstants.QueryParmGroupBy, groupby); parms.Add(KeenConstants.QueryParmTimeframe, timeframe.ToSafeString()); parms.Add(KeenConstants.QueryParmTimezone, timezone); parms.Add(KeenConstants.QueryParmFilters, filters == null ? "" : JArray.FromObject(filters).ToString()); var reply = await KeenWebApiRequest(queryType.ToString(), parms).ConfigureAwait(false); IEnumerable <QueryGroupValue <string> > result; if (queryType == QueryType.SelectUnique()) { // This is to support SelectUnique which is the only query type with a list-type result. result = from r in reply.Value <JArray>("result") let c = string.Join(",", r.Value <JArray>("result").Values <string>()) let g = r.Value <string>(groupby) select new QueryGroupValue <string>(c, g); } else { result = from r in reply.Value <JArray>("result") let c = r.Value <string>("result") let g = r.Value <string>(groupby) select new QueryGroupValue <string>(c, g); } return(result); }
public async Task <IDictionary <string, string> > MultiAnalysis(string collection, IEnumerable <MultiAnalysisParam> analysisParams, IQueryTimeframe timeframe = 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.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 Dictionary <string, string>(); foreach (JProperty i in reply.Value <JObject>("result").Children()) { result.Add(i.Name, (string)i.Value); } return(result); }
public async Task <IEnumerable <QueryGroupValue <IDictionary <string, string> > > > MultiAnalysis(string collection, IEnumerable <MultiAnalysisParam> analysisParams, IQueryTimeframe timeframe = null, IEnumerable <QueryFilter> filters = null, string groupby = "", string timezone = "") { var parms = new Dictionary <string, string>(); parms.Add(KeenConstants.QueryParmEventCollection, collection); parms.Add(KeenConstants.QueryParmTimeframe, timeframe.ToSafeString()); parms.Add(KeenConstants.QueryParmTimezone, timezone); parms.Add(KeenConstants.QueryParmFilters, filters == null ? "" : JArray.FromObject(filters).ToString()); parms.Add(KeenConstants.QueryParmGroupBy, groupby); parms.Add(KeenConstants.QueryParmAnalyses, SerializeMultiAnalysisQueryParameter(analysisParams)); var reply = await KeenWebApiRequest(KeenConstants.QueryMultiAnalysis, parms).ConfigureAwait(false); var result = new List <QueryGroupValue <IDictionary <string, string> > >(); foreach (JObject i in reply.Value <JArray>("result")) { var d = new Dictionary <string, string>(); string grpVal = ""; foreach (JProperty p in i.Values <JProperty>()) { if (p.Name == groupby) { grpVal = (string)p.Value; } else { d.Add(p.Name, (string)p.Value); } } var qg = new QueryGroupValue <IDictionary <string, string> >(d, grpVal); result.Add(qg); } return(result); }