Skip to content

Commit

Permalink
*changes according to discussion.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsuhinin committed Jan 24, 2024
1 parent f7dc098 commit ef3eb20
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
21 changes: 13 additions & 8 deletions pkg/api/aim/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,24 +191,29 @@ func GetProjectParams(c *fiber.Ctx) error {
).Joins(
"INNER JOIN experiments ON experiments.experiment_id = runs.experiment_id AND experiments.namespace_id = ?",
ns.ID,
).Preload(
).Joins(
"Context",
).Where(
"runs.lifecycle_stage = ?", database.LifecycleStageActive,
).Find(&metrics); tx.Error != nil {
return fmt.Errorf("error retrieving metric keys: %w", tx.Error)
}

data := make(map[string][]fiber.Map, len(metrics))
data, mapped := make(map[string][]fiber.Map, len(metrics)), make(map[string]map[string]fiber.Map, len(metrics))
for _, metric := range metrics {
// to be properly decoded by AIM UI, json should be represented as a key:value object.
context := fiber.Map{}
if err := json.Unmarshal(metric.Context.Json, &context); err != nil {
return eris.Wrap(err, "error unmarshalling `context` json to `fiber.Map` object")
if mapped[metric.Key] == nil {
mapped[metric.Key] = map[string]fiber.Map{}
}
if _, ok := mapped[metric.Key][metric.Context.GetJsonHash()]; !ok {
// to be properly decoded by AIM UI, json should be represented as a key:value object.
context := fiber.Map{}
if err := json.Unmarshal(metric.Context.Json, &context); err != nil {
return eris.Wrap(err, "error unmarshalling `context` json to `fiber.Map` object")
}
mapped[metric.Key][metric.Context.GetJsonHash()] = context
data[metric.Key] = append(data[metric.Key], context)
}
data[metric.Key] = append(data[metric.Key], context)
}

resp[s] = data
default:
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("%q is not a valid Sequence", s))
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/aim/runs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ func SearchAlignedMetrics(c *fiber.Ctx) error {
" FROM params AS p"+
" LEFT JOIN latest_metrics AS lm USING(run_uuid, key, context_id)"+
" INNER JOIN contexts ON contexts.id = lm.context_id"+
" ) rm USING(run_uuid)"+
" ) rm USING(run_uuid, context_id)"+
" INNER JOIN runs AS r ON m.run_uuid = r.run_uuid"+
" INNER JOIN experiments AS e ON r.experiment_id = e.experiment_id AND e.namespace_id = ?"+
" WHERE m.key = ?"+
Expand Down
7 changes: 7 additions & 0 deletions pkg/database/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package database

import (
"context"
"crypto/sha256"
"database/sql"
"database/sql/driver"
"encoding/hex"
Expand Down Expand Up @@ -167,6 +168,12 @@ type Context struct {
Json datatypes.JSON `gorm:"not null;unique;index"`
}

// GetJsonHash returns hash of the Context.Json
func (c Context) GetJsonHash() string {
hash := sha256.Sum256(c.Json)
return string(hash[:])
}

type AlembicVersion struct {
Version string `gorm:"column:version_num;type:varchar(32);not null;primaryKey"`
}
Expand Down

0 comments on commit ef3eb20

Please sign in to comment.