Пример #1
0
 def test_get_average_view(self):
     older = Stats(created_at=datetime.datetime(2015, 1, 1, 1, 1, 1),
                   view_count=100)
     newer = Stats(created_at=datetime.datetime(2015, 1, 1, 1, 2, 40),
                   view_count=199)
     average_view = services._get_average_view_per_seconds(newer_stat=newer, older_stat=older)
     self.assertEqual(average_view, 1)
Пример #2
0
def save_stats(dictionary):
    obj = Stats()
    # set regular fields
    for field, value in dictionary.items():
        if not isinstance(value, list):
            setattr(obj, field, value)
    try:
        obj.save()
    except IntegrityError as e:
        print("Error saving obj {}".format(e))
        return False
    return True
Пример #3
0
 def setUp(self):
     self.num_states = 2
     self.num_cities_per_state = 5
     self.num_users = 10
     for istate in range(self.num_states):
         for icity in range(self.num_cities_per_state):
             for iuser in range(self.num_users):
                 Messages.objects.create(
                     state='state-{istate}'.format(istate=istate),
                     city='city-{icity}'.format(icity=icity),
                     username='******'.format(user=iuser),
                     message='msg-{s}-{c}-{u}'.format(s=istate, c=icity, u=iuser)
                 )
     Stats.update()
Пример #4
0
 def setUp(self):
     self.num_states = 2
     self.num_cities_per_state = 5
     self.num_users = 10
     for istate in range(self.num_states):
         for icity in range(self.num_cities_per_state):
             for iuser in range(self.num_users):
                 Messages.objects.create(
                     state='state-{istate}'.format(istate=istate),
                     city='city-{icity}'.format(icity=icity),
                     username='******'.format(user=iuser),
                     message='msg-{s}-{c}-{u}'.format(s=istate,
                                                      c=icity,
                                                      u=iuser))
     Stats.update()
Пример #5
0
def view(request):
    stats = Stats.all().filter("completed = ", True).order("date")[:30]
    stats = [ {"object":s, "stats":s.get_stats()} for s in stats ]
    return direct_to_template(request, "stats.html", {
        "stats": stats,
        "nav": {"selected": "stats",}
        })
Пример #6
0
def get_stats1(request):
    """Get the statistics from the Stats Table"""
    try:
        stats = Stats.get_stats()
        ret = ('{{ "users": {users}, "cities": {cities}, '
               '"ts": "{ts}", "result": "success" }}').format(**stats.__dict__)
    except Exception, err:
        ret = '{{ "result": "error", "error": "{err}" }}'.format(err=err)
Пример #7
0
    def save_stat(self, video_detail):
        stats = video_detail['statistics']

        Stats(video_id=helpers.get_video_id(video_detail),
              view_count=stats.get('viewCount', None),
              like_count=stats.get('likeCount', None),
              dislike_count=stats.get('dislikeCount', None),
              favorite_count=stats.get('favoriteCount', None),
              comment_count=stats.get('commentCount', None)).save()
Пример #8
0
def get_stats1(request):
    """Get the statistics from the Stats Table"""
    try:
        stats = Stats.get_stats()
        ret = ('{{ "users": {users}, "cities": {cities}, '
               '"ts": "{ts}", "result": "success" }}').format(
                **stats.__dict__)
    except Exception, err:
        ret = '{{ "result": "error", "error": "{err}" }}'.format(err=err)
Пример #9
0
def get_action(request, action, pk):
    stats = Stats.get(pk)
    current = stats.get_stats()
    if action not in registered:
        raise ValueError, "Action: %s not registered" % action
    current[action] = registered[action](stats)
    stats.set_stats(current)
    stats.save()
    return render_plain("total done: %s" % current)
Пример #10
0
def create(date):
    existing = Stats.all().filter("date = ", date)
    try:
        stats = existing[0]
    except IndexError:
        stats = Stats()
    stats.date = date
    data = dict([(key, None) for key in registered.keys()])
    stats.set_stats(data)
    stats.save()

    for key in registered.keys():
        taskqueue.add(url=reverse("stats-action", kwargs={"action":key, "pk":stats.id}))
Пример #11
0
def init_database(database):
    example = Stats()
    example.author_id = 1
    example.likes = 5
    example.dislikes = 3
    example.stories_written = 15
    example.n_dice = 4
    database.session.add(example)

    database.session.commit()
Пример #12
0
def calculate_view_diff(video, start_day, end_day):
    older_stat = video.stats_set.filter(
        created_at__gte=start_day).order_by('created_at')[0]
    newer_stat = video.stats_set.filter(
        created_at__lte=end_day).order_by('-created_at')[0]

    if newer_stat == older_stat:
        older_stat = Stats(view_count=0, created_at=video.published_at)

    total_seconds = (end_day - start_day).total_seconds()
    return _get_average_view_per_seconds(older_stat,
                                         newer_stat) * total_seconds
Пример #13
0
def poll_refresh():
    try:
        response = requests.get(
            f'{app.config["STORIES_ENDPOINT"]}/stories/stats/refresh')
    except Timeout:
        return

    to_update = response.json()
    for author in to_update:
        auth_stats = Stats.query.get(int(author))

        add = auth_stats is None
        if auth_stats is None:
            auth_stats = Stats()

        auth_stats.n_dice = 0
        auth_stats.stories_written = 0
        auth_stats.likes = 0
        auth_stats.dislikes = 0

        for story in to_update[author]:
            auth_stats.n_dice += story['dice']
            auth_stats.stories_written += 1
            auth_stats.likes += story['likes']
            auth_stats.dislikes += story['dislikes']

        if add:
            db.session.add(auth_stats)

        db.session.commit()
Пример #14
0
project_dir = "/home/django/mmashnik/mmashnik"

sys.path.append(project_dir)

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

import django

django.setup()

from stats.models import Stats

data = csv.reader(open("/home/django/mmashnik/fighters.csv"), delimiter=',')

for row in data:
    post = Stats()
    post.id = row[0]
    post.image_stats = row[1]
    post.first_name = row[2]
    post.last_name = row[3]
    post.nick_name = row[4]
    post.date_of_birth = row[5]
    post.place_of_birth = row[6]
    post.height = row[7]
    post.weight = row[8]
    post.weight_class = row[9]
    post.win = row[10]
    post.ko_win = row[11]
    post.sub_win = row[12]
    post.dec_win = row[13]
    post.other_win = row[14]
Пример #15
0
 def handle(self, *args, **kwargs):
     Stats.update()
Пример #16
0
 def handle(self, *args, **kwargs):
     Stats.update()