You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
117 lines
2.9 KiB
117 lines
2.9 KiB
package projects
|
|
|
|
import (
|
|
"git.aiterp.net/stufflog3/stufflog3/entities"
|
|
"git.aiterp.net/stufflog3/stufflog3/models"
|
|
"git.aiterp.net/stufflog3/stufflog3/usecases/items"
|
|
"time"
|
|
)
|
|
|
|
type Entry struct {
|
|
ID int `json:"id"`
|
|
OwnerID string `json:"ownerId"`
|
|
CreatedTime time.Time `json:"createdTime"`
|
|
Name string `json:"name"`
|
|
Status models.Status `json:"status"`
|
|
}
|
|
|
|
func generateEntry(project entities.Project) Entry {
|
|
return Entry{
|
|
ID: project.ID,
|
|
OwnerID: project.OwnerID,
|
|
CreatedTime: project.CreatedTime,
|
|
Name: project.Name,
|
|
Status: project.Status,
|
|
}
|
|
}
|
|
|
|
type Result struct {
|
|
entities.Project
|
|
Requirements []ResultRequirement `json:"requirements"`
|
|
}
|
|
|
|
type ResultRequirement struct {
|
|
ID int `json:"id"`
|
|
Name string `json:"name"`
|
|
Description string `json:"description"`
|
|
Status models.Status `json:"status"`
|
|
Stats []ResultRequirementStat `json:"stats"`
|
|
Items []items.Result `json:"items"`
|
|
}
|
|
|
|
type ResultRequirementStat struct {
|
|
ID int `json:"id"`
|
|
Name string `json:"name"`
|
|
Weight float64 `json:"weight"`
|
|
Acquired int `json:"acquired"`
|
|
Required int `json:"required"`
|
|
Planned int `json:"planned"`
|
|
}
|
|
|
|
func generateResult(
|
|
project entities.Project,
|
|
requirement []entities.Requirement,
|
|
requirementStats []entities.RequirementStat,
|
|
projectItems []items.Result,
|
|
stats []entities.Stat,
|
|
) Result {
|
|
res := Result{
|
|
Project: project,
|
|
Requirements: make([]ResultRequirement, 0, 8),
|
|
}
|
|
|
|
for _, req := range requirement {
|
|
if req.ProjectID != project.ID {
|
|
continue
|
|
}
|
|
|
|
resReq := ResultRequirement{
|
|
ID: req.ID,
|
|
Name: req.Name,
|
|
Description: req.Description,
|
|
Status: req.Status,
|
|
Stats: make([]ResultRequirementStat, 0, 8),
|
|
Items: make([]items.Result, 0, 8),
|
|
}
|
|
statIndices := make(map[int]int)
|
|
for _, reqStat := range requirementStats {
|
|
if reqStat.RequirementID != req.ID {
|
|
continue
|
|
}
|
|
|
|
resStat := ResultRequirementStat{
|
|
ID: reqStat.StatID,
|
|
Required: reqStat.Required,
|
|
}
|
|
for _, stat := range stats {
|
|
if stat.ID == resStat.ID {
|
|
resStat.Name = stat.Name
|
|
resStat.Weight = stat.Weight
|
|
break
|
|
}
|
|
}
|
|
|
|
resReq.Stats = append(resReq.Stats, resStat)
|
|
statIndices[reqStat.StatID] = len(resReq.Stats) - 1
|
|
}
|
|
|
|
for _, item := range projectItems {
|
|
if item.ProjectRequirementID == nil || *item.ProjectRequirementID != req.ID {
|
|
continue
|
|
}
|
|
|
|
for _, stat := range item.Stats {
|
|
if statIndex, ok := statIndices[stat.ID]; ok {
|
|
resReq.Stats[statIndex].Acquired += stat.Acquired
|
|
resReq.Stats[statIndex].Planned += stat.Required
|
|
}
|
|
}
|
|
|
|
resReq.Items = append(resReq.Items, item)
|
|
}
|
|
|
|
res.Requirements = append(res.Requirements, resReq)
|
|
}
|
|
|
|
return res
|
|
}
|