How to use Suggestion method of validation Package

Best Gauge code snippet using validation.Suggestion

database.go

Source:database.go Github

copy

Full Screen

...404 `SELECT revision 405 FROM image_annotation WHERE uuid = $1`, annotationId).Scan(&revision)406 return revision, err407}408func (p *ImageMonkeyDatabase) GetAnnotationSuggestionRevision(annotationId string) (int32, error) {409 var revision int32410 err := p.db.QueryRow(context.TODO(),411 `SELECT revision 412 FROM image_annotation_suggestion WHERE uuid = $1`, annotationId).Scan(&revision)413 return revision, err414}415func (p *ImageMonkeyDatabase) GetOldAnnotationDataIds(annotationId string, revision int32) ([]int64, error) {416 var ids []int64417 rows, err := p.db.Query(context.TODO(),418 `SELECT d.id419 FROM annotation_data d420 JOIN image_annotation_revision r ON d.image_annotation_revision_id = r.id421 JOIN image_annotation a ON r.image_annotation_id = a.id422 WHERE a.uuid = $1 AND r.revision = $2`, annotationId, revision)423 if err != nil {424 return ids, err425 }426 defer rows.Close()427 for rows.Next() {428 var id int64429 err = rows.Scan(&id)430 if err != nil {431 return ids, err432 }433 ids = append(ids, id) 434 }435 return ids, nil436}437func (p *ImageMonkeyDatabase) GetOldAnnotationSuggestionDataIds(annotationId string, revision int32) ([]int64, error) {438 var ids []int64439 rows, err := p.db.Query(context.TODO(),440 `SELECT d.id441 FROM annotation_suggestion_data d442 JOIN image_annotation_suggestion_revision r ON d.image_annotation_suggestion_revision_id = r.id443 JOIN image_annotation_suggestion a ON r.image_annotation_suggestion_id = a.id444 WHERE a.uuid = $1 AND r.revision = $2`, annotationId, revision)445 if err != nil {446 return ids, err447 }448 defer rows.Close()449 for rows.Next() {450 var id int64451 err = rows.Scan(&id)452 if err != nil {453 return ids, err454 }455 ids = append(ids, id) 456 }457 return ids, nil458}459func (p *ImageMonkeyDatabase) GetAnnotationDataIds(annotationId string) ([]int64, error) {460 var ids []int64461 rows, err := p.db.Query(context.TODO(),462 `SELECT d.id 463 FROM annotation_data d464 JOIN image_annotation a ON d.image_annotation_id = a.id465 WHERE a.uuid = $1`, annotationId)466 if err != nil {467 return ids, err468 }469 defer rows.Close()470 for rows.Next() {471 var id int64472 err = rows.Scan(&id)473 if err != nil {474 return ids, err475 }476 ids = append(ids, id)477 }478 return ids, nil479}480func (p *ImageMonkeyDatabase) GetAnnotationSuggestionDataIds(annotationId string) ([]int64, error) {481 var ids []int64482 rows, err := p.db.Query(context.TODO(),483 `SELECT d.id 484 FROM annotation_suggestion_data d485 JOIN image_annotation_suggestion a ON d.image_annotation_suggestion_id = a.id486 WHERE a.uuid = $1`, annotationId)487 if err != nil {488 return ids, err489 }490 defer rows.Close()491 for rows.Next() {492 var id int64493 err = rows.Scan(&id)494 if err != nil {495 return ids, err496 }497 ids = append(ids, id)498 }499 return ids, nil500}501func (p *ImageMonkeyDatabase) GetRandomImageForAnnotation() (AnnotationRow, error) {502 var annotationRow AnnotationRow503 err := p.db.QueryRow(context.TODO(),504 `SELECT i.key, v.uuid, l.name, COALESCE(pl.name, '')505 FROM image i 506 JOIN image_validation v ON v.image_id = i.id 507 JOIN label l ON v.label_id = l.id508 LEFT JOIN label pl ON pl.id = l.parent_id 509 WHERE NOT EXISTS (510 SELECT 1 FROM image_annotation a 511 WHERE a.label_id = l.id AND a.image_id = i.id512 ) LIMIT 1`).Scan(&annotationRow.Image.Id, &annotationRow.Validation.Id,513 &annotationRow.Validation.Label, &annotationRow.Validation.Sublabel)514 return annotationRow, err515}516func (p *ImageMonkeyDatabase) AnnotationUuidIsASuggestion(annotationUuid string) (bool, error) {517 var isSuggestion bool = false518 err := p.db.QueryRow(context.TODO(),519 `SELECT is_suggestion FROM520 (521 SELECT count(*) as count, false as is_suggestion522 FROM image_annotation a 523 WHERE a.uuid = $1::uuid524 UNION ALL525 SELECT count(*) as count, true as is_suggestion526 FROM image_annotation_suggestion a527 WHERE a.uuid = $1::uuid528 ) q WHERE q.count > 0`, annotationUuid).Scan(&isSuggestion)529 if err != nil {530 return isSuggestion, err531 }532 return isSuggestion, nil533}534func (p *ImageMonkeyDatabase) GetImageAnnotationSuggestionIdsForImage(imageId string) ([]string, error) {535 annotationUuids := []string{}536 rows, err := p.db.Query(context.TODO(),537 `SELECT a.uuid538 FROM image_annotation_suggestion a539 JOIN image i ON a.image_id = i.id540 WHERE i.key = $1`, imageId)541 if err != nil {542 return annotationUuids, err543 }544 545 defer rows.Close()546 for rows.Next() {547 var annotationUuid string548 err = rows.Scan(&annotationUuid)549 if err != nil {550 return annotationUuids, err551 }552 annotationUuids = append(annotationUuids, annotationUuid)553 }554 return annotationUuids, nil555}556func (p *ImageMonkeyDatabase) GetRandomAnnotationId() (string, error) {557 var annotationId string558 err := p.db.QueryRow(context.TODO(), `SELECT a.uuid FROM image_annotation a ORDER BY random() LIMIT 1`).Scan(&annotationId)559 return annotationId, err560}561func (p *ImageMonkeyDatabase) GetLastAddedAnnotationDataId() (string, error) {562 var annotationDataId string563 err := p.db.QueryRow(context.TODO(), `SELECT d.uuid FROM annotation_data d ORDER BY d.id DESC LIMIT 1`).Scan(&annotationDataId)564 return annotationDataId, err565}566func (p *ImageMonkeyDatabase) GetLastAddedAnnotationId() (string, error) {567 var annotationId string568 err := p.db.QueryRow(context.TODO(), `SELECT a.uuid FROM image_annotation a ORDER BY a.id DESC LIMIT 1`).Scan(&annotationId)569 return annotationId, err570}571func (p *ImageMonkeyDatabase) GetRandomLabelId() (int64, error) {572 var labelId int64573 err := p.db.QueryRow(context.TODO(), `SELECT l.id FROM label l ORDER BY random() LIMIT 1`).Scan(&labelId)574 return labelId, err575}576func (p *ImageMonkeyDatabase) GetRandomLabelUuid() (string, error) {577 var labelUuid string578 err := p.db.QueryRow(context.TODO(), `SELECT l.uuid FROM label l ORDER BY random() LIMIT 1`).Scan(&labelUuid)579 return labelUuid, err580}581func (p *ImageMonkeyDatabase) GetRandomAnnotationData() (string, string, error) {582 var annotationId string583 var annotationDataId string584 err := p.db.QueryRow(context.TODO(),585 `SELECT a.uuid, d.uuid586 FROM image_annotation a 587 JOIN annotation_data d ON d.image_annotation_id = a.id588 ORDER BY random() LIMIT 1`).Scan(&annotationId, &annotationDataId)589 return annotationId, annotationDataId, err590}591func (p *ImageMonkeyDatabase) GetLastAddedAnnotationData() (string, string, error) {592 var annotationId string593 var annotationDataId string594 err := p.db.QueryRow(context.TODO(),595 `SELECT a.uuid, d.uuid596 FROM image_annotation a 597 JOIN annotation_data d ON d.image_annotation_id = a.id598 ORDER BY a.id DESC LIMIT 1`).Scan(&annotationId, &annotationDataId)599 return annotationId, annotationDataId, err600}601func (p *ImageMonkeyDatabase) GetNumberOfImagesWithLabel(label string) (int32, error) {602 var num int32603 err := p.db.QueryRow(context.TODO(),604 `SELECT count(*) 605 FROM image_validation v 606 JOIN label l ON v.label_id = l.id607 WHERE l.name = $1 AND l.parent_id is null`, label).Scan(&num)608 return num, err609}610func (p *ImageMonkeyDatabase) GetNumberOfImagesWithLabelUuid(labelUuid string) (int32, error) {611 var num int32612 err := p.db.QueryRow(context.TODO(),613 `SELECT count(*) 614 FROM image_validation v 615 JOIN label l ON v.label_id = l.id616 WHERE l.uuid::text = $1`, labelUuid).Scan(&num)617 return num, err618}619func (p *ImageMonkeyDatabase) GetNumberOfImagesWithLabelSuggestions(label string) (int32, error) {620 var num int32621 err := p.db.QueryRow(context.TODO(),622 `SELECT count(*) 623 FROM image_label_suggestion ils624 JOIN label_suggestion l ON l.id = ils.label_suggestion_id625 WHERE l.name = $1626 `, label).Scan(&num)627 return num, err628}629func (p *ImageMonkeyDatabase) GetNumberOfTrendingLabelSuggestions() (int32, error) {630 var num int32631 err := p.db.QueryRow(context.TODO(),632 `SELECT count(*) 633 FROM trending_label_suggestion`).Scan(&num)634 return num, err635}636func (p *ImageMonkeyDatabase) GetNumberOfImageHuntTasksForImageWithLabel(imageId string, label string) (int32, error) {637 var num int32638 err := p.db.QueryRow(context.TODO(),639 `SELECT count(*) 640 FROM imagehunt_task h641 JOIN image_validation v ON v.id = h.image_validation_id642 JOIN label l ON l.id = v.label_id643 JOIN image i ON i.id = v.image_id644 WHERE i.key = $1 AND l.name = $2`, imageId, label).Scan(&num)645 return num, err646}647func (p *ImageMonkeyDatabase) GetNumberOfImageUserEntriesForImageAndUser(imageId string, username string) (int32, error) {648 var num int32649 err := p.db.QueryRow(context.TODO(),650 `SELECT count(*) 651 FROM image i652 JOIN user_image u ON u.image_id = i.id653 JOIN account a ON a.id = u.account_id654 WHERE i.key = $1 AND a.name = $2`, imageId, username).Scan(&num)655 return num, err656}657func (p *ImageMonkeyDatabase) GetProductiveLabelIdsForTrendingLabels() ([]int64, error) {658 productiveLabelIds := []int64{}659 rows, err := p.db.Query(context.TODO(),660 `SELECT t.productive_label_id FROM trending_label_suggestion t 661 WHERE t.productive_label_id is not null`)662 if err != nil {663 return productiveLabelIds, err664 }665 defer rows.Close()666 for rows.Next() {667 var productiveLabelId int64668 err = rows.Scan(&productiveLabelId)669 if err != nil {670 return productiveLabelIds, err671 }672 productiveLabelIds = append(productiveLabelIds, productiveLabelId)673 }674 return productiveLabelIds, nil675}676func (p *ImageMonkeyDatabase) GetRandomLabelName(skipLabel string) (string, error) {677 var queryParams []interface{}678 skipLabelStr := ""679 if skipLabel != "" {680 skipLabelStr = "AND l.name != $1"681 queryParams = append(queryParams, skipLabel)682 }683 684 query := fmt.Sprintf(`SELECT l.name685 FROM label l686 WHERE l.parent_id is null AND l.label_type = 'normal'687 %s688 ORDER BY random() LIMIT 1`, skipLabelStr) 689 690 691 692 var label string693 err := p.db.QueryRow(context.TODO(), query, queryParams...).Scan(&label)694 return label, err695}696func (p *ImageMonkeyDatabase) GetAllImageIds() ([]string, error) {697 var imageIds []string698 rows, err := p.db.Query(context.TODO(), `SELECT i.key FROM image i ORDER BY random()`)699 if err != nil {700 return imageIds, err701 }702 defer rows.Close()703 for rows.Next() {704 var imageId string705 err = rows.Scan(&imageId)706 if err != nil {707 return imageIds, err708 }709 imageIds = append(imageIds, imageId)710 }711 return imageIds, nil712}713func (p *ImageMonkeyDatabase) GetLatestDonatedImageId() (string,error) {714 var imageId string 715 err := p.db.QueryRow(context.TODO(), `SELECT i.key FROM image i ORDER BY id DESC LIMIT 1`).Scan(&imageId)716 return imageId, err717}718func (p *ImageMonkeyDatabase) PutImageInQuarantine(imageId string) error { 719 _, err := p.db.Exec(context.TODO(), 720 `INSERT INTO image_quarantine(image_id)721 SELECT id FROM image WHERE key = $1`, imageId)722 return err723}724func (p *ImageMonkeyDatabase) GetLabelUuidFromName(label string) (string, error) {725 var uuid string 726 err := p.db.QueryRow(context.TODO(),727 `SELECT l.uuid 728 FROM label l 729 WHERE l.name = $1 and l.parent_id is null`, label).Scan(&uuid)730 return uuid, err731}732func (p *ImageMonkeyDatabase) GetLabelIdFromName(label string) (int64, error) {733 var labelId int64 734 err := p.db.QueryRow(context.TODO(),735 `SELECT l.id 736 FROM label l 737 WHERE l.name = $1 and l.parent_id is null`, label).Scan(&labelId)738 return labelId, err739}740func (p *ImageMonkeyDatabase) GetLabelIdFromSublabelName(label string, parentLabel string) (int64, error) {741 var labelId int64 742 err := p.db.QueryRow(context.TODO(),743 `SELECT l.id 744 FROM label l745 JOIN label pl ON pl.id = l.parent_id746 WHERE l.name = $1 and pl.name = $2`, label, parentLabel).Scan(&labelId)747 return labelId, err748}749func (p *ImageMonkeyDatabase) GetLabelIdFromUuid(labelUuid string) (int64, error) {750 var labelId int64 751 err := p.db.QueryRow(context.TODO(),752 `SELECT l.id 753 FROM label l 754 WHERE l.uuid::text = $1`, labelUuid).Scan(&labelId)755 return labelId, err756}757func (p *ImageMonkeyDatabase) GetLabelNameFromId(id int64) (string, error) {758 var labelName string 759 err := p.db.QueryRow(context.TODO(),760 `SELECT l.name 761 FROM label l 762 WHERE l.id = $1`, id).Scan(&labelName)763 return labelName, err764}765func (p *ImageMonkeyDatabase) GetLabelSuggestionNameFromId(id int64) (string, error) {766 var labelName string 767 err := p.db.QueryRow(context.TODO(),768 `SELECT l.name 769 FROM label_suggestion l 770 WHERE l.id = $1`, id).Scan(&labelName)771 return labelName, err772}773func (p *ImageMonkeyDatabase) GetNumOfSentOfTrendingLabel(tendingLabel string) (int, error) {774 var tendingLabelId int 775 err := p.db.QueryRow(context.TODO(),776 `SELECT t.num_of_last_sent 777 FROM trending_label_suggestion t778 JOIN label_suggestion l ON t.label_suggestion_id = l.id779 WHERE l.name = $1`, tendingLabel).Scan(&tendingLabelId)780 return tendingLabelId, err781}782func (p *ImageMonkeyDatabase) SetValidationValid(validationId string, num int) error {783 _, err := p.db.Exec(context.TODO(),784 `UPDATE image_validation 785 SET num_of_valid = $2 786 WHERE uuid = $1`, validationId, num)787 return err788}789func (p *ImageMonkeyDatabase) GetNumOfRefinements() (int, error) {790 var num int 791 err := p.db.QueryRow(context.TODO(), `SELECT count(*) FROM image_annotation_refinement`).Scan(&num)792 return num, err793}794func (p *ImageMonkeyDatabase) GetAllAnnotationIds() ([]string, error) {795 var annotationIds []string796 rows, err := p.db.Query(context.TODO(), "SELECT uuid FROM image_annotation")797 if err != nil {798 return annotationIds, err799 }800 defer rows.Close()801 for rows.Next() {802 var annotationId string803 err = rows.Scan(&annotationId)804 if err != nil {805 return annotationIds, err806 }807 annotationIds = append(annotationIds, annotationId)808 }809 return annotationIds, nil810}811func (p *ImageMonkeyDatabase) SetAnnotationValid(annotationId string, num int) error {812 _, err := p.db.Exec(context.TODO(),813 `UPDATE image_annotation 814 SET num_of_valid = $2 815 WHERE uuid = $1`, annotationId, num)816 return err817}818func (p *ImageMonkeyDatabase) GetImageAnnotationCoverageForImageId(imageId string) (int, error) {819 rows, err := p.db.Query(context.TODO(),820 `SELECT annotated_percentage 821 FROM image_annotation_coverage c822 JOIN image i ON i.id = c.image_id823 WHERE i.key = $1`, imageId)824 if err != nil {825 return 0, err826 }827 defer rows.Close()828 if rows.Next() {829 var coverage int830 err = rows.Scan(&coverage)831 if err != nil {832 return 0, err833 }834 return coverage, nil835 }836 return 0, errors.New("missing result set")837}838func (p *ImageMonkeyDatabase) GetImageDescriptionForImageId(imageId string) ([]ImageDescriptionSummary, error) {839 var descriptionSummaries []ImageDescriptionSummary840 rows, err := p.db.Query(context.TODO(),841 `SELECT dsc.description, dsc.num_of_valid, dsc.uuid, dsc.state, l.name842 FROM image_description dsc843 JOIN language l ON l.id = dsc.language_id844 JOIN image i ON i.id = dsc.image_id845 WHERE i.key = $1846 ORDER BY dsc.id asc`, imageId)847 if err != nil {848 return descriptionSummaries, err849 }850 defer rows.Close()851 for rows.Next() {852 var dsc ImageDescriptionSummary853 var state string854 err = rows.Scan(&dsc.Description, &dsc.NumOfValid, &dsc.Uuid, &state, &dsc.Language)855 if err != nil {856 return descriptionSummaries, err857 }858 if state == "unknown" {859 dsc.State = ImageDescriptionStateUnknown860 } else if state == "locked" {861 dsc.State = ImageDescriptionStateLocked862 } else if state == "unlocked" {863 dsc.State = ImageDescriptionStateUnlocked864 }865 descriptionSummaries = append(descriptionSummaries, dsc)866 }867 return descriptionSummaries, nil868}869func (p *ImageMonkeyDatabase) GetModeratorWhoProcessedImageDescription(imageId string, imageDescription string) (string, error) {870 rows, err := p.db.Query(context.TODO(),871 `SELECT a.name872 FROM image_description dsc873 JOIN image i ON i.id = dsc.image_id874 JOIN account a ON a.id = dsc.processed_by875 WHERE i.key = $1 AND dsc.description = $2`, imageId, imageDescription)876 if err != nil {877 return "", err878 }879 defer rows.Close()880 if rows.Next() {881 var moderator string882 err = rows.Scan(&moderator)883 if err != nil {884 return "", err885 }886 return moderator, nil887 }888 return "", errors.New("missing result set")889}890func (p *ImageMonkeyDatabase) IsImageUnlocked(imageId string) (bool, error) {891 rows, err := p.db.Query(context.TODO(), `SELECT unlocked FROM image i WHERE i.key = $1`, imageId)892 if err != nil {893 return false, err894 }895 defer rows.Close()896 if rows.Next() {897 var unlocked bool898 err = rows.Scan(&unlocked)899 if err != nil {900 return false, err901 }902 return unlocked, nil903 }904 return false, errors.New("missing result set")905}906func (p *ImageMonkeyDatabase) IsImageInQuarantine(imageId string) (bool, error) {907 rows, err := p.db.Query(context.TODO(),908 `SELECT CASE 909 WHEN COUNT(*) <> 0 THEN true 910 ELSE false911 END as in_quarantine912 FROM image_quarantine q 913 WHERE q.image_id IN (914 SELECT i.id FROM image i WHERE i.key = $1915 )`, imageId)916 if err != nil {917 return false, err918 }919 defer rows.Close()920 if rows.Next() {921 var inQuarantine bool922 err = rows.Scan(&inQuarantine)923 if err != nil {924 return false, err925 }926 return inQuarantine, nil927 }928 return false, errors.New("missing result set")929}930func (p *ImageMonkeyDatabase) DoLabelAccessorsBelongToMoreThanOneLabelId() (bool, error) {931 rows, err := p.db.Query(context.TODO(),932 `SELECT label_id 933 FROM label_accessor934 GROUP BY label_id935 HAVING COUNT(label_id) > 1`)936 if err != nil {937 return false, err938 }939 defer rows.Close()940 if rows.Next() {941 return true, nil942 }943 return false, nil944}945func (p *ImageMonkeyDatabase) GetNumOfMetaLabelImageValidations() (int, error) {946 var num int 947 err := p.db.QueryRow(context.TODO(),948 `SELECT count(*) FROM 949 image_validation v 950 JOIN label l ON l.id = v.label_id951 WHERE l.label_type = 'meta'`).Scan(&num)952 return num, err953}954func (p *ImageMonkeyDatabase) GetNumOfDatesFromNowTilOneMonthAgo() (int, error) {955 var num int956 err := p.db.QueryRow(context.TODO(),957 `SELECT COUNT(*)958 FROM generate_series((CURRENT_DATE - interval '1 month'), CURRENT_DATE, '1 day')`).Scan(&num)959 return num, err960}961func (p *ImageMonkeyDatabase) RemoveLabel(labelName string) error {962 tx, err := p.db.Begin(context.TODO())963 if err != nil {964 tx.Rollback(context.TODO())965 return err966 }967 968 _, err = tx.Exec(context.TODO(),969 "DELETE FROM label_accessor a WHERE a.label_id IN (SELECT l.id FROM label l WHERE l.name = $1 AND l.parent_id is null)", labelName)970 if err != nil {971 tx.Rollback(context.TODO())972 return err973 }974 _, err = tx.Exec(context.TODO(),975 "DELETE FROM label_accessor a WHERE a.label_id IN (SELECT l.id FROM label l JOIN label pl ON pl.id = l.parent_id WHERE pl.name = $1)", labelName)976 if err != nil {977 tx.Rollback(context.TODO())978 return err979 }980 _, err = tx.Exec(context.TODO(),981 "DELETE FROM quiz_answer q WHERE q.label_id IN (SELECT l.id FROM label l WHERE l.name = $1 AND l.parent_id is null)", labelName)982 if err != nil {983 tx.Rollback(context.TODO())984 return err985 }986 _, err = tx.Exec(context.TODO(),987 "DELETE FROM quiz_answer q WHERE q.label_id IN (SELECT l.id FROM label l JOIN label pl ON pl.id = l.parent_id WHERE pl.name = $1)", labelName)988 if err != nil {989 tx.Rollback(context.TODO())990 return err991 }992 _, err = tx.Exec(context.TODO(),993 "DELETE FROM quiz_question q WHERE q.refines_label_id IN (SELECT l.id FROM label l WHERE l.name = $1 AND l.parent_id is null)", labelName)994 if err != nil {995 tx.Rollback(context.TODO())996 return err997 }998 _, err = tx.Exec(context.TODO(),999 "DELETE FROM quiz_question q WHERE q.refines_label_id IN (SELECT l.id FROM label l JOIN label pl ON pl.id = l.parent_id WHERE pl.name = $1)", labelName)1000 if err != nil {1001 tx.Rollback(context.TODO())1002 return err1003 }1004 _, err = tx.Exec(context.TODO(),1005 "DELETE FROM label l WHERE l.parent_id IN (SELECT id FROM label pl WHERE pl.name = $1)", labelName)1006 if err != nil {1007 tx.Rollback(context.TODO())1008 return err1009 }1010 _, err = tx.Exec(context.TODO(), 1011 "DELETE FROM label l WHERE l.name = $1 AND l.parent_id is null", labelName)1012 if err != nil {1013 tx.Rollback(context.TODO())1014 return err1015 }1016 err = tx.Commit(context.TODO())1017 return err1018} 1019func (p *ImageMonkeyDatabase) GetNumOfNotAnnotatable(uuid string) (int, error) {1020 rows, err := p.db.Query(context.TODO(),1021 "SELECT num_of_not_annotatable FROM image_validation WHERE uuid = $1", uuid)1022 if err != nil {1023 return 0, err1024 }1025 defer rows.Close()1026 1027 var num int1028 if rows.Next() {1029 err = rows.Scan(&num)1030 if err != nil {1031 return 0, err1032 }1033 }1034 return num, nil1035} 1036func (p *ImageMonkeyDatabase) GetTrendingLabelBotTaskState(labelSuggestion string) (string, error) {1037 rows, err := p.db.Query(context.TODO(),1038 `SELECT COALESCE(bt.state::text, '') 1039 FROM trending_label_bot_task bt 1040 RIGHT JOIN trending_label_suggestion l ON l.id = bt.trending_label_suggestion_id1041 RIGHT JOIN label_suggestion s ON s.id = l.label_suggestion_id1042 WHERE s.name = $1`, labelSuggestion) 1043 if err != nil {1044 return "", err1045 }1046 defer rows.Close()1047 if rows.Next() {1048 var state string1049 err = rows.Scan(&state)1050 if err != nil {1051 return "", err1052 }1053 return state, nil1054 }1055 return "", errors.New("nothing found")1056}1057func (p *ImageMonkeyDatabase) GetTrendingLabelBotTaskParentId(labelSuggestion string) (int64, error) {1058 rows, err := p.db.Query(context.TODO(),1059 `SELECT COALESCE(bt.parent_label_id::bigint, -1) 1060 FROM trending_label_bot_task bt 1061 RIGHT JOIN trending_label_suggestion l ON l.id = bt.trending_label_suggestion_id1062 RIGHT JOIN label_suggestion s ON s.id = l.label_suggestion_id1063 WHERE s.name = $1`, labelSuggestion) 1064 if err != nil {1065 return -1, err1066 }1067 defer rows.Close()1068 if rows.Next() {1069 var parentLabelId int641070 err = rows.Scan(&parentLabelId)1071 if err != nil {1072 return -1, err1073 }1074 return parentLabelId, nil1075 }1076 return -1, errors.New("nothing found")1077}1078func (p *ImageMonkeyDatabase) SetTrendingLabelBotTaskState(labelSuggestion string, state string) error {1079 _, err := p.db.Exec(context.TODO(),1080 `UPDATE trending_label_bot_task 1081 SET state = $21082 FROM (1083 SELECT l.id as lid1084 FROM trending_label_suggestion l1085 JOIN label_suggestion s ON s.id = l.label_suggestion_id1086 WHERE s.name = $1 1087 ) q1088 WHERE q.lid = trending_label_suggestion_id`, labelSuggestion, state)1089 return err1090}1091func (p *ImageMonkeyDatabase) Close() {1092 p.db.Close(context.TODO())1093}1094func (p *ImageMonkeyDatabase) AddDummyTrendingLabelBotTask(trendingLabelName string, renameTo string, 1095 branchName string, labelType string, state string) (int64, error) {1096 var trendingLabelBotTaskId int641097 1098 rows, err := p.db.Query(context.TODO(),1099 `INSERT INTO trending_label_bot_task (trending_label_suggestion_id, branch_name, state, label_type, rename_to)1100 SELECT t.id, $1, $2 , $3, $41101 FROM trending_label_suggestion t1102 JOIN label_suggestion l ON t.label_suggestion_id = l.id1103 RETURNING id`, branchName, state, labelType, renameTo)1104 if err != nil {1105 return trendingLabelBotTaskId, err1106 }1107 defer rows.Close()1108 if rows.Next() { 1109 err = rows.Scan(&trendingLabelBotTaskId)1110 return trendingLabelBotTaskId, err1111 }1112 return trendingLabelBotTaskId, errors.New("nothing found")1113}1114type ImageAnnotationEntry struct {1115 Uuid string1116 ImageId int641117 NumOfValid int321118 NumOfInvalid int321119 FingerprintOfLastModification string1120 SysPeriod string1121 LabelId int641122 AutoGenerated bool1123 Revision int1124 Id int641125}1126func (p *ImageMonkeyDatabase) GetImageAnnotationEntries() ([]ImageAnnotationEntry, error) {1127 imageAnnotationEntries :=[]ImageAnnotationEntry{}1128 rows, err := p.db.Query(context.TODO(),1129 `SELECT uuid, image_id, num_of_valid, num_of_invalid, 1130 COALESCE(fingerprint_of_last_modification, ''), sys_period::text, label_id, auto_generated, revision, id1131 FROM image_annotation1132 ORDER BY uuid`)1133 if err != nil {1134 return imageAnnotationEntries, err1135 }1136 defer rows.Close()1137 for rows.Next() {1138 var imageAnnotationEntry ImageAnnotationEntry1139 err = rows.Scan(&imageAnnotationEntry.Uuid, &imageAnnotationEntry.ImageId, &imageAnnotationEntry.NumOfValid, &imageAnnotationEntry.NumOfInvalid,1140 &imageAnnotationEntry.FingerprintOfLastModification, &imageAnnotationEntry.SysPeriod, &imageAnnotationEntry.LabelId,1141 &imageAnnotationEntry.AutoGenerated, &imageAnnotationEntry.Revision, &imageAnnotationEntry.Id)1142 if err != nil {1143 return imageAnnotationEntries, err1144 }1145 imageAnnotationEntries = append(imageAnnotationEntries, imageAnnotationEntry)1146 }1147 return imageAnnotationEntries, nil1148}1149func (p *ImageMonkeyDatabase) GetImageAnnotationSuggestionEntries() ([]ImageAnnotationEntry, error) {1150 imageAnnotationSuggestionEntries :=[]ImageAnnotationEntry{}1151 rows, err := p.db.Query(context.TODO(),1152 `SELECT uuid, image_id, num_of_valid, num_of_invalid, 1153 COALESCE(fingerprint_of_last_modification, ''), sys_period::text, label_suggestion_id, auto_generated, revision, id1154 FROM image_annotation_suggestion1155 ORDER BY uuid`)1156 if err != nil {1157 return imageAnnotationSuggestionEntries, err1158 }1159 defer rows.Close()1160 for rows.Next() {1161 var imageAnnotationSuggestionEntry ImageAnnotationEntry1162 err = rows.Scan(&imageAnnotationSuggestionEntry.Uuid, &imageAnnotationSuggestionEntry.ImageId, &imageAnnotationSuggestionEntry.NumOfValid, 1163 &imageAnnotationSuggestionEntry.NumOfInvalid, &imageAnnotationSuggestionEntry.FingerprintOfLastModification, 1164 &imageAnnotationSuggestionEntry.SysPeriod, &imageAnnotationSuggestionEntry.LabelId,1165 &imageAnnotationSuggestionEntry.AutoGenerated, &imageAnnotationSuggestionEntry.Revision,1166 &imageAnnotationSuggestionEntry.Id)1167 if err != nil {1168 return imageAnnotationSuggestionEntries, err1169 }1170 imageAnnotationSuggestionEntries = append(imageAnnotationSuggestionEntries, imageAnnotationSuggestionEntry)1171 }1172 return imageAnnotationSuggestionEntries, nil1173}1174type AnnotationDataEntry struct {1175 Uuid string1176 ImageAnnotationRevisionId int641177 AnnotationTypeId int641178 Annotation string1179 ImageAnnotationId int641180}1181func (p *ImageMonkeyDatabase) GetAnnotationDataEntries() ([]AnnotationDataEntry, error) {1182 annotationDataEntries := []AnnotationDataEntry{}1183 rows, err := p.db.Query(context.TODO(),1184 `SELECT COALESCE(image_annotation_id, -1), annotation, 1185 annotation_type_id, COALESCE(image_annotation_revision_id, 0), uuid1186 FROM annotation_data1187 ORDER BY uuid`)1188 if err != nil {1189 return annotationDataEntries, err1190 }1191 defer rows.Close()1192 for rows.Next() {1193 var annotationDataEntry AnnotationDataEntry1194 err = rows.Scan(&annotationDataEntry.ImageAnnotationId, &annotationDataEntry.Annotation, &annotationDataEntry.AnnotationTypeId, 1195 &annotationDataEntry.ImageAnnotationRevisionId, &annotationDataEntry.Uuid)1196 if err != nil {1197 return annotationDataEntries, err1198 }1199 annotationDataEntries = append(annotationDataEntries, annotationDataEntry)1200 }1201 return annotationDataEntries, nil1202}1203func (p *ImageMonkeyDatabase) GetAnnotationSuggestionDataEntries() ([]AnnotationDataEntry, error) {1204 annotationSuggestionDataEntries := []AnnotationDataEntry{}1205 rows, err := p.db.Query(context.TODO(),1206 `SELECT COALESCE(image_annotation_suggestion_id, -1), annotation, 1207 annotation_type_id, COALESCE(image_annotation_suggestion_revision_id, 0), uuid1208 FROM annotation_suggestion_data1209 ORDER BY uuid`)1210 if err != nil {1211 return annotationSuggestionDataEntries, err1212 }1213 defer rows.Close()1214 for rows.Next() {1215 var annotationSuggestionDataEntry AnnotationDataEntry1216 err = rows.Scan(&annotationSuggestionDataEntry.ImageAnnotationId, &annotationSuggestionDataEntry.Annotation, 1217 &annotationSuggestionDataEntry.AnnotationTypeId, &annotationSuggestionDataEntry.ImageAnnotationRevisionId, 1218 &annotationSuggestionDataEntry.Uuid)1219 if err != nil {1220 return annotationSuggestionDataEntries, err1221 }1222 annotationSuggestionDataEntries = append(annotationSuggestionDataEntries, annotationSuggestionDataEntry)1223 }1224 return annotationSuggestionDataEntries, nil1225}1226type ImageAnnotationRevisionEntry struct {1227 Id int641228 ImageAnnotationId int641229 Revision int1230}1231func (p *ImageMonkeyDatabase) GetImageAnnotationRevisionEntries() ([]ImageAnnotationRevisionEntry, error) {1232 imageAnnotationRevisions := []ImageAnnotationRevisionEntry{}1233 1234 rows, err := p.db.Query(context.TODO(),1235 `SELECT r.id, r.image_annotation_id, r.revision 1236 FROM image_annotation_revision r1237 JOIN image_annotation a ON r.image_annotation_id = a.id1238 ORDER BY uuid`)1239 if err != nil {1240 return imageAnnotationRevisions, err1241 }1242 defer rows.Close()1243 for rows.Next() { 1244 var imageAnnotationRevision ImageAnnotationRevisionEntry1245 err = rows.Scan(&imageAnnotationRevision.Id, &imageAnnotationRevision.ImageAnnotationId, 1246 &imageAnnotationRevision.Revision)1247 if err != nil {1248 return imageAnnotationRevisions, err1249 }1250 imageAnnotationRevisions = append(imageAnnotationRevisions, imageAnnotationRevision)1251 }1252 return imageAnnotationRevisions, nil1253}1254func (p *ImageMonkeyDatabase) GetImageAnnotationSuggestionRevisionEntries() ([]ImageAnnotationRevisionEntry, error) {1255 imageAnnotationSuggestionRevisions := []ImageAnnotationRevisionEntry{}1256 1257 rows, err := p.db.Query(context.TODO(),1258 `SELECT r.id, r.image_annotation_suggestion_id, r.revision 1259 FROM image_annotation_suggestion_revision r1260 JOIN image_annotation_suggestion a ON r.image_annotation_suggestion_id = a.id1261 ORDER BY uuid`)1262 if err != nil {1263 return imageAnnotationSuggestionRevisions, err1264 }1265 defer rows.Close()1266 for rows.Next() { 1267 var imageAnnotationSuggestionRevision ImageAnnotationRevisionEntry1268 err = rows.Scan(&imageAnnotationSuggestionRevision.Id, &imageAnnotationSuggestionRevision.ImageAnnotationId, 1269 &imageAnnotationSuggestionRevision.Revision)1270 if err != nil {1271 return imageAnnotationSuggestionRevisions, err1272 }1273 imageAnnotationSuggestionRevisions = append(imageAnnotationSuggestionRevisions, imageAnnotationSuggestionRevision)1274 }1275 return imageAnnotationSuggestionRevisions, nil1276}1277func (p *ImageMonkeyDatabase) GetNumberOfLabelSuggestionsForImage(imageId string) (int, error) {1278 var num int1279 err := p.db.QueryRow(context.TODO(),1280 `SELECT count(*) 1281 FROM image_label_suggestion ils1282 JOIN label_suggestion l ON l.id = ils.label_suggestion_id1283 JOIN image i ON i.id = ils.image_id1284 WHERE i.key = $1`, imageId).Scan(&num)1285 if err != nil {1286 return num, err1287 }1288 return num, nil1289}1290func (p *ImageMonkeyDatabase) GetNumberOfLabelSuggestionsWithLabelForImage(imageId string, labelName string) (int, error) {1291 var num int1292 err := p.db.QueryRow(context.TODO(),1293 `SELECT count(*) 1294 FROM image_label_suggestion ils1295 JOIN label_suggestion l ON l.id = ils.label_suggestion_id1296 JOIN image i ON i.id = ils.image_id1297 WHERE i.key = $1 AND l.name = $2`, imageId, labelName).Scan(&num)1298 if err != nil {1299 return num, err1300 }1301 return num, nil1302}1303func (p *ImageMonkeyDatabase) GetLabelUuidsForImage(imageId string) ([]string, error) {1304 labelUuids := []string{}...

Full Screen

Full Screen

suggest_test.go

Source:suggest_test.go Github

copy

Full Screen

...36 if !reflect.DeepEqual(got, want) {37 t.Errorf("Grouping of step validation errors failed. got: %v, want: %v", got, want)38 }39}40func TestGetSuggestionMessageForStepImplNotFoundError(t *testing.T) {41 want := message[implNotFound]42 got := getSuggestionMessage(implNotFound)43 if got != want {44 t.Errorf("Wrong suggestion message. got: %v, want: %v", got, want)45 }46}47func TestFilterDuplicateSuggestions(t *testing.T) {48 dupImplFoundError := StepValidationError{49 errorType: &dupImplFound,50 suggestion: "suggestion1",51 }52 want := []string{"suggestion1"}53 got := filterDuplicateSuggestions([]StepValidationError{dupImplFoundError, dupImplFoundError})54 if !reflect.DeepEqual(want, got) {55 t.Errorf("Wrong suggestion message. got: %v, want: %v", got, want)56 }57}58func TestGetSuggestionMessageForOtherValidationErrors(t *testing.T) {59 want := "Suggestions for fixing `Duplicate step implementation` errors.\n"60 got := getSuggestionMessage(dupImplFound)61 if got != want {62 t.Errorf("Wrong suggestion message. got: %v, want: %v", got, want)63 }64}...

