Skip to content

Commit

Permalink
temporal changes
Browse files Browse the repository at this point in the history
  • Loading branch information
noctillion committed Oct 10, 2023
1 parent 5340a7f commit 3a89736
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
15 changes: 13 additions & 2 deletions src/api/mvc/data-types/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dataTypes

import (
"fmt"
"net/http"

"gohan/api/contexts"
Expand All @@ -20,13 +21,16 @@ var variantDataTypeJson = map[string]interface{}{
}

func GetDataTypes(c echo.Context) error {
es := c.(*contexts.GohanContext).Es7Client
cfg := c.(*contexts.GohanContext).Config
gc := c.(*contexts.GohanContext)
cfg := gc.Config
es := gc.Es7Client

// accumulate number of variants associated with each
// sampleId fetched from the variants overview
resultsMap, err := variantService.GetVariantsOverview(es, cfg)

fmt.Printf("resultsMapDDD: %v\n", resultsMap)

if err != nil {
// Could not talk to Elasticsearch, return an error
return c.JSON(http.StatusInternalServerError, map[string]interface{}{
Expand All @@ -36,6 +40,13 @@ func GetDataTypes(c echo.Context) error {

variantDataTypeJson["count"] = sumAllValues(resultsMap["sampleIDs"])

// Fetch the last_created value from resultsMap and add to variantDataTypeJson
if latestCreated, ok := resultsMap["last_created_time"].(string); ok {
variantDataTypeJson["last_created"] = latestCreated
}

fmt.Printf("variantDataTypeJson: %v\n", variantDataTypeJson)

// Data types are basically stand-ins for schema blocks
return c.JSON(http.StatusOK, []map[string]interface{}{
variantDataTypeJson,
Expand Down
4 changes: 4 additions & 0 deletions src/api/mvc/variants/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,10 @@ func GetLastCreatedVariantForDataset(c echo.Context) string {

g.Go(func() error {
timestamp, timestampError := esRepo.GetMostRecentVariantTimestamp(cfg, es, dataset.String())
fmt.Printf("timestamp: %v\n", timestamp)
fmt.Printf("timestampError: %v\n", timestampError)
fmt.Printf("timestampError == nil: %v\n", es)
fmt.Printf("timestampError == nil: %v\n", dataset.String())
if timestampError != nil {
fmt.Printf("Failed to fetch the most recent 'created' timestamp for dataset %s. Error: %v\n", dataset, timestampError)
return timestampError
Expand Down
7 changes: 7 additions & 0 deletions src/api/repositories/elasticsearch/variants.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ func CountDocumentsContainerVariantOrSampleIdInPositionRange(cfg *models.Config,

func GetVariantsBucketsByKeyword(cfg *models.Config, es *elasticsearch.Client, keyword string) (map[string]interface{}, error) {
// begin building the request body.
fmt.Printf("Query StartKEYWORD: %s\n", keyword)
var buf bytes.Buffer
aggMap := map[string]interface{}{
"size": "0",
Expand All @@ -602,6 +603,12 @@ func GetVariantsBucketsByKeyword(cfg *models.Config, es *elasticsearch.Client, k
},
},
},
"latest_created": map[string]interface{}{
"max": map[string]interface{}{
"field": "createdTime",
"format": "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
},
},
},
}

Expand Down
26 changes: 18 additions & 8 deletions src/api/services/variants/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func GetVariantsOverview(es *elasticsearch.Client, cfg *models.Config) (map[stri
defer _wg.Done()

results, bucketsError := esRepo.GetVariantsBucketsByKeyword(cfg, es, keyword)
fmt.Printf("resultsCFCFCF: %v\n", results)
if bucketsError != nil {
resultsMux.Lock()
defer resultsMux.Unlock()
Expand All @@ -45,14 +46,17 @@ func GetVariantsOverview(es *elasticsearch.Client, cfg *models.Config) (map[stri

// retrieve aggregations.items.buckets
bucketsMapped := []interface{}{}
if aggs, aggsOk := results["aggregations"]; aggsOk {
aggsMapped := aggs.(map[string]interface{})

if items, itemsOk := aggsMapped["items"]; itemsOk {
itemsMapped := items.(map[string]interface{})

if buckets, bucketsOk := itemsMapped["buckets"]; bucketsOk {
bucketsMapped = buckets.([]interface{})
if aggs, aggsOk := results["aggregations"].(map[string]interface{}); aggsOk {
if latest, latestOk := aggs["latest_created"].(map[string]interface{}); latestOk {
if valueAsString, valOk := latest["value_as_string"].(string); valOk {
resultsMux.Lock()
resultsMap["last_created_time"] = valueAsString
resultsMux.Unlock()
}
}
if items, itemsOk := aggs["items"].(map[string]interface{}); itemsOk {
if buckets, bucketsOk := items["buckets"].([]interface{}); bucketsOk {
bucketsMapped = buckets
}
}
}
Expand All @@ -77,6 +81,12 @@ func GetVariantsOverview(es *elasticsearch.Client, cfg *models.Config) (map[stri
return nil, errors.New("could not contact Elasticsearch - make sure it's running")
}

// Extract latest created time
if latest, exists := resultsMap["last_created"].(map[string]interface{}); exists {
latestCreatedTime := latest["value_as_string"].(string)
resultsMap["last_created_time"] = latestCreatedTime
}

// get distribution of chromosomes
wg.Add(1)
go callGetBucketsByKeyword("chromosomes", "chrom.keyword", &wg)
Expand Down

0 comments on commit 3a89736

Please sign in to comment.