Skip to content

Commit

Permalink
import changed, readme, license
Browse files Browse the repository at this point in the history
  • Loading branch information
zhebrak committed Feb 8, 2015
1 parent d4072f1 commit a0272cb
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 6 deletions.
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2015 Alexander Zhebrak <fata2ex@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
113 changes: 113 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,116 @@ Django Statsy
[![Build Status](https://travis-ci.org/fata1ex/django-statsy.svg)](https://travis-ci.org/fata1ex/django-statsy) [![Coverage Status](https://coveralls.io/repos/fata1ex/django-statsy/badge.svg)](https://coveralls.io/r/fata1ex/django-statsy) [![Requirements Status](https://requires.io/github/fata1ex/django-statsy/requirements.svg?branch=master)](https://requires.io/github/fata1ex/django-statsy/requirements/?branch=master)

[![Stories in Ready](https://badge.waffle.io/fata1ex/django-statsy.svg?label=in%20progress&title=In%20Progress)](https://waffle.io/fata1ex/django-statsy)

Statsy is an application for collecting and displaying statistics in your Django project.


### Basic Usage

As view decorator:

```python
@statsy.watch
def index(request):
...
```

```python
@statsy.watch(group='index', event='page_view')
def index(request):
...
```

Inside the view:

```python
def like(request):
...

statsy.send(
group='post', event='like', user=request.user,
value=17, related_object=post
)

...
```

From the template:

```javascript
{% statsy %}

...

Statsy.send({
'group': 'post',
'event': 'subscription'
});
```

### Installation

```
pip install django-statsy
```

```
# settings.py
INSTALLED_APPS = (
...
'statsy',
)
```

If you want to display collected statistics you will also have to add Statsy's URLs to your project's URLs.

```python
# urls.py
...

url(r'^stats/', include('statsy.urls')),
...
```

### Collect Options

All is optional.
```python
# categorizing options
'group'
'event'

# some additional info about the stats object
'label'

# user associated with the action
# collected by default in @watch
'user'

# object of the action
'related_object'

# value can be <int>, <float> or <str>/<unicode>/etc.
'value'

# where did it happen
# collected by default in @watch
'url'

# how long did it take <int>
# collected by default in @watch
'duration'

# JSON for an extra data
'extra'
```

### Roadmap
- Enhanced statistics view
- User tracking
- Realtime statistics

### License
[MIT](https://github.com/fata1ex/django-statsy/raw/master/LICENSE)
2 changes: 1 addition & 1 deletion example/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from example.models import Post

from statsy import statsy
import statsy


@statsy.watch(group='index', event='page_view', value='123.1')
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
django==1.7.4
django-celery==3.1.16
jsonfield==1.0.0
jsonfield==1.0.1
9 changes: 8 additions & 1 deletion statsy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@
from statsy.core import Statsy


statsy = Statsy()
_statsy = Statsy()

send = _statsy.send
watch = _statsy.watch

objects = Statsy.objects
groups = Statsy.groups
events = Statsy.events
1 change: 1 addition & 0 deletions statsy/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def by_time(self, start=None, end=None, include_start=True, include_end=True):
return self.filter(**filter_args) if filter_args else self

def today(self):
# use d.replace
now = datetime.now()
start_of_today = datetime(
year=now.year, month=now.month, day=now.day,
Expand Down
2 changes: 1 addition & 1 deletion statsy/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json

from django.db.models import Count
from django.http import HttpResponse, HttpResponse
from django.http import HttpResponse
from django.shortcuts import render_to_response

from statsy import statsy
Expand Down
3 changes: 1 addition & 2 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import unittest

from statsy import statsy
import statsy


class CoreTest(unittest.TestCase):
Expand All @@ -23,4 +23,3 @@ def test_send_basic(self):
self.assertEqual(self.event_name, statsy_object.event.name)
self.assertEqual(self.label, statsy_object.label)
self.assertEqual(self.value, statsy_object.value)

0 comments on commit a0272cb

Please sign in to comment.