Skip to content

Commit

Permalink
Merge pull request #49 from lucasrodes/release/0.2.6
Browse files Browse the repository at this point in the history
Release/0.2.6
  • Loading branch information
lucasrodes committed May 6, 2020
2 parents 7b77ed8 + 7619bf5 commit 56d129f
Show file tree
Hide file tree
Showing 11 changed files with 197 additions and 138 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.2.5
current_version = 0.2.6

[bumpversion:file:setup.py]

Expand Down
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# whatstk: python whatsapp parser and analysis tool

![Package version](https://img.shields.io/badge/whatstk-v0.2.5-teal.svg?style=for-the-badge&color=25D366&logo=whatsapp)
![Package version](https://img.shields.io/badge/whatstk-v0.2.6-teal.svg?style=for-the-badge&color=25D366&logo=whatsapp)

[![Build Status](https://travis-ci.com/lucasrodes/whatstk.svg?branch=develop)](https://travis-ci.com/lucasrodes/whatstk)
[![Build Status](https://travis-ci.com/lucasrodes/whatstk.svg?branch=develop)](https://travis-ci.org/lucasrodes/whatstk)
[![codecov](https://codecov.io/gh/lucasrodes/whatstk/branch/master/graph/badge.svg)](https://codecov.io/gh/lucasrodes/whatstk)
[![Python 3.6](https://img.shields.io/badge/python-3.7|3.8-blue.svg)](https://www.python.org/downloads/release/python-3/)
[![Documentation](https://img.shields.io/badge/documentation-royalblue.svg)](docs/index.md)
Expand Down Expand Up @@ -162,15 +162,10 @@ header unit.

---

## Known issues
- 12h clock header format is not supported.

---

## Contributing

We are very open to have collaborators. You can freely fork and issue a pull request with your updates!
For other issues/bugs/suggestions, please report it as an issue or [text me](mailto:[email protected]).
For other issues/bugs/suggestions, please report it in the [issues section](https://github.com/lucasrodes/whatstk/issues).

### Pull Requests

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setup(
name='whatstk',
version="0.2.5",
version="0.2.6",
description="Parser and analytics tools for WhatsApp group chats",
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down
20 changes: 20 additions & 0 deletions tests/chats/example-12h-2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
2016-04-15, 3:04 p.m. - You created group “Sample Group”
2016-08-06, 1:18 p.m. - Messages you send to this group are now secured with end-to-end encryption. Tap for more info.
2016-08-06, 1:23 p.m. - Ash Ketchum: Hey guys!
2016-08-06, 1:25 p.m. - Brock: Hey Ash, good to have a common group!
2016-08-06, 1:30 p.m. - Misty: Hey guys! Long time haven't heard anything from you
2016-08-06, 1:45 p.m. - Ash Ketchum: Indeed. I think having a whatsapp group nowadays is a good idea
2016-08-06, 2:30 p.m. - Misty: Definetly
2016-08-06, 5:25 p.m. - Brock: I totally agree
2016-08-07, 11:45 p.m. - Prof. Oak: Kids, shall I design a smart poke-ball?
2016-08-07, 6:45 p.m. - Ash Ketchum: I don't mind Prof. I quitted capturing pokemon.
2016-08-07, 7:30 p.m. - Misty: Was a great time, but had enough also.
2016-08-07, 11:25 p.m. - Brock: Guys, I am still in the first gym. No one is playing pokemon, they went crazy with pokemon Go.
2016-08-10, 09:45 p.m. - Jessie & James: Hey, thanks for adding us. Wanna meet soon? Just for the old times.
2016-08-10, 11:25 p.m. - Raichu: I am in!
2016-08-10, 1:23 p.m. - Ash Ketchum: FFS, no way, Pikachu did you evolve?
2016-08-10, 3:23 p.m. - Raichu: Yes... Weird to have a different body!
2016-08-11, 7:30 p.m. - Misty: Gotta see that.
2016-09-11, 8:25 p.m. - Meowth: Hey people, I was on holidays in Sinnoh. Crazy region.
2016-10-31, 11:45 p.m. - Prof. Oak: Smart-pokeball is created.
2016-10-31, 02:23 p.m. - Wobbuffet: Wo-bbu-ffet
20 changes: 20 additions & 0 deletions tests/chats/example-12h.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
2016-04-15, 3:04 PM - You created group “Sample Group”
2016-08-06, 1:18 PM - Messages you send to this group are now secured with end-to-end encryption. Tap for more info.
2016-08-06, 1:23 PM - Ash Ketchum: Hey guys!
2016-08-06, 1:25 PM - Brock: Hey Ash, good to have a common group!
2016-08-06, 1:30 PM - Misty: Hey guys! Long time haven't heard anything from you
2016-08-06, 1:45 PM - Ash Ketchum: Indeed. I think having a whatsapp group nowadays is a good idea
2016-08-06, 2:30 PM - Misty: Definetly
2016-08-06, 5:25 PM - Brock: I totally agree
2016-08-07, 11:45 PM - Prof. Oak: Kids, shall I design a smart poke-ball?
2016-08-07, 6:45 PM - Ash Ketchum: I don't mind Prof. I quitted capturing pokemon.
2016-08-07, 7:30 PM - Misty: Was a great time, but had enough also.
2016-08-07, 11:25 PM - Brock: Guys, I am still in the first gym. No one is playing pokemon, they went crazy with pokemon Go.
2016-08-10, 09:45 AM - Jessie & James: Hey, thanks for adding us. Wanna meet soon? Just for the old times.
2016-08-10, 11:25 AM - Raichu: I am in!
2016-08-10, 1:23 PM - Ash Ketchum: FFS, no way, Pikachu did you evolve?
2016-08-10, 3:23 PM - Raichu: Yes... Weird to have a different body!
2016-08-11, 7:30 PM - Misty: Gotta see that.
2016-09-11, 8:25 PM - Meowth: Hey people, I was on holidays in Sinnoh. Crazy region.
2016-10-31, 11:45 PM - Prof. Oak: Smart-pokeball is created.
2016-10-31, 02:23 PM - Wobbuffet: Wo-bbu-ffet
209 changes: 107 additions & 102 deletions tests/test_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,174 +2,179 @@
from whatstk.objects import WhatsAppChat
import pandas as pd
import pytest
import os


filenames_path = "./tests/chats"
filenames = [os.path.join(filenames_path, f) for f in os.listdir(filenames_path) if f.endswith(".txt")]


def test_interventions_date():

filename = 'tests/chats/example_1.txt'
chat = WhatsAppChat.from_txt(filename)
counts = interventions(chat, date_mode='date', msg_length=False)
for filename in filenames:
chat = WhatsAppChat.from_txt(filename)
counts = interventions(chat, date_mode='date', msg_length=False)

assert(isinstance(counts, pd.DataFrame))
# Asswert chat df and counts df have same users
assert(set(chat.users) == set(counts.columns))
assert(isinstance(counts, pd.DataFrame))
# Asswert chat df and counts df have same users
assert(set(chat.users) == set(counts.columns))

# Assert chat df and counts df have same date window
assert(chat.df.index.max().date() == counts.index.max().date())
assert(chat.df.index.min().date() == counts.index.min().date())
# Assert chat df and counts df have same date window
assert(chat.df.index.max().date() == counts.index.max().date())
assert(chat.df.index.min().date() == counts.index.min().date())


def test_interventions_date_msg_length():

filename = 'tests/chats/example_1.txt'
chat = WhatsAppChat.from_txt(filename)
counts = interventions(chat, date_mode='date', msg_length=True)
for filename in filenames:
chat = WhatsAppChat.from_txt(filename)
counts = interventions(chat, date_mode='date', msg_length=True)

assert(isinstance(counts, pd.DataFrame))
# Asswert chat df and counts df have same users
assert(set(chat.users) == set(counts.columns))
assert(isinstance(counts, pd.DataFrame))
# Asswert chat df and counts df have same users
assert(set(chat.users) == set(counts.columns))

# Assert chat df and counts df have same date window
assert(chat.df.index.max().date() == counts.index.max().date())
assert(chat.df.index.min().date() == counts.index.min().date())
# Assert chat df and counts df have same date window
assert(chat.df.index.max().date() == counts.index.max().date())
assert(chat.df.index.min().date() == counts.index.min().date())


def test_interventions_hour():

filename = 'tests/chats/example_1.txt'
chat = WhatsAppChat.from_txt(filename)
counts = interventions(chat, date_mode='hour', msg_length=False)
for filename in filenames:
chat = WhatsAppChat.from_txt(filename)
counts = interventions(chat, date_mode='hour', msg_length=False)

assert(isinstance(counts, pd.DataFrame))
# Asswert chat df and counts df have same users
assert(set(chat.users) == set(counts.columns))
assert(isinstance(counts, pd.DataFrame))
# Asswert chat df and counts df have same users
assert(set(chat.users) == set(counts.columns))

# Check range hours
assert(counts.index.max() == chat.df.index.hour.max())
assert(counts.index.min() == chat.df.index.hour.min())
# Check range hours
assert(counts.index.max() == chat.df.index.hour.max())
assert(counts.index.min() == chat.df.index.hour.min())



def test_interventions_hour_msg_length():

filename = 'tests/chats/example_1.txt'
chat = WhatsAppChat.from_txt(filename)
counts = interventions(chat, date_mode='hour', msg_length=True)
for filename in filenames:
chat = WhatsAppChat.from_txt(filename)
counts = interventions(chat, date_mode='hour', msg_length=True)

assert(isinstance(counts, pd.DataFrame))
# Asswert chat df and counts df have same users
assert(set(chat.users) == set(counts.columns))
assert(isinstance(counts, pd.DataFrame))
# Asswert chat df and counts df have same users
assert(set(chat.users) == set(counts.columns))

# Check range hours
assert(counts.index.max() == chat.df.index.hour.max())
assert(counts.index.min() == chat.df.index.hour.min())
# Check range hours
assert(counts.index.max() == chat.df.index.hour.max())
assert(counts.index.min() == chat.df.index.hour.min())


def test_interventions_month():

filename = 'tests/chats/example_1.txt'
chat = WhatsAppChat.from_txt(filename)
counts = interventions(chat, date_mode='month', msg_length=False)
for filename in filenames:
chat = WhatsAppChat.from_txt(filename)
counts = interventions(chat, date_mode='month', msg_length=False)

assert(isinstance(counts, pd.DataFrame))
# Asswert chat df and counts df have same users
assert(set(chat.users) == set(counts.columns))
assert(isinstance(counts, pd.DataFrame))
# Asswert chat df and counts df have same users
assert(set(chat.users) == set(counts.columns))

# Check range hours
assert(counts.index.max() == chat.df.index.month.max())
assert(counts.index.min() == chat.df.index.month.min())
# Check range hours
assert(counts.index.max() == chat.df.index.month.max())
assert(counts.index.min() == chat.df.index.month.min())



def test_interventions_month_msg_length():

filename = 'tests/chats/example_1.txt'
chat = WhatsAppChat.from_txt(filename)
counts = interventions(chat, date_mode='month', msg_length=False)
for filename in filenames:
chat = WhatsAppChat.from_txt(filename)
counts = interventions(chat, date_mode='month', msg_length=False)

assert(isinstance(counts, pd.DataFrame))
# Asswert chat df and counts df have same users
assert(set(chat.users) == set(counts.columns))
assert(isinstance(counts, pd.DataFrame))
# Asswert chat df and counts df have same users
assert(set(chat.users) == set(counts.columns))

# Check range hours
assert(counts.index.max() == chat.df.index.month.max())
assert(counts.index.min() == chat.df.index.month.min())
# Check range hours
assert(counts.index.max() == chat.df.index.month.max())
assert(counts.index.min() == chat.df.index.month.min())


def test_interventions_weekday():

filename = 'tests/chats/example_1.txt'
chat = WhatsAppChat.from_txt(filename)
counts = interventions(chat, date_mode='weekday', msg_length=False)
for filename in filenames:
chat = WhatsAppChat.from_txt(filename)
counts = interventions(chat, date_mode='weekday', msg_length=False)

assert(isinstance(counts, pd.DataFrame))
# Asswert chat df and counts df have same users
assert(set(chat.users) == set(counts.columns))
assert(isinstance(counts, pd.DataFrame))
# Asswert chat df and counts df have same users
assert(set(chat.users) == set(counts.columns))

# Check range hours
assert(counts.index.max() == chat.df.index.weekday.max())
assert(counts.index.min() == chat.df.index.weekday.min())
# Check range hours
assert(counts.index.max() == chat.df.index.weekday.max())
assert(counts.index.min() == chat.df.index.weekday.min())



def test_interventions_weekday_msg_length():

filename = 'tests/chats/example_1.txt'
chat = WhatsAppChat.from_txt(filename)
counts = interventions(chat, date_mode='weekday', msg_length=True)
for filename in filenames:
chat = WhatsAppChat.from_txt(filename)
counts = interventions(chat, date_mode='weekday', msg_length=True)

assert(isinstance(counts, pd.DataFrame))
# Asswert chat df and counts df have same users
assert(set(chat.users) == set(counts.columns))
assert(isinstance(counts, pd.DataFrame))
# Asswert chat df and counts df have same users
assert(set(chat.users) == set(counts.columns))

# Check range hours
assert(counts.index.max() == chat.df.index.weekday.max())
assert(counts.index.min() == chat.df.index.weekday.min())
# Check range hours
assert(counts.index.max() == chat.df.index.weekday.max())
assert(counts.index.min() == chat.df.index.weekday.min())



def test_interventions_hourweekday():

filename = 'tests/chats/example_1.txt'
chat = WhatsAppChat.from_txt(filename)
counts = interventions(chat, date_mode='hourweekday', msg_length=False)
for filename in filenames:
chat = WhatsAppChat.from_txt(filename)
counts = interventions(chat, date_mode='hourweekday', msg_length=False)

assert(isinstance(counts, pd.DataFrame))
# Asswert chat df and counts df have same users
assert(set(chat.users) == set(counts.columns))
assert(isinstance(counts, pd.DataFrame))
# Asswert chat df and counts df have same users
assert(set(chat.users) == set(counts.columns))

# Check range days
assert(counts.index.levels[0].max() == chat.df.index.weekday.max())
assert(counts.index.levels[0].min() == chat.df.index.weekday.min())
# Check range days
assert(counts.index.levels[0].max() == chat.df.index.weekday.max())
assert(counts.index.levels[0].min() == chat.df.index.weekday.min())

# Check range hours
assert(counts.index.levels[1].max() == chat.df.index.hour.max())
assert(counts.index.levels[1].min() == chat.df.index.hour.min())
# Check range hours
assert(counts.index.levels[1].max() == chat.df.index.hour.max())
assert(counts.index.levels[1].min() == chat.df.index.hour.min())


def test_interventions_hourweekday_msg_length():

filename = 'tests/chats/example_1.txt'
chat = WhatsAppChat.from_txt(filename)
counts = interventions(chat, date_mode='hourweekday', msg_length=True)
for filename in filenames:
chat = WhatsAppChat.from_txt(filename)
counts = interventions(chat, date_mode='hourweekday', msg_length=True)

assert(isinstance(counts, pd.DataFrame))
# Asswert chat df and counts df have same users
assert(set(chat.users) == set(counts.columns))
assert(isinstance(counts, pd.DataFrame))
# Asswert chat df and counts df have same users
assert(set(chat.users) == set(counts.columns))

# Check range days
assert(counts.index.levels[0].max() == chat.df.index.weekday.max())
assert(counts.index.levels[0].min() == chat.df.index.weekday.min())
# Check range days
assert(counts.index.levels[0].max() == chat.df.index.weekday.max())
assert(counts.index.levels[0].min() == chat.df.index.weekday.min())

# Check range hours
assert(counts.index.levels[1].max() == chat.df.index.hour.max())
assert(counts.index.levels[1].min() == chat.df.index.hour.min())
# Check range hours
assert(counts.index.levels[1].max() == chat.df.index.hour.max())
assert(counts.index.levels[1].min() == chat.df.index.hour.min())

def test_interventions_error():

filename = 'tests/chats/example_1.txt'
chat = WhatsAppChat.from_txt(filename)
with pytest.raises(ValueError):
counts = interventions(chat, date_mode='error', msg_length=False)
with pytest.raises(ValueError):
counts = interventions(chat, date_mode='error', msg_length=True)
for filename in filenames:
chat = WhatsAppChat.from_txt(filename)
with pytest.raises(ValueError):
counts = interventions(chat, date_mode='error', msg_length=False)
with pytest.raises(ValueError):
counts = interventions(chat, date_mode='error', msg_length=True)
Loading

0 comments on commit 56d129f

Please sign in to comment.