示例#1
0
        public static void Main(string[] args)
        {
            StatXClient statxClient = new StatXClient();

            Configuration configuration = statxClient.getConfiguration();

            Console.WriteLine("Enter Stat Title");

            string statTitle = Console.ReadLine();

            string    groupName = "StatX-API-Examples";
            GroupsApi groupsApi = new GroupsApi(configuration);
            GroupList groupList = groupsApi.GetGroups(groupName);
            Group     group;

            if ((groupList == null) || (groupList.Data == null) || (groupList.Data.Count == 0))
            {
                // The group does not exist. Let's create one. Since we are creating the group
                // the api will add the current user as a member and admin of the group.
                group = new Group(null, groupName, null);
                group = groupsApi.CreateGroup(group);
            }
            else
            {
                // Pick the first group (should be the only one).
                group = groupList.Data[0];
            }

            // Find the stat by name. If the stat does not exist then create it.
            //
            // Note: The stat title is not unique. In general it is not a good idea to use
            // the stat title as a key to determine whether the stat exists or not. If possible
            // use the statid instead.
            StatsApi statsApi = new StatsApi(configuration);
            StatList statList = statsApi.GetStats(group.Name, statTitle);

            if ((statList == null) || (statList.Data == null) || (statList.Data.Count == 0))
            {
                // The stat does not exist. Let's create a number stat.
                HorizontalBarStat horizontalBar = new HorizontalBarStat();
                horizontalBar.Title      = statTitle;
                horizontalBar.VisualType = Stat.VisualTypeEnum.HorizontalBars;
                horizontalBar.Items      = getStockInfo();
                statsApi.CreateStat(group.Id, horizontalBar);
            }
            else
            {
                // Pick the first stat (should be the only one) and get the statId from it.
                string            statId            = statList.Data[0].Id;
                HorizontalBarStat horizontalBarStat = (HorizontalBarStat)statList.Data[0];

                // Create the stat to update.
                HorizontalBarStat newHorizontalBardStat = new HorizontalBarStat();
                newHorizontalBardStat.Items = getStockInfo();
                newHorizontalBardStat.LastUpdatedDateTime = DateTime.Now;
                statsApi.UpdateStat(group.Id, statId, newHorizontalBardStat);
            }

            Console.WriteLine("Last update at: " + DateTime.Now);
        }
示例#2
0
        public static void Main(string[] args)
        {
            StatXClient statxClient = new StatXClient();

            Configuration configuration = statxClient.getConfiguration();

            Console.WriteLine("Enter Target Date in mm/dd/yyy format:");

            string targetDate = Console.ReadLine();

            Console.WriteLine("Enter Stat Title");

            string statTitle = Console.ReadLine();


            // Repeat once every 24 hours (see parameter below).
            while (true)
            {
                string    groupName = "StatX-API-Examples";
                GroupsApi groupsApi = new GroupsApi(configuration);
                GroupList groupList = groupsApi.GetGroups(groupName);
                Group     group;
                if ((groupList == null) || (groupList.Data == null) || (groupList.Data.Count == 0))
                {
                    // The group does not exist. Let's create one. Since we are creating the group
                    // the api will add the current user as a member and admin of the group.
                    group = new Group(null, groupName, null);
                    group = groupsApi.CreateGroup(group);
                }
                else
                {
                    // Pick the first group (should be the only one).
                    group = groupList.Data[0];
                }


                // Find the stat by name. If the stat does not exist then create it.
                //
                // Note: The stat title is not unique. In general it is not a good idea to use
                // the stat title as a key to determine whether the stat exists or not. If possible
                // use the statid instead.
                StatsApi statsApi = new StatsApi(configuration);
                StatList statList = statsApi.GetStats(group.Name, statTitle);
                if ((statList == null) || (statList.Data == null) || (statList.Data.Count == 0))
                {
                    // The stat does not exist. Let's create a number stat.
                    NumberStat numberStat = new NumberStat();
                    numberStat.Title      = statTitle;
                    numberStat.VisualType = Stat.VisualTypeEnum.Number;
                    numberStat.Value      = getRemainingDays(targetDate);
                    statsApi.CreateStat(group.Id, numberStat);
                }
                else
                {
                    // Pick the first stat (should be the only one) and get the statId from it.
                    string statId = statList.Data[0].Id;

                    // Create the stat to update.
                    NumberStat numberStat = new NumberStat();
                    numberStat.Value = getRemainingDays(targetDate);
                    numberStat.LastUpdatedDateTime = DateTime.Now;
                    statsApi.UpdateStat(group.Id, statId, numberStat);
                }

                Console.WriteLine("Last update at: " + DateTime.Now);

                System.Threading.Thread.Sleep(TimeSpan.FromDays(1));
            }
        }