示例#1
0
	CpFilter                                                             int  //5,20,60 sec etc...
	ShowCPs                                                              bool //whether user wishes to show notable CPs on graph
	HvpTo, HvpFrom                                                       int  //time in minutes
	OffsetDays                                                           int  //number of days to end filter period
	StandardRides                                                        []int
}

//create a data type to represent aggregated sample data
type Samples struct {
	Power, Hr, Cad, Samplecount, Freewheelcount int
}

//general
var day = time.Hour * 24
var history_days = 90
var config = conf.Configuration()

func AnalysisHandler(w http.ResponseWriter, r *http.Request) {
	// http://stackoverflow.com/questions/12830095/setting-http-headers-in-golang
	if origin := r.Header.Get("Origin"); origin != "" {
		w.Header().Set("Access-Control-Allow-Origin", origin)
	}
	w.Header().Set("Access-Control-Allow-Credentials", "true")
	w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
	w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token")

	var user types.UserSettings //user info
	var filter Filter           //filter settings
	filter.Historylen = history_days

	urlpath := r.URL.Path[1:] //get the path (after the domain:port slash)/eg view/activity/ActIviTyiD
示例#2
0
func Get(enc_uid string) (user types.UserSettings, _err error) {
	conf := conf.Configuration()

	db, err := sql.Open("mysql", conf.MySQLUser+":"+conf.MySQLPass+"@tcp("+conf.MySQLHost+":3306)/"+conf.MySQLDB)

	var uid string
	err = db.QueryRow("SELECT email FROM user WHERE access_token=? LIMIT 1", enc_uid).Scan(&uid)

	//get the decoded user email (id)
	//uid, err := utility.Decode(enc_uid)

	if uid == "" {
		uid = conf.DemoUser
		user.Demo = true
	}

	var paid_account bool
	var my_ftp, my_thr, my_rhr, my_weight, set_ncp_rolloff, my_age, set_data_cutoff, id int
	var set_autofill, my_gender, ride_label string
	var my_vo2 float32
	var standard_ride types.StandardRide
	var standard_rides []types.StandardRide

	err = db.QueryRow("SELECT paid_account, my_ftp, my_thr, my_rhr, my_weight, set_ncp_rolloff, set_autofill, set_data_cutoff, my_age, my_vo2, my_gender FROM user WHERE email=?", uid).Scan(
		&paid_account,
		&my_ftp,
		&my_thr,
		&my_rhr,
		&my_weight,
		&set_ncp_rolloff,
		&set_autofill,
		&set_data_cutoff,
		&my_age,
		&my_vo2,
		&my_gender,
	)

	if err != nil {
		_err = err
	}
	//get the user's standard rides
	rows, err := db.Query("SELECT id, ride_label FROM standard_rides WHERE email=?", uid)
	defer rows.Close()

	for rows.Next() {
		rows.Scan(&id, &ride_label)
		standard_ride.Id = id
		standard_ride.Label = ride_label
		standard_rides = append(standard_rides, standard_ride)
	}
	defer db.Close()

	user.EncId = url.QueryEscape(enc_uid)
	user.Email = uid
	user.Id = strings.Replace(uid, "@", "%40", 1) //respecting the initial cookie based auth..
	user.Paid_account = paid_account
	user.Ftp = my_ftp
	user.Thr = my_thr
	user.Rhr = my_rhr
	user.Weight = my_weight
	user.Ncp_rolloff = set_ncp_rolloff
	user.Autofill = set_autofill
	user.Stopgap = time.Duration(set_data_cutoff)
	user.Age = my_age
	user.Vo2 = my_vo2
	user.Gender = my_gender
	user.StandardRides = standard_rides

	//hardcoded (for now) settings
	user.Atl_constant = 7
	user.Ctl_constant = 42
	user.SampleSize = 5
	user.TimeOffset = 0 //eg 0, -1, -2 etc... or 7 go forward a week

	return

}