package store import ( "github.com/nspcc-dev/neo-go/pkg/interop/native/std" "github.com/nspcc-dev/neo-go/pkg/interop/storage" ) type User struct { balance int titanic int diabetes int punk_rock []string } const storeURLKey = "storeURL" func _deploy(data interface{}, isUpdate bool) { if isUpdate { return } ctx := storage.GetContext() storeURL := "" storage.Put(ctx, storeURLKey, storeURL) } func NewUser(name string) { ctx := storage.GetContext() existingUser := storage.Get(ctx, name) if existingUser != nil { panic("user already exists") } punk_rock := make([]string, 0) user := User{ balance: 1000, titanic: -1, diabetes: -1, punk_rock: punk_rock, } storage.Put(ctx, name, std.Serialize(user)) } func getUser(name string) User { ctx := storage.GetReadOnlyContext() data := storage.Get(ctx, name) if data == nil { panic("user not found") } return std.Deserialize(data.([]byte)).(User) } func Balance(name string) int { u := getUser(name) return u.balance } func Titanic(name string) int { u := getUser(name) return u.titanic } func Diabetes(name string) int { u := getUser(name) return u.diabetes } func Punk_rock(name string) []string { u := getUser(name) return u.punk_rock } func DiabetesModel(name string, age int, sex int, w int, h int) { h = h / 100 var bmi int = w / (h * h) user := getUser(name) //Predicted = 152.1335 + age*138.9039 + sex*-36.1353 + bmi*926.9120 var predicted = (1521335 + age*1389039 + sex*-361353 + bmi*9269120) / 100 user.diabetes = predicted user.balance -= 400 ctx := storage.GetContext() storage.Put(ctx, name, std.Serialize(user)) /* f, err := os.Open("diabetes.csv") if err != nil { log.Fatal(err) } defer f.Close() reader := csv.NewReader(f) reader.FieldsPerRecord = -1 trainingData, err := reader.ReadAll() if err != nil { log.Fatal(err) } var r regression.Regression r.SetObserved("y") r.SetVar(0, "age") r.SetVar(1, "sex") r.SetVar(2, "bmi") for i, record := range trainingData { if i == 0 { continue } yVal, err := strconv.ParseFloat(record[10], 64) if err != nil { log.Fatal(err) } ageVal, err := strconv.ParseFloat(record[0], 64) if err != nil { log.Fatal(err) } sexVal, err := strconv.ParseFloat(record[1], 64) if err != nil { log.Fatal(err) } bmiVal, err := strconv.ParseFloat(record[2], 64) if err != nil { log.Fatal(err) } r.Train(regression.DataPoint(yVal, []float64{ageVal, sexVal, bmiVal})) } r.Run() Predicted, err := r.Predict([]float64{age, sex, bmi}) if err != nil { log.Fatal(err) }*/ } func TitanicModel(name string, age int, sibSp int, parch int, embarked int, sex int, pclass int) { user := getUser(name) //Predicted = 0.9438 + Age*-0.0065 + SibSp*-0.0507 + Parch*-0.0081 + Embarked*-0.0320 + Sex*0.4848 + Pclass*-0.1973 var predicted = (9438 + age*-65 + sibSp*-507 + parch*-81 + embarked*-320 + sex*4848 + pclass*-1973) / 100 user.titanic = predicted user.balance -= 400 ctx := storage.GetContext() storage.Put(ctx, name, std.Serialize(user)) /* f, err := os.Open("titanic_numeric.csv") if err != nil { log.Fatal(err) } defer f.Close() reader := csv.NewReader(f) reader.FieldsPerRecord = 7 trainingData, err := reader.ReadAll() if err != nil { log.Fatal(err) } var r regression.Regression r.SetObserved("Survived") r.SetVar(0, "Age") r.SetVar(1, "SibSp") r.SetVar(2, "Parch") r.SetVar(3, "Embarked") r.SetVar(4, "Sex") r.SetVar(5, "Pclass") for i, record := range trainingData { if i == 0 { continue } survivedVal, err := strconv.ParseFloat(record[6], 64) if err != nil { log.Fatal(err) } ageVal, err := strconv.ParseFloat(record[0], 64) if err != nil { log.Fatal(err) } sibSpVal, err := strconv.ParseFloat(record[1], 64) if err != nil { log.Fatal(err) } parchVal, err := strconv.ParseFloat(record[2], 64) if err != nil { log.Fatal(err) } embarkedVal, err := strconv.ParseFloat(record[3], 64) if err != nil { log.Fatal(err) } sexVal, err := strconv.ParseFloat(record[4], 64) if err != nil { log.Fatal(err) } pclassVal, err := strconv.ParseFloat(record[5], 64) if err != nil { log.Fatal(err) } r.Train(regression.DataPoint(survivedVal, []float64{ageVal, sibSpVal, parchVal, embarkedVal, sexVal, pclassVal})) } r.Run() predicted, err := r.Predict([]float64{age, sibSp, parch, embarked, sex, pclass}) if err != nil { log.Fatal(err) } */ } func Punk_Rock(name string, group string) { user := getUser(name) punkRockGroups := []string{"Йорш", "Элизиум", "Бригадный подряд", "Порнофильмы"} for _, g := range punkRockGroups { if group == g { user.punk_rock = append(user.punk_rock, "good") } else { user.punk_rock = append(user.punk_rock, "hmm") } } user.balance -= 700 ctx := storage.GetContext() storage.Put(ctx, name, std.Serialize(user)) }