How to use Select method of prog Package

Best Syzkaller code snippet using prog.Select

prog.go

Source:prog.go Github

copy

Full Screen

1package models2import (3 "database/sql"4 "fmt"5 "time"6 "github.com/lib/pq"7)8// Prog model includes fields for a better readability in frontend and matching9// pre programmation fields10type Prog struct {11 CommissionID int64 `json:"CommissionID"`12 CommissionDate NullTime `json:"CommissionDate"`13 CommissionName string `json:"CommissionName"`14 ActionID int64 `json:"ActionID"`15 ActionCode int64 `json:"ActionCode"`16 ActionName string `json:"ActionName"`17 Kind int64 `json:"Kind"`18 KindID NullInt64 `json:"KindID"`19 KindName NullString `json:"KindName"`20 ForecastValue NullInt64 `json:"ForecastValue"`21 ForecastComment NullString `json:"ForecastComment"`22 PreProgValue NullInt64 `json:"PreProgValue"`23 PreProgComment NullString `json:"PreProgComment"`24 ID NullInt64 `json:"ID"`25 Value NullInt64 `json:"Value"`26 Comment NullString `json:"Comment"`27}28// Progs embeddes an array of Prog for json export29type Progs struct {30 Progs []Prog `json:"Prog"`31}32// ProgLine is used to decode one line of Prog batch33type ProgLine struct {34 CommissionID int64 `json:"CommissionID"`35 Value int64 `json:"Value"`36 Kind int64 `json:"Kind"`37 KindID NullInt64 `json:"KindID"`38 Comment NullString `json:"Comment"`39 ActionID int64 `json:"ActionID"`40}41// ProgBatch embeddes an array of ProgLine to import a batch42type ProgBatch struct {43 Lines []ProgLine `json:"Prog"`44}45// ProgYears embeddes an array of int64 for json export fetching the available46// years with programmation data in the database47type ProgYears struct {48 Years []int64 `json:"ProgYear"`49}50// CumulatedProgrammation is used for json export51type CumulatedProgrammation struct {52 Programmation []MonthCumulatedValue `json:"Programmation"`53}54// GetAll fetches all Prog of a given year from the database55func (p *Progs) GetAll(year int64, db *sql.DB) error {56 rows, err := db.Query(`WITH p AS (SELECT * FROM prog WHERE year=$1),57 pp AS (SELECT * FROM pre_prog WHERE year=$1)58 SELECT q.commission_id,c.date,c.name,q.action_id,b.code,b.name,q.kind,q.kind_id,59 q.kind_name,q.forecast_value,q.forecast_comment,q.pre_prog_value,60 q.pre_prog_comment,q.id,q.value,q.prog_comment61 FROM62 (63 SELECT p.id,COALESCE(p.commission_id,pre.commission_id) AS commission_id,64 COALESCE(p.action_id,pre.action_id) as action_id,65 p.value,pre.pre_prog_value,NULL::int as kind_id,1 as kind,66 NULL::varchar(150) as kind_name,p.comment as prog_comment,67 pre.pre_prog_comment,pre.forecast_value,pre.forecast_comment68 FROM p69 FULL OUTER JOIN70 (SELECT DISTINCT COALESCE(pp.commission_id,hf.commission_id) AS commission_id,71 pp.value AS pre_prog_value,pp.comment AS pre_prog_comment,72 COALESCE(pp.action_id,hf.action_id) AS action_id,hf.value AS forecast_value,73 hf.comment AS forecast_comment74 FROM pp 75 FULL OUTER JOIN76 (SELECT DISTINCT hf.commission_id, hf.action_id, hf.value,hf.comment 77 FROM housing_forecast hf 78 JOIN commission co ON hf.commission_id=co.id79 WHERE extract(year FROM co.date) = $1) hf80 ON pp.commission_id=hf.commission_id AND pp.action_id=hf.action_id AND pp.value=hf.value81 WHERE pp.kind=1 OR pp.kind ISNULL) pre82 ON p.commission_id=pre.commission_id AND p.action_id=pre.action_id AND p.value=pre.pre_prog_value83 WHERE p.kind ISNULL or p.kind=184 UNION ALL85 SELECT pc.id,COALESCE(pc.commission_id,pre.commission_id) AS commission_id,86 COALESCE(pc.action_id,pre.action_id) as action_id,87 pc.value,pre.pre_prog_value,COALESCE(pc.kind_id,pre.kind_id) AS kind_id,88 2 as kind,COALESCE(pc.name,pre.name) as kind_name,pc.comment as prog_comment,89 pre.pre_prog_comment,pre.forecast_value, pre.forecast_comment90 FROM91 (SELECT p.id,p.year,p.commission_id,p.value,p.kind_id,p.kind,p.comment,92 c.name,p.action_id93 FROM p94 JOIN copro c ON p.kind_id=c.id95 WHERE kind=296 ) pc97 FULL OUTER JOIN98 (SELECT DISTINCT COALESCE(pp.commission_id,cf.commission_id) AS commission_id,99 pp.value AS pre_prog_value,2::int as kind,COALESCE(pp.kind_id,cf.kind_id) AS kind_id,100 COALESCE(c.name,cf.name) as name,pp.comment as pre_prog_comment,101 COALESCE(pp.action_id,cf.action_id) AS action_id,cf.value as forecast_value,102 cf.comment AS forecast_comment103 FROM pp104 JOIN copro c ON pp.kind_id=c.id 105 FULL OUTER JOIN106 (SELECT DISTINCT cf.commission_id, cf.action_id, cf.value,cf.comment,107 cf.copro_id as kind_id,c.name108 FROM copro_forecast cf 109 JOIN commission co ON cf.commission_id=co.id110 JOIN copro c ON cf.copro_id=c.id111 WHERE extract(year FROM co.date) = $1) cf112 ON pp.commission_id=cf.commission_id AND pp.action_id=cf.action_id 113 AND pp.kind_id=cf.kind_id AND pp.value=cf.value114 WHERE pp.kind=2 OR pp.kind ISNULL115 ) pre116 ON pc.commission_id=pre.commission_id AND pc.action_id=pre.action_id117 AND pc.kind_id=pre.kind_id AND pc.value=pre.pre_prog_value118 WHERE pc.kind ISNULL or pc.kind=2119 120 UNION ALL121 122 SELECT pc.id,COALESCE(pc.commission_id,pre.commission_id) AS commission_id,123 COALESCE(pc.action_id,pre.action_id) as action_id,pc.value,124 pre.pre_prog_value AS pre_prog_value,COALESCE(pc.kind_id,pre.kind_id) AS kind_id,125 3 AS kind,COALESCE(pc.name,pre.name) as kind_name,pc.comment as prog_comment,126 pre.pre_prog_comment,pre.forecast_value,pre.forecast_comment127 FROM128 (SELECT p.id,p.year,p.commission_id,p.value,p.kind_id,p.kind,p.comment,129 c.name,p.action_id130 FROM p131 JOIN renew_project c132 ON p.kind_id=c.id133 WHERE kind=3) pc134 FULL OUTER JOIN135 (SELECT DISTINCT 136 COALESCE(pp.commission_id,rf.commission_id) AS commission_id,pp.value AS pre_prog_value,137 COALESCE(pp.kind_id,rf.kind_id) AS kind_id,COALESCE(c.name,rf.name) AS name,138 pp.comment AS pre_prog_comment,COALESCE(pp.action_id,rf.action_id) AS action_id,139 rf.value AS forecast_value,rf.comment AS forecast_comment140 FROM pp141 JOIN renew_project c ON pp.kind_id=c.id142 FULL OUTER JOIN143 (SELECT DISTINCT rf.commission_id, rf.action_id, rf.value,rf.comment,144 rf.renew_project_id as kind_id,rp.name145 FROM renew_project_forecast rf 146 JOIN commission co ON rf.commission_id=co.id147 JOIN renew_project rp ON rf.renew_project_id=rp.id148 WHERE extract(year FROM co.date) = $1) rf149 ON pp.commission_id=rf.commission_id AND pp.action_id=rf.action_id150 AND pp.kind_id=rf.kind_id AND pp.value=rf.value151 WHERE pp.kind=3 OR pp.kind ISNULL152 ) pre153 ON pc.commission_id=pre.commission_id AND pc.action_id=pre.action_id154 AND pc.kind_id=pre.kind_id AND pc.value=pre.pre_prog_value155 WHERE pc.kind ISNULL or pc.kind=3156 ) q157 JOIN budget_action b ON q.action_id=b.id158 JOIN commission c ON q.commission_id=c.id159 ORDER BY date,kind,code,kind_id`, year)160 if err != nil {161 return fmt.Errorf("select %v", err)162 }163 var row Prog164 defer rows.Close()165 for rows.Next() {166 if err = rows.Scan(&row.CommissionID, &row.CommissionDate, &row.CommissionName,167 &row.ActionID, &row.ActionCode, &row.ActionName, &row.Kind, &row.KindID,168 &row.KindName, &row.ForecastValue, &row.ForecastComment, &row.PreProgValue,169 &row.PreProgComment, &row.ID, &row.Value, &row.Comment); err != nil {170 return fmt.Errorf("scan %v", err)171 }172 p.Progs = append(p.Progs, row)173 }174 err = rows.Err()175 if err != nil {176 return fmt.Errorf("rows err %v", err)177 }178 if len(p.Progs) == 0 {179 p.Progs = []Prog{}180 }181 return nil182}183// Save insert a batch of ProgLine into the database. It checks if the184// batch includes only one year , otherwise throw an error. It replaces all the185// datas of the given year, deleting the programming data of that year186// in the database187func (p *ProgBatch) Save(year int64, db *sql.DB) error {188 for i, l := range p.Lines {189 if l.CommissionID == 0 {190 return fmt.Errorf("ligne %d, CommissionID nul", i+1)191 }192 if l.Value == 0 {193 return fmt.Errorf("ligne %d, Value nul", i+1)194 }195 if l.ActionID == 0 {196 return fmt.Errorf("ligne %d, ActionID nul", i+1)197 }198 if l.Kind != KindCopro && l.Kind != KindRenewProject && l.Kind != KindHousing {199 return fmt.Errorf("linge %d, Kind de mauvais type", i+1)200 }201 }202 tx, err := db.Begin()203 if err != nil {204 return fmt.Errorf("tx begin %v", err)205 }206 stmt, err := tx.Prepare(pq.CopyIn("temp_prog", "commission_id",207 "year", "value", "kind", "kind_id", "comment", "action_id"))208 if err != nil {209 return fmt.Errorf("insert statement %v", err)210 }211 defer stmt.Close()212 for _, l := range p.Lines {213 if _, err = stmt.Exec(l.CommissionID, year, l.Value, l.Kind, l.KindID,214 l.Comment, l.ActionID); err != nil {215 tx.Rollback()216 return fmt.Errorf("statement execution %v", err)217 }218 }219 if _, err = stmt.Exec(); err != nil {220 tx.Rollback()221 return fmt.Errorf("statement flush exec %v", err)222 }223 if _, err = tx.Exec(`DELETE FROM prog WHERE year=$1`, year); err != nil {224 tx.Rollback()225 return fmt.Errorf("delete query %v", err)226 }227 queries := []string{`INSERT INTO prog (commission_id,year,value,kind,kind_id,228 comment,action_id) SELECT DISTINCT commission_id,year,value,kind,kind_id,229 comment,action_id FROM temp_prog `,230 `DELETE from temp_prog`,231 }232 for i, q := range queries {233 _, err = tx.Exec(q)234 if err != nil {235 tx.Rollback()236 return fmt.Errorf("requête %d : %s", i, err.Error())237 }238 }239 return tx.Commit()240}241// GetAll fetches all programmation years in the database242func (p *ProgYears) GetAll(db *sql.DB) error {243 rows, err := db.Query(`SELECT DISTINCT year from prog`)244 if err != nil {245 return fmt.Errorf("select %v", err)246 }247 var y int64248 defer rows.Close()249 for rows.Next() {250 if err = rows.Scan(&y); err != nil {251 return fmt.Errorf("scan %v", err)252 }253 p.Years = append(p.Years, y)254 }255 err = rows.Err()256 if err != nil {257 return fmt.Errorf("rows err %v", err)258 }259 if len(p.Years) == 0 {260 p.Years = []int64{}261 }262 return nil263}264// GetAll fetches all cumulated programmation value of the current year265func (c *CumulatedProgrammation) GetAll(db *sql.DB) error {266 query := `WITH prg_month as (267 select max(extract(month from c.date))::int as max_month268 from prog,commission c 269 where prog.year=$1 and prog.commission_id=c.id)270 SELECT prg.m,SUM(0.01 * prg.v) OVER (ORDER BY m) FROM271 (SELECT q.m as m,COALESCE(prg.v,0) as v FROM272 (SELECT generate_series(1,max_month) AS m from prg_month) q273 LEFT OUTER JOIN274 (SELECT EXTRACT(month FROM c.date)::int AS m,sum(prog.value)::bigint AS v FROM275 prog,commission c WHERE prog.year=$1 AND prog.commission_id=c.id276 GROUP BY 1) prg277 ON q.m=prg.m) prg;`278 actualYear := time.Now().Year()279 rows, err := db.Query(query, actualYear)280 if err != nil {281 return fmt.Errorf("select %v", err)282 }283 defer rows.Close()284 var row MonthCumulatedValue285 for rows.Next() {286 if err = rows.Scan(&row.Month, &row.Value); err != nil {287 return fmt.Errorf("scan %v", err)288 }289 c.Programmation = append(c.Programmation, row)290 }291 err = rows.Err()292 if err != nil {293 return fmt.Errorf("rows err %v", err)294 }295 if len(c.Programmation) == 0 {296 c.Programmation = []MonthCumulatedValue{}297 }298 return nil299}...

