public Charts() { this.InitializeComponent(); library = new Library(); this.Loaded += MainPage_Loaded; rtrackact = new RootObjectTrackAct(); }
public AllTheData() { this.InitializeComponent(); library = new Library(); activity = new ObservableCollection<ActivityData>(); tmdata = new ObservableCollection<TimerData>(); rtrackact = new RootObjectTrackAct(); }
private async void stuffToDoWhenNavigatedTo() { //activity_d = new ObservableCollection<ActivityData>(); bool res = await library.checkIfFileExists("activityDB"); rtrackact = new RootObjectTrackAct(); if (res) { //activityComboBox actiboxtemp = new activityComboBox(); string restring = await library.readFile("activityDB"); if (String.IsNullOrEmpty(restring)) { firstLaunch(); } else { activityName.Text = (string)ApplicationData.Current.LocalSettings.Values["CurrentAct"]; rtrackact = TrackAct.trackactDataDeserializer(restring); Debug.WriteLine("Not the first Launch"); 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) { StatisticsGrid.Opacity = 0; personalBestGrid.Opacity = 0; } else { MedianTextBlock.Text = rtrackact.activity[activity_pos].median; NinetyPercentileTextBlock.Text = rtrackact.activity[activity_pos].ninetypercentile; personalBest.Text = rtrackact.activity[activity_pos].personal_best; } } } else { firstLaunch(); } }
protected override async void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if(await library.checkIfFileExists("activityDB")) { string fileres = await library.readFile("activityDB"); rtrackact = TrackAct.trackactDataDeserializer(fileres); var activityD = rtrackact.activity; foreach(var actv in activityD) { activity.Add(actv); } var timedata = rtrackact.activity[0].timer_data; foreach(var tdata in timedata) { tmdata.Add(tdata); } } }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); rtrackact = (RootObjectTrackAct)e.Parameter; // progressRing.IsActive = true; }
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; }
public static string trackactSerializer(RootObjectTrackAct rtrackact) { string response = JsonConvert.SerializeObject(rtrackact); return response; }