Esempio n. 1
0
func ServeWorkout(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	wIdStr := vars["workoutId"]
	wId, err := strconv.ParseInt(wIdStr, 10, 64)
	if err != nil {
		failParams := models.Response{Success: false, Debug: fmt.Sprintf("Invalid workout id, %s", wIdStr), Message: "Failed Retrieving the Workout"}
		api.JSONResponse(w, failParams, 400)
		return
	}
	pl := models.WorkoutResponse{Id: wId}
	err = pl.FindById()
	if err != nil {
		failParams := models.Response{Success: false, Debug: "Internal server error. If this issue persists, please submit a bug report to {{serviceName}}", Message: "Failed Retrieving the Workout"}
		api.JSONResponse(w, failParams, 500)
		return
	}
	w.Header().Set("Content-Type", "text/html; charset=utf-8")
	workoutTempl.Execute(w, pl)
}
Esempio n. 2
0
func V0_API_Get_Workout(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	wIdStr := vars["workoutId"]
	wId, err := strconv.ParseInt(wIdStr, 10, 64)
	if err != nil {
		failParams := models.Response{Success: false, Debug: fmt.Sprintf("Invalid workout id, %s", wIdStr), Message: "Failed Retrieving the Workout"}
		JSONResponse(w, failParams, 400)
		return
	}
	pl := models.WorkoutResponse{Id: wId}
	err = pl.FindById()
	if err != nil {
		failParams := models.Response{Success: false, Debug: "Internal server error. If this issue persists, please submit a bug report to {{serviceName}}", Message: "Failed Retrieving the Workout"}
		JSONResponse(w, failParams, 500)
		return
	}
	successResp := models.Response{Success: true, Data: pl, Message: "Successfully Retrieved the Workout"}
	JSONResponse(w, successResp, 200)
}
Esempio n. 3
0
func WorkoutOne(req models.WorkoutRequest) (models.WorkoutResponse, error) {
	resp := models.WorkoutResponse{}
	resp.TimeSpentS = req.TimeSpentS
	resp.PostPoints = calculateWorkoutOneImage(req.PostImage)
	resp.PrePoints = calculateWorkoutOneImage(req.PreImage)
	resp.DeltaPoints = models.FindDeltasForSetOfPoints(resp.PrePoints, resp.PostPoints)
	populateWorkoutOneBody(&resp)
	populateWorkoutOneTitle(&resp)
	resp.PreImage = req.PreImage.ImageURL
	resp.PostImage = req.PostImage.ImageURL
	return resp, nil
}
Esempio n. 4
0
func populateWorkoutOneBody(req *models.WorkoutResponse) {
	var sumIncreased int64 = 0
	for _, p := range req.DeltaPoints {
		sumIncreased += statistics.Round(math.Abs(float64(p.MedianTemp)))
	}
	meanIncrease := float64(sumIncreased) / float64(len(req.DeltaPoints))
	var sumMins int64
	for _, p := range req.PrePoints {
		sumMins += p.MinTemp - 273
	}
	meanMins := float64(sumMins) / float64(len(req.PrePoints))
	var sumMaxs int64
	for _, p := range req.PostPoints {
		sumMaxs += p.MaxTemp - 273
	}
	meanMaxs := float64(sumMaxs) / float64(len(req.PostPoints))
	req.Body += "Woah! What a great work out! The overall temperature of your targeted muscles increased by "
	req.Body += fmt.Sprintf("an average of %.2f˚C, with extremes of %.2f˚C to %.2f˚C. ", math.Abs(meanIncrease), meanMins, meanMaxs)
	lMedians := make([]int64, 6)
	rMedians := make([]int64, 6)
	for _, p := range req.PostPoints {
		alpha := p.Name[0:1]
		num, _ := strconv.Atoi(p.Name[1:2])
		if alpha == "R" {
			rMedians[num] = p.MedianTemp
		} else {
			lMedians[num] = p.MedianTemp
		}
	}
	diffHamstrings := float64((lMedians[0]+lMedians[1]))/2.0 - float64((rMedians[0]+rMedians[1]))/2.0
	if diffHamstrings > 0 {
		req.Body += fmt.Sprintf("In addition, we noticed that you worked your left hamstrings a bit harder than your right hamstrings. ")
	} else {
		req.Body += fmt.Sprintf("In addition, we noticed that you worked your right hamstrings a bit harder than your left hamstrings. ")
	}
	diffCalves := float64((lMedians[2]+lMedians[3]+lMedians[4]))/2.0 - float64((rMedians[2]+rMedians[3]+rMedians[4]))/2.0
	if diffCalves > 0 {
		req.Body += fmt.Sprintf("You also worked your left calves a bit harder than your right calves. ")
	} else {
		req.Body += fmt.Sprintf("You also worked your left calves a bit harder than your right calves. ")
	}
	diffAchilles := lMedians[5] - rMedians[5]
	if diffAchilles > -3 && diffAchilles < 3 {
		req.Body += fmt.Sprintf("On the other hand, your achilles are both of nearly the same temperature. ")
	}
	if (float64((lMedians[0]+lMedians[1]))/2.0+float64((rMedians[0]+rMedians[1]))/2.0)/2.0 > (float64((lMedians[2]+lMedians[3]+lMedians[4]))/2.0+float64((rMedians[2]+rMedians[3]+rMedians[4]))/2.0)/2.0 {
		req.Body += fmt.Sprintf("During your work out, you warmed up your calves more than your hamstrings. Good job, if this was your goal, if not, work on targeting your hamstrings with some hamstring curls, or Romanian deadlift. ")
	} else {
		req.Body += fmt.Sprintf("During your work out, you warmed up your hamstrings more than your calves. Good job, if this was your goal, if not, work on targeting your calves more with some calf raises. ")
	}
	if req.TimeSpentS < 60 {
		req.Body += fmt.Sprintf("Spend more time working out! You worked out for less 60 seconds, so next time try to do it for a few minutes! ")
	} else if req.TimeSpentS < 150 {
		req.Body += fmt.Sprintf("For spending less than two and a half minutes working out, this wasn't bad, next time try for a few minutes! ")
	} else {
		req.Body += fmt.Sprintf("Amazing job, you spent over two and a half minutes working out. Listen to these tips, and keep pushin' it! ")
	}
}
Esempio n. 5
0
func populateWorkoutOneTitle(req *models.WorkoutResponse) {
	req.Title = "Good Job, Mate!"
}