Full Screen

Full Screen

programmer.go

Source:programmer.go Github

copy

Full Screen

1package controllers2import (3 "fmt"4 "os"5 "context"6 "strconv"7 "reflect"8 // "strings"9 "time"10 "crypto/md5"11 "encoding/hex"12 "github.com/gofiber/fiber/v2"13 "github.com/jackc/pgconn"14 "github.com/jackc/pgx/v4"15 "github.com/go-playground/validator/v10"16 "github.com/ganindrag/go-task-tracker/konst"17 "github.com/ganindrag/go-task-tracker/utils"18 jwt "github.com/form3tech-oss/jwt-go"19)20type Programmer struct {21 Id int `json:"id"`22 Name string `json:"name" validate:"required"`23 Email string `json:"email" validate:"required,email"`24 Password string `json:"password,omitempty"`25 Role string `json:"role" validate:"required"`26}27func (prog Programmer) ValidateStruct() map[string]string {28 validate := validator.New()29 err := validate.Struct(prog)30 if err != nil {31 return utils.ParseValidator(err.(validator.ValidationErrors))32 }33 return nil34}35func GetProgrammer(c *fiber.Ctx) error {36 conn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE_URL"))37 if err != nil {38 fmt.Println(err.Error())39 return fiber.NewError(500, "Cannot connect to the database!")40 }41 defer conn.Close(context.Background());42 rows, err := conn.Query(context.Background(), "select id, name, email, role from programmer where id <> 1")43 if err != nil {44 fmt.Println(err.Error())45 return fiber.NewError(500, err.Error())46 }47 var result []Programmer48 for rows.Next() {49 var programmer Programmer50 if err := rows.Scan(&programmer.Id, &programmer.Name, &programmer.Email, &programmer.Role); err != nil {51 fmt.Println(err.Error())52 panic(err)53 } else {54 result = append(result, programmer)55 }56 }57 return c.JSON(result)58}59func GetSingleProgrammer(c *fiber.Ctx) error {60 conn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE_URL"))61 if err != nil {62 fmt.Println(err.Error())63 return fiber.NewError(500, "Cannot connect to the database!")64 }65 defer conn.Close(context.Background());66 67 var prog Programmer68 prog.Id, err = strconv.Atoi(c.Params("id"))69 err = conn.QueryRow(context.Background(), "select id, name, email, role from programmer where id = $1", prog.Id).Scan(&prog.Id, &prog.Name, &prog.Email, &prog.Role)70 if err != nil {71 fmt.Println(err.Error())72 return fiber.NewError(500, "Data not found!")73 }74 return c.JSON(prog)75}76func CreateProgrammer(c *fiber.Ctx) error {77 conn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE_URL"))78 if err != nil {79 fmt.Println(err.Error())80 return fiber.NewError(500, "Cannot connect to the database!")81 }82 defer conn.Close(context.Background())83 var prog Programmer84 if err := c.BodyParser(&prog); err != nil {85 return fiber.NewError(400, err.Error())86 }87 if errValidator := prog.ValidateStruct(); errValidator != nil {88 return c.Status(400).JSON(fiber.Map{89 "message": errValidator,90 })91 }92 err = conn.QueryRow(context.Background(), "select nextval('programmer_id_seq'::regclass);").Scan(&prog.Id)93 if err != nil {94 return err95 }96 commandTag, err := conn.Exec(context.Background(), "insert into programmer(name, email, password, role) values($1, $2, md5($3), $4);", prog.Name, prog.Email, prog.Password, prog.Role)97 if err != nil {98 fmt.Println(err.Error())99 if err, ok := err.(*pgconn.PgError); ok && err.Code == konst.UniqViolation {100 return fiber.NewError(500, "Data already been used!")101 }102 return err103 }104 if commandTag.RowsAffected() > 0 {105 prog.Password = ""106 return c.Status(201).JSON(fiber.Map{107 "message": "Success",108 "data": prog,109 })110 }111 fmt.Println("prog not saved", prog)112 return c.JSON(fiber.Map{113 "message": "Success but not saved",114 })115}116func UpdateProgrammer(c *fiber.Ctx) error {117 conn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE_URL"))118 if err != nil {119 fmt.Println(err.Error())120 return fiber.NewError(500, "Cannot connect to the database!")121 }122 defer conn.Close(context.Background())123 124 var prog Programmer125 prog.Id, err = strconv.Atoi(c.Params("id"))126 var idExists uint8127 err = conn.QueryRow(context.Background(), "select 1 from programmer where id = $1", prog.Id).Scan(&idExists)128 if err != nil {129 fmt.Println(err.Error())130 return fiber.NewError(404, "Data Not Found")131 }132 if err := c.BodyParser(&prog); err != nil {133 return fiber.NewError(400, err.Error())134 }135 if prog.Password != "" {136 passByte := md5.Sum([]byte(prog.Password))137 prog.Password = hex.EncodeToString(passByte[:])138 }139 140 // if errValidator := ValidateStruct(prog); errValidator != nil {141 // return c.Status(400).JSON(fiber.Map{142 // "message": errValidator,143 // })144 // }145 sqlUpdate, paramsUpdate := utils.ParseStructToUpdateSql(reflect.TypeOf(prog), reflect.ValueOf(prog))146 sql := fmt.Sprintf("update programmer set %s where id = $1;", sqlUpdate)147 _, err = conn.Exec(context.Background(), sql, paramsUpdate...)148 if err != nil {149 fmt.Println(err.Error())150 fmt.Println(sql)151 fmt.Println(sqlUpdate)152 return err153 }154 return c.JSON(fiber.Map{155 "message": "Success",156 })157}158func DeleteProgrammer(c *fiber.Ctx) error {159 conn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE_URL"))160 if err != nil {161 fmt.Println(err.Error())162 return fiber.NewError(500, "Cannot connect to the database!")163 }164 defer conn.Close(context.Background())165 166 var prog Programmer167 prog.Id, err = strconv.Atoi(c.Params("id"))168 commandTag, err := conn.Exec(context.Background(), "delete from feedback where programmer_id = $1;", prog.Id)169 commandTag, err = conn.Exec(context.Background(), "delete from programmer where id = $1;", prog.Id)170 if err != nil {171 fmt.Println(err.Error())172 return err173 }174 if commandTag.RowsAffected() > 0 {175 return c.JSON(fiber.Map{176 "message": "Success",177 })178 }179 return fiber.NewError(404, "Data not found!")180}181func Login(c *fiber.Ctx) error {182 conn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE_URL"))183 if err != nil {184 fmt.Println(err.Error())185 return fiber.NewError(500, "Cannot connect to the database!")186 }187 defer conn.Close(context.Background())188 var prog Programmer189 if err := c.BodyParser(&prog); err != nil {190 return fiber.NewError(400, err.Error())191 }192 err = conn.QueryRow(context.Background(), "select id, name, email, password, role from programmer where email=$1 and password=md5($2)", prog.Email, prog.Password).Scan(&prog.Id, &prog.Name, &prog.Email, &prog.Password, &prog.Role)193 if err != nil {194 return fiber.NewError(401, "Email or Password incorrect!")195 }196 token := jwt.New(jwt.SigningMethodHS256)197 // Set claims198 claims := token.Claims.(jwt.MapClaims)199 claims["id"] = prog.Id200 claims["name"] = prog.Name201 claims["email"] = prog.Email202 claims["role"] = prog.Role203 claims["exp"] = time.Now().Add(time.Hour * 8).Unix()204 // Generate encoded token and send it as response.205 t, err := token.SignedString([]byte("mysecret"))206 if err != nil {207 return c.SendStatus(fiber.StatusInternalServerError)208 }209 return c.JSON(fiber.Map{"token": t})210}211func CheckAuth(c *fiber.Ctx) error {212 conn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE_URL"))213 if err != nil {214 fmt.Println(err.Error())215 return fiber.NewError(500, "Cannot connect to the database!")216 }217 defer conn.Close(context.Background());218 219 user := c.Locals("user").(*jwt.Token).Claims.(jwt.MapClaims)220 var prog Programmer221 err = conn.QueryRow(context.Background(), "select id, name, email, role from programmer where id = $1", user["id"].(float64)).Scan(&prog.Id, &prog.Name, &prog.Email, &prog.Role)222 if err != nil {223 fmt.Println(err.Error())224 return fiber.NewError(500, "Data User not found!")225 }226 return c.JSON(prog)227}...

Full Screen

Full Screen

tasks.go

Source:tasks.go Github

copy

Full Screen

...25}26// LoadTasksProgression fetches the progression of one student against27// the given tasks.28func LoadTasksProgression(db DB, idStudent teacher.IdStudent, idTasks []IdTask) (map[IdTask]TaskProgressionHeader, error) {29 tasks, err := SelectTasks(db, idTasks...)30 if err != nil {31 return nil, utils.SQLError(err)32 }33 exercices, err := ed.SelectExercices(db, tasks.IdExercices()...)34 if err != nil {35 return nil, utils.SQLError(err)36 }37 links1, err := SelectProgressionsByIdStudents(db, idStudent)38 if err != nil {39 return nil, utils.SQLError(err)40 }41 // collect the student progressions (we load all the student progression)42 extendedProgressions, err := loadProgressions(db, links1)43 if err != nil {44 return nil, utils.SQLError(err)45 }46 // load the questions of each exercice47 links2, err := ed.SelectExerciceQuestionsByIdExercices(db, exercices.IDs()...)48 if err != nil {49 return nil, utils.SQLError(err)50 }51 questionsByExercice := links2.ByIdExercice()52 progressionsByTask := links1.ByIdTask()53 out := make(map[IdTask]TaskProgressionHeader, len(tasks))54 for _, task := range tasks {55 // select the right progression, which may be empty56 // before the student starts the exercice,57 // that is progs has either length one or zero58 progs, hasProg := progressionsByTask[task.Id]59 var idProg IdProgression60 if hasProg {61 idProg = progs.IDs()[0]62 }63 exercice := exercices[task.IdExercice]64 questions := questionsByExercice[task.IdExercice]65 progression := extendedProgressions[idProg]66 out[task.Id] = TaskProgressionHeader{67 Id: task.Id,68 IdExercice: exercice.Id,69 TitleExercice: exercice.Title,70 HasProgression: hasProg,71 Progression: progression,72 Bareme: questions.Bareme(),73 Mark: computeMark(questions, progression.Questions),74 }75 }76 return out, nil77}78// loadProgressions loads the progression contents79func loadProgressions(db DB, prs Progressions) (map[IdProgression]ed.ProgressionExt, error) {80 // select the associated exercices81 exercices := make(ed.IdExerciceSet)82 for _, pr := range prs {83 exercices.Add(pr.IdExercice)84 }85 links1, err := ed.SelectExerciceQuestionsByIdExercices(db, exercices.Keys()...)86 if err != nil {87 return nil, utils.SQLError(err)88 }89 questionsExesMap := links1.ByIdExercice() // reference from the exercice90 links2, err := SelectProgressionQuestionsByIdProgressions(db, prs.IDs()...)91 if err != nil {92 return nil, utils.SQLError(err)93 }94 questionsProgMap := links2.ByIdProgression() // (incomplete) progression of the student95 out := make(map[IdProgression]ed.ProgressionExt, len(prs))96 for _, pr := range prs {97 questions := questionsExesMap[pr.IdExercice]98 questions.EnsureOrder()99 // beware that some questions may not have a link item yet100 progExt := ed.ProgressionExt{101 Questions: make([]ed.QuestionHistory, len(questions)),102 }103 prog := questionsProgMap[pr.Id]104 for _, link := range prog {105 progExt.Questions[link.Index] = ed.QuestionHistory(link.History)106 }107 progExt.InferNextQuestion()108 out[pr.Id] = progExt109 }110 return out, nil111}112// updateProgression write the question results for the given progression.113func updateProgression(db *sql.DB, prog Progression, questions []ed.QuestionHistory) error {114 tx, err := db.Begin()115 if err != nil {116 return utils.SQLError(err)117 }118 _, err = DeleteProgressionQuestionsByIdProgressions(tx, prog.Id)119 if err != nil {120 return utils.SQLError(err)121 }122 links := make(ProgressionQuestions, len(questions))123 for i, qu := range questions {124 links[i] = ProgressionQuestion{125 IdProgression: prog.Id,126 IdExercice: prog.IdExercice,127 Index: i,128 History: QuestionHistory(qu),129 }130 }131 err = InsertManyProgressionQuestions(tx, links...)132 if err != nil {133 return utils.SQLError(err)134 }135 err = tx.Commit()136 if err != nil {137 return utils.SQLError(err)138 }139 return nil140}141// loadOrCreateProgressionFor ensures a progression item exists for142// the given task and student, and returns it.143func loadOrCreateProgressionFor(db DB, idTask IdTask, idStudent teacher.IdStudent) (Progression, error) {144 task, err := SelectTask(db, idTask)145 if err != nil {146 return Progression{}, utils.SQLError(err)147 }148 prog, has, err := SelectProgressionByIdStudentAndIdTask(db, idStudent, idTask)149 if err != nil {150 return Progression{}, utils.SQLError(err)151 }152 if has {153 return prog, nil154 }155 // else, create an entry156 prog, err = Progression{IdStudent: idStudent, IdTask: idTask, IdExercice: task.IdExercice}.Insert(db)157 if err != nil {158 return Progression{}, utils.SQLError(err)159 }160 return prog, nil161}162// EvaluateTaskExercice calls `editor.EvaluateTaskExercice` and registers163// the student progression, returning the updated mark.164// If needed, a new progression item is created.165func EvaluateTaskExercice(db *sql.DB, idTask IdTask, idStudent teacher.IdStudent, ex ed.EvaluateExerciceIn) (out ed.EvaluateExerciceOut, mark int, err error) {166 out, err = ed.EvaluateExercice(db, ex)167 if err != nil {168 return169 }170 // persists the progression on DB ...171 prog, err := loadOrCreateProgressionFor(db, idTask, idStudent)172 if err != nil {173 return174 }175 // ... update the progression questions176 err = updateProgression(db, prog, out.Progression.Questions)177 if err != nil {178 return179 }180 // and compute the new mark181 questions, err := ed.SelectExerciceQuestionsByIdExercices(db, ex.IdExercice)182 if err != nil {183 return out, mark, utils.SQLError(err)184 }185 mark = computeMark(questions, out.Progression.Questions)186 return out, mark, nil187}188// compute the student mark189// an empty progression is supported and returns 0190func computeMark(questions ed.ExerciceQuestions, progression []ed.QuestionHistory) int {191 if len(progression) == 0 {192 return 0193 }194 questions.EnsureOrder()195 var out int...

