Skip to content

Commit

Permalink
change data type of sid to be string
Browse files Browse the repository at this point in the history
  • Loading branch information
keara-soloway committed Jan 14, 2025
1 parent 1743fd9 commit 42b3b0a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
6 changes: 3 additions & 3 deletions motorsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
var MotorsDb *sql.DB

type MotorRecord struct {
ScanId float64
ScanId string
Motors map[string]float64
}

Expand All @@ -30,7 +30,7 @@ type MotorPositionQuery struct {
Max float64
}
type MotorsDbQuery struct {
Sids []float64
Sids []string
MotorPositionQueries []MotorPositionQuery
}

Expand Down Expand Up @@ -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
}
Expand Down
17 changes: 9 additions & 8 deletions record.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"log"
"strconv"
"time"

schema "github.com/CHESSComputing/golib/beamlines"
Expand All @@ -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"`
Expand All @@ -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"`
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions static/schema.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[
{
"key": "sid",
"type": "float64",
"type": "string",
"optional": true,
"description": "Scan ID (usually same as start_time)",
"description": "Scan ID",
"utils": ""
},
{
Expand Down
2 changes: 1 addition & 1 deletion static/sql/mysql.sql
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion static/sql/sqlite.sql
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down

0 comments on commit 42b3b0a

Please sign in to comment.