소스 검색

Fix for deploy

Dasflugen 5 년 전
부모
커밋
f024020cce
9개의 변경된 파일105개의 추가작업 그리고 58개의 파일을 삭제
  1. 4 4
      api/authorization.go
  2. 0 0
      go.mod1
  3. 3 0
      log/Requests_URL.log
  4. BIN
      main
  5. 5 3
      main.go
  6. 0 30
      schedule/generator.go
  7. 7 6
      schedule/models.go
  8. 4 0
      schedule/settings.go
  9. 82 15
      schedule/xlsx.go

+ 4 - 4
api/authorization.go

@@ -11,7 +11,7 @@ type User struct{
 	Password string `json:"password"`
 }
 
-func (u User) SetCookie(w http.ResponseWriter, r *http.Request){
+/*func (u User) SetCookie(w http.ResponseWriter, r *http.Request){
 	cookie := http.Cookie{
 		Name: u.Login,
 		Value: "logged in",
@@ -21,7 +21,7 @@ func (u User) SetCookie(w http.ResponseWriter, r *http.Request){
 		HttpOnly: true,
 	}
 	http.SetCookie(rw, &cookie)
-}
+}*/
 
 func LoginRoute(w http.ResponseWriter, r *http.Request){
 	showAPIRequest(r)
@@ -42,7 +42,7 @@ func LoginRoute(w http.ResponseWriter, r *http.Request){
 			showError(r, error)
 			return
 		}
-		status, entry, groups, err := auth.AuthenticateExtended(config, user.Login, user.Password, []string{"cn"}, Groups)
+		status, /*entry*/_, groups, err := auth.AuthenticateExtended(config, user.Login, user.Password, []string{"cn"}, Groups)
 		if err != nil {
 	   	 	json.NewEncoder(w).Encode(struct{ Error string }{Error: "an error has occured"})
 	   	 	showError(r, err)
@@ -58,7 +58,7 @@ func LoginRoute(w http.ResponseWriter, r *http.Request){
 				}
 			}
 		}
-		user.SetCookie(w, r)
+		//user.SetCookie(w, r)
 		json.NewEncoder(w).Encode(userGroups)
 		return
 	}

go.mod → go.mod1


+ 3 - 0
log/Requests_URL.log

@@ -0,0 +1,3 @@
+[15:21] Request from [::1]:46402 to /
+[15:21] Request from [::1]:46402 to /
+[15:21] Request from [::1]:46402 to /plan/

BIN
main


+ 5 - 3
main.go

@@ -104,10 +104,12 @@ func main() {
 	http.HandleFunc("/test/", testPage) // testing token
 	// HTTP pages handling end
 	api.PrintConsole("Server is starting...")
-
-	err := http.ListenAndServe(":" + os.Args[1], nil)
+	err = nil
+	err = http.ListenAndServe(":" + os.Args[1], nil)
 	if err!=nil{
-		api.PrintConsole("Error while starting server")
+		t := time.Now()
+		s := "[" + t.Format(settings.TimeLayout) + "] " + "Error:" + err.Error()
+		fmt.Println(s)
 	}
 }
 

+ 0 - 30
schedule/generator.go

@@ -3,7 +3,6 @@ package schedule
 import (
     "fmt"
     "encoding/json"
-    "github.com/tealeg/xlsx"
 )
 
 func NewGenerator(data *Generator) *Generator {
@@ -110,35 +109,6 @@ func ReadCabinets(filename string) map[string]*Cabinet {
     return cabinets
 }
 
-const (
-    OUTDATA = "output/"
-)
-func (gen *Generator) Template() [][]*Schedule {
-    var (
-        weekLessons = make([][]*Schedule, 7)
-        generator = new(Generator)
-        file *xlsx.File
-        name string
-    )
-    unpackJSON(packJSON(gen), generator)
-    if gen.Debug {
-        file, name = CreateXLSX(OUTDATA + "template.xlsx")
-    }
-    day := generator.Day
-    for i := day; i < day+7; i++ {
-        weekLessons[i % 7] = generator.Generate(nil)
-        if gen.Debug {
-            generator.WriteXLSX(
-                file,
-                name,
-                weekLessons[i % 7],
-                int(i % 7),
-            )
-        }
-    }
-    return weekLessons
-}
-
 func (gen *Generator) Generate(template [][]*Schedule) []*Schedule {
     var (
         list   []*Schedule

+ 7 - 6
schedule/models.go

@@ -26,12 +26,13 @@ type LineXLSX struct {
 }
 
 type StudyLoadXLSX struct {
-	Max       int `json:"max"`
-	SelfStudy int `json:"self_study"`
-	AllStudy  int `json:"all_study"`
-	Lectures  int `json:"lectures"`
-	Labs      int `json:"labs"`
-	Projects  int `json:"projects"`
+	Max          int `json:"max"`
+	SelfStudy    int `json:"self_study"`
+	AllStudy     int `json:"all_study"`
+	Lectures     int `json:"lectures"`
+	Labs         int `json:"labs"`
+	Projects     int `json:"projects"`
+	Consultation int `json:"consultation"`
 }
 
 type DayType uint8

+ 4 - 0
schedule/settings.go

@@ -16,3 +16,7 @@ const (
 	COL_W = 30
 	COL_W_CAB = 10
 )
+
+const (
+	OUTDATA = "output/"
+)

+ 82 - 15
schedule/xlsx.go

@@ -7,6 +7,32 @@ import (
     "github.com/tealeg/xlsx"
 )
 
+func (gen *Generator) Template() [][]*Schedule {
+    var (
+        weekLessons = make([][]*Schedule, 7)
+        generator = new(Generator)
+        file *xlsx.File
+        name string
+    )
+    unpackJSON(packJSON(gen), generator)
+    if gen.Debug {
+        file, name = CreateXLSX(OUTDATA + "template.xlsx")
+    }
+    day := generator.Day
+    for i := day; i < day+7; i++ {
+        weekLessons[i % 7] = generator.Generate(nil)
+        if gen.Debug {
+            generator.WriteXLSX(
+                file,
+                name,
+                weekLessons[i % 7],
+                int(i % 7),
+            )
+        }
+    }
+    return weekLessons
+}
+
 func ImportXLSX(filename string) []*PlanXLSX {
     var (
         listOfPlans []*PlanXLSX
@@ -17,19 +43,35 @@ func ImportXLSX(filename string) []*PlanXLSX {
     }
     for _, sheet := range xlFile.Sheets {
         var plan = new(PlanXLSX)
+        
         plan.ProgramCode   = sheet.Rows[5].Cells[1].String()
         plan.NameCode      = strings.Split(sheet.Rows[5].Cells[6].String(), " ")[0]
         plan.PeriodOfStudy = sheet.Rows[7].Cells[6].String()
         splited := strings.Split(sheet.Rows[9].Cells[1].String(), " ")
         plan.GroupNumber   = strings.Split(splited[len(splited)-1], "-")[0]
 
+        maxCells := 18
+        consultExist := false
+        if strings.HasPrefix(sheet.Rows[13].Cells[9].String(), "Консультации") {
+            maxCells = 19
+            consultExist = true
+        }
+
+        plusTable := 0
+        if sheet.Rows[11].Cells[10].String() == "" || sheet.Rows[11].Cells[11].String() == "" {
+            plusTable = 2
+        }
+
         for i, row := range sheet.Rows {
             if i < 20 {
                 continue
             }
-            if len(row.Cells) < 20 {
+
+            if len(row.Cells) < maxCells {
+                // fmt.Println(len(row.Cells))
                 continue
             }
+            
             if row.Cells[2].String() == "" || row.Cells[2].String() == "ИТОГО" {
                 continue
             }
@@ -53,20 +95,44 @@ func ImportXLSX(filename string) []*PlanXLSX {
                 typerow = IsPmTR
             }
 
-            max, _       := row.Cells[4].Int()
-            selfstudy, _ := row.Cells[5].Int()
-            allstudy, _  := row.Cells[6].Int()
-            lectures, _  := row.Cells[7].Int()
-            labs, _      := row.Cells[8].Int()
-            projects, _  := row.Cells[9].Int()
-            c1s1, _      := row.Cells[12].Int()
-            c1s2, _      := row.Cells[13].Int()
-            c2s1, _      := row.Cells[14].Int()
-            c2s2, _      := row.Cells[15].Int()
-            c3s1, _      := row.Cells[16].Int()
-            c3s2, _      := row.Cells[17].Int()
-            c4s1, _      := row.Cells[18].Int()
-            c4s2, _      := row.Cells[19].Int()
+            var (
+                max, selfstudy, allstudy, lectures, labs, consult, projects int
+                c1s1, c1s2, c2s1, c2s2, c3s1, c3s2, c4s1, c4s2 int
+            )
+
+            max, _       = row.Cells[4].Int()
+            selfstudy, _ = row.Cells[5].Int()
+            allstudy, _  = row.Cells[6].Int()
+            lectures, _  = row.Cells[7].Int()
+            labs, _      = row.Cells[8].Int()
+
+            if consultExist {
+                consult, _   = row.Cells[9].Int()
+                projects, _  = row.Cells[10].Int()
+                c1s1, _      = row.Cells[11+plusTable].Int()
+                c1s2, _      = row.Cells[12+plusTable].Int()
+                c2s1, _      = row.Cells[13+plusTable].Int()
+                c2s2, _      = row.Cells[14+plusTable].Int()
+                c3s1, _      = row.Cells[15+plusTable].Int()
+                c3s2, _      = row.Cells[16+plusTable].Int()
+                if plusTable == 0 {
+                    c4s1, _      = row.Cells[17+plusTable].Int()
+                    c4s2, _      = row.Cells[18+plusTable].Int()
+                }
+            } else {
+                consult      = -1
+                projects, _  = row.Cells[9].Int()
+                c1s1, _      = row.Cells[10+plusTable].Int()
+                c1s2, _      = row.Cells[11+plusTable].Int()
+                c2s1, _      = row.Cells[12+plusTable].Int()
+                c2s2, _      = row.Cells[13+plusTable].Int()
+                c3s1, _      = row.Cells[14+plusTable].Int()
+                c3s2, _      = row.Cells[15+plusTable].Int()
+                if plusTable == 0 {
+                    c4s1, _      = row.Cells[16+plusTable].Int()
+                    c4s2, _      = row.Cells[17+plusTable].Int()
+                }
+            }
 
             certform := ""
             splited = strings.Split(row.Cells[3].String(), ",")
@@ -87,6 +153,7 @@ func ImportXLSX(filename string) []*PlanXLSX {
                     AllStudy:  allstudy,
                     Lectures:  lectures,
                     Labs:      labs,
+                    Consultation: consult,
                     Projects:  projects,
                 },
                 Course: [4][2]int{