From 3a89736d78aee1ef2a5541e526ee261e1e79fd76 Mon Sep 17 00:00:00 2001 From: Julian Date: Tue, 10 Oct 2023 08:41:31 -0400 Subject: [PATCH] temporal changes --- src/api/mvc/data-types/main.go | 15 +++++++++-- src/api/mvc/variants/main.go | 4 +++ .../repositories/elasticsearch/variants.go | 7 +++++ src/api/services/variants/main.go | 26 +++++++++++++------ 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/api/mvc/data-types/main.go b/src/api/mvc/data-types/main.go index 9484056..dd8765a 100644 --- a/src/api/mvc/data-types/main.go +++ b/src/api/mvc/data-types/main.go @@ -1,6 +1,7 @@ package dataTypes import ( + "fmt" "net/http" "gohan/api/contexts" @@ -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{}{ @@ -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, diff --git a/src/api/mvc/variants/main.go b/src/api/mvc/variants/main.go index 08b9596..738191c 100644 --- a/src/api/mvc/variants/main.go +++ b/src/api/mvc/variants/main.go @@ -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 diff --git a/src/api/repositories/elasticsearch/variants.go b/src/api/repositories/elasticsearch/variants.go index 0cb65e8..661d7da 100644 --- a/src/api/repositories/elasticsearch/variants.go +++ b/src/api/repositories/elasticsearch/variants.go @@ -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", @@ -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'", + }, + }, }, } diff --git a/src/api/services/variants/main.go b/src/api/services/variants/main.go index 68d0c92..f63f631 100644 --- a/src/api/services/variants/main.go +++ b/src/api/services/variants/main.go @@ -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() @@ -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 } } } @@ -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)