insights

package module
v0.0.0-...-9b6f7ed Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2020 License: MIT Imports: 6 Imported by: 0

README

WhatsApp Insights Analyzer Using GoLang

This code generates brief insights for a WhatsApp chat of a given user.

Usage

   # you can clone the repository and make the binary yourself
   λ git clone git@github.com:VEDANTGHODKE/WhatsApp-Insights-Analyzer-Using-GoLang
   λ cd insights
   λ make
   λ ./bin/insights ./path/to/chat/file.txt
   # for different timezones you can use -timezone flag
   λ insights -pretty -timezone=Asia/Kolkata ./path/to/chat/file.txt

Or you can just download prebuilt binaries from here: Link

Metrics

  • First Message
  • Last Message
  • Duration
  • Frequency (how many messages in every hour of day)
  • Total Messages
  • Total Words
  • Total Letters
  • Average Words Per Message
  • Average Letters Per Message
  • Average Messages Per Day
  • Average Words Per Day
  • Average Letters Per Day
  • Participants
  • Contribution Per Participant
  • Contribution Count Per Participant
  • Contribution Words Per Participant
  • Contribution Letters Per Participant
  • Contribution Frequency Per Participant
  • Timeline (how many messages per day/week/month/year)
  • Timeline Count
  • Timeline Words
  • Timeline Letters
  • Most Active Day
  • Most Active Count
  • Least Active Day
  • Least Active Count
  • Emoji Used

Graphs

It also comes with a server that would represent the data extracted from the chat in graphical format it would require -server argument during execution, it would look like this:

Implementations

This is a very crude implementation that I coded within a single day, hence there are lots of potential improvements that could be done. In any case, please feel free to send a PR or raise an issue if you find anything interesting.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidMessage = fmt.Errorf("invalid message")

Functions

func CountEmoji

func CountEmoji(src string) (m map[string]int)

Types

type Contribution

type Contribution map[string]Conversation

func NewContribution

func NewContribution(c Conversation) (contrib Contribution)

func (Contribution) Extract

func (c Contribution) Extract() (count, words, letters map[string]int, frequency map[string]map[string]int)

type Conversation

type Conversation []*Message

func NewConversation

func NewConversation(src string, tz string) (c Conversation, err error)

func (Conversation) Average

func (c Conversation) Average() (words, letters float64)

func (Conversation) Contribution

func (c Conversation) Contribution() (contrib Contribution)

func (Conversation) Count

func (c Conversation) Count() int

func (Conversation) Duration

func (c Conversation) Duration() time.Duration

func (Conversation) Emoji

func (c Conversation) Emoji() map[string]map[string]int

func (Conversation) First

func (c Conversation) First() (m *Message)

func (Conversation) Frequency

func (c Conversation) Frequency() (m map[string]int)

func (Conversation) Last

func (c Conversation) Last() (m *Message)

func (Conversation) Letters

func (c Conversation) Letters() int

func (Conversation) Participants

func (c Conversation) Participants() (p Participants)

func (Conversation) Timeline

func (c Conversation) Timeline(period time.Duration) (t Timeline)

func (Conversation) Words

func (c Conversation) Words() int

type Insights

type Insights struct {
	First     *Message       `json:"first"`
	Last      *Message       `json:"last"`
	Duration  time.Duration  `json:"duration"`
	Frequency map[string]int `json:"frequency"`

	TotalMessages int `json:"totalMessages"`
	TotalWords    int `json:"totalWords"`
	TotalLetters  int `json:"totalLetters"`

	AverageWordsPerMessage   float64 `json:"averageWordsPerMessage"`
	AverageLettersPerMessage float64 `json:"averageLettersPerMessage"`

	Participants Participants `json:"participants"`

	Contribution          Contribution              `json:"contribution"`
	ContributionCount     map[string]int            `json:"contributionCount"`
	ContributionWords     map[string]int            `json:"contributionWords"`
	ContributionLetters   map[string]int            `json:"contributionLetters"`
	ContributionFrequency map[string]map[string]int `json:"contributionFrequency"`

	Timeline        Timeline          `json:"timeline"`
	TimelineCount   map[time.Time]int `json:"timelineCount"`
	TimelineWords   map[time.Time]int `json:"timelineWords"`
	TimelineLetters map[time.Time]int `json:"timelineLetters"`

	MostActiveDay    time.Time `json:"mostActiveDay"`
	MostActiveCount  int       `json:"mostActiveCount"`
	LeastActiveDay   time.Time `json:"leastActiveDay"`
	LeastActiveCount int       `json:"leastActiveCount"`

	AverageMessagesPerDay float64 `json:"averageMessagesPerDay"`
	AverageWordsPerDay    float64 `json:"averageWordsPerDay"`
	AverageLettersPerDay  float64 `json:"averageLettersPerDay"`

	EmojisUsed map[string]map[string]int `json:"emojisUsed"`
}

func New

func New(c Conversation) *Insights

type Message

type Message struct {
	Sender string    `json:"sender"`
	Time   time.Time `json:"time"`
	Text   string    `json:"text"`
	Type   Type      `json:"type"`
	// contains filtered or unexported fields
}

func NewMessage

func NewMessage(raw string, loc *time.Location) (*Message, error)

type Participants

type Participants []string

func NewParticipants

func NewParticipants(c Conversation) (p Participants)

type Timeline

type Timeline map[time.Time]Conversation

func NewTimeline

func NewTimeline(c Conversation, d time.Duration) (t Timeline)

func (Timeline) Average

func (t Timeline) Average() (messages, words, letters float64)

func (Timeline) Days

func (t Timeline) Days() (keys []time.Time)

func (Timeline) Extract

func (t Timeline) Extract() (count, words, letters map[time.Time]int)

func (Timeline) Least

func (t Timeline) Least() (date time.Time, count int)

func (Timeline) Most

func (t Timeline) Most() (date time.Time, count int)

type Type

type Type int
const (
	MessageTypeText Type = iota
	MessageTypeVideo
	MessageTypeAudio
	MessageTypeImage
	MessageTypeContact
)

func (Type) MarshalJSON

func (t Type) MarshalJSON() (b []byte, err error)

func (*Type) UnmarshalJSON

func (t *Type) UnmarshalJSON(b []byte) (err error)

Directories

Path Synopsis
cmd
insights command

Jump to

Keyboard shortcuts

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