Skip to content

Commit

Permalink
Merge pull request #15 from xzebra/fix-practical
Browse files Browse the repository at this point in the history
Fix practical
  • Loading branch information
xzebra authored Feb 9, 2021
2 parents 039e706 + f7785dc commit 2bbb43b
Show file tree
Hide file tree
Showing 10 changed files with 210 additions and 55 deletions.
16 changes: 15 additions & 1 deletion internal/semester/merged.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,26 @@ func isWildcardDay(dayType string) bool {
return dayType[1] == 'x'
}

func removePracticalClasses(sched []*schedules.ScheduleClass) []*schedules.ScheduleClass {
var out []*schedules.ScheduleClass

for _, class := range sched {
if !class.IsPractical {
out = append(out, class)
}
}

return out
}

// getSchedGivenDayType returns the schedule associated with a day
// type. If that day type is a non wildcard day, it also returns the
// wildcarded classes (classes that happen all weeks).
func (s *Data) getSchedGivenDayType(dayType string) (sched []*schedules.ScheduleClass) {
sched = s.Schedule[dayType]
if !isWildcardDay(dayType) {
if isWildcardDay(dayType) { // Day with classes but not practical classes
sched = removePracticalClasses(sched)
} else { // Day with practical classes
// We have to extract also the wildcard day classes.
wildcardType := fmt.Sprintf("%c%c", dayType[0], 'x')
for _, class := range s.Schedule[wildcardType] {
Expand Down
67 changes: 67 additions & 0 deletions internal/semester/merged_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package semester

import (
"io/ioutil"
"os"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/xzebra/unizar-calendar/pkg/schedules"
)

func TestNewData(t *testing.T) {
f, err := os.Open("./testdata/semester.json")
assert.Nil(t, err)
defer f.Close()

semData, err := ioutil.ReadAll(f)
assert.Nil(t, err)

sem, err := NewSemesterFromData(semData)
assert.Nil(t, err)

parsed, err := schedules.ParseSemesterFiles(&schedules.SemesterFiles{
Subjects: "./testdata/asignaturas.csv",
Schedule: "./testdata/mixed.csv",
})
assert.Nil(t, err)

data, err := NewData(sem, parsed, 1)
assert.Nil(t, err)

// Check: Merged map[string][]timeRange
assert.Equal(t,
map[string][]timeRange{
"ssdd": {
{ // Lx
Start: time.Date(2021, 1, 11, 17, 0, 0, 0, time.UTC),
End: time.Date(2021, 1, 11, 17, 50, 0, 0, time.UTC),
},
{ // Lb
Start: time.Date(2020, 12, 21, 17, 0, 0, 0, time.UTC),
End: time.Date(2020, 12, 21, 17, 50, 0, 0, time.UTC),
},
},
"ing_soft": {
{ // Lb
Start: time.Date(2020, 12, 21, 18, 10, 0, 0, time.UTC),
End: time.Date(2020, 12, 21, 19, 00, 0, 0, time.UTC),
},
},
"ph": {
{ // Lb
Start: time.Date(2020, 12, 21, 10, 0, 0, 0, time.UTC),
End: time.Date(2020, 12, 21, 14, 0, 0, 0, time.UTC),
},
},
"ia": {
{ // Mb
Start: time.Date(2020, 12, 22, 17, 0, 0, 0, time.UTC),
End: time.Date(2020, 12, 22, 20, 0, 0, 0, time.UTC),
},
},
},
data.Merged,
)
}
55 changes: 55 additions & 0 deletions internal/semester/semester_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package semester_test

import (
"fmt"
"io/ioutil"
"os"
"path"
"runtime"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/xzebra/unizar-calendar/internal/semester"
"github.com/xzebra/unizar-calendar/pkg/gcal"
)

// func NewSemesterFromData(data []byte) (semester *Semester, err error)
func TestNewSemesterFromData(t *testing.T) {
f, err := os.Open("./testdata/semester.json")
assert.Nil(t, err)
defer f.Close()

data, err := ioutil.ReadAll(f)
assert.Nil(t, err)

sem, err := semester.NewSemesterFromData(data)
assert.Nil(t, err)

assert.Equal(t, time.Date(2020, 9, 14, 0, 0, 0, 0, time.UTC), sem.Begin)
assert.Equal(t, time.Date(2021, 1, 13, 0, 0, 0, 0, time.UTC), sem.End)

assert.Equal(t, gcal.EventDays{
time.Date(2021, 1, 11, 0, 0, 0, 0, time.UTC): "Lx",
time.Date(2021, 1, 8, 0, 0, 0, 0, time.UTC): "Vx",
time.Date(2020, 12, 22, 0, 0, 0, 0, time.UTC): "Mb",
time.Date(2020, 12, 21, 0, 0, 0, 0, time.UTC): "Lb",
}, sem.Days)
}

// ----------------------------------------------------------
// Test initialization
// ----------------------------------------------------------

func TestMain(t *testing.M) {
// Run everything from project root folder
_, filename, _, _ := runtime.Caller(0)
dir := path.Join(path.Dir(filename), "..", "..")
err := os.Chdir(dir)
if err != nil {
fmt.Println("error returning to root folder: ", err)
os.Exit(1)
}

os.Exit(t.Run())
}
9 changes: 5 additions & 4 deletions pkg/schedules/schedules.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ type ClassName struct {
type Schedule map[string][]*ScheduleClass

type ScheduleClass struct {
Weekday string `csv:"weekday"`
ID string `csv:"class_id"`
Start hour `csv:"start_hour"`
End hour `csv:"end_hour"`
Weekday string `csv:"weekday"`
ID string `csv:"class_id"`
Start hour `csv:"start_hour"`
End hour `csv:"end_hour"`
IsPractical bool `csv:"is_practical"`
}

func ParseClassNames(in io.Reader) (out ClassNames, err error) {
Expand Down
32 changes: 31 additions & 1 deletion pkg/schedules/schedules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestParseClassNames(t *testing.T) {
assert.Equal(t, expected, returned)
}

func TestParseSchedule(t *testing.T) {
func TestParseSchedule_Classes(t *testing.T) {
class1 := &ScheduleClass{
Weekday: "Lx",
ID: "ssdd",
Expand Down Expand Up @@ -63,6 +63,36 @@ func TestParseSchedule(t *testing.T) {
assert.Equal(t, expected, returned)
}

func TestParseSchedule_Practical(t *testing.T) {
class1 := &ScheduleClass{
Weekday: "Xx",
ID: "ph",
Start: hour{10, 0},
End: hour{14, 0},
IsPractical: true,
}
class2 := &ScheduleClass{
Weekday: "Ja",
ID: "ia",
Start: hour{17, 0},
End: hour{20, 0},
IsPractical: true,
}
expected := Schedule{
"Xx": {class1},
"Ja": {class2},
}

f2, err := os.Open("./testdata/practicas.csv")
assert.Nil(t, err)
defer f2.Close()

returned, err := ParseSchedule(f2)
assert.Nil(t, err)

assert.Equal(t, expected, returned)
}

// ----------------------------------------------------------
// Test initialization
// ----------------------------------------------------------
Expand Down
39 changes: 11 additions & 28 deletions testdata/clases.csv
Original file line number Diff line number Diff line change
@@ -1,35 +1,18 @@
weekday;class_id;start_hour;end_hour;desc
weekday;class_id;start_hour;end_hour;desc;is_practical
# IA
Lx;ia;15:00;15:50;"
https://meet.google.com/iig-sbwa-kdn?pli=1&authuser=1
https://meet.google.com/xzt-imof-jsw?pli=1&authuser=1"
Lx;ia;16:00;16:50;"
https://meet.google.com/iig-sbwa-kdn?pli=1&authuser=1
https://meet.google.com/xzt-imof-jsw?pli=1&authuser=1"
Xx;ia;17:00;17:50;"
https://meet.google.com/iig-sbwa-kdn?pli=1&authuser=1
https://meet.google.com/xzt-imof-jsw?pli=1&authuser=1"
Lx;ia;15:00;15:50;false
Lx;ia;16:00;16:50;false
Xx;ia;17:00;17:50;false

#Sist Inf
Mx;sist_inf;15:00;15:50;"
https://meet.google.com/tqk-zssa-pmp?pli=1&authuser=1"
Mx;sist_inf;16:00;16:50;"
https://meet.google.com/tqk-zssa-pmp?pli=1&authuser=1"
Xx;sist_inf;18:00;18:50;"
https://meet.google.com/tqk-zssa-pmp?pli=1&authuser=1"
Mx;sist_inf;15:00;15:50;false
Mx;sist_inf;16:00;16:50;false
Xx;sist_inf;18:00;18:50;false

#SSDD
Jx;sist_inf;15:00;15:50;"
- Google Meet (Rafa) https://meet.google.com/tqk-zssa-pmp?pli=1&authuser=1
- Microsoft Teams (Rafa): https://teams.microsoft.com/dl/launcher/launcher.html?url=%2F_%23%2Fl%2Fmeetup-join%2F19%3A3ec116dc5a8941eda39f8e8c4d831ae1%40thread.tacv2%2F1601481330986%3Fcontext%3D%257B%2522Tid%2522%253A%25223f227dba-f3f4-4544-b314-c6efd30e0d00%2522%252C%2522Oid%2522%253A%25226f6be409-9319-4b90-a817-7e05df5b1ce9%2522%257D%26anon%3Dtrue&type=meetup-join&deeplinkId=4803e452-eae3-424c-b262-40878a17fa57&directDl=true&msLaunch=true&enableMobilePage=true&suppressPrompt=true
- Google Meet (Unai): https://meet.google.com/ijq-umtk-ewp?pli=1&authuser=1"
Jx;sist_inf;16:00;16:50;"
- Google Meet (Rafa) https://meet.google.com/tqk-zssa-pmp?pli=1&authuser=1
- Microsoft Teams (Rafa): https://teams.microsoft.com/dl/launcher/launcher.html?url=%2F_%23%2Fl%2Fmeetup-join%2F19%3A3ec116dc5a8941eda39f8e8c4d831ae1%40thread.tacv2%2F1601481330986%3Fcontext%3D%257B%2522Tid%2522%253A%25223f227dba-f3f4-4544-b314-c6efd30e0d00%2522%252C%2522Oid%2522%253A%25226f6be409-9319-4b90-a817-7e05df5b1ce9%2522%257D%26anon%3Dtrue&type=meetup-join&deeplinkId=4803e452-eae3-424c-b262-40878a17fa57&directDl=true&msLaunch=true&enableMobilePage=true&suppressPrompt=true
- Google Meet (Unai): https://meet.google.com/ijq-umtk-ewp?pli=1&authuser=1"
Jx;sist_inf;15:00;15:50;false
Jx;sist_inf;16:00;16:50;false

#Ing Soft
Xx;ing_soft;15:00;15:50;"
https://meet.google.com/hdj-whng-oqw?pli=1&authuser=1"
Xx;ing_soft;16:00;16:50;"
https://meet.google.com/hdj-whng-oqw?pli=1&authuser=1"
Xx;ing_soft;15:00;15:50;false
Xx;ing_soft;16:00;16:50;false
9 changes: 9 additions & 0 deletions testdata/mixed.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
weekday;class_id;start_hour;end_hour;is_practical
#SSDD class
Lx;ssdd;17:00;17:50;false
#Ing Soft class
Lb;ing_soft;18:10;19:00;false
#PH practical class
Lx;ph;10:00;14:00;true
#IA practical class
Mb;ia;17:00;20:00;true
21 changes: 3 additions & 18 deletions testdata/practicas.csv
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
weekday;class_id;start_hour;end_hour;desc
Xx;ph;10:00;14:00;"
- Compa�eros: Carlos
- Google Meet: https://meet.google.com/iac-dfzy-kwb?pli=1&authuser=1
- Google Meet privado: https://meet.google.com/xfi-bemu-raa?pli=1&authuser=1"
Ja;ia;17:00;20:00;"
- Google Meet: https://meet.google.com/iig-sbwa-kdn?pli=1&authuser=1"
Jb;ing_soft;17:00;19:00;"
- Compa�eros: Carlos
- Google Meet: https://meet.google.com/fsi-kspo-ifv?pli=1&authuser=1
- Google Meet privado: https://meet.google.com/rpi-fgre-wce?pli=1&authuser=1"
Va;ssdd;10:00;12:00;"
- Compa�eros: Mario
- Google Meet: https://meet.google.com/ijq-umtk-ewp?pli=1&authuser=1"
Vx;sist_info;12:00;14:00;"
- Compa�eros: Carlos, Mario
- Google Meet: https://meet.google.com/ooo-gnvy-zyw?pli=1&authuser=1
- Google Meet privado: https://meet.google.com/pxd-yhzu-zrk?pli=1&authuser=1"
weekday;class_id;start_hour;end_hour;is_practical
Xx;ph;10:00;14:00;true
Ja;ia;17:00;20:00;true
6 changes: 3 additions & 3 deletions testdata/problemas.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
weekday;class_id;start_hour;end_hour
weekday;class_id;start_hour;end_hour;is_practical
#SSDD
Lx;ssdd;17:00;17:50
Lx;ssdd;17:00;17:50;false

#Ing Soft
Lb;ing_soft;18:10;19:00
Lb;ing_soft;18:10;19:00;false
11 changes: 11 additions & 0 deletions testdata/semester.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"Days": {
"2021-01-11T00:00:00Z": "Lx",
"2021-01-08T00:00:00Z": "Vx",
"2020-12-22T00:00:00Z": "Mb",
"2020-12-21T00:00:00Z": "Lb"
},
"End": "2021-01-13T00:00:00Z",
"Begin": "2020-09-14T00:00:00Z",
"Number": 1
}

0 comments on commit 2bbb43b

Please sign in to comment.