当前位置: 首页>>代码示例>>C#>>正文


C# SortedSet.ElementAtOrDefault方法代码示例

本文整理汇总了C#中SortedSet.ElementAtOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# SortedSet.ElementAtOrDefault方法的具体用法?C# SortedSet.ElementAtOrDefault怎么用?C# SortedSet.ElementAtOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SortedSet的用法示例。


在下文中一共展示了SortedSet.ElementAtOrDefault方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RefreshUI


//.........这里部分代码省略.........
                    tdata.endTime = timerendTime;
                    ractivitydata.lastattempt = String.Format("{0:00}:{1:00}:{2:00}", (long)timerdata_TimeSpan.TotalSeconds / 3600, ((long)timerdata_TimeSpan.TotalSeconds / 60) % 60, (long)timerdata_TimeSpan.TotalSeconds % 60);
                    //lastTime.Text = ractivitydata.lastattempt;
                    ractivitydata.timer_data = new List<TimerData>();
                    ractivitydata.timer_data.Add(tdata);
                    ractivitydata.personal_best = String.Format("{0:00}:{1:00}:{2:00}", (long)timerdata_TimeSpan.TotalSeconds / 3600, ((long)timerdata_TimeSpan.TotalSeconds / 60) % 60, (long)timerdata_TimeSpan.TotalSeconds % 60);
                    ractivitydata.median = String.Format("{0:00}:{1:00}:{2:00}", (long)timerdata_TimeSpan.TotalSeconds / 3600, ((long)timerdata_TimeSpan.TotalSeconds / 60) % 60, (long)timerdata_TimeSpan.TotalSeconds % 60);
                    ractivitydata.ninetypercentile = String.Format("{0:00}:{1:00}:{2:00}", (long)timerdata_TimeSpan.TotalSeconds / 3600, ((long)timerdata_TimeSpan.TotalSeconds / 60) % 60, (long)timerdata_TimeSpan.TotalSeconds % 60);
                    rtrackact.activity = new List<ActivityData>();
                    rtrackact.activity.Add(ractivitydata);
                    personalBest.Text = ractivitydata.personal_best;
                    personalBestGrid.Opacity = 100;
                    MedianTextBlock.Text = ractivitydata.median;
                    NinetyPercentileTextBlock.Text = ractivitydata.ninetypercentile;
                    StatisticsGrid.Opacity = 100;
                    ApplicationData.Current.LocalSettings.Values["FirstLaunch"] = false;
                    activity_d.Add(ractivitydata);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("In Refresh UI FirstLaunch set to true : " + ex);
                }
            }
            else
            {

                int activity_pos = -1;
                for (int i = 0; i < rtrackact.activity.Count; i++)
                {
                    if (rtrackact.activity[i].name == activityName.Text)
                    {
                        activity_pos = i;
                    }
                    
                }
                if (activity_pos == -1)
                {
                    Debug.Write("In RefreshUI. Activity doesn't exist");
                    ActivityData ractivitydata = new ActivityData();
                    ractivitydata.name = activityName.Text;
                    ractivitydata.createdTime = DateTime.UtcNow;
                    ractivitydata.totalTime = 0;
                    TimerData tdata = new TimerData();
                    //tdata.position = 0;             // Since this is a new activity, it won't have any data already associated with it.
                    tdata.time_in_seconds = (long)timerdata_TimeSpan.TotalSeconds;
                    ractivitydata.lastattempt = String.Format("{0:00}:{1:00}:{2:00}", (long)timerdata_TimeSpan.TotalSeconds / 3600, ((long)timerdata_TimeSpan.TotalSeconds / 60) % 60, (long)timerdata_TimeSpan.TotalSeconds % 60);
                    ractivitydata.totalTime = ractivitydata.totalTime + tdata.time_in_seconds;
                    //lastTime.Text = ractivitydata.lastattempt;
                    tdata.startTime = timerstartTime;
                    tdata.endTime = timerendTime;
                    ractivitydata.timer_data = new List<TimerData>();
                    ractivitydata.timer_data.Add(tdata);
                    ractivitydata.personal_best = String.Format("{0:00}:{1:00}:{2:00}", (long)timerdata_TimeSpan.TotalSeconds / 3600, ((long)timerdata_TimeSpan.TotalSeconds / 60) % 60, (long)timerdata_TimeSpan.TotalSeconds % 60);
                    ractivitydata.median = String.Format("{0:00}:{1:00}:{2:00}", (long)timerdata_TimeSpan.TotalSeconds / 3600, ((long)timerdata_TimeSpan.TotalSeconds / 60) % 60, (long)timerdata_TimeSpan.TotalSeconds % 60);
                    ractivitydata.ninetypercentile = String.Format("{0:00}:{1:00}:{2:00}", (long)timerdata_TimeSpan.TotalSeconds / 3600, ((long)timerdata_TimeSpan.TotalSeconds / 60) % 60, (long)timerdata_TimeSpan.TotalSeconds % 60);
                    rtrackact.activity.Add(ractivitydata);
                    personalBest.Text = ractivitydata.personal_best;
                    personalBestGrid.Opacity = 100;
                    MedianTextBlock.Text = ractivitydata.median;
                    NinetyPercentileTextBlock.Text = ractivitydata.ninetypercentile;
                    StatisticsGrid.Opacity = 100;
                    
                }
                else
                {
                    TimerData tdata = new TimerData();
                    tdata.position = rtrackact.activity[activity_pos].timer_data[rtrackact.activity[activity_pos].timer_data.Count - 1].position + 1; // The mumbo jumbo is to get the value of 'position' in the last element in the track_data list and adding 1 to it.
                    tdata.startTime = timerstartTime;
                    tdata.endTime = timerendTime;
                    if (tdata.position >= countLimit)
                    {
                        rtrackact.activity[activity_pos].timer_data.RemoveAt(0);
                    }
                    tdata.time_in_seconds = (long)timerdata_TimeSpan.TotalSeconds;

                    SortedSet<long> time_in_seconds = new SortedSet<long>();
                    for (int i = 0; i < rtrackact.activity[activity_pos].timer_data.Count; i++)
                    {
                        time_in_seconds.Add(rtrackact.activity[activity_pos].timer_data[i].time_in_seconds);
                    }
                    time_in_seconds.Add((long)timerdata_TimeSpan.TotalSeconds);
                    long mediansec = (time_in_seconds.ElementAtOrDefault(time_in_seconds.Count / 2));//time_in_seconds[time_in_seconds.Count / 2];
                    rtrackact.activity[activity_pos].totalTime = rtrackact.activity[activity_pos].totalTime + tdata.time_in_seconds;
                    rtrackact.activity[activity_pos].median = String.Format("{0:00}:{1:00}:{2:00}", mediansec / 3600, (mediansec / 60) % 60, mediansec % 60);
                    rtrackact.activity[activity_pos].lastattempt = String.Format("{0:00}:{1:00}:{2:00}", (long)timerdata_TimeSpan.TotalSeconds / 3600, ((long)timerdata_TimeSpan.TotalSeconds / 60) % 60, (long)timerdata_TimeSpan.TotalSeconds % 60);
                   // lastTime.Text = rtrackact.activity[activity_pos].lastattempt;
                    int pos = (int)(0.9 * (time_in_seconds.Count - 1) + 1); // 0 1 3 4 5 8
                    long ninentypercentilesecond = (time_in_seconds.ElementAtOrDefault(pos));
                    rtrackact.activity[activity_pos].ninetypercentile = String.Format("{0:00}:{1:00}:{2:00}", ninentypercentilesecond / 3600, (ninentypercentilesecond / 60) % 60, ninentypercentilesecond % 60);
                    long personal_best = (time_in_seconds.ElementAtOrDefault(time_in_seconds.Count - 1));
                    rtrackact.activity[activity_pos].personal_best = String.Format("{0:00}:{1:00}:{2:00}", (personal_best) / 3600, ((personal_best) / 60) % 60, (personal_best) % 60);
                    rtrackact.activity[activity_pos].timer_data.Add(tdata);
                    personalBest.Text = rtrackact.activity[activity_pos].personal_best;
                    personalBestGrid.Opacity = 100;
                    MedianTextBlock.Text = rtrackact.activity[activity_pos].median;
                    NinetyPercentileTextBlock.Text = rtrackact.activity[activity_pos].ninetypercentile;
                    StatisticsGrid.Opacity = 100;
                }
            }
        }
