Exemple #1
0
func (ingest *Ingestion) formatTimeBounds(bounds *xdr.TimeBounds) interface{} {
	if bounds == nil {
		return nil
	}

	if bounds.MaxTime == 0 {
		return sq.Expr("?::int8range", fmt.Sprintf("[%d,]", bounds.MinTime))
	}

	return sq.Expr("?::int8range", fmt.Sprintf("[%d,%d]", bounds.MinTime, bounds.MaxTime))
}
Exemple #2
0
func GetAllProfiles(user_id int, timestamp int64) []profile.Profile {
	query := squirrel.Select(`
		id, user_id, timestamp,
		agent, level, ap,
		unique_portals_visited, portals_discovered, xm_collected,
		hacks, resonators_deployed, links_created, control_fields_created, mind_units_captured,
		longest_link_ever_created, largest_control_field, xm_recharged, portals_captured,
		unique_portals_captured, mods_deployed,
		resonators_destroyed, portals_neutralized, enemy_links_destroyed, enemy_control_fields_destroyed,
		distance_walked,
		max_time_portal_held, max_time_link_maintained, max_link_length_x_days, max_time_field_held,
		largest_field_mus_x_days,
		glyph_hack_points, consecutive_days_hacking,
		unique_missions_completed,
		agents_successfully_recruited,
		innovator
	`).From("tiers_profiles").OrderBy("timestamp ASC")

	query = query.Where(
		squirrel.And{
			squirrel.Eq{"user_id": user_id},
			squirrel.Expr("timestamp >= ?", timestamp),
		},
	)

	// XXX: Handle errors.
	rows, _ := query.RunWith(db).Query()
	defer rows.Close()

	var profiles []profile.Profile
	for rows.Next() {
		var p profile.Profile

		rows.Scan(
			&p.Id, &p.UserId, &p.Timestamp,
			&p.Nick, &p.Level, &p.AP,
			&p.UniquePortalsVisited, &p.PortalsDiscovered, &p.XMCollected,
			&p.Hacks, &p.ResonatorsDeployed, &p.LinksCreated, &p.ControlFieldsCreated, &p.MindUnitsCaptured,
			&p.LongestLinkEverCreated, &p.LargestControlField, &p.XMRecharged, &p.PortalsCaptured,
			&p.UniquePortalsCaptured, &p.ModsDeployed,
			&p.ResonatorsDestroyed, &p.PortalsNeutralized, &p.EnemyLinksDestroyed, &p.EnemyControlFieldsDestroyed,
			&p.DistanceWalked,
			&p.MaxTimePortalHeld, &p.MaxTimeLinkMaintained, &p.MaxLinkLengthXDays, &p.MaxTimeFieldHeld,
			&p.LargestFieldMUsXDays,
			&p.GlyphHackPoints, &p.ConsecutiveDaysHacking,
			&p.UniqueMissionsCompleted,
			&p.AgentsSuccessfullyRecruited,
			&p.InnovatorLevel,
		)

		profiles = append(profiles, p)
	}

	return profiles
}
Exemple #3
0
// StringArray returns a sq.Expr suitable for inclusion in an insert that represents
// the Postgres-compatible array insert.
func StringArray(str []string) interface{} {
	return sq.Expr(
		"?::character varying[]",
		fmt.Sprintf("{%s}", strings.Join(str, ",")),
	)
}