logstf

package module
v0.0.0-...-c08a5d1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2020 License: MIT Imports: 22 Imported by: 0

README

logstf

A library for downloading, parsing and summarizing logs.tf data.

Documentation

Overview

logstf does mostly ETL stuff for the logstf data

Index

Constants

This section is empty.

Variables

View Source
var ErrBadStatus error
View Source
var ErrNotFound error
View Source
var ErrTooMany error

Functions

func DefaultTableOpts

func DefaultTableOpts() *tableOpts

func Exists

func Exists(path string) bool

func FetchAPIFile

func FetchAPIFile(logId int64, path string) error

func FetchLogFile

func FetchLogFile(client *http.Client, logId int64, savePath string) error

func GetLatestLogId

func GetLatestLogId() (int64, error)

func Insert

func Insert(conn *sqlx.DB, s *LogSummary) error

func LogCacheFile

func LogCacheFile(logId int64, fileType FileFormat) string

func Rollback

func Rollback(tx *sqlx.Tx)

Rollback will rollback a transaction, logging any errors that happen

func ToTable

func ToTable(rows [][]string, opts *tableOpts) string

func UpdateCache

func UpdateCache(baseDir string, lookBackSize int64) error

UpdateCache does a more shallow update cycle meant to watch the homepage for new logs. Use the Downloader for fetching the full database from logstf

Types

type AmmoPack

type AmmoPack int

type ApiResponse

type ApiResponse struct {
	Version int `json:"version"`
	Teams   struct {
		Red  TeamStats `json:"Red"`
		Blue TeamStats `json:"Blue"`
	} `json:"teams"`
	Length  int                    `json:"length"`
	Players map[string]playerStats `json:"players"`
	Names   map[string]string      `json:"names"`
	Rounds  []struct {
		StartTime int    `json:"start_time"`
		Winner    string `json:"winner"`
		Team      struct {
			Blu teamRound `json:"blue"`
			Red teamRound `json:"red"`
		} `json:"team"`
		Events []struct {
			Type    string `json:"type"`
			Time    int    `json:"time"`
			Team    string `json:"team"`
			Steamid string `json:"steamid,omitempty"`
			Killer  string `json:"killer,omitempty"`
			Point   int    `json:"point,omitempty"`
			Medigun string `json:"medigun,omitempty"`
		} `json:"events"`
		//Players interface{} `json:"players"`
		FirstCap string `json:"firstcap"`
		Length   int64  `json:"length"`
	} `json:"rounds"`

	HealSpread map[string]map[string]int `json:"healspread"`

	ClassKills       map[string]classKills `json:"classkills"`
	ClassDeaths      map[string]classKills `json:"classdeaths"`
	ClassKillAssists map[string]classKills `json:"classkillassists"`
	Chat             []struct {
		Steamid string `json:"steamid"`
		Name    string `json:"name"`
		Msg     string `json:"msg"`
	} `json:"chat"`
	Info struct {
		Map             string        `json:"map"`
		Supplemental    bool          `json:"supplemental"`
		TotalLength     int64         `json:"total_length"`
		HasRealDamage   bool          `json:"hasRealDamage"`
		HasWeaponDamage bool          `json:"hasWeaponDamage"`
		HasAccuracy     bool          `json:"hasAccuracy"`
		HasHP           bool          `json:"hasHP"`
		HasHPReal       bool          `json:"hasHP_real"`
		HasHS           bool          `json:"hasHS"`
		HasHSHit        bool          `json:"hasHS_hit"`
		HasBS           bool          `json:"hasBS"`
		HasCP           bool          `json:"hasCP"`
		HasSB           bool          `json:"hasSB"`
		HasDT           bool          `json:"hasDT"`
		HasAS           bool          `json:"hasAS"`
		HasHR           bool          `json:"hasHR"`
		HasIntel        bool          `json:"hasIntel"`
		ADScoring       bool          `json:"AD_scoring"`
		Notifications   []interface{} `json:"notifications"`
		Title           string        `json:"title"`
		Date            int64         `json:"date"`
		Uploader        struct {
			ID   string `json:"id"`
			Name string `json:"name"`
			Info string `json:"info"`
		} `json:"uploader"`
	} `json:"info"`
	KillStreaks []killStreak `json:"killstreaks"`
	Success     bool         `json:"success"`
}

func FetchAPI

func FetchAPI(logId int64) (*ApiResponse, error)

func ReadJSON

func ReadJSON(logId int64) (*ApiResponse, error)

func (*ApiResponse) Summary

func (a *ApiResponse) Summary() *LogSummary

type Downloader

type Downloader struct {
	Failures  int64
	Successes int64

	Overwrite bool
	// contains filtered or unexported fields
}

func NewDownloader

func NewDownloader(penaltyIncrement int) *Downloader

func (*Downloader) AddRequest

func (d *Downloader) AddRequest(url string, path string)

func (*Downloader) Start

func (d *Downloader) Start(workers int, ctx context.Context)

func (*Downloader) Stop

func (d *Downloader) Stop()

func (*Downloader) Wait

func (d *Downloader) Wait()

type FileFormat

