1
|
|
|
# coding: utf8 |
2
|
|
|
|
3
|
|
|
""" |
4
|
|
|
This software is licensed under the Apache 2 license, quoted below. |
5
|
|
|
|
6
|
|
|
Copyright 2014 Crystalnix Limited |
7
|
|
|
|
8
|
|
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not |
9
|
|
|
use this file except in compliance with the License. You may obtain a copy of |
10
|
|
|
the License at |
11
|
|
|
|
12
|
|
|
http://www.apache.org/licenses/LICENSE-2.0 |
13
|
|
|
|
14
|
|
|
Unless required by applicable law or agreed to in writing, software |
15
|
|
|
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
16
|
|
|
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
17
|
|
|
License for the specific language governing permissions and limitations under |
18
|
|
|
the License. |
19
|
|
|
""" |
20
|
|
|
|
21
|
|
|
from __future__ import print_function |
22
|
|
|
from builtins import range, bytes |
23
|
|
|
|
24
|
|
|
import random |
25
|
|
|
import uuid |
26
|
|
|
|
27
|
|
|
from django.core.management.base import BaseCommand |
28
|
|
|
from django.utils import timezone |
29
|
|
|
from django.test import RequestFactory |
30
|
|
|
|
31
|
|
|
from freezegun import freeze_time |
32
|
|
|
|
33
|
|
|
from sparkle.statistics import collect_statistics |
34
|
|
|
from sparkle.models import SparkleVersion |
35
|
|
|
from omaha.models import Application |
36
|
|
|
|
37
|
|
View Code Duplication |
def generate_events(app_name, **options): |
|
|
|
|
38
|
|
|
app_id = Application.objects.get(name=app_name).id |
39
|
|
|
versions = SparkleVersion.objects.filter_by_enabled(app__name=app_name) |
40
|
|
|
request_factory = RequestFactory() |
41
|
|
|
|
42
|
|
|
def generate_fake_hour(): |
43
|
|
|
for version in versions: |
44
|
|
|
for i in range(random.randint(0, 20)): |
45
|
|
|
id = uuid.UUID(int=i) |
46
|
|
|
request = request_factory.get('/sparkle/%s/%s/appcast.xml?appVersionShort=%s&deviceID=%s' % ( |
47
|
|
|
app_name, |
48
|
|
|
version.channel, |
49
|
|
|
version.short_version, |
50
|
|
|
id |
51
|
|
|
)) |
52
|
|
|
collect_statistics(request, app_id, version.channel) |
53
|
|
|
|
54
|
|
|
start = timezone.now() - timezone.timedelta(days=1) |
55
|
|
|
|
56
|
|
|
for hourdelta in range(1, 25): |
57
|
|
|
if hourdelta % 10 == 0: |
58
|
|
|
print('=> ', hourdelta) |
59
|
|
|
with freeze_time(start + timezone.timedelta(hours=hourdelta)): |
60
|
|
|
generate_fake_hour() |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
class Command(BaseCommand): |
64
|
|
|
args = '<app_name>' |
65
|
|
|
help = 'A command for generating fake live statistics' |
66
|
|
|
|
67
|
|
|
def handle(self, app_name, *args, **options): |
68
|
|
|
generate_events(app_name, **options) |
69
|
|
|
|