@@ -6,6 +6,7 @@ require ( | |||||
github.com/astaxie/beego v1.12.3 | github.com/astaxie/beego v1.12.3 | ||||
github.com/casdoor/casdoor-go-sdk v0.3.3 | github.com/casdoor/casdoor-go-sdk v0.3.3 | ||||
github.com/go-sql-driver/mysql v1.6.0 | github.com/go-sql-driver/mysql v1.6.0 | ||||
github.com/tealeg/xlsx v1.0.5 | |||||
xorm.io/core v0.7.3 | xorm.io/core v0.7.3 | ||||
xorm.io/xorm v1.2.5 | xorm.io/xorm v1.2.5 | ||||
) | ) |
@@ -471,6 +471,8 @@ github.com/syndtr/goleveldb v0.0.0-20160425020131-cfa635847112/go.mod h1:Z4AUp2K | |||||
github.com/syndtr/goleveldb v0.0.0-20181127023241-353a9fca669c/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0= | github.com/syndtr/goleveldb v0.0.0-20181127023241-353a9fca669c/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0= | ||||
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE= | github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE= | ||||
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= | github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= | ||||
github.com/tealeg/xlsx v1.0.5 h1:+f8oFmvY8Gw1iUXzPk+kz+4GpbDZPK1FhPiQRd+ypgE= | |||||
github.com/tealeg/xlsx v1.0.5/go.mod h1:btRS8dz54TDnvKNosuAqxrM1QgN1udgk9O34bDCnORM= | |||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= | github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= | ||||
github.com/ugorji/go v0.0.0-20171122102828-84cb69a8af83/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ= | github.com/ugorji/go v0.0.0-20171122102828-84cb69a8af83/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ= | ||||
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= | github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= | ||||
@@ -0,0 +1,29 @@ | |||||
package object | |||||
import ( | |||||
"github.com/casbin/casbase/util" | |||||
"github.com/casbin/casbase/xlsx" | |||||
) | |||||
func uploadVectorNames(owner string, fileId string) bool { | |||||
table := xlsx.ReadXlsxFile(fileId) | |||||
vectors := []*Vector{} | |||||
for _, line := range table { | |||||
vector := &Vector{ | |||||
Name: line[0], | |||||
Data: []float64{}, | |||||
} | |||||
vectors = append(vectors, vector) | |||||
} | |||||
dataset := &Dataset{ | |||||
Owner: owner, | |||||
Name: "word", | |||||
CreatedTime: util.GetCurrentTime(), | |||||
DisplayName: "word", | |||||
Distance: 100, | |||||
Vectors: vectors, | |||||
} | |||||
return AddDataset(dataset) | |||||
} |
@@ -0,0 +1,9 @@ | |||||
package object | |||||
import "testing" | |||||
func TestUploadVectorNames(t *testing.T) { | |||||
InitConfig() | |||||
uploadVectorNames("admin", "../../tmpFiles/filename") | |||||
} |
@@ -0,0 +1,7 @@ | |||||
package util | |||||
import "fmt" | |||||
func GetUploadXlsxPath(fileId string) string { | |||||
return fmt.Sprintf("tmpFiles/%s.xlsx", fileId) | |||||
} |
@@ -0,0 +1,9 @@ | |||||
package util | |||||
import "time" | |||||
func GetCurrentTime() string { | |||||
timestamp := time.Now().Unix() | |||||
tm := time.Unix(timestamp, 0) | |||||
return tm.Format(time.RFC3339) | |||||
} |
@@ -0,0 +1,29 @@ | |||||
package xlsx | |||||
import ( | |||||
"github.com/casbin/casbase/util" | |||||
"github.com/tealeg/xlsx" | |||||
) | |||||
func ReadXlsxFile(fileId string) [][]string { | |||||
path := util.GetUploadXlsxPath(fileId) | |||||
file, err := xlsx.OpenFile(path) | |||||
if err != nil { | |||||
panic(err) | |||||
} | |||||
res := [][]string{} | |||||
for _, sheet := range file.Sheets { | |||||
for _, row := range sheet.Rows { | |||||
line := []string{} | |||||
for _, cell := range row.Cells { | |||||
text := cell.String() | |||||
line = append(line, text) | |||||
} | |||||
res = append(res, line) | |||||
} | |||||
break | |||||
} | |||||
return res | |||||
} |