/**
         * Returns a new object whose values are the values in this array, and whose
         * names are the values in {@code names}. Names and values are paired up by
         * index from 0 through to the shorter array's length. Names that are not
         * strings will be coerced to strings. This method returns null if either
         * array is empty.
         */
        public JsonObject ToJSONObject(JsonArray names)
        {
            JsonObject result = new JsonObject();
            int        length = Math.Min(names.Length(), values.Count);

            if (length == 0)
            {
                return(null);
            }
            for (int i = 0; i < length; i++)
            {
                String name = Json.ToString(names.Opt(i));
                result.Put(name, Opt(i));
            }
            return(result);
        }
Beispiel #2
0
        /**
         * Returns an array with the values corresponding to {@code names}. The
         * array contains null for names that aren't mapped. This method returns
         * null if {@code names} is either null or empty.
         */
        public JsonArray ToJSONArray(JsonArray names)
        {
            JsonArray result = new JsonArray();

            if (names == null)
            {
                return(null);
            }
            int length = names.Length();

            if (length == 0)
            {
                return(null);
            }
            for (int i = 0; i < length; i++)
            {
                string name = Json.ToString(names.Opt(i));
                result.Put(Opt(name));
            }
            return(result);
        }
    void FetchAvgDeathTime()
    {
        if (GameConfig.ANALYTICS_RULE_ID == 0)
        {
            Debug.Log("See Assets/Readme.txt for instructions on how to replace the rule ID and use analytics");
            return;
        }
        Debug.Log("Getting analytics snapshots");

        // Define filters
        ResultCondition condition = new ResultCondition();

        //condition.AddFilter("AppVersion", "9");
        //condition.AddFilter("location", "UK");
        //condition.GroupingKey = "gender";
        //condition.GroupingKey = "UserLevel";
        condition.DateRange = new DateRange(new DateTime(2014, 2, 2), DateTime.Now);

        try
        {               // My id is 147, but the ID must match the analytic rule you should create on developer.kii.com this way:
                        // Go to developer.kii.com, go to your app's console
                        // Click on Analytics on the left side bar, then lick on "Create a new rule"
                        // Name your rule AvgDeathTime or whichever name you like, select "Event Data"
                        // In the function dropdown select "Avg" and in the field enter the word "time"
                        // In the type combo select "float"
                        // In the dimensions fields enter "time", "time" and "float"
                        // Click on Save and activate the rule
                        // Once active copy the ID assigned to the rule and replace the 147 below with that

            KiiAnalytics.GetResult(GameConfig.ANALYTICS_RULE_ID.ToString(), condition, (string ruleId, ResultCondition condition2, GroupedResult result2, Exception e) => {
                if (e == null)
                {
                    Debug.Log("Analytics event upload successful");
                    IList <GroupedSnapShot> snapshots = result2.SnapShots;
                    Debug.Log("Cycling through analytics snapshots");
                    foreach (GroupedSnapShot snapshot in snapshots)
                    {
                        Debug.Log("Found a snapshot: " + snapshot.Data);
                        JsonOrg.JsonArray array = snapshot.Data;
                        int j          = 0;
                        Score.avgDeath = 0;
                        for (int i = array.Length(); i > 0; i--)
                        {
                            if (array.Get(i - 1).GetType() == typeof(JsonOrg.JsonNull))
                            {
                                j++;
                            }
                            else
                            {
                                Score.avgDeath += (float)array.GetDouble(i - 1);
                            }
                        }
                        Score.avgDeath /= (array.Length() - j);
                    }
                }
                else
                {
                    Debug.Log("Analytics snapshot fetch error: " + e.ToString());
                }
            });
        }
        catch (Exception e)
        {
            Debug.Log("Analytics snapshot fetch error: " + e.ToString());
        }
    }