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.4 kB

3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. ModelVersion: task.ModelVersion,
  30. CkptName: task.CkptName,
  31. StartTime: int64(task.StartTime),
  32. EndTime: int64(task.EndTime),
  33. Spec: ToSpecification(task.Spec),
  34. }
  35. }
  36. func ToAttachment(attachment *models.Attachment) *api.AttachmentShow {
  37. return &api.AttachmentShow{
  38. ID: attachment.ID,
  39. UUID: attachment.UUID,
  40. DatasetID: attachment.DatasetID,
  41. ReleaseID: attachment.ReleaseID,
  42. UploaderID: attachment.UploaderID,
  43. CommentID: attachment.CommentID,
  44. Name: attachment.Name,
  45. Description: attachment.Description,
  46. DownloadCount: attachment.DownloadCount,
  47. UseNumber: attachment.UseNumber,
  48. Size: attachment.Size,
  49. IsPrivate: attachment.IsPrivate,
  50. DecompressState: attachment.DecompressState,
  51. Type: attachment.Type,
  52. CreatedUnix: int64(attachment.CreatedUnix),
  53. }
  54. }
  55. func ToDataset(dataset *models.Dataset) *api.Dataset {
  56. var convertAttachments []*api.AttachmentShow
  57. for _, attachment := range dataset.Attachments {
  58. convertAttachments = append(convertAttachments, ToAttachment(attachment))
  59. }
  60. return &api.Dataset{
  61. ID: dataset.ID,
  62. Title: dataset.Title,
  63. Status: dataset.Status,
  64. Category: dataset.Category,
  65. Description: dataset.Description,
  66. DownloadTimes: dataset.DownloadTimes,
  67. UseCount: dataset.UseCount,
  68. NumStars: dataset.NumStars,
  69. Recommend: dataset.Recommend,
  70. License: dataset.License,
  71. Task: dataset.Task,
  72. ReleaseID: dataset.ReleaseID,
  73. UserID: dataset.UserID,
  74. RepoID: dataset.RepoID,
  75. Repo: &api.RepositoryShow{
  76. OwnerName: dataset.Repo.OwnerName,
  77. Name: dataset.Repo.Name,
  78. },
  79. CreatedUnix: int64(dataset.CreatedUnix),
  80. UpdatedUnix: int64(dataset.UpdatedUnix),
  81. Attachments: convertAttachments,
  82. }
  83. }
  84. func ToSpecification(s *models.Specification) *api.SpecificationShow {
  85. return &api.SpecificationShow{
  86. ID: s.ID,
  87. AccCardsNum: s.AccCardsNum,
  88. AccCardType: s.AccCardType,
  89. CpuCores: s.CpuCores,
  90. MemGiB: s.MemGiB,
  91. GPUMemGiB: s.GPUMemGiB,
  92. ShareMemGiB: s.ShareMemGiB,
  93. ComputeResource: s.ComputeResource,
  94. UnitPrice: s.UnitPrice,
  95. }
  96. }
  97. func ToTagger(user *models.User) *api.Tagger {
  98. return &api.Tagger{
  99. Name: user.Name,
  100. RelAvatarURL: user.RelAvatarLink(),
  101. Email: user.Email,
  102. }
  103. }