Full Screen

Full Screen

suggest.go

Source:suggest.go Github

copy

Full Screen

...11)12var message = map[gm.StepValidateResponse_ErrorType]string{13 gm.StepValidateResponse_STEP_IMPLEMENTATION_NOT_FOUND: "Add the following missing implementations to fix `Step implementation not found` errors.\n",14}15func showSuggestion(validationErrors validationErrors) {16 if !HideSuggestion {17 for t, errs := range groupErrors(validationErrors) {18 logger.Infof(true, getSuggestionMessage(t))19 suggestions := filterDuplicateSuggestions(errs)20 for _, suggestion := range suggestions {21 logger.Infof(true, suggestion)22 }23 }24 }25}26func filterDuplicateSuggestions(errors []StepValidationError) []string {27 suggestionMap := make(map[string]error)28 filteredSuggestions := make([]string, 0)29 for _, err := range errors {30 if _, ok := suggestionMap[err.Suggestion()]; !ok {31 suggestionMap[err.Suggestion()] = err32 filteredSuggestions = append(filteredSuggestions, err.Suggestion())33 }34 }35 return filteredSuggestions36}37func getSuggestionMessage(t gm.StepValidateResponse_ErrorType) string {38 if msg, ok := message[t]; ok {39 return msg40 }41 return fmt.Sprintf("Suggestions for fixing `%s` errors.\n", getMessage(t.String()))42}43func groupErrors(validationErrors validationErrors) map[gm.StepValidateResponse_ErrorType][]StepValidationError {44 errMap := make(map[gm.StepValidateResponse_ErrorType][]StepValidationError)45 for _, errs := range validationErrors {46 for _, v := range errs {47 if e, ok := v.(StepValidationError); ok && e.suggestion != "" {48 errType := *(v.(StepValidationError).errorType)49 errMap[errType] = append(errMap[errType], e)50 }51 }52 }53 return errMap54}...

