Skip to content
This repository was archived by the owner on Mar 22, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
b3481c4
new branch test
SimonPergel Jan 21, 2025
a6f269d
new test file added
SimonPergel Jan 22, 2025
1223c78
Corrected the calculating function
Jan 22, 2025
f5ded85
Fixed API calls to only do it one time with several instances?
Jan 23, 2025
a146df7
Small fix to make the instances sleep a bit
Jan 23, 2025
5f9f8e4
Merge branch 'master' into Comfortstat
Jan 23, 2025
7ca06c1
Added Alex fix to Jan's code
Jan 23, 2025
a95b553
Ran go mod tidy
Jan 23, 2025
cc8ff43
more tests added
SimonPergel Jan 23, 2025
d6e6a1f
added more tests for the getters in things.go
SimonPergel Jan 23, 2025
df3d27c
Merge branch 'master' into Comfortstat
Jan 24, 2025
8fb3b25
Fixed API to not be called in init_template
Jan 24, 2025
8800a7e
Installs dependencies for the tests too in the workflow
lmas Jan 24, 2025
6bd7214
fixed the set-functions in thing.go and added more tests
SimonPergel Jan 24, 2025
8b9f869
Added working tests for getters och setters functions
SimonPergel Jan 24, 2025
260cba2
added some more tests
SimonPergel Jan 24, 2025
2b73ffa
Merge remote-tracking branch 'origin/workflow' into Comfortstat
SimonPergel Jan 24, 2025
ffe9cc1
adding tests plus cleaning up things.go
SimonPergel Jan 28, 2025
95fac3b
trying to test processfeedbackLoop
SimonPergel Jan 28, 2025
1ea88dc
trying to test processfeedbackLoop
SimonPergel Jan 28, 2025
db73ae6
cleand up some things
SimonPergel Jan 29, 2025
d453a4a
working in GetapiPrice test
SimonPergel Jan 29, 2025
39b6aa0
cleaned up some comments and added some comments to parts with no ex…
SimonPergel Jan 29, 2025
f5fef4b
More tests
SimonPergel Jan 29, 2025
2224f3d
not there yet, but the push tests are woring fine
SimonPergel Jan 30, 2025
41add31
not there yet, but the pushed tests are working fine
SimonPergel Jan 30, 2025
1281db4
more tests
SimonPergel Jan 30, 2025
2cf76b6
fixes testing bad body
lmas Jan 30, 2025
b2dbfe2
test for things.go is completed
SimonPergel Jan 30, 2025
29b556d
added working test of the GET parts
SimonPergel Jan 31, 2025
2521e46
cleaned up and added some comments to clarify diffrent parts
SimonPergel Feb 2, 2025
161e287
added test for the PUT part in Comfortstat.go
SimonPergel Feb 3, 2025
8b7971b
Updated newUnitAsset
SimonPergel Feb 3, 2025
2434825
updated getapiprice function to match linter tests
SimonPergel Feb 3, 2025
64b925d
added a part that validate the url in getApiPricedata
SimonPergel Feb 4, 2025
79cab32
added error handling in getApiPricedata
SimonPergel Feb 4, 2025
de331da
added error handling in the pricefeedbackloop
SimonPergel Feb 4, 2025
9b0086a
added error handling in pricefeedbackloop
SimonPergel Feb 4, 2025
9a8d9af
cleaned up some log.prints in the set-functions
SimonPergel Feb 4, 2025
01af2e1
moved the check for the statuscode to the right place, before reading…
SimonPergel Feb 4, 2025
e4dca4e
fixed so that i run the tests directly after the fuction call
SimonPergel Feb 4, 2025
4e22141
changed the name to a more suitable name
SimonPergel Feb 4, 2025
7ccffce
Reverts " changed the name to a more suitable name"
lmas Feb 4, 2025
108b245
changed to a more suitable name
SimonPergel Feb 4, 2025
9308c0a
replaced the sleep in things.go to Comfortstat.go
Feb 5, 2025
2e32040
Added user temperature to the comfortstat
Feb 7, 2025
4897efb
added some comments and removed emty lines
SimonPergel Feb 7, 2025
27915d7
fixed the setter-methods
SimonPergel Feb 7, 2025
f4667fe
Added special case for the user temp
Feb 10, 2025
dfb65b5
Changed userTemp to UserTemp so it is exported as json
Feb 10, 2025
aed44a4
cleaned up some emty rows and created some explanatory comments
SimonPergel Feb 11, 2025
e68e039
Resolved all the comments in the review part
SimonPergel Feb 11, 2025
ed7d584
Removed one feedbackloop as it was unnecessary, fixed the hourly pric…
Feb 11, 2025
9b7a64b
added so the user can choose price region
SimonPergel Feb 12, 2025
885c07a
cleand up the new switchRegion function and added some comments
SimonPergel Feb 12, 2025
b59a0fe
Added tests for the newly implemented features(Usertemp and REgion c…
SimonPergel Feb 13, 2025
9cc8398
Cleand up the new funtions that have been implemented
SimonPergel Feb 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
uses: actions/setup-go@v5
with:
go-version: 1.23
- name: Install dependencies
run: make deps
- name: Run tests
run: make test
- name: Report stats
Expand Down
134 changes: 92 additions & 42 deletions Comfortstat/Comfortstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func main() {

// instantiate a template unit asset
assetTemplate := initTemplate()
// Calling initAPI() starts the pricefeedbackloop that fetches the current electrisity price for the particular hour
initAPI()
time.Sleep(1 * time.Second)
assetName := assetTemplate.GetName()
sys.UAssets[assetName] = &assetTemplate

Expand All @@ -45,8 +48,8 @@ func main() {
if err := json.Unmarshal(raw, &uac); err != nil {
log.Fatalf("Resource configuration error: %+v\n", err)
}
ua, cleanup := newUnitAsset(uac, &sys, servsTemp)
defer cleanup()
ua, startup := newUnitAsset(uac, &sys, servsTemp)
startup()
sys.UAssets[ua.GetName()] = &ua
}

Expand All @@ -66,117 +69,164 @@ func main() {
time.Sleep(2 * time.Second) // allow the go routines to be executed, which might take more time than the main routine to end
}

// TODO: change the namne, will get one function for each of the four cases
// Serving handles the resources services. NOTE: it exepcts those names from the request URL path
func (t *UnitAsset) Serving(w http.ResponseWriter, r *http.Request, servicePath string) {
switch servicePath {
case "min_temperature":
t.set_minTemp(w, r)
case "max_temperature":
t.set_maxTemp(w, r)
case "max_price":
t.set_maxPrice(w, r)
case "min_price":
t.set_minPrice(w, r)
case "SEK_price":
t.set_SEKprice(w, r)
case "desired_temp":
t.set_desiredTemp(w, r)
case "MinTemperature":
Copy link
Owner Author

@lmas lmas Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An observation here, there's no need for action.
These aren't function names and didn't need to be updated. I admit I could have spent more time writing better comments and clarify this better.

Have you thought about any side effects this change may have? This block of code is part of your system's public API.
Changing these names here resulted in a change in the API and broke for example the GUI app and the influxdb system (as both have hard-coded dependencies on the previous names).

This is why we do code reviews, to find oversights like this.

t.httpSetMinTemp(w, r)
case "MaxTemperature":
t.httpSetMaxTemp(w, r)
case "MaxPrice":
t.httpSetMaxPrice(w, r)
case "MinPrice":
t.httpSetMinPrice(w, r)
case "SEKPrice":
t.httpSetSEKPrice(w, r)
case "DesiredTemp":
t.httpSetDesiredTemp(w, r)
case "userTemp":
t.httpSetUserTemp(w, r)
case "Region":
t.httpSetRegion(w, r)
default:
http.Error(w, "Invalid service request [Do not modify the services subpath in the configurration file]", http.StatusBadRequest)
}
}

func (rsc *UnitAsset) set_SEKprice(w http.ResponseWriter, r *http.Request) {
func (rsc *UnitAsset) httpSetSEKPrice(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "GET":
signalErr := rsc.getSEK_price()
signalErr := rsc.getSEKPrice()
usecases.HTTPProcessGetRequest(w, r, &signalErr)
default:
http.Error(w, "Method is not supported.", http.StatusNotFound)
}
}

// TODO: split up this function to two sepreate function that sets on max and min price.
func (rsc *UnitAsset) set_minTemp(w http.ResponseWriter, r *http.Request) {
// All these functions below handles HTTP "PUT" or "GET" requests to modefy or retrieve the MAX/MIN temprature/price and desierd temprature
// For the PUT case - the "HTTPProcessSetRequest(w, r)" is called to prosses the data given from the user and if no error,
// call the set functions in things.go with the value witch updates the value in the struct
func (rsc *UnitAsset) httpSetMinTemp(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "PUT":
sig, err := usecases.HTTPProcessSetRequest(w, r)
if err != nil {
log.Println("Error with the setting request of the position ", err)
//log.Println("Error with the setting request of the position ", err)
http.Error(w, "request incorreclty formated", http.StatusBadRequest)
return

}
rsc.setMin_temp(sig)
rsc.setMinTemp(sig)
case "GET":
signalErr := rsc.getMin_temp()
signalErr := rsc.getMinTemp()
usecases.HTTPProcessGetRequest(w, r, &signalErr)
default:
http.Error(w, "Method is not supported.", http.StatusNotFound)
}
}
func (rsc *UnitAsset) set_maxTemp(w http.ResponseWriter, r *http.Request) {
func (rsc *UnitAsset) httpSetMaxTemp(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "PUT":
sig, err := usecases.HTTPProcessSetRequest(w, r)
if err != nil {
//log.Println("Error with the setting request of the position ", err)
http.Error(w, "request incorreclty formated", http.StatusBadRequest)
return
}
rsc.setMaxTemp(sig)
case "GET":
signalErr := rsc.getMaxTemp()
usecases.HTTPProcessGetRequest(w, r, &signalErr)
default:
http.Error(w, "Method is not supported.", http.StatusNotFound)
}
}

func (rsc *UnitAsset) httpSetMinPrice(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "PUT":
sig, err := usecases.HTTPProcessSetRequest(w, r)
if err != nil {
log.Println("Error with the setting request of the position ", err)
//log.Println("Error with the setting request of the position ", err)
http.Error(w, "request incorreclty formated", http.StatusBadRequest)
return
}
rsc.setMax_temp(sig)
rsc.setMinPrice(sig)
case "GET":
signalErr := rsc.getMax_temp()
signalErr := rsc.getMinPrice()
usecases.HTTPProcessGetRequest(w, r, &signalErr)
default:
http.Error(w, "Method is not supported.", http.StatusNotFound)

}
}

// LOOK AT: I guess that we probable only need to if there is a PUT from user?
// LOOK AT: so not the GET!
// For PUT - the "HTTPProcessSetRequest(w, r)" is called to prosses the data given from the user and if no error, call set_minMaxprice with the value
// wich updates the value in thge struct
func (rsc *UnitAsset) set_minPrice(w http.ResponseWriter, r *http.Request) {
func (rsc *UnitAsset) httpSetMaxPrice(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "PUT":
sig, err := usecases.HTTPProcessSetRequest(w, r)
if err != nil {
log.Println("Error with the setting request of the position ", err)
//log.Println("Error with the setting request of the position ", err)
http.Error(w, "request incorreclty formated", http.StatusBadRequest)
return
}
rsc.setMin_price(sig)
rsc.setMaxPrice(sig)
case "GET":
signalErr := rsc.getMin_price()
signalErr := rsc.getMaxPrice()
usecases.HTTPProcessGetRequest(w, r, &signalErr)
default:
http.Error(w, "Method is not supported.", http.StatusNotFound)

}
}

func (rsc *UnitAsset) set_maxPrice(w http.ResponseWriter, r *http.Request) {
func (rsc *UnitAsset) httpSetDesiredTemp(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "PUT":
sig, err := usecases.HTTPProcessSetRequest(w, r)
if err != nil {
log.Println("Error with the setting request of the position ", err)
//log.Println("Error with the setting request of the position ", err)
http.Error(w, "request incorreclty formated", http.StatusBadRequest)
return
}
rsc.setMax_price(sig)
rsc.setDesiredTemp(sig)
case "GET":
signalErr := rsc.getMax_price()
signalErr := rsc.getDesiredTemp()
usecases.HTTPProcessGetRequest(w, r, &signalErr)
default:
http.Error(w, "Method is not supported.", http.StatusNotFound)
}

}

func (rsc *UnitAsset) httpSetUserTemp(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "PUT":
sig, err := usecases.HTTPProcessSetRequest(w, r)
if err != nil {
http.Error(w, "request incorrectly formated", http.StatusBadRequest)
return
}
rsc.setUserTemp(sig)
case "GET":
signalErr := rsc.getUserTemp()
usecases.HTTPProcessGetRequest(w, r, &signalErr)
default:
http.Error(w, "Method is not supported.", http.StatusNotFound)
}
}

func (rsc *UnitAsset) set_desiredTemp(w http.ResponseWriter, r *http.Request) {
func (rsc *UnitAsset) httpSetRegion(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "PUT":
sig, err := usecases.HTTPProcessSetRequest(w, r)
if err != nil {
log.Println("Error with the setting request of the position ", err)
http.Error(w, "request incorrectly formated", http.StatusBadRequest)
return
}
rsc.setDesired_temp(sig)
rsc.setRegion(sig)
case "GET":
signalErr := rsc.getDesired_temp()
signalErr := rsc.getRegion()
usecases.HTTPProcessGetRequest(w, r, &signalErr)
default:
http.Error(w, "Method is not supported.", http.StatusNotFound)
Expand Down
Loading