You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

cloudbrain.go 3.5 kB

3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package convert
  2. import (
  3. "code.gitea.io/gitea/models"
  4. api "code.gitea.io/gitea/modules/structs"
  5. )
  6. func ToCloudBrain(task *models.Cloudbrain) *api.Cloudbrain {
  7. return &api.Cloudbrain{
  8. ID: task.ID,
  9. JobID: task.JobID,
  10. JobType: task.JobType,
  11. Type: task.Type,
  12. DisplayJobName: task.DisplayJobName,
  13. Status: task.Status,
  14. CreatedUnix: int64(task.CreatedUnix),
  15. RepoID: task.RepoID,
  16. Duration: task.Duration,
  17. TrainJobDuration: task.TrainJobDuration,
  18. ImageID: task.ImageID,
  19. Image: task.Image,
  20. Uuid: task.Uuid,
  21. DatasetName: task.DatasetName,
  22. ComputeResource: task.ComputeResource,
  23. AiCenter: task.AiCenter,
  24. BranchName: task.BranchName,
  25. Parameters: task.Parameters,
  26. BootFile: task.BootFile,
  27. Description: task.Description,
  28. ModelName: task.ModelName,
  29. VersionName: task.VersionName,
  30. ModelVersion: task.ModelVersion,
  31. CkptName: task.CkptName,
  32. StartTime: int64(task.StartTime),
  33. EndTime: int64(task.EndTime),
  34. Spec: ToSpecification(task.Spec),
  35. }
  36. }
  37. func ToAttachment(attachment *models.Attachment) *api.AttachmentShow {
  38. return &api.AttachmentShow{
  39. ID: attachment.ID,
  40. UUID: attachment.UUID,
  41. DatasetID: attachment.DatasetID,
  42. ReleaseID: attachment.ReleaseID,
  43. UploaderID: attachment.UploaderID,
  44. CommentID: attachment.CommentID,
  45. Name: attachment.Name,
  46. Description: attachment.Description,
  47. DownloadCount: attachment.DownloadCount,
  48. UseNumber: attachment.UseNumber,
  49. Size: attachment.Size,
  50. IsPrivate: attachment.IsPrivate,
  51. DecompressState: attachment.DecompressState,
  52. Type: attachment.Type,
  53. CreatedUnix: int64(attachment.CreatedUnix),
  54. }
  55. }
  56. func ToDataset(dataset *models.Dataset) *api.Dataset {
  57. var convertAttachments []*api.AttachmentShow
  58. for _, attachment := range dataset.Attachments {
  59. convertAttachments = append(convertAttachments, ToAttachment(attachment))
  60. }
  61. return &api.Dataset{
  62. ID: dataset.ID,
  63. Title: dataset.Title,
  64. Status: dataset.Status,
  65. Category: dataset.Category,
  66. Description: dataset.Description,
  67. DownloadTimes: dataset.DownloadTimes,
  68. UseCount: dataset.UseCount,
  69. NumStars: dataset.NumStars,
  70. Recommend: dataset.Recommend,
  71. License: dataset.License,
  72. Task: dataset.Task,
  73. ReleaseID: dataset.ReleaseID,
  74. UserID: dataset.UserID,
  75. RepoID: dataset.RepoID,
  76. Repo: &api.RepositoryShow{
  77. OwnerName: dataset.Repo.OwnerName,
  78. Name: dataset.Repo.Name,
  79. },
  80. CreatedUnix: int64(dataset.CreatedUnix),
  81. UpdatedUnix: int64(dataset.UpdatedUnix),
  82. Attachments: convertAttachments,
  83. }
  84. }
  85. func ToSpecification(s *models.Specification) *api.SpecificationShow {
  86. if s == nil {
  87. return nil
  88. }
  89. return &api.SpecificationShow{
  90. ID: s.ID,
  91. AccCardsNum: s.AccCardsNum,
  92. AccCardType: s.AccCardType,
  93. CpuCores: s.CpuCores,
  94. MemGiB: s.MemGiB,
  95. GPUMemGiB: s.GPUMemGiB,
  96. ShareMemGiB: s.ShareMemGiB,
  97. ComputeResource: s.ComputeResource,
  98. UnitPrice: s.UnitPrice,
  99. }
  100. }
  101. func ToTagger(user *models.User) *api.Tagger {
  102. return &api.Tagger{
  103. ID: user.ID,
  104. Name: user.Name,
  105. RelAvatarURL: user.RelAvatarLink(),
  106. Email: user.Email,
  107. }
  108. }