Exemple #1
0
// Updates the common game information
func updateGameInfo(games <-chan GameInfo, db *gorp.DbMap) <-chan GameInfo {
	// TODO: Use insert/update query instead
	var gameInfoQuery string = `
                            INSERT IGNORE INTO game_info
                                (id, mode, type, subType, mapId, date)
                            VALUES
                                (?, ?, ?, ?, ?, FROM_UNIXTIME(?))`

	out := make(chan GameInfo)
	globalWg.Add(1)
	go func() {

		for gi := range games {
			_, infoErr := db.Exec(
				gameInfoQuery,
				gi.Game.GameID,
				gi.Game.GameMode,
				gi.Game.GameType,
				gi.Game.SubType,
				gi.Game.MapID,
				gi.Game.CreateDate/1000)
			checkErr(infoErr, "Unable to insert new game info")

			out <- gi
		}
		close(out)

		globalWg.Done()
	}()

	return out
}
Exemple #2
0
func AdminSetPublished(db *gorp.DbMap, id int64, published bool) error {
	p := 0
	if published {
		p = 1
	}
	_, err := db.Exec("update New set Published = ? where Id =?", p, id)
	return err
}
// Saves runttime report to db
func saveLoadReport(StartTime string, EndTime string, Records int, dbmap *gorp.DbMap) {
	var reportQuery string = `INSERT INTO runtimes
            (startTime, endTime, records)
         VALUES
            (?,?,?)`
	_, err := dbmap.Exec(reportQuery,
		StartTime,
		EndTime,
		Records)

	checkErr(err, "Could not report to database")

	fmt.Println("Reported")
}
Exemple #4
0
// Updates summoner name and level
func updateSummoners(summoners <-chan SummonerInfo, dbmap *gorp.DbMap) {

	// we'll keep all the summoners details in here
	var SummonersGoRiot map[int64]goriot.Summoner = make(map[int64]goriot.Summoner)

	// Get summoner data from Riot in batches of
	// forty and then combine them
	go func() {
		globalWg.Add(1)
		var selectQueries []string
		for s := range summoners {

			// get riot data
			riotData, err := goriot.SummonerByID(goriot.NA, s.ID)
			checkErr(err, "Could not load summoners from Riot")

			// add to larger structure
			for k, v := range riotData {
				SummonersGoRiot[k] = v
			}

		}

		// Build a slice of select queries that will be UNIONd
		// together to help reduce DB calls
		for _, summoner := range SummonersGoRiot {
			selectQueries = append(
				selectQueries,
				fmt.Sprintf(
					"SELECT %d id, %d level, '%s' name",
					summoner.ID,
					summoner.SummonerLevel,
					summoner.Name))
		}

		// build final update query
		var updateQuery string = fmt.Sprintf(
			`UPDATE summoners s INNER JOIN (
				%s
			) r USING(id)
			SET s.level = r.level, s.name = r.name, s.last_update = UTC_TIMESTAMP();`,
			strings.Join(selectQueries, " UNION "))

		// run query and check for errors
		_, err := dbmap.Exec(updateQuery)
		checkErr(err, "Summoner update failed")
		globalWg.Done()
	}()

}
Exemple #5
0
// Updates a summoners specific game information
func updateSummonerGames(
	gameStats <-chan GameInfo,
	db *gorp.DbMap) {

	// save summoner_game
	// TODO: Use insert/update query instead
	var summonerGameQuery string = `
                        INSERT IGNORE INTO summoner_games
                            (summonerId,
							 gameId,
							 championId,
							 spellOne,
							 spellTwo,
							 minionsKilled,
							 numDeaths,
							 assists,
							 championsKilled,
                             won)
                        VALUES
                            (?,?,?,?,?,?,?,?,?,?)`
	globalWg.Add(1)
	go func() {

		for gs := range gameStats {
			_, sgErr := db.Exec(
				summonerGameQuery,
				gs.SummonerID,
				gs.Game.GameID,
				gs.Game.ChampionID,
				gs.Game.Spell1,
				gs.Game.Spell2,
				gs.Game.Statistics.MinionsKilled,
				gs.Game.Statistics.NumDeaths,
				gs.Game.Statistics.Assists,
				gs.Game.Statistics.ChampionsKilled,
				gs.Game.Statistics.Win)
			checkErr(sgErr, "Could not save summoner game info")
		}

		globalWg.Done()
	}()
}
Exemple #6
0
func (r Rate) Vote(Db *gorp.DbMap, v string, u int64) (Rate, error) {
	var el int64
	if r.Id == 0 {
		return Rate{}, errors.New("Rate not found")
	}
	r = r.GetRate(Db, r.ItemType, r.ItemId)
	id, err := Db.SelectInt("select RateId from Vote where RateId = ? and"+
		" UserId = ?", r.Id, u)
	if err != nil {
		return Rate{}, err
	}
	if id != 0 {
		return Rate{}, errors.New("You have already voted")
	}
	switch v {
	case "a":
		el = -1
		r.Against++
		Db.Exec("update Rate set Against = Against+1 where Id = ?", r)
		break
	case "b":
		el = 1
		r.Behind++
		Db.Exec("update Rate set Behind = Behind+1 where Id = ?", r)
		break
	default:
		return Rate{}, errors.New("Vote election undefined")
	}

	r.Rate = WilsonSum(r.Behind-r.Against, r.Against+r.Behind)

	vote := Vote{
		RateId: r.Id,

		Value:  el,
		UserId: u,
	}

	Db.Update(&r)
	Db.Insert(&vote)
	return r, nil
}
Exemple #7
0
func BasketAdd(db *gorp.DbMap, userid, storeid, productid, count int64) error {
	t := time.Now().UnixNano()
	b := StoreBasket{
		UserId:    userid,
		StoreId:   storeid,
		ProductId: productid,
		Count:     count,
		Created:   t,
		Updated:   t,
	}

	res, err := db.Exec("update StoreBasket set Count = Count + ?, Updated = ?"+
		" where UserId = ? and StoreId=? and ProductId=?",
		count, t, userid, storeid, productid)
	if err != nil {
		return err
	}
	if num, err := res.RowsAffected(); err == nil && num == 0 {
		err := db.Insert(&b)
		return err
	}
	return err
}
Exemple #8
0
func SentenceDelete(ren render.Render, params martini.Params, dbmap *gorp.DbMap) {
	_, err := dbmap.Exec("DELETE FROM sentences WHERE id= $1", params["id"])
	PanicIf(err)
	ren.JSON(200, nil)
}
Exemple #9
0
func AdminSetDeleted(db *gorp.DbMap, id int64) error {
	_, err := db.Exec("update New set Deleted = ? where Id = ?",
		time.Now().UnixNano(), id)
	return err
}
Exemple #10
0
func BasketClean(db *gorp.DbMap, userid, storeid int64) error {
	_, err := db.Exec("delete from StoreBasket where UserId = ? and "+
		"StoreId = ?", userid, storeid)
	return err
}
Exemple #11
0
func BasketRemove(db *gorp.DbMap, userid, storeid, productid int64) error {
	_, err := db.Exec("delete from StoreBasket where UserId = ? and "+
		"StoreId = ? and ProductId=?", userid, storeid, productid)
	return err
}
Exemple #12
0
func DeleteComment(db *gorp.DbMap, commentId int64) error {
	_, err := db.Exec("update Comment set Deleted = ? where Id = ?",
		time.Now().UnixNano(), commentId)
	return err
}