From 42b3b0a9dad9cf2f452e963f18b78aed174a746b Mon Sep 17 00:00:00 2001 From: keara-soloway Date: Tue, 14 Jan 2025 13:07:57 -0500 Subject: [PATCH] change data type of sid to be string --- motorsdb.go | 6 +++--- record.go | 17 +++++++++-------- static/schema.json | 4 ++-- static/sql/mysql.sql | 2 +- static/sql/sqlite.sql | 2 +- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/motorsdb.go b/motorsdb.go index 32364f9..eddefd5 100644 --- a/motorsdb.go +++ b/motorsdb.go @@ -19,7 +19,7 @@ import ( var MotorsDb *sql.DB type MotorRecord struct { - ScanId float64 + ScanId string Motors map[string]float64 } @@ -30,7 +30,7 @@ type MotorPositionQuery struct { Max float64 } type MotorsDbQuery struct { - Sids []float64 + Sids []string MotorPositionQueries []MotorPositionQuery } @@ -95,7 +95,7 @@ func QueryMotorPosition(mne string, pos float64) []MotorRecord { return queryMotorsDb(query) } -func GetMotorRecords(sids ...float64) ([]MotorRecord, error) { +func GetMotorRecords(sids ...string) ([]MotorRecord, error) { query := MotorsDbQuery{Sids: sids} return queryMotorsDb(query), nil } diff --git a/record.go b/record.go index 3b1ac99..da12dd1 100644 --- a/record.go +++ b/record.go @@ -2,6 +2,7 @@ package main import ( "log" + "strconv" "time" schema "github.com/CHESSComputing/golib/beamlines" @@ -13,7 +14,7 @@ import ( var Schema *schema.Schema type UserRecord struct { - ScanId float64 `json:"sid,omitempty" mapstructure:"did,omitempty"` + ScanId string `json:"sid,omitempty" mapstructure:"sid,omitempty"` DatasetId string `json:"did" mapstructure:"did"` Cycle string `json:"cycle" mapstructure:"cycle"` Beamline string `json:"beamline" mapstructure:"beamline"` @@ -30,7 +31,7 @@ type UserRecord struct { } type MongoRecord struct { - ScanId float64 `mapstructure:"sid"` + ScanId string `mapstructure:"sid"` DatasetId string `mapstructure:"did"` Cycle string `mapstructure:"cycle"` Beamline string `mapstructure:"beamline"` @@ -60,12 +61,12 @@ func InitSchemaManager() { // reside in the MongoDB, and the motor positions (which will reside in the SQL // db). func DecomposeRecord(user_record UserRecord) (MongoRecord, MotorRecord) { - var scan_id float64 - if user_record.ScanId < 0 { + var scan_id string + if user_record.ScanId == "test" { // This is a test record, so force a unique scan id - scan_id = float64(time.Now().UnixNano()) + scan_id = strconv.Itoa(int(time.Now().UnixNano())) } else { - scan_id = user_record.StartTime * 1e9 + scan_id = strconv.Itoa(int(user_record.StartTime * 1e9)) } mongo_record := MongoRecord{ ScanId: scan_id, @@ -116,7 +117,7 @@ func CompleteMongoRecords(mongo_records ...MongoRecord) ([]UserRecord, error) { if len(mongo_records) == 0 { return user_records, nil } - var sids []float64 + var sids []string for _, mongo_record := range mongo_records { sids = append(sids, mongo_record.ScanId) } @@ -140,7 +141,7 @@ func CompleteMotorRecords(motor_records ...MotorRecord) ([]UserRecord, error) { if len(motor_records) == 0 { return user_records, nil } - var sids []float64 + var sids []string for _, motor_record := range motor_records { sids = append(sids, motor_record.ScanId) } diff --git a/static/schema.json b/static/schema.json index 75f4f0d..59eccee 100644 --- a/static/schema.json +++ b/static/schema.json @@ -1,9 +1,9 @@ [ { "key": "sid", - "type": "float64", + "type": "string", "optional": true, - "description": "Scan ID (usually same as start_time)", + "description": "Scan ID", "utils": "" }, { diff --git a/static/sql/mysql.sql b/static/sql/mysql.sql index 86e1408..c04e8e0 100644 --- a/static/sql/mysql.sql +++ b/static/sql/mysql.sql @@ -1,6 +1,6 @@ CREATE TABLE IF NOT EXISTS ScanIds ( scan_id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, -sid BIGINT UNSIGNED NOT NULL UNIQUE +sid VARCHAR(50) NOT NULL UNIQUE ); CREATE TABLE IF NOT EXISTS MotorMnes ( diff --git a/static/sql/sqlite.sql b/static/sql/sqlite.sql index 42fe5a2..5ba2263 100644 --- a/static/sql/sqlite.sql +++ b/static/sql/sqlite.sql @@ -1,6 +1,6 @@ CREATE TABLE IF NOT EXISTS ScanIds ( scan_id INTEGER PRIMARY KEY AUTOINCREMENT, -sid FLOAT(8) NOT NULL UNIQUE +sid VARCHAR(50) NOT NULL UNIQUE ); CREATE TABLE IF NOT EXISTS MotorMnes (