func TestConvertor(t *testing.T) {
	//expected
	theTime, _ := time.Parse("Mon Jan 2 15:04:05 -0700 MST 2006", "Mon Jan 2 15:04:05 -0700 MST 2006")
	duration := 10000
	theType := "Running"
	name := "Test Activity"
	notes := "Some Random\n Bullshit"

	stvActivity := stravalib.ActivityDetailed{}
	stvActivity.Name = name
	stvActivity.ElapsedTime = duration
	stvActivity.StartDate = theTime
	stvActivity.Description = notes
	stvActivity.Type = stravalib.ActivityTypes.Run

	activity := ConvertToActivity(&stvActivity, nil, nil, nil)
	resultActivity := dm.CreateActivity()
	resultActivity.StartTime = int(theTime.Unix())
	resultActivity.Duration = duration
	resultActivity.Type = theType
	resultActivity.Name = name

	fmt.Printf("%s\n", activity)
	fmt.Printf("%s\n", resultActivity)

	//this compare probably doesnt work as expected
	if !activity.ConsideredEqual(resultActivity) {
		t.Error("activity should match resultActivity")
	}
}
func ConvertToActivity(rkActivity *runkeeper.FitnessActivity) *dm.Activity {
	returnActivity := dm.CreateActivity()
	if rkActivity.Type == "Other" {
		returnActivity.Type = "Activity"
	} else {
		returnActivity.Type = rkActivity.Type
	}

	//RK time is 'Local'
	correctedTime := time.Time(rkActivity.StartTime).Add(time.Duration(rkActivity.UtcOffset) * time.Hour)
	log.Printf("RK Local date: %s, start date: %s, unix: %d, offset: %d", time.Time(rkActivity.StartTime), correctedTime, time.Time(rkActivity.StartTime).Unix(), rkActivity.UtcOffset)
	returnActivity.StartTime = int(time.Time(correctedTime).Unix())
	returnActivity.UtcOffSet = rkActivity.UtcOffset
	returnActivity.Duration = int(rkActivity.Duration)
	returnActivity.Name = rkActivity.Notes
	returnActivity.Notes = "" //rkActivity.Comment //hmm dunno
	returnActivity.Private = false
	returnActivity.Stationary = rkActivity.HasMap
	returnActivity.AverageHeartRate = 0 //rkActivity.AverageHeartRate
	returnActivity.Calories = rkActivity.TotalCalories
	returnActivity.Distance = rkActivity.TotalDistance
	returnActivity.GPS = convertFromPath(rkActivity.Path)
	returnActivity.HeartRate = convertFromHR(rkActivity.HeartRate)

	//log.Printf("INPUT: %s, OUTPUT: %s", rkActivity, returnActivity)
	return returnActivity
}
func TestFromRKConvertor(t *testing.T) {
	rkActivity := runkeeper.FitnessActivity{}
	rkActivity.Type = "Running"
	tim, _ := time.Parse("Mon, 2 Jan 2006 15:04:05", "Tue, 1 Mar 2011 07:00:00")
	rkActivity.StartTime = runkeeper.Time(tim)
	rkActivity.Duration = 10
	rkActivity.Source = "RunKeeper"
	rkActivity.EntryMode = "API"
	rkActivity.HasMap = true
	rkActivity.Uri = "/activities/40"
	rkActivity.Path = make([]runkeeper.Path, 2)
	rkActivity.Path[0] = runkeeper.Path{1.0, 0.0, "gps", 10.0, 11.0}
	rkActivity.Path[1] = runkeeper.Path{2.0, 0.0, "gps", 15.0, 13.0}
	rkActivity.HeartRate = make([]runkeeper.HeartRate, 1)
	rkActivity.HeartRate[0] = runkeeper.HeartRate{1.0, 2}

	expectedActivity := dm.CreateActivity()
	expectedActivity.StartTime = int(tim.Unix())
	expectedActivity.Duration = 10
	expectedActivity.Type = "Running"
	activity := ConvertToActivity(&rkActivity)

	if !activity.ConsideredEqual(expectedActivity) ||
		len(activity.GPS) != 2 ||
		len(activity.HeartRate) != 1 {

		t.Error(fmt.Sprintf("activity %s should match result activity", activity))
	}
}
func TestToRKConvertor(t *testing.T) {
	activity := dm.CreateActivity()
	activity.Type = "Activity"

	rkActivity := ConvertToRkActivity(activity)

	if rkActivity.Type != "Other" {
		t.Error(fmt.Sprintf("Type %s of activity should match \"Other\"", rkActivity.Type))
	}
}
func TestOtherActivityType(t *testing.T) {
	rkActivity := runkeeper.FitnessActivity{}
	rkActivity.Type = "Other"

	expectedActivity := dm.CreateActivity()
	expectedActivity.Type = "Activity"

	activity := ConvertToActivity(&rkActivity)
	if activity.Type != expectedActivity.Type {
		t.Error(fmt.Sprintf("Type %s of activity should match %s", activity.Type, expectedActivity.Type))
	}
}
func ConvertToActivity(stravaActivity *stravalib.ActivityDetailed, timeStream *stravalib.StreamSet, gpsTrack *stravalib.StreamSet, hrTrack *stravalib.StreamSet) *dm.Activity {
	stvActivity := dm.CreateActivity()
	stvActivity.StartTime = int(stravaActivity.StartDate.Unix()) //UTC date
	//stvActivity.StartTime = int(stravaActivity.StartDateLocal.Unix()) //UTC +1 Date (local)
	log.Printf("STV Local date: %s, start date: %s, unix: %d", stravaActivity.StartDateLocal, stravaActivity.StartDate, stravaActivity.StartDate.Unix())
	stvActivity.Duration = stravaActivity.ElapsedTime
	stvActivity.Name = stravaActivity.Name
	stvActivity.Calories = stravaActivity.Calories
	stvActivity.Distance = stravaActivity.Distance
	stvActivity.AverageHeartRate = int(stravaActivity.AverageHeartrate)
	loc, err := time.LoadLocation(stravaActivity.TimeZone)
	if err != nil {
		timeInTZ := time.Time(stravaActivity.StartDate).In(loc)
		_, offsetInSeconds := timeInTZ.Zone()
		stvActivity.UtcOffSet = offsetInSeconds / 60 / 60
	} else {
		log.Print("Error reading location from strava Activity: %s", err)
	}

	if stravaActivity.Type.String() == "Run" {
		stvActivity.Type = "Running"
	} else if stravaActivity.Type.String() == "Ride" || stravaActivity.Type.String() == "EBikeRide" || stravaActivity.Type.String() == "VirtualRide" {
		stvActivity.Type = "Cycling"
	} else if stravaActivity.Type.String() == "Swim" {
		stvActivity.Type = "Swimming"
	} else {
		//I don't know, call it Activity
		stvActivity.Type = "Activity"
	}

	if gpsTrack != nil && gpsTrack.Location != nil && timeStream != nil {
		stvActivity.GPS = convertGPSTrack(gpsTrack, timeStream)
	}
	if hrTrack != nil && hrTrack.HeartRate != nil && timeStream != nil {
		stvActivity.HeartRate = convertHeartRateTrack(hrTrack, timeStream)
	}
	return stvActivity
}