开发者ID:agangal,项目名称:TrackMyAct,代码行数:101,代码来源:MainPage.xaml.cs

示例2: updateDB

        public async Task<bool> updateDB(string timerText, TimeSpan timerdata, string activityName)
        {
            bool res = await checkIfFileExists("activityDB");
            RootObjectTrackAct rtrackact = new RootObjectTrackAct();
            if (res)
            {
                string response = await readFile("activityDB");
                rtrackact = TrackAct.trackactDataDeserializer(response);
                int activity_pos = -1;
                for (int i = 0; i < rtrackact.activity.Count; i++)
                {
                    if (rtrackact.activity[i].name == activityName)
                    {
                        activity_pos = i;
                    }
                }
                /// If the activity exists 
                if (activity_pos != -1)
                {
                    TimerData tdata = new TimerData();
                    tdata.position = rtrackact.activity[activity_pos].timer_data[rtrackact.activity[activity_pos].timer_data.Count - 1].position + 1; // The mumbo jumbo is to get the value of 'position' in the last element in the track_data list and adding 1 to it.
                    if (tdata.position >= countLimit)
                    {
                        rtrackact.activity[activity_pos].timer_data.RemoveAt(0);
                    }
                    tdata.time_in_seconds = (long)timerdata.TotalSeconds;

                    SortedSet<long> time_in_seconds = new SortedSet<long>();
                    for (int i = 0; i < rtrackact.activity[activity_pos].timer_data.Count; i++)
                    {
                        time_in_seconds.Add(rtrackact.activity[activity_pos].timer_data[i].time_in_seconds);
                    }
                    time_in_seconds.Add((long)timerdata.TotalSeconds);
                    long mediansec = (time_in_seconds.ElementAtOrDefault(time_in_seconds.Count / 2)) ;//time_in_seconds[time_in_seconds.Count / 2];
                    rtrackact.activity[activity_pos].median = String.Format("{0:00}:{1:00}:{2:00}", mediansec / 3600, (mediansec / 60) % 60, mediansec % 60);
                    int pos = (int)(0.9 * (time_in_seconds.Count - 1) + 1); // 0 1 3 4 5 8
                    long ninentypercentilesecond = (time_in_seconds.ElementAtOrDefault(pos));
                    rtrackact.activity[activity_pos].ninetypercentile = String.Format("{0:00}:{1:00}:{2:00}", ninentypercentilesecond / 3600, (ninentypercentilesecond / 60) % 60, ninentypercentilesecond % 60);
                    long personal_best = (time_in_seconds.ElementAtOrDefault(time_in_seconds.Count - 1));
                    rtrackact.activity[activity_pos].personal_best = String.Format("{0:00}:{1:00}:{2:00}", (personal_best) / 3600, ((personal_best) / 60) % 60, (personal_best) % 60);
                    rtrackact.activity[activity_pos].timer_data.Add(tdata);
                    //findMedian(rtrackact.activity[activity_pos]);
                }
                /// If the activity does not exist
                else
                {
                    ActivityData ractivitydata = new ActivityData();
                    ractivitydata.name = activityName;
                    TimerData tdata = new TimerData();
                    tdata.position = 0;             // Since this is a new activity, it won't have any data already associated with it.
                    tdata.time_in_seconds = (long)timerdata.TotalSeconds;
                    ractivitydata.timer_data.Add(tdata);
                    ractivitydata.personal_best = String.Format("{0:00}:{1:00}:{2:00}", timerdata.Hours, (timerdata.Minutes), (long)timerdata.Seconds);
                    ractivitydata.median = String.Format("{0:00}:{1:00}:{2:00}", timerdata.Hours, timerdata.Minutes, (long)timerdata.Seconds);
                    ractivitydata.ninetypercentile = String.Format("{0:00}:{1:00}:{2:00}", timerdata.Hours, (timerdata.Minutes), (long)timerdata.Seconds);
                    rtrackact.activity.Add(ractivitydata);
                }
            }
            else
            {
                ActivityData ractivitydata = new ActivityData();
                ractivitydata.name = activityName;
                TimerData tdata = new TimerData();
                tdata.position = 0;             // Since this is a new activity, it won't have any data already associated with it.
                tdata.time_in_seconds = (long)timerdata.TotalSeconds;
                ractivitydata.timer_data = new List<TimerData>();
                ractivitydata.timer_data.Add(tdata);
                rtrackact.activity = new List<ActivityData>();
                ractivitydata.personal_best = String.Format("{0:00}:{1:00}:{2:00}", timerdata.Hours, (timerdata.Minutes), (long)timerdata.Seconds); 
                ractivitydata.median = String.Format("{0:00}:{1:00}:{2:00}", timerdata.Hours, (timerdata.Minutes), (long)timerdata.Seconds);
                ractivitydata.ninetypercentile = String.Format("{0:00}:{1:00}:{2:00}", timerdata.Hours, (timerdata.Minutes), (long)timerdata.Seconds);
                rtrackact.activity.Add(ractivitydata);
            }
            try
            {
                await writeFile("activityDB", TrackAct.trackactSerializer(rtrackact));
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            Debug.WriteLine("DB update finished at : " + DateTime.Now.Millisecond);
            return true;
        }
开发者ID:agangal,项目名称:TrackMyAct,代码行数:84,代码来源:Library.cs


注:本文中的SortedSet.ElementAtOrDefault方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。