コード例 #1
0
        public static int BitmapFromStringList(List <string> strList)
        { // Generate bitmap from string list
          //AppDebug.Line("MedicalEnum isStrNull = " + (strList == null).ToString());

            List <MedicalEnum> enumList = new List <MedicalEnum>(strList.Count);
            //AppDebug.Line("Created List<MedicalEnum>");

            int bitmap = 0;

            foreach (string s in strList)
            {
                try
                {
                    //AppDebug.Line($"Trying to parse '{s}'");
                    Enum.TryParse(s.ToUpper().Replace(' ', '_'), out MedicalEnum val);

                    bitmap |= 1 << (((int)val) - 1);
                }
                catch
                {
                    AppDebug.Line($"Failed FromStringList:\nValue '{s}' unknown");
                }
            }

            return(bitmap);
        }
コード例 #2
0
        private void AutoSuggestBox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
        {
            if (isStrainListFull == false)
            {
                return;
            }

            var item = args.ChosenSuggestion;

            if (item != null)
            {
                var itemString = item.ToString();

                if (itemString != NoResult)
                {
                    ErrorNoStrainChosen.Visibility = Visibility.Collapsed;

                    AppDebug.Line($"AutoSuggestBox_QuerySubmitted [{item}]");

                    sender.Text  = itemString;
                    StrainChosen = itemString;
                }
                else
                {
                    sender.Text = "";
                }
            }
        }
コード例 #3
0
        private async void LoadStrainList(object sender, object e)
        {
            if (StrainsNamesList == null)
            {
                progressRing.IsActive = true;
                await Task.Run(async() =>
                {
                    AppDebug.Line("Loading strain list..");
                    try
                    { // Get strain list from DB
                        var res = await HttpManager.Manager.Get(Constants.MakeUrl("strains/all/"));

                        if (res == null)
                        {
                            throw new Exception("Get operation failed, response is null");
                        }

                        StrainsDict = HttpManager.ParseJson <Dictionary <string, string> >(res); // Parse JSON to dictionary

                        StrainsNamesList = StrainsDict.Keys.ToList();                            // Keys - strain names
                        StrainsNamesList.Sort();
                        isStrainListFull = true;

                        AppDebug.Line($"loaded {StrainsNamesList.Count} strains");
                    }
                    catch (Exception exc)
                    {
                        AppDebug.Exception(exc, "LoadStrainList");
                        await new MessageDialog($"Strain list loading operation failed. Please try again or use suggested strain option.", "Error").ShowAsync();
                    }
                });

                progressRing.IsActive = false;
            }
        }
コード例 #4
0
        public void OnPageLoaded(object sender, RoutedEventArgs e) // Import doctors list into objects
        {
            string[] data;
            AppDebug.Line("Loading doctors list..");
            try
            {
                doctors = File.ReadAllLines("Assets/doctors.txt") // Read into dictionary, doctor name as key
                          .Select(a => a.Split(' '))
                          .ToDictionary(x => x[0].Replace('-', ' ').Replace('_', ' '),
                                        x => x[1].Replace('-', ' '));

                doctorNames = doctors.Keys.ToList();
                foreach (string val in doctors.Values)
                {
                    data = val.Split('_'); // Split into city and medical center
                    if (!medicalCenters.Contains(data[0].Replace('-', ' ')))
                    {
                        medicalCenters.Add(data[0].Replace('-', ' '));
                    }
                    if (!cities.Contains(data[1].Replace('-', ' ')))
                    {
                        cities.Add(data[1].Replace('-', ' '));
                    }
                }

                AppDebug.Line($"loaded {doctorNames.Count} doctors");
            }
            catch (Exception exc)
            {
                AppDebug.Exception(exc, "LoadDoctorsList");
            }
        }
コード例 #5
0
        private async void SearchStrain(object sender, RoutedEventArgs e)
        {
            // Get checked effects
            PagesUtilities.GetAllCheckBoxesTags(MedicalSearchGrid, out List <int> MedicalList);
            PagesUtilities.GetAllCheckBoxesTags(PositiveSearchGrid, out List <int> PositiveList);

            // Produce bitmap of effects
            int MedicalBitMap  = StrainToInt.FromIntListToBitmap(MedicalList);
            int PositiveBitMap = StrainToInt.FromIntListToBitmap(PositiveList);
            var url            = "";

            if ((MedicalList.Count == 0) && (PositiveList.Count == 0) && ((StrainName.Text == "") || (StrainName.Text == "e.g. 'Alaska'")))
            { // Nothing chosen
                Status.Text = "Invaild Search! Please enter search parameter";
            }
            else
            {
                Status.Text = "";

                if ((StrainName.Text != "") && (StrainName.Text != "e.g. 'Alaska'"))
                { // Search by strain name
                    url = Constants.MakeUrl("strain/name/" + StrainName.Text);
                    GlobalContext.searchType = 1;
                }
                else
                { // Search by effect
                    url = Constants.MakeUrl($"strain/effects?medical={MedicalBitMap}&positive={PositiveBitMap}");
                    GlobalContext.searchType = 2;
                }
                try
                { // Build request for information
                    var res = HttpManager.Manager.Get(url);

                    if (res == null)
                    {
                        return;
                    }

                    var str = await res.Result.Content.ReadAsStringAsync();

                    AppDebug.Line(str);
                    if (GlobalContext.searchType == 1)
                    {
                        Frame.Navigate(typeof(StrainSearchResults), str);                                // Search by name
                    }
                    else if (GlobalContext.searchType == 2)
                    { // Search by effect
                        GlobalContext.searchResult = str;
                        Frame.Navigate(typeof(EffectsSearchResults));
                    }
                }
                catch (Exception ex)
                {
                    AppDebug.Exception(ex, "SearchStrain");
                    await new MessageDialog("Failed get: \n" + url, "Exception in Search Strain").ShowAsync();
                }
            }
        }
コード例 #6
0
        private void UsageSelected(object sender, ItemClickEventArgs e)
        { // Select usage to view details on
            ListView  lst = sender as ListView;
            UsageData u   = e.ClickedItem as UsageData;

            AppDebug.Line($"Selected usage on [{u.StartTimeString}]");
            UsageContext.DisplayUsage = u;
            Frame.Navigate(typeof(UsageDisplay));
        }
コード例 #7
0
        public static List <MedicalEnum> FromIntList(List <int> intList)
        { // Generate enum list from int list
            List <MedicalEnum> enumList = new List <MedicalEnum>(intList.Count);

            foreach (int i in intList)
            {
                MedicalEnum m = ((MedicalEnum)i);
                enumList.Add(m);
                AppDebug.Line(m.GetType().GetMember(m.ToString()));//.First().GetCustomAttributes<TAttribute>();
            }

            return(enumList);
        }
コード例 #8
0
        private void AutoSuggestBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
        {
            var item = args.SelectedItem.ToString();

            if (item != NoResult)
            {
                AppDebug.Line($"AutoSuggestBox_SuggestionChosen [{item}]");

                sender.Text = item;
            }
            else
            {
                sender.Text = "";
            }
        }
コード例 #9
0
 private void ListView_RightTapped(object sender, RightTappedRoutedEventArgs e)
 {
     try
     { // Open right click menu
         ListView lst = sender as ListView;
         selectedUsage = ((FrameworkElement)e.OriginalSource).DataContext as UsageData;
         if (selectedUsage != null)
         {
             UsageMenu.ShowAt(lst, e.GetPosition(lst));
             AppDebug.Line($"Right click usage on [{selectedUsage.StartTimeString}]");
         }
     }
     catch (Exception x)
     {
         AppDebug.Exception(x, "ListView_RightTapped");
     }
 }
コード例 #10
0
        private async Task SubmitStringTask()
        {
            await Task.Run(async() =>
            { // Submit chosen strain
                AppDebug.Line("Submit string: " + StrainChosen);
                try
                {
                    if (!StrainsDict.ContainsKey(StrainChosen))
                    {
                        AppDebug.Line($"Strain '{StrainChosen}' not found in list");
                    }
                    else
                    {
                        var strainId = StrainsDict[StrainChosen];
                        AppDebug.Line($"Strain: [{StrainChosen}], ID: {strainId}");

                        // Get strain properties
                        var res = await HttpManager.Manager.Get(Constants.MakeUrl("/strain/id/" + strainId));

                        if (res == null)
                        {
                            return;
                        }

                        UsageContext.ChosenStrain = HttpManager.ParseJson <Strain>(res); // Parse Json to strain

                        /*
                         * UsageContext.ChosenStrain = new Strain(StrainChosen, int.Parse(strainId))
                         * {
                         *  BitmapMedicalNeeds = MedicalEnumMethods.BitmapFromStringList(values["medical"].ToList()),
                         *  BitmapPositivePreferences = PositivePreferencesEnumMethods.BitmapFromStringList(values["positive"].ToList()),
                         *  BitmapNegativePreferences = NegativePreferencesEnumMethods.BitmapFromStringList(values["negative"].ToList())
                         * };*/


                        AppDebug.Line("Finished submit");
                    }
                }
                catch (Exception exc)
                {
                    AppDebug.Exception(exc, "SubmitString");
                    progressRing.IsActive = false;
                }
            });
        }
コード例 #11
0
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     base.OnNavigatedTo(e);
     if (GlobalContext.searchType == 1) // Searched by strain
     {
         var req = (string)e.Parameter;
         searchByStrain(req);
     }
     else if (GlobalContext.searchType == 2) // Navigated from effect search
     {
         var req = (Strain)e.Parameter;
         searchFromEffects(req);
     }
     else
     {
         AppDebug.Line("Invalid navigation!");
     }
 }
コード例 #12
0
        public static List <PositivePreferencesEnum> FromStringList(List <string> strList)
        {
            List <PositivePreferencesEnum> enumList = new List <PositivePreferencesEnum>(strList.Count);

            foreach (string s in strList)
            {
                try
                {
                    Enum.TryParse(s, out PositivePreferencesEnum val);
                    enumList.Add(val);
                }
                catch
                {
                    AppDebug.Line($"Failed FromStringList:\nValue '{s}' unknown");
                }
            }

            return(enumList);
        }
コード例 #13
0
        private async void EndSessionAsync(object sender, RoutedEventArgs e)
        {
            try
            {
                var yesCommand = new UICommand("End Session", cmd =>
                {
                    AppDebug.Line("ending session...");
                    progressRing.IsActive = true;
                    try
                    {
                        if (UsageContext.Usage.UseBandData)
                        { // Stop band usage
                            GlobalContext.Band.StopHeartRate();
                            PagesUtilities.SleepSeconds(0.5);
                        }
                        UsageContext.Usage.EndUsage();
                    }
                    catch (Exception x)
                    {
                        AppDebug.Exception(x, "EndSession");
                    }
                    progressRing.IsActive = false;
                    Frame.Navigate(typeof(PostTreatment));
                });
                var noCommand = new UICommand("Continue Session", cmd =>
                {
                    AppDebug.Line("Cancel end session");
                });
                var dialog = new MessageDialog("Are you sure you want to end the session", "End Session")
                {
                    Options = MessageDialogOptions.None
                };
                dialog.Commands.Add(yesCommand);
                dialog.Commands.Add(noCommand);

                await dialog.ShowAsync();
            }
            catch (Exception x)
            {
                AppDebug.Exception(x, "Remove_Click");
            }
        }
コード例 #14
0
        private async void OnPageLoaded(object sender, RoutedEventArgs e)
        {
            progressRing.IsActive = true;

            do
            {
                if (GlobalContext.CurrentUser == null)
                {
                    AppDebug.Line("GlobalContext.CurrentUser == null");
                    break;
                }

                // Update usage history
                await Task.Run(() => GlobalContext.UpdateUsagesContextIfEmptyAsync());

                if (GlobalContext.CurrentUser.UsageSessions == null)
                { // No usages
                    AppDebug.Line("GlobalContext.CurrentUser.UsageSessions == null");
                    break;
                }
                if (GlobalContext.CurrentUser.UsageSessions.Count == 0)
                { // No usages
                    UsageListGui.Visibility  = Visibility.Collapsed;
                    NoUsageButton.Visibility = Visibility.Visible;
                    AppDebug.Line("GlobalContext.CurrentUser.UsageSessions.Count == 0");
                    break;
                }

                foreach (var usage in GlobalContext.CurrentUser.UsageSessions)
                {
                    if (usage == null)
                    {
                        AppDebug.Line("usage == null");
                        continue;
                    }
                    // Add usage to usage list displayed
                    UsageListGui.Items.Add(usage);
                }
            } while (false);
            progressRing.IsActive = false;
        }
コード例 #15
0
        private async void Remove_Click(object sender, RoutedEventArgs e)
        { // Remove usage from history
            AppDebug.Line($"Remove usage on [{selectedUsage.StartTimeString}]");
            try
            {
                var yesCommand = new UICommand("Remove", async cmd =>
                {
                    AppDebug.Line("removing...");
                    var b = await GlobalContext.CurrentUser.RemoveUsage(selectedUsage);
                    if (!b)
                    {
                        await new MessageDialog("There was an error while deleting the usage from the server.", "Error").ShowAsync();
                    }
                    else
                    {
                        await new MessageDialog("Usage removed successfuly.", "Success").ShowAsync();
                    }
                    Frame.Navigate(typeof(UsageHistory));
                });
                var noCommand = new UICommand("Cancel", cmd =>
                {
                    AppDebug.Line("Cancel remove");
                });
                var dialog = new MessageDialog("Are you sure you want to remove the usage from the history?", "Remove Usage")
                {
                    Options = MessageDialogOptions.None
                };
                dialog.Commands.Add(yesCommand);
                dialog.Commands.Add(noCommand);

                await dialog.ShowAsync();
            }
            catch (Exception x)
            {
                AppDebug.Exception(x, "Remove_Click");
            }
        }
コード例 #16
0
        public static List <MedicalEnum> FromStringList(List <string> strList)
        { // Generate enum list from string list
            AppDebug.Line("MedicalEnum isStrNull = " + (strList == null).ToString());

            List <MedicalEnum> enumList = new List <MedicalEnum>(strList.Count);

            AppDebug.Line("Created List<MedicalEnum>");

            foreach (string s in strList)
            {
                try
                { // Try to get number from string
                    AppDebug.Line($"Trying to parse '{s}'");
                    Enum.TryParse(s, out MedicalEnum val);
                    enumList.Add(val);
                }
                catch
                {
                    AppDebug.Line($"Failed FromStringList:\nValue '{s}' unknown");
                }
            }

            return(enumList);
        }
コード例 #17
0
        private async void OnPageLoaded(object sender, RoutedEventArgs e)
        {
            progressRing.IsActive     = true;
            UsageContext.ChosenStrain = null;
            if (GlobalContext.CurrentUser != null)
            { // Get recommended strains for user from server
                Message.Text = "Searching for matching strains based on your profile...";

                var user_id = GlobalContext.CurrentUser.Data.UserID;
                var url     = Constants.MakeUrl($"strains/recommended/{user_id}/"); // Build url for user

                try
                { // Send request to server
                    var res = await HttpManager.Manager.Get(url);

                    if (res == null)
                    {
                        progressRing.IsActive = false;
                        return;
                    }
                    // Successful request
                    PagesUtilities.SleepSeconds(0.2);

                    // Recommended strain list
                    strains = await Task.Run(() => HttpManager.ParseJson <SuggestedStrains>(res)); // Parsing JSON

                    if (strains.SuggestedStrainList.Count == 0)
                    {
                        ErrorNoStrainFound.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        switch (strains.Status)
                        {       // Status for match type
                        case 0: // Full match
                            Message.Text = $"Showing {strains.SuggestedStrainList.Count} exactly matched strains:";
                            break;

                        case 1:     // Partial match - medical match but positive dont
                            Message.Text = $"No exact matches found!\nTry updating your positive preferences.\nShowing {strains.SuggestedStrainList.Count} partially matching strains:";
                            break;

                        case 2:     // Partial match - medical and positive don't match
                            Message.Text = $"No exact matches found!\nTry updating your positive and medical preferences.\nShowing {strains.SuggestedStrainList.Count} partially matching strains:";
                            break;
                        }
                        Scroller.Height = Stack.ActualHeight - Message.ActualHeight - 20;

                        Random rnd = new Random();

                        foreach (var strain in strains.SuggestedStrainList)
                        { // **Random numbers**
                            strain.Rank           = rnd.Next(1, 100);
                            strain.NumberOfUsages = rnd.Next(0, 1000);
                        }

                        if (strains.Status != 0)
                        { // Calculate partal match rate
                            foreach (var strain in strains.SuggestedStrainList)
                            {
                                strain.MatchingPercent = strain / GlobalContext.CurrentUser;
                            }

                            strains.SuggestedStrainList.Sort(Strain.MatchComparison);
                            matchSortedStrains = new SuggestedStrains(strains.Status, new List <Strain>(strains.SuggestedStrainList));;
                        }

                        var names = $"[{string.Join(", ", from u in strains.SuggestedStrainList select $"{u.Name}")}]";
                        AppDebug.Line($"Status={strains.Status} Got {strains.SuggestedStrainList.Count} strains: {names}");

                        FillStrainList(strains);

                        foreach (var child in ButtonsGrid.Children)
                        { // Display buttons to choose strains
                            if (child.GetType() == typeof(Viewbox))
                            {
                                var b = (child as Viewbox).Child as RadioButton;
                                if (!((string)b.Tag == "match" && strains.Status == 0))
                                {
                                    b.IsEnabled = true;
                                }
                            }
                        }
                        ButtonsGrid.Opacity = 1;
                        //StrainList.Height = Scroller.ActualHeight;
                    }
                }
                catch (Exception x)
                {
                    AppDebug.Exception(x, "OnPageLoaded");
                    await new MessageDialog("Error while getting suggestions from the server", "Error").ShowAsync();
                }

                progressRing.IsActive = false;
            }
        }