fix
This commit is contained in:
+32
-25
@@ -3,10 +3,10 @@ package control_case
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/otiai10/copy"
|
||||
@@ -22,16 +22,19 @@ type ControlCase struct {
|
||||
}
|
||||
|
||||
type Params struct {
|
||||
gorm.Model
|
||||
ID uint `toml:"-" csv:"id"`
|
||||
Rel float64 `toml:"rel" csv:"rel"`
|
||||
RelC float64 `toml:"rel_c" csv:"rel_c"`
|
||||
Le float64 `toml:"le" csv:"le"`
|
||||
Pr float64 `toml:"pr" csv:"pr"`
|
||||
Pe float64 `toml:"pe" csv:"pe"`
|
||||
InitialCondition string `toml:"-" csv:"initial_condition"`
|
||||
Time float64 `toml:"time" csv:"time"`
|
||||
FolderPath string `toml:"-" csv:"-"`
|
||||
ID uint `gorm:"primaryKey" json:"id" toml:"-" csv:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"`
|
||||
Rel float64 `json:"rel" toml:"rel" csv:"rel"`
|
||||
RelC float64 `json:"rel_c" toml:"rel_c" csv:"rel_c"`
|
||||
Le float64 `json:"le" toml:"le" csv:"le"`
|
||||
Pr float64 `json:"pr" toml:"pr" csv:"pr"`
|
||||
Pe float64 `json:"pe" toml:"pe" csv:"pe"`
|
||||
Ma float64 `json:"ma" toml:"ma" csv:"ma"`
|
||||
InitialCondition string `json:"initial_condition" toml:"-" csv:"initial_condition"`
|
||||
Time float64 `json:"time" toml:"time" csv:"time"`
|
||||
FolderPath string `json:"folder_path" toml:"-" csv:"-"`
|
||||
}
|
||||
|
||||
func (p *Params) ToTOML(filename string) error {
|
||||
@@ -45,37 +48,40 @@ func (p *Params) ToTOML(filename string) error {
|
||||
return encoder.Encode(p)
|
||||
}
|
||||
|
||||
func (u *Params) AfterCreate(tx *gorm.DB) (err error) {
|
||||
control_case := ControlCase{ParamsID: u.ID, Status: "N"}
|
||||
tx.Create(&control_case)
|
||||
return
|
||||
}
|
||||
func (p *Params) Exist() (bool, error) {
|
||||
folderPath := filepath.Join("./", fmt.Sprintf("%d", p.ID))
|
||||
return exists(folderPath)
|
||||
}
|
||||
func (p *Params) CreateFolder() {
|
||||
func (p *Params) CreateFolder() error {
|
||||
BIN_PATH := "./bio-convect"
|
||||
folderPath := filepath.Join("./", fmt.Sprintf("%d", p.ID))
|
||||
os.MkdirAll(folderPath, os.ModePerm)
|
||||
if err := os.MkdirAll(folderPath, os.ModePerm); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("folder: %s\n", folderPath)
|
||||
execPath := filepath.Join("./", folderPath, BIN_PATH)
|
||||
err := copy.Copy(BIN_PATH, execPath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
if p.InitialCondition != "E" {
|
||||
startPath := filepath.Join("./", folderPath, "storag.h5")
|
||||
if err := os.Chmod(execPath, 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
if p.InitialCondition != "" && p.InitialCondition != "E" {
|
||||
startPath := filepath.Join("./", folderPath, "storage.h5")
|
||||
err = copy.Copy(p.InitialCondition, startPath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
p.ToTOML(filepath.Join(folderPath, "config.toml"))
|
||||
if err := p.ToTOML(filepath.Join(folderPath, "config.toml")); err != nil {
|
||||
return err
|
||||
}
|
||||
p.FolderPath = folderPath
|
||||
return nil
|
||||
|
||||
}
|
||||
func (p *Params) Run(ctx context.Context) {
|
||||
func (p *Params) Run(ctx context.Context) error {
|
||||
BIN_PATH := "./bio-convect"
|
||||
cmd := exec.CommandContext(ctx, BIN_PATH)
|
||||
cmd.Dir = p.FolderPath
|
||||
@@ -86,7 +92,8 @@ func (p *Params) Run(ctx context.Context) {
|
||||
err := cmd.Run()
|
||||
fmt.Printf("afrer run")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user