private void AddRole_Click(object sender, RoutedEventArgs e)
        {
            Dictionary <string, UserInputWindow.Input> input = new Dictionary <string, UserInputWindow.Input>();

            input["name"] = new UserInputWindow.Input()
            {
                Label = "Name", DefaultValue = ""
            };
            input["hasStreams"] = new UserInputWindow.Input()
            {
                Label = "Has streams", DefaultValue = "true"
            };
            UserInputWindow dialog = new UserInputWindow("Add new role", input);

            dialog.ShowDialog();
            if (dialog.DialogResult == true)
            {
                string name       = dialog.Result("name");
                bool   hasStreams = true;
                bool.TryParse(dialog.Result("hasStreams"), out hasStreams);
                DatabaseRole role = new DatabaseRole()
                {
                    Name = name, HasStreams = hasStreams
                };
                if (DatabaseHandler.AddRole(role))
                {
                    GetRoles(dialog.Result("name"));
                }
            }
        }
示例#2
0
        private void exportToGenie_Click(object sender, RoutedEventArgs e)
        {
            Dictionary <string, UserInputWindow.Input> input = new Dictionary <string, UserInputWindow.Input>();

            input["separator"] = new UserInputWindow.Input()
            {
                Label = "File seperator", DefaultValue = ";"
            };
            input["sr"] = new UserInputWindow.Input()
            {
                Label = "Sample rate", DefaultValue = "100"
            };
            input["label"] = new UserInputWindow.Input()
            {
                Label = "Label of rest class", DefaultValue = "REST"
            };
            UserInputWindow dialog = new UserInputWindow("Export frame-wise annotation", input);

            dialog.ShowDialog();

            if (dialog.DialogResult == true)
            {
                int sr;
                if (Int32.TryParse(dialog.Result("sr"), out sr))
                {
                    ExportFrameWiseAnnotations(sr, dialog.Result("separator"), dialog.Result("label"));
                }
            }
        }
        private void CopySession_Click(object sender, RoutedEventArgs e)
        {
            if (SessionsBox.SelectedItem != null)
            {
                DatabaseSession session = (DatabaseSession)SessionsBox.SelectedItem;

                Dictionary <string, UserInputWindow.Input> input = new Dictionary <string, UserInputWindow.Input>();
                input["names"] = new UserInputWindow.Input()
                {
                    Label = "Name", DefaultValue = session.Name
                };
                UserInputWindow dialog = new UserInputWindow("Enter new name (if several separate by ';')", input);
                dialog.ShowDialog();
                if (dialog.DialogResult == true)
                {
                    string   names  = dialog.Result("names");
                    string[] tokens = names.Split(';');
                    foreach (string token in tokens)
                    {
                        DatabaseSession newSession = new DatabaseSession()
                        {
                            Name     = token,
                            Date     = session.Date,
                            Language = session.Language,
                            Location = session.Location
                        };
                        DatabaseHandler.AddSession(newSession);
                    }

                    GetSessions(session.Name);
                }
            }
        }
        private void EditStream_Click(object sender, RoutedEventArgs e)
        {
            if (StreamsBox.SelectedItem != null)
            {
                string         name   = (string)StreamsBox.SelectedItem;
                DatabaseStream stream = new DatabaseStream()
                {
                    Name = name
                };
                if (DatabaseHandler.GetStream(ref stream))
                {
                    Dictionary <string, UserInputWindow.Input> input = new Dictionary <string, UserInputWindow.Input>();
                    input["name"] = new UserInputWindow.Input()
                    {
                        Label = "Name", DefaultValue = stream.Name
                    };
                    input["fileExt"] = new UserInputWindow.Input()
                    {
                        Label = "File extension", DefaultValue = stream.FileExt
                    };
                    input["type"] = new UserInputWindow.Input()
                    {
                        Label = "Type", DefaultValue = stream.Type
                    };
                    input["sr"] = new UserInputWindow.Input()
                    {
                        Label = "Sample rate", DefaultValue = stream.SampleRate.ToString()
                    };
                    UserInputWindow dialog = new UserInputWindow("Edit stream type", input);
                    dialog.ShowDialog();

                    if (dialog.DialogResult == true)
                    {
                        stream.Name    = dialog.Result("name");
                        stream.FileExt = dialog.Result("fileExt");
                        stream.Type    = dialog.Result("type");
                        double sr = 25.0;
                        double.TryParse(dialog.Result("sr"), out sr);
                        stream.SampleRate = sr;
                        if (DatabaseHandler.UpdateStream(name, stream))
                        {
                            GetStreamTypes(name);
                        }
                    }
                }
            }
        }
        private void AddStream_Click(object sender, RoutedEventArgs e)
        {
            Dictionary <string, UserInputWindow.Input> input = new Dictionary <string, UserInputWindow.Input>();

            input["name"] = new UserInputWindow.Input()
            {
                Label = "Name", DefaultValue = ""
            };
            input["fileExt"] = new UserInputWindow.Input()
            {
                Label = "File extension", DefaultValue = ""
            };
            input["type"] = new UserInputWindow.Input()
            {
                Label = "Type", DefaultValue = ""
            };
            input["sr"] = new UserInputWindow.Input()
            {
                Label = "Sample rate", DefaultValue = ""
            };
            UserInputWindow dialog = new UserInputWindow("Add new stream type", input);

            dialog.ShowDialog();
            if (dialog.DialogResult == true)
            {
                string name    = dialog.Result("name");
                string fileExt = dialog.Result("fileExt");
                string type    = dialog.Result("type");
                double sr      = 25.0;
                double.TryParse(dialog.Result("sr"), out sr);
                DatabaseStream streamType = new DatabaseStream()
                {
                    Name = name, FileExt = fileExt, Type = type, SampleRate = sr
                };
                if (DatabaseHandler.AddStream(streamType))
                {
                    GetStreamTypes(dialog.Result("name"));
                }
            }
        }
        private void EditRole_Click(object sender, RoutedEventArgs e)
        {
            if (RolesBox.SelectedItem != null)
            {
                string old_name = (string)RolesBox.SelectedItem;

                DatabaseRole old_role = DatabaseHandler.Roles.Find(r => r.Name == old_name);

                Dictionary <string, UserInputWindow.Input> input = new Dictionary <string, UserInputWindow.Input>();
                input["name"] = new UserInputWindow.Input()
                {
                    Label = "Name", DefaultValue = old_name
                };
                input["hasStreams"] = new UserInputWindow.Input()
                {
                    Label = "Has streams", DefaultValue = (old_role == null ? "true" : old_role.HasStreams.ToString())
                };
                UserInputWindow dialog = new UserInputWindow("Edit role", input);
                dialog.ShowDialog();

                if (dialog.DialogResult == true)
                {
                    string name       = dialog.Result("name");
                    bool   hasStreams = true;
                    bool.TryParse(dialog.Result("hasStreams"), out hasStreams);

                    DatabaseRole role = new DatabaseRole()
                    {
                        Name = name, HasStreams = hasStreams
                    };

                    if (DatabaseHandler.UpdateRole(old_name, role))
                    {
                        GetRoles(name);
                    }
                }
            }
        }
        private void AddAnnotation_Click(object sender, RoutedEventArgs e)
        {
            Dictionary <string, UserInputWindow.Input> input = new Dictionary <string, UserInputWindow.Input>();

            input["label"] = new UserInputWindow.Input()
            {
                Label = "Class label", DefaultValue = ""
            };
            input["color"] = new UserInputWindow.Input()
            {
                Label = "Color code (#RGB)", DefaultValue = ""
            };
            UserInputWindow dialog = new UserInputWindow("Add a new class label", input);

            dialog.ShowDialog();

            if (dialog.DialogResult == true)
            {
                items = new List <AnnoScheme.Label>();
                string           label = dialog.Result("label");
                Color            color = (Color)ColorConverter.ConvertFromString(dialog.Result("color"));
                AnnoScheme.Label lcp   = new AnnoScheme.Label(label, color);

                labelcolors.Add(lcp);

                foreach (AnnoScheme.Label lp in labelcolors)
                {
                    items.Add(new AnnoScheme.Label(label, color)
                    {
                        Name = lp.Name, Color = lp.Color
                    });
                }

                AnnotationResultBox.ItemsSource = items;
            }
        }
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            if (allowEdit)
            {
                string name = null;
                Brush  col1 = null;
                Brush  col2 = null;
                string sr   = null;
                string min  = null;
                string max  = null;

                if (annoList != null)
                {
                    name = annoList.Scheme.Name;

                    if (annoList.Scheme.Type == AnnoScheme.TYPE.DISCRETE ||
                        annoList.Scheme.Type == AnnoScheme.TYPE.FREE)
                    {
                        usedlabels = new HashSet <AnnoScheme.Label>();

                        foreach (AnnoListItem item in annoList)
                        {
                            AnnoScheme.Label l        = new AnnoScheme.Label(item.Label, item.Color);
                            bool             detected = false;
                            foreach (AnnoScheme.Label p in usedlabels)
                            {
                                if (p.Name == l.Name)
                                {
                                    detected = true;
                                }
                            }

                            if (detected == false)
                            {
                                usedlabels.Add(l);
                            }
                        }
                        col1 = new SolidColorBrush(annoList.Scheme.MinOrBackColor);
                    }
                    else
                    {
                        col1 = new SolidColorBrush(annoList.Scheme.MinOrBackColor);
                        col2 = new SolidColorBrush(annoList.Scheme.MaxOrForeColor);
                        sr   = (1000.0 / (annoList.Scheme.SampleRate * 1000.0)).ToString();
                        min  = annoList.Scheme.MinScore.ToString();
                        max  = annoList.Scheme.MaxScore.ToString();
                    }
                }

                storeAnnotationSchemetoDatabase(name, usedlabels, annoList.Scheme.Type, col1, col2, sr, min, max);
            }
            else
            {
                Dictionary <string, UserInputWindow.Input> input = new Dictionary <string, UserInputWindow.Input>();
                input["name"] = new UserInputWindow.Input()
                {
                    Label = "Name", DefaultValue = ""
                };
                UserInputWindow dialog = new UserInputWindow("Add new name", input);
                dialog.ShowDialog();

                if (dialog.DialogResult == true)
                {
                    DataBaseResultsBox.Items.Add(dialog.Result("name"));
                    DataBaseResultsBox.SelectedItem = dialog.Result("name");
                }
            }
        }