Full Screen

Full Screen

Select

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c1 := make(chan string)4 c2 := make(chan string)5 go func() {6 for {7 time.Sleep(time.Millisecond * 500)8 }9 }()10 go func() {11 for {12 time.Sleep(time.Second * 2)13 }14 }()15 for {16 select {17 fmt.Println(msg1)

Full Screen

Full Screen

Select

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 a := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}4 fmt.Println(b)5}6import "fmt"7func main() {8 a := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}9 fmt.Println(b)10 fmt.Println(c)11}12import "fmt"13func main() {14 a := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}15 fmt.Println(b)16 fmt.Println(c)17 fmt.Println(d)18}19import "fmt"20func main() {21 a := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}22 fmt.Println(b)23 fmt.Println(c)24 fmt.Println(d)25 fmt.Println(e)26}

Full Screen

Full Screen

Select

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 err := ui.Main(func() {4 button := ui.NewButton("Click Me!")5 button.OnClicked(func(*ui.Button) {6 fmt.Println("Hello, World!")7 })8 ui.Quit()9 })10 if err != nil {11 panic(err)12 }13}14Go | ui package - ui.Init() function15Go | ui package - ui.Quit()

Full Screen

Full Screen

Select

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 err := ui.Main(func() {4 window := ui.NewWindow("Select", 200, 200, false)5 label := ui.NewLabel("Select a file")6 button := ui.NewButton("Select")7 vbox := ui.NewVerticalBox()8 vbox.Append(label, false)9 vbox.Append(button, false)10 window.SetChild(vbox)11 button.OnClicked(func(*ui.Button) {12 onButtonClicked(label)13 })14 window.OnClosing(func(*ui.Window) bool {15 ui.Quit()16 })17 window.Show()18 })19 if err != nil {20 panic(err)21 }22}23func onButtonClicked(label *ui.Label) {24 dlg := ui.NewOpenFile(window)25 dlg.OnClosing(func(*ui.OpenFile) bool {26 ui.Quit()27 })28 dlg.Show()29 label.SetText(dlg.Selected())30}31import (32func main() {33 err := ui.Main(func() {34 window := ui.NewWindow("SaveFile", 200, 200, false)35 label := ui.NewLabel("Save a file")36 button := ui.NewButton("Save")37 vbox := ui.NewVerticalBox()

Full Screen

Full Screen

Select

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Enter the number of elements")4 fmt.Scanln(&n)5 fmt.Println("Enter the elements")6 for i := 0; i < n; i++ {7 fmt.Scanln(&temp)8 arr = append(arr, temp)9 }10 fmt.Println("Enter the number to search")11 fmt.Scanln(&num)12 p := prog.Prog{Arr: arr}13 p.Select()14 fmt.Println("The number", num, "is present at", p.Search(num))15}16type Prog struct {17}18func (p *Prog) Select() {19 for i := 0; i < len(p.Arr)-1; i++ {20 for j := i + 1; j < len(p.Arr); j++ {21 if p.Arr[j] < p.Arr[min] {22 }23 }24 }25}26func (p *Prog) Search(num int) int {27 for i := 0; i < len(p.Arr); i++ {28 if p.Arr[i] == num {29 }30 }31}

Full Screen

Full Screen

Select

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 var prog = Prog{}4 prog.Select(1)5}6import "fmt"7func main() {8 var prog = Prog{}9 prog.Select(1)10}11import "fmt"12func main() {13 var prog = Prog{}14 prog.Select(1)15}16import "fmt"17func main() {18 var prog = Prog{}19 prog.Select(1)20}21import "fmt"22func main() {23 var prog = Prog{}24 prog.Select(1)25}26import "fmt"27func main() {28 var prog = Prog{}29 prog.Select(1)30}31import "fmt"32func main() {33 var prog = Prog{}34 prog.Select(1)35}36import "fmt"37func main() {38 var prog = Prog{}39 prog.Select(1)40}41import "fmt"42func main() {43 var prog = Prog{}44 prog.Select(1)45}46import "fmt"47func main() {48 var prog = Prog{}49 prog.Select(1)50}51import "fmt"52func main() {53 var prog = Prog{}54 prog.Select(1)55}56import "fmt"57func main() {58 var prog = Prog{}59 prog.Select(1)60}

Full Screen

Full Screen

Select

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "math/rand"3import "time"4func main() {5 rand.Seed(time.Now().Unix())6 for count < 6 {7 var temp = rand.Intn(49) + 18 for i := 0; i < 6; i++ {9 if prog[i] == temp {10 }11 }12 if flag == 0 {13 }14 }15 fmt.Println(prog)16}17import "fmt"18import "math/rand"19import "time"20func main() {21 rand.Seed(time.Now().Unix())22 for count < 6 {23 var temp = rand.Intn(49) + 124 for i := 0; i < 6; i++ {25 if prog[i] == temp {26 }27 }28 if flag == 0 {29 }30 }31 fmt.Println(prog)32}33import "fmt"34import "math/rand"35import "time"36func main() {37 rand.Seed(time.Now().Unix())38 for count < 6 {39 var temp = rand.Intn(49) + 140 for i := 0; i < 6; i++ {41 if prog[i] == temp {42 }43 }44 if flag == 0 {45 }46 }47 fmt.Println(prog)48}49import "fmt"50import "math/rand"51import "time"52func main() {53 rand.Seed(time.Now().Unix())54 for count < 6 {55 var temp = rand.Intn(49

Full Screen

Full Screen

Select

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(prog.Select(2, 4, 6))4}5func Select(x, y, z int) int {6 if x > y {7 } else {8 }9 if max < z {10 }11}

Full Screen

Full Screen

Select

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 driver := agouti.ChromeDriver()4 if err := driver.Start(); err != nil {5 panic(err)6 }7 defer driver.Stop()8 page, err := driver.NewPage()9 if err != nil {10 panic(err)11 }12 panic(err)13 }14 if err := page.Find("#myButton").Click(); err != nil {15 panic(err)16 }17 if err := page.Find("#myDiv").Wait(10); err != nil {18 panic(err)19 }20 text, err := page.Find("#myDiv").Text()21 if err != nil {22 panic(err)23 }24 fmt.Println(text)25}

Full Screen

Full Screen

Select

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "os"3import "strings"4import "bufio"5func main() {6 reader = bufio.NewReader(os.Stdin)7 for {8 fmt.Println("Enter your choice: ")9 fmt.Println("1. Select")10 fmt.Println("2. Exit")11 fmt.Scanf("%d", &choice)12 switch choice {13 fmt.Println("Enter the string: ")14 input, _ = reader.ReadString('\n')15 input = strings.TrimSpace(input)16 err = prog.Select(input)17 if err != nil {18 fmt.Println(err)19 }20 os.Exit(0)21 fmt.Println("Invalid choice")22 }23 }24}25import "fmt"26import "strings"27type Prog struct {28}29func (p *Prog) Select(str string) error {

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful