Skip to content

Commit

Permalink
fixed some minor typing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
smeggmann99 committed Oct 19, 2024
1 parent 38b00e4 commit b25db21
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 122 deletions.
36 changes: 18 additions & 18 deletions api/v1/handlers/atmosphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ import (
// }

// Helper function to get the day of the week from a timestamp
func getDayOfWeek(timestamp int64) int32 {
return int32(time.Unix(timestamp, 0).Weekday())
func getDayOfWeek(timestamp int64) int64 {
return int64(time.Unix(timestamp, 0).Weekday())
}

/* Example response:
Expand Down Expand Up @@ -151,13 +151,13 @@ func WeatherForecastHandler(c *gin.Context) {
Description: condition["description"].(string),
},
Temperature: &models.Temperature{
Current: float32(temperature["temp"].(float64)),
Min: float32(temperature["temp_min"].(float64)),
Max: float32(temperature["temp_max"].(float64)),
Current: temperature["temp"].(float64),
Min: temperature["temp_min"].(float64),
Max: temperature["temp_max"].(float64),
},
Sunrise: sunrise,
Sunset: sunset,
DayOfWeek: getDayOfWeek(int64(forecastMap["dt"].(float64))),
DayOfWeek: getDayOfWeek(forecastMap["dt"].(int64)),
})
}

Expand Down Expand Up @@ -220,9 +220,9 @@ func CurrentWeatherHandler(c *gin.Context) {
Description: condition["description"].(string),
},
Temperature: &models.Temperature{
Current: float32(temperature["temp"].(float64)),
Min: float32(temperature["temp_min"].(float64)),
Max: float32(temperature["temp_max"].(float64)),
Current: temperature["temp"].(float64),
Min: temperature["temp_min"].(float64),
Max: temperature["temp_max"].(float64),
},
Sunrise: sunrise,
Sunset: sunset,
Expand Down Expand Up @@ -275,15 +275,15 @@ func CurrentAirPollutionHandler(c *gin.Context) {
components := openWeatherData["list"].([]interface{})[0].(map[string]interface{})["components"].(map[string]interface{})

airPollutionResponse := &models.AirPollutionResponse{
Components: map[string]float32{
"co": float32(components["co"].(float64)),
"no": float32(components["no"].(float64)),
"no2": float32(components["no2"].(float64)),
"o3": float32(components["o3"].(float64)),
"so2": float32(components["so2"].(float64)),
"pm2_5": float32(components["pm2_5"].(float64)),
"pm10": float32(components["pm10"].(float64)),
"nh3": float32(components["nh3"].(float64)),
Components: map[string]float64{
"co": components["co"].(float64),
"no": components["no"].(float64),
"no2": components["no2"].(float64),
"o3": components["o3"].(float64),
"so2": components["so2"].(float64),
"pm2_5": components["pm2_5"].(float64),
"pm10": components["pm10"].(float64),
"nh3": components["nh3"].(float64),
},
}

Expand Down
6 changes: 3 additions & 3 deletions api/v1/handlers/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func GetDivisionHandler(c *gin.Context) {
return
}

division, err := datastore.GetDivision(uint32(index))
division, err := datastore.GetDivision(uint64(index))
if err != nil {
if division == nil {
c.JSON(http.StatusNotFound, gin.H{
Expand Down Expand Up @@ -53,7 +53,7 @@ func GetTeacherHandler(c *gin.Context) {
return
}

teacher, err := datastore.GetTeacher(uint32(index))
teacher, err := datastore.GetTeacher(uint64(index))
if err != nil {
if teacher == nil {
c.JSON(http.StatusNotFound, gin.H{
Expand Down Expand Up @@ -84,7 +84,7 @@ func GetRoomHandler(c *gin.Context) {
return
}

room, err := datastore.GetRoom(uint32(index))
room, err := datastore.GetRoom(uint64(index))
if err != nil {
if room == nil {
c.JSON(http.StatusNotFound, gin.H{
Expand Down
78 changes: 39 additions & 39 deletions common/models/data.pb.go

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions core/datastore/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func SetDivision(division *models.Division) error {
return setItem(key, division)
}

func GetDivision(index uint32) (*models.Division, error) {
func GetDivision(index uint64) (*models.Division, error) {
key := []byte(fmt.Sprintf("division:%d", index))
division := &models.Division{}
err := getItem(key, division)
Expand All @@ -61,7 +61,7 @@ func GetDivision(index uint32) (*models.Division, error) {
return division, nil
}

func DeleteDivision(index uint32) error {
func DeleteDivision(index uint64) error {
key := []byte(fmt.Sprintf("division:%d", index))
return deleteItem(key)
}
Expand All @@ -71,7 +71,7 @@ func SetTeacher(teacher *models.Teacher) error {
return setItem(key, teacher)
}

func GetTeacher(index uint32) (*models.Teacher, error) {
func GetTeacher(index uint64) (*models.Teacher, error) {
key := []byte(fmt.Sprintf("teacher:%d", index))
teacher := &models.Teacher{}
err := getItem(key, teacher)
Expand All @@ -81,7 +81,7 @@ func GetTeacher(index uint32) (*models.Teacher, error) {
return teacher, nil
}

func DeleteTeacher(index uint32) error {
func DeleteTeacher(index uint64) error {
key := []byte(fmt.Sprintf("teacher:%d", index))
return deleteItem(key)
}
Expand All @@ -91,7 +91,7 @@ func SetRoom(room *models.Room) error {
return setItem(key, room)
}

func GetRoom(index uint32) (*models.Room, error) {
func GetRoom(index uint64) (*models.Room, error) {
key := []byte(fmt.Sprintf("room:%d", index))
room := &models.Room{}
err := getItem(key, room)
Expand All @@ -101,7 +101,7 @@ func GetRoom(index uint32) (*models.Room, error) {
return room, nil
}

func DeleteRoom(index uint32) error {
func DeleteRoom(index uint64) error {
key := []byte(fmt.Sprintf("room:%d", index))
return deleteItem(key)
}
22 changes: 11 additions & 11 deletions core/scraper/observers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
func ObserveDivisions() {
fmt.Println("observing divisions")

newDivisionObserver := func(index uint32) *observer.Observer {
url := fmt.Sprintf(Config.BaseUrl+Config.Endpoints.Division, index)
newDivisionObserver := func(index uint64) *observer.Observer {
url := fmt.Sprintf(Config.BaseUrl + Config.Endpoints.Division, index)
// So they don't all refresh at the same time
interval := time.Duration((index+1)/10+15) * time.Second
interval := time.Duration((index + 1) / 10 + 15) * time.Second
return observer.NewObserver(url, interval, func(doc *goquery.Document) string {
var content []string
doc.Find("table.tabela").Each(func(i int, table *goquery.Selection) {
Expand All @@ -36,7 +36,7 @@ func ObserveDivisions() {
})
}

startDivisionObserver := func(observer *observer.Observer, index uint32) {
startDivisionObserver := func(observer *observer.Observer, index uint64) {
observer.Start(func() {
division, err := ScrapeDivision(index)
if err != nil {
Expand All @@ -52,7 +52,7 @@ func ObserveDivisions() {
}

refreshDivisionsObservers := func() {
existingIndexes := make(map[uint32]bool)
existingIndexes := make(map[uint64]bool)
for _, index := range DivisionsIndexes {
existingIndexes[index] = true
if _, exists := DivisionsObservers[index]; !exists {
Expand Down Expand Up @@ -110,7 +110,7 @@ func ObserveDivisions() {
func ObserveTeachers() {
fmt.Println("observing teachers")

newTeacherObserver := func(index uint32) *observer.Observer {
newTeacherObserver := func(index uint64) *observer.Observer {
url := fmt.Sprintf(Config.BaseUrl+Config.Endpoints.Teacher, index)
interval := time.Duration((index+1)/10+15) * time.Second
return observer.NewObserver(url, interval, func(doc *goquery.Document) string {
Expand All @@ -125,7 +125,7 @@ func ObserveTeachers() {
})
}

startTeacherObserver := func(observer *observer.Observer, index uint32) {
startTeacherObserver := func(observer *observer.Observer, index uint64) {
observer.Start(func() {
teacher, err := ScrapeTeacher(index)
if err != nil {
Expand All @@ -141,7 +141,7 @@ func ObserveTeachers() {
}

refreshTeachersObservers := func() {
existingIndexes := make(map[uint32]bool)
existingIndexes := make(map[uint64]bool)
for _, index := range TeachersIndexes {
existingIndexes[index] = true
if _, exists := TeachersObservers[index]; !exists {
Expand Down Expand Up @@ -197,7 +197,7 @@ func ObserveTeachers() {
func ObserveRooms() {
fmt.Println("observing rooms")

newRoomObserver := func(index uint32) *observer.Observer {
newRoomObserver := func(index uint64) *observer.Observer {
url := fmt.Sprintf(Config.BaseUrl + Config.Endpoints.Room, index)
interval := time.Duration((index + 1) / 10 + 15) * time.Second
return observer.NewObserver(url, interval, func(doc *goquery.Document) string {
Expand All @@ -212,7 +212,7 @@ func ObserveRooms() {
})
}

startRoomObserver := func(observer *observer.Observer, index uint32) {
startRoomObserver := func(observer *observer.Observer, index uint64) {
observer.Start(func() {
room, err := ScrapeRoom(index)
if err != nil {
Expand All @@ -228,7 +228,7 @@ func ObserveRooms() {
}

refreshRoomsObservers := func() {
existingIndexes := make(map[uint32]bool)
existingIndexes := make(map[uint64]bool)
for _, index := range RoomsIndexes {
existingIndexes[index] = true
if _, exists := RoomsObservers[index]; !exists {
Expand Down
Loading

0 comments on commit b25db21

Please sign in to comment.