示例#9
0
        private void ExportAnnoContinuousToDiscrete()
        {
            if (AnnoTierStatic.Selected != null && !AnnoTierStatic.Selected.IsDiscreteOrFree)
            {
                Dictionary <string, UserInputWindow.Input> input = new Dictionary <string, UserInputWindow.Input>();
                input["labels"] = new UserInputWindow.Input()
                {
                    Label = "Class labels (separated by ;)", DefaultValue = Properties.Settings.Default.ConvertToDiscreteClasses
                };
                input["thresholds"] = new UserInputWindow.Input()
                {
                    Label = "Upper thresholds (separated by ;)", DefaultValue = Properties.Settings.Default.ConvertToDiscreteThreshs
                };
                input["offset"] = new UserInputWindow.Input()
                {
                    Label = "Optional offset (s)", DefaultValue = Properties.Settings.Default.ConvertToDiscreteDelays
                };
                UserInputWindow dialog = new UserInputWindow("Convert to discrete annotation", input);
                dialog.ShowDialog();

                List <string> classes         = new List <string>();
                List <double> upperThresholds = new List <double>();
                double        offset          = 0.0;

                if (dialog.DialogResult == true)
                {
                    Properties.Settings.Default.ConvertToDiscreteClasses = dialog.Result("labels");
                    Properties.Settings.Default.ConvertToDiscreteThreshs = dialog.Result("thresholds");
                    Properties.Settings.Default.ConvertToDiscreteDelays  = dialog.Result("offset");
                    Properties.Settings.Default.Save();


                    string[] labels = dialog.Result("labels").Split(';');
                    for (int i = 0; i < labels.Length; i++)
                    {
                        classes.Add(labels[i]);
                    }

                    string[] thresholds = dialog.Result("thresholds").Split(';');
                    for (int i = 0; i < thresholds.Length; i++)
                    {
                        double thresh = -1;
                        double.TryParse(thresholds[i], out thresh);
                        if (thresh > -1)
                        {
                            upperThresholds.Add(thresh);
                        }
                        else
                        {
                            MessageTools.Warning("Could not parse input");
                        }
                    }

                    if (thresholds.Length == labels.Length - 1)
                    {
                        upperThresholds.Add(1.0);
                    }
                    else if (thresholds.Length == labels.Length + 1)
                    {
                        classes.Add("REST");
                    }
                    else if (thresholds.Length != labels.Length)
                    {
                        MessageBox.Show("Number of labels does not match number of threshholds");
                    }

                    double.TryParse(dialog.Result("offset"), out offset);
                }
                Mouse.SetCursor(Cursors.No);

                AnnoList discretevalues = new AnnoList();
                discretevalues.Scheme         = new AnnoScheme();
                discretevalues.Scheme.Type    = AnnoScheme.TYPE.DISCRETE;
                discretevalues.Meta.Role      = AnnoTier.Selected.AnnoList.Meta.Role;
                discretevalues.Meta.Annotator = AnnoTier.Selected.AnnoList.Meta.Annotator;
                discretevalues.Scheme.Name    = AnnoTier.Selected.AnnoList.Scheme.Name;

                foreach (string label in classes)
                {
                    AnnoScheme.Label item = new AnnoScheme.Label(label, System.Windows.Media.Colors.Black);
                    discretevalues.Scheme.Labels.Add(item);
                }

                AnnoScheme.Label garbage = new AnnoScheme.Label("GARBAGE", Colors.Black);
                discretevalues.Scheme.Labels.Add(garbage);

                double lowThres  = -Double.MaxValue;
                double highThres = 1.0;

                foreach (AnnoListItem ali in AnnoTierStatic.Selected.AnnoList)
                {
                    double val = ali.Score;

                    for (int i = 0; i < classes.Count; i++)
                    {
                        highThres = upperThresholds[i];
                        if (i > 0)
                        {
                            lowThres = upperThresholds[i - 1];
                        }
                        else
                        {
                            lowThres = -Double.MaxValue;
                        }

                        if (val > lowThres && val <= highThres)
                        {
                            if (!(discretevalues.Count > 0 && discretevalues[discretevalues.Count - 1].Label == classes[i]))
                            {
                                AnnoListItem newItem = new AnnoListItem(ali.Start + offset, ali.Duration, classes[i], "", discretevalues.Scheme.GetColorForLabel(classes[i]));
                                if (newItem.Start < 0.0)
                                {
                                    newItem.Duration = ali.Duration + offset + newItem.Start;
                                    newItem.Start    = 0.0;
                                    newItem.Stop     = newItem.Duration;
                                }
                                if (newItem.Duration > 0.0)
                                {
                                    discretevalues.Add(newItem);
                                }
                            }
                            else
                            {
                                discretevalues[discretevalues.Count - 1].Stop = discretevalues[discretevalues.Count - 1].Stop + ali.Duration;
                            }
                            break;
                        }
                    }
                }

                AnnoTier.Unselect();
                addAnnoTierFromList(discretevalues);

                Mouse.SetCursor(System.Windows.Input.Cursors.Arrow);
            }
            else
            {
                MessageBox.Show("Tier is already discrete");
            }
        }