github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/modelarts/v2/dataset/requests.go (about)

     1  package dataset
     2  
     3  import (
     4  	"github.com/chnsz/golangsdk"
     5  	"github.com/chnsz/golangsdk/pagination"
     6  )
     7  
     8  type CreateOpts struct {
     9  	DataFormat           string                `json:"data_format,omitempty"`
    10  	DataSources          []DataSource          `json:"data_sources,omitempty"`
    11  	DatasetName          string                `json:"dataset_name" required:"true"`
    12  	DatasetType          int                   `json:"dataset_type,omitempty"`
    13  	Description          string                `json:"description,omitempty"`
    14  	ImportAnnotations    *bool                 `json:"import_annotations,omitempty"`
    15  	ImportData           bool                  `json:"import_data,omitempty"`
    16  	LabelFormat          LabelFormat           `json:"label_format,omitempty"`
    17  	Labels               []Label               `json:"labels,omitempty"`
    18  	Managed              bool                  `json:"managed,omitempty"`
    19  	Schema               []Field               `json:"schema,omitempty"`
    20  	WorkPath             string                `json:"work_path" required:"true"`
    21  	WorkPathType         int                   `json:"work_path_type"`
    22  	WorkforceInformation *WorkforceInformation `json:"workforce_information,omitempty"`
    23  	WorkspaceId          string                `json:"workspace_id,omitempty"`
    24  }
    25  
    26  type DataSource struct {
    27  	DataPath         string      `json:"data_path,omitempty"`
    28  	DataType         int         `json:"data_type,omitempty"`
    29  	SchemaMaps       []SchemaMap `json:"schema_maps,omitempty"`
    30  	SourceInfo       SourceInfo  `json:"source_info,omitempty"`
    31  	WithColumnHeader *bool       `json:"with_column_header,omitempty"`
    32  }
    33  
    34  type SchemaMap struct {
    35  	DestName string `json:"dest_name,omitempty"`
    36  	SrcName  string `json:"src_name,omitempty"`
    37  }
    38  
    39  type SourceInfo struct {
    40  	ClusterId    string `json:"cluster_id,omitempty"`
    41  	ClusterMode  string `json:"cluster_mode,omitempty"`
    42  	ClusterName  string `json:"cluster_name,omitempty"`
    43  	DatabaseName string `json:"database_name,omitempty"`
    44  	Input        string `json:"input,omitempty"`
    45  	Ip           string `json:"ip,omitempty"`
    46  	Port         string `json:"port,omitempty"`
    47  	QueueName    string `json:"queue_name,omitempty"`
    48  	SubnetId     string `json:"subnet_id,omitempty"`
    49  	TableName    string `json:"table_name,omitempty"`
    50  	UserName     string `json:"user_name,omitempty"`
    51  	UserPassword string `json:"user_password,omitempty"`
    52  	VpcId        string `json:"vpc_id,omitempty"`
    53  }
    54  
    55  type LabelFormat struct {
    56  	LabelType           string `json:"label_type,omitempty"`
    57  	TextLabelSeparator  string `json:"text_label_separator,omitempty"`
    58  	TextSampleSeparator string `json:"text_sample_separator,omitempty"`
    59  }
    60  
    61  type Label struct {
    62  	Attributes []LabelAttribute `json:"attributes,omitempty"`
    63  	Name       string           `json:"name,omitempty"`
    64  	Property   LabelProperty    `json:"property,omitempty"`
    65  	Type       *int             `json:"type,omitempty"`
    66  }
    67  
    68  type LabelAttribute struct {
    69  	DefaultValue string              `json:"default_value,omitempty"`
    70  	Id           string              `json:"id,omitempty"`
    71  	Name         string              `json:"name,omitempty"`
    72  	Type         string              `json:"type,omitempty"`
    73  	Values       LabelAttributeValue `json:"values,omitempty"`
    74  }
    75  
    76  type LabelAttributeValue struct {
    77  	Id    string `json:"id,omitempty"`
    78  	Value string `json:"value,omitempty"`
    79  }
    80  
    81  type LabelProperty struct {
    82  	Color        string `json:"@modelarts:color,omitempty"`
    83  	DefaultShape string `json:"@modelarts:default_shape,omitempty"`
    84  	FromType     string `json:"@modelarts:from_type,omitempty"`
    85  	RenameTo     string `json:"@modelarts:rename_to,omitempty"`
    86  	Shortcut     string `json:"@modelarts:shortcut,omitempty"`
    87  	ToType       string `json:"@modelarts:to_type,omitempty"`
    88  }
    89  
    90  type Field struct {
    91  	Description string `json:"description,omitempty"`
    92  	Name        string `json:"name,omitempty"`
    93  	SchemaId    int    `json:"schema_id,omitempty"`
    94  	Type        string `json:"type,omitempty"`
    95  }
    96  
    97  type WorkforceInformation struct {
    98  	DataSyncType                *int             `json:"data_sync_type,omitempty"`
    99  	Repetition                  int              `json:"repetition,omitempty"`
   100  	SynchronizeAutoLabelingData *bool            `json:"synchronize_auto_labeling_data,omitempty"`
   101  	SynchronizeData             *bool            `json:"synchronize_data,omitempty"`
   102  	TaskId                      string           `json:"task_id,omitempty"`
   103  	TaskName                    string           `json:"task_name" required:"true"`
   104  	WorkforcesConfig            WorkforcesConfig `json:"workforces_config,omitempty"`
   105  }
   106  
   107  type WorkforcesConfig struct {
   108  	Agency     string            `json:"agency,omitempty"`
   109  	Workforces []WorkforceConfig `json:"workforces,omitempty"`
   110  }
   111  
   112  type WorkforceConfig struct {
   113  	Workers       []Worker `json:"workers,omitempty"`
   114  	WorkforceId   string   `json:"workforce_id,omitempty"`
   115  	WorkforceName string   `json:"workforce_name,omitempty"`
   116  }
   117  
   118  type Worker struct {
   119  	CreateTime  *int   `json:"create_time,omitempty"`
   120  	Description string `json:"description,omitempty"`
   121  	Email       string `json:"email,omitempty"`
   122  	Role        *int   `json:"role,omitempty"`
   123  	Status      *int   `json:"status,omitempty"`
   124  	UpdateTime  *int   `json:"update_time,omitempty"`
   125  	WorkerId    string `json:"worker_id,omitempty"`
   126  	WorkforceId string `json:"workforce_id,omitempty"`
   127  }
   128  
   129  type UpdateOpts struct {
   130  	AddLabels        []Label `json:"add_labels,omitempty"`
   131  	CurrentVersionId string  `json:"current_version_id,omitempty"`
   132  	DatasetName      string  `json:"dataset_name,omitempty"`
   133  	DeleteLabels     []Label `json:"delete_labels,omitempty"`
   134  	Description      *string `json:"description,omitempty"`
   135  	UpdateLabels     []Label `json:"update_labels,omitempty"`
   136  }
   137  
   138  type ListOpts struct {
   139  	CheckRunningTask   bool   `q:"check_running_task,omitempty"`
   140  	ContainVersions    *bool  `q:"contain_versions,omitempty"`
   141  	DatasetType        *int   `q:"dataset_type,omitempty"`
   142  	FilePreview        bool   `q:"file_preview,omitempty"`
   143  	Limit              *int   `q:"limit,omitempty"`
   144  	Offset             int    `q:"offset,omitempty"`
   145  	Order              string `q:"order,omitempty"`
   146  	RunningTaskType    *int   `q:"running_task_type,omitempty"`
   147  	SearchContent      string `q:"search_content,omitempty"`
   148  	SortBy             string `q:"sort_by,omitempty"`
   149  	SupportExport      bool   `q:"support_export,omitempty"`
   150  	TrainEvaluateRatio string `q:"train_evaluate_ratio,omitempty"`
   151  	VersionFormat      *int   `q:"version_format,omitempty"`
   152  	WithLabels         bool   `q:"with_labels,omitempty"`
   153  	WorkspaceId        string `q:"workspace_id,omitempty"`
   154  }
   155  
   156  type GetOpts struct {
   157  	CheckRunningTask bool `q:"check_running_task,omitempty"`
   158  	RunningTaskType  *int `q:"running_task_type,omitempty"`
   159  }
   160  
   161  var RequestOpts = golangsdk.RequestOpts{
   162  	MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"},
   163  }
   164  
   165  func Create(c *golangsdk.ServiceClient, opts CreateOpts) (*CreateResp, error) {
   166  	b, err := golangsdk.BuildRequestBody(opts, "")
   167  	if err != nil {
   168  		return nil, err
   169  	}
   170  
   171  	var rst CreateResp
   172  	_, err = c.Post(createURL(c), b, &rst, &golangsdk.RequestOpts{
   173  		MoreHeaders: RequestOpts.MoreHeaders,
   174  	})
   175  
   176  	return &rst, err
   177  }
   178  
   179  func Get(c *golangsdk.ServiceClient, id string, opts GetOpts) (*Dataset, error) {
   180  	var rst Dataset
   181  
   182  	url := getURL(c, id)
   183  	query, err := golangsdk.BuildQueryString(opts)
   184  	if err != nil {
   185  		return nil, err
   186  	}
   187  	url += query.String()
   188  
   189  	_, err = c.Get(url, &rst, &golangsdk.RequestOpts{
   190  		MoreHeaders: RequestOpts.MoreHeaders,
   191  	})
   192  	return &rst, err
   193  }
   194  
   195  func Update(c *golangsdk.ServiceClient, id string, opts UpdateOpts) *golangsdk.ErrResult {
   196  	var rst golangsdk.ErrResult
   197  	b, err := golangsdk.BuildRequestBody(opts, "")
   198  	if err != nil {
   199  		rst.Err = err
   200  		return &rst
   201  	}
   202  
   203  	_, rst.Err = c.Put(updateURL(c, id), b, &rst.Body, &golangsdk.RequestOpts{
   204  		MoreHeaders: RequestOpts.MoreHeaders,
   205  	})
   206  
   207  	return &rst
   208  }
   209  
   210  func Delete(c *golangsdk.ServiceClient, id string) *golangsdk.ErrResult {
   211  	url := deleteURL(c, id)
   212  	var rst golangsdk.ErrResult
   213  	_, rst.Err = c.Delete(url, &golangsdk.RequestOpts{
   214  		MoreHeaders: RequestOpts.MoreHeaders,
   215  	})
   216  
   217  	return &rst
   218  }
   219  
   220  func List(c *golangsdk.ServiceClient, opts ListOpts) (*pagination.Pager, error) {
   221  	url := listURL(c)
   222  	query, err := golangsdk.BuildQueryString(opts)
   223  	if err != nil {
   224  		return nil, err
   225  	}
   226  	url += query.String()
   227  
   228  	page := pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page {
   229  		p := DatasetPage{pagination.OffsetPageBase{PageResult: r}}
   230  		return p
   231  	})
   232  
   233  	return &page, nil
   234  }