type FileFormat string
const JSONFormat FileFormat = ".json"
const ZipFormat FileFormat = ".zip"

type HealingSummary

type HealingSummary struct {
	Healing              int64
	Charges              map[Medigun]int
	ChargeLengths        []float64
	Drops                int
	AvgTimeToBuild       int
	AvgTimeBeforeUsing   int
	NearFullChargeDeaths int
	DeathsAfterCharge    int
	MajorAdvantagesLost  int
	BiggestAdvantageLost int

	Targets map[*Player]int64
	// contains filtered or unexported fields
}

func NewHealingSummary

func NewHealingSummary() *HealingSummary

func (*HealingSummary) AvgUberLen

func (h *HealingSummary) AvgUberLen() float64

func (*HealingSummary) Table

func (h *HealingSummary) Table(name string) string

type HealthPack

type HealthPack int

type Kill

type Kill struct {
	APOS      Position
	VPOS      Position
	Victim    steamid.SID64
	CreatedOn time.Time
}

Kill tracks the number, via instances, and positions of the attacker/victim

type LogSummary

type LogSummary struct {
	Id         int
	Players    map[steamid.SID64]*Player
	Teams      map[Team]*TeamSummary
	MatchName  string
	ServerName string
	Map        string
	ScoreRed   int
	ScoreBlu   int
	Duration   time.Duration
	CreatedOn  time.Time
	Rounds     []*RoundSummary
	Messages   []Message
	// contains filtered or unexported fields
}

func Get

func Get(logId int64) (*LogSummary, error)

func NewSummary

func NewSummary() *LogSummary

func (*LogSummary) Apply

func (s *LogSummary) Apply(line string)

Apply will parse the input line and send the results to the appropriate method to apply the state update.1

NOTE We are relying on the rx engine to match group names, so we dont check most keys first

func (*LogSummary) GetPlayersByClass

func (s *LogSummary) GetPlayersByClass(class PlayerClass) []*Player

func (*LogSummary) LoadApiResponse

func (s *LogSummary) LoadApiResponse(r *ApiResponse) error

func (*LogSummary) PrintHealing

func (s *LogSummary) PrintHealing()

func (*LogSummary) PrintPlayers

func (s *LogSummary) PrintPlayers(sortBy SortAttr)

func (*LogSummary) TotalLength

func (s *LogSummary) TotalLength() time.Duration

type Medigun

type Medigun int

type Message

type Message struct {
	Player    *Player
	TeamChat  bool
	Message   string
	Timestamp time.Time
}

type MsgType

type MsgType int

type Player

type Player struct {
	Name           string
	SteamId        steamid.SID64
	Team           Team
	Kills          []Kill
	Deaths         []Kill
	Assists        int
	Revenges       int
	Dominations    int
	Dominated      int
	Healed         int64 // self healing, not medic healing
	Damage         int64
	DamageTaken    int64
	SmallMedPacks  int
	MediumMedPacks int
	FullMedPacks   int
	ShotsFired     int
	ShotsHit       int
	BackStabs      int
	HeadShots      int
	AirShots       int
	Captures       int
	Defenses       int
	Classes        map[PlayerClass]classStats // Classes we have played
	HealingSum     *HealingSummary            // Medic players will get a healing summary
	CurrentClass   PlayerClass
	// contains filtered or unexported fields
}

Player represents a player on the server. The base properties are global across the match.

func NewPlayer

func NewPlayer(sum *LogSummary) *Player

func (*Player) AddClass

func (p *Player) AddClass(cls PlayerClass)

func (*Player) DamagePerMin

func (p *Player) DamagePerMin() float64

func (*Player) DamageTakenPerMin

func (p *Player) DamageTakenPerMin() float64

func (*Player) KAD

func (p *Player) KAD() float64

KAD returns kills and assists per death

func (*Player) KD

func (p *Player) KD() float64

KD returns kills per death

func (*Player) Packs

func (p *Player) Packs() int

type PlayerClass

type PlayerClass int

type Position

type Position struct {
	X int64
	Y int64
	Z int64
}

type RoundSummary

type RoundSummary struct {
	Length    time.Duration
	LengthRt  time.Duration
	ScoreRed  int
	ScoreBlu  int
	KillsRed  int
	KillsBlu  int
	UbersRed  int
	UbersBlu  int
	DamageRed int64
	DamageBlu int64
	Winner    Team
	MidFight  Team // SPEC == nobody has capped mid yet for the round
}

type SortAttr

type SortAttr int

type Team

type Team uint8
const (
	SPEC Team = 0
	RED  Team = 1
	BLU  Team = 2
)

type TeamStats

type TeamStats struct {
	Score     int `json:"score"`
	Kills     int `json:"kills"`
	Deaths    int `json:"deaths"`
	Dmg       int `json:"dmg"`
	Charges   int `json:"charges"`
	Drops     int `json:"drops"`
	Firstcaps int `json:"firstcaps"`
	Caps      int `json:"caps"`
}

type TeamSummary

type TeamSummary struct {
	Kills     int
	Damage    int64
	Charges   int
	Drops     int
	Caps      int
	MidFights int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL