scheduleGenerator.go 728 B

1234567891011121314151617181920212223242526272829303132333435
  1. package api
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "net/http"
  6. "../schedule"
  7. )
  8. const (
  9. INDATA = "input/"
  10. )
  11. func Generate(w http.ResponseWriter, r *http.Request) {
  12. showAPIRequest(r)
  13. if r.Method == "GET" {
  14. var result [][]*schedule.Schedule
  15. var generator = schedule.NewGenerator(&schedule.Generator{
  16. Day: schedule.MONDAY,
  17. // NumTables: 11,
  18. Groups: schedule.ReadGroups(INDATA + "groups.json"),
  19. Teachers: schedule.ReadTeachers(INDATA + "teachers.json"),
  20. })
  21. for iter := 1; iter <= 7; iter++ {
  22. result = append(result, generator.Generate(nil))
  23. }
  24. json.NewEncoder(w).Encode(result)
  25. }
  26. }
  27. func printJSON(data interface{}) {
  28. jsonData, _ := json.MarshalIndent(data, "", "\t")
  29. fmt.Println(string(jsonData))
  30. }