Full Screen

Full Screen

Suggestion

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Enter your name")4 fmt.Scan(&name)5 if govalidator.IsAlpha(name) {6 fmt.Println("Valid name")7 } else {8 fmt.Println("Invalid name")9 fmt.Println("Did you mean", govalidator.Suggestion(name))10 }11}12import (13func main() {14 fmt.Println("Enter your name")15 fmt.Scan(&name)16 if govalidator.Contains(name, "Nikhil") {17 fmt.Println("Valid name")18 } else {19 fmt.Println("Invalid name")20 }21}22import (23func main() {24 fmt.Println("Enter your credit card number")25 fmt.Scan(&number)26 if govalidator.CreditCard(number) {27 fmt.Println("Valid credit card number")28 } else {29 fmt.Println("Invalid credit card number")30 }31}

Full Screen

Full Screen

Suggestion

Using AI Code Generation

copy

Full Screen

1import (2type User struct {3}4func main() {5 validate := validator.New()6 user := User{

Full Screen

Full Screen

Suggestion

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(govalidator.Suggestion("email"))4}5import (6func main() {7 fmt.Println(govalidator.Suggestion("email"))8}9import (10func main() {11 fmt.Println(govalidator.Suggestion("email"))12}13import (14func main() {15 fmt.Println(govalidator.Suggestion("email"))16}17import (18func main() {19 fmt.Println(govalidator.Suggestion("email"))20}

Full Screen

Full Screen

Suggestion

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Enter your name")4 fmt.Scanln(&name)5 if govalidator.IsAlpha(name) {6 fmt.Println("Valid name")7 } else {8 fmt.Println("Invalid name")9 fmt.Println("Suggestion", govalidator.Suggestion(name))10 }11}

Full Screen

Full Screen

Suggestion

Using AI Code Generation

copy

Full Screen

1func main() {2 fmt.Println("Enter your name")3 fmt.Scanln(&input)4 fmt.Println(validation.Suggestion(input))5}6func main() {7 fmt.Println("Enter your name")8 fmt.Scanln(&input)9 fmt.Println(validation.Suggestion(input))10}11func Suggestion(name string) string {12}13func main() {14 fmt.Println("Enter your name")15 fmt.Scanln(&input)16 fmt.Println(validation.Suggestion(input))17}18func main() {19 fmt.Println("Enter your name")20 fmt.Scanln(&input)21 fmt.Println(validation.Suggestion(input))22}

Full Screen

Full Screen

Suggestion

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 suggestions := levenshtein.Suggest("hello", []string{"world", "hello", "hell", "helo", "hella", "helllo"}, 2)4 fmt.Println(suggestions)5}6import (7func main() {8 distance := levenshtein.Distance("hello", "hella", 2)9 fmt.Println(distance)10}11import (12func main() {13 distance := levenshtein.DistanceForStrings([]rune("hello"), []rune("hella"), 2)14 fmt.Println(distance)15}16import (17func main() {18 distance := levenshtein.DistanceForBytes([]byte("hello"), []byte("hella"), 2)19 fmt.Println(distance)20}21import (

Full Screen

Full Screen

Suggestion

Using AI Code Generation

copy

Full Screen

1func main() {2 fmt.Println("Enter a string:")3 fmt.Scanf("%s", &s)4 val := validation.New()5 fmt.Println(val.Suggestion(s))6}7func main() {8 fmt.Println("Enter a string:")9 fmt.Scanf("%s", &s)10 val := validation.New()11 fmt.Println(val.Suggestion(s))12}13func main() {14 fmt.Println("Enter a string:")15 fmt.Scanf("%s", &s)16 val := validation.New()17 fmt.Println(val.Suggestion(s))18}19func main() {20 fmt.Println("Enter a string:")21 fmt.Scanf("%s", &s)22 val := validation.New()23 fmt.Println(val.Suggestion(s))24}25func main() {26 fmt.Println("Enter a string:")27 fmt.Scanf("%s", &s)28 val := validation.New()29 fmt.Println(val.Suggestion(s))30}31func main() {32 fmt.Println("Enter a string:")33 fmt.Scanf("%s", &s)34 val := validation.New()35 fmt.Println(val.Suggestion(s))36}37func main() {38 fmt.Println("Enter a string:")39 fmt.Scanf("%s", &s)40 val := validation.New()41 fmt.Println(val.Suggestion(s))42}43func main() {44 fmt.Println("Enter a string:")45 fmt.Scanf("%s", &s)46 val := validation.New()47 fmt.Println(val.Suggestion(s))48}49func main() {50 fmt.Println("Enter a string:")

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful