def log(request):
    if request.method == 'POST':
        date = request.GET.get('date', datetime.datetime.now())

        user_id = request.POST['user_id']
        content_id = request.POST['content_id']
        event = request.POST['event_type']

        l = Log(created=date,
                user_id=user_id,
                content_id=str(content_id),
                event=event)
        l.save()
    else:
        HttpResponse('log only works with POST')

    return HttpResponse('ok')
Beispiel #2
0
def main():
    Log.objects.all().delete()

    random.seed(SEED)
    number_of_events = 10000

    print("Generating Data")
    users = [
        User(1, 20, 30, 50),
        User(2, 50, 20, 40),
        User(3, 20, 30, 50),
        User(4, 100, 0, 0),
        User(5, 0, 100, 0),
        User(6, 0, 0, 100),
    ]
    print("Simulating " + str(len(users)) + " visitors")

    for x in range(0, number_of_events):
        randomuser_id = random.randint(0, len(users) - 1)
        user = users[randomuser_id]
        selected_film = select_film(user)
        action = select_action(user)
        if action == 'buy':
            user.events[user.sessionId].append(selected_film)
        print("user id " + str(user.userId) + " selects film " +
              str(selected_film) + " and " + action)

        l = Log(
            user_id=str(user.userId),
            content_id=selected_film,
            event=action,
            session_id=str(user.get_session_id()),
            #created=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
            created="2017-04-03 12:00:00",
            visit_count=0)
        l.save()

    print("users\n")
    for u in users:
        print("user with id {} \n".format(u.userId))
        for key, value in u.events.items():
            if len(value) > 0:
                print(" {}: {}".format(key, value))
Beispiel #3
0
def main():
    Log.objects.all().delete()
    random.seed(SEED)

    number_of_events = 100000

    print("Generating Data")
    users = [
        User(400001, 20, 30, 50),
        User(400002, 50, 20, 40),
        User(400003, 20, 30, 50),
        User(400004, 100, 0, 0),
        User(400005, 0, 100, 0),
        User(400006, 0, 0, 100),
    ]
    print("Simulating " + str(len(users)) + " visitors")

    for x in range(0, number_of_events):
        random_user_id = random.randint(0, len(users) - 1)
        user = users[random_user_id]
        selected_film = select_film(user)
        action = select_action(user)
        if action == 'buy':
            user.events[user.sessionId].append(selected_film)
        print("user id " + str(user.userId) + " selects film " +
              str(selected_film) + " and " + action)

        log = Log(
            user_id=str(user.userId),
            content_id=selected_film,
            event=action,
            session_id=str(user.get_session_id()),
            created=datetime.now(tz=timezone.utc),
        )
        log.save()

    print("users\n")
    for u in users:
        print("user with id {} \n".format(u.userId))
        for key, value in u.events.items():
            if len(value) > 0:
                print(" {}: {}".format(key, value))
def log(request):

    if request.method == 'POST':
        date = request.GET.get('date', datetime.datetime.now())

        user_id = request.POST['user_id']
        content_id = request.POST['content_id']
        event = request.POST['event_type']
        session_id = request.POST['session_id']

        l = Log(
            created=date,
            user_id=user_id,
            content_id=str(content_id),
            event=event,
            session_id=str(session_id))
        l.save()
    else:
        HttpResponse('log only works with POST')

    return HttpResponse('ok')
def main():
    Log.objects.all().delete()
    random.seed(SEED)

    number_of_events = 100000

    print("Generating Data")
    users = [
        User(400001, 20, 30, 50),
        User(400002, 50, 20, 40),
        User(400003, 20, 30, 50),
        User(400004, 100, 0, 0),
        User(400005, 0, 100, 0),
        User(400006, 0, 0, 100),
    ]
    print("Simulating " + str(len(users)) + " visitors")

    for x in range(0, number_of_events):
        randomuser_id = random.randint(0, len(users) - 1)
        user = users[randomuser_id]
        selected_film = select_film(user)
        action = select_action(user)
        if action == 'buy':
            user.events[user.sessionId].append(selected_film)
        print("user id " + str(user.userId) + " selects film " + str(selected_film) + " and " + action)

        l = Log(user_id=str(user.userId),
                content_id=selected_film,
                event=action,
                session_id=str(user.get_session_id()),
                created=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
                )
        l.save()

    print("users\n")
    for u in users:
        print("user with id {} \n".format(u.userId))
        for key, value in u.events.items():
            if len(value) > 0:
                print(" {}: {}".format(key, value))
def main():
    Log.objects.all().delete()
    random.seed(SEED)

    number_of_event = 100000

    print("Generating Data")
    users = [
        User("400001"),
        User("400002"),
        User("400003"),
        User("400004"),
        User("400005"),
        User("400006"),
        User("400007"),
        User("400008"),
        User("400009"),
        User("4000010"),
        User("4000011"),
        User("4000012"),
        User("4000013"),
        User("4000013"),
        User("4000015"),
        User("4000016"),
        User("4000017"),
        User("4000018"),
        User("4000019"),
        User("4000020"),
        User("4000021"),
        User("4000022"),
        User("4000023"),
        User("4000024"),
        User("4000025"),
        User("4000026"),
        User("4000027"),
        User("4000028"),
        User("4000029"),
        User("4000030"),
        User("4000031"),
        User("4000032"),
        User("4000033"),
        User("4000033"),
        User("4000035"),
        User("4000036"),
        User("4000037"),
        User("4000038"),
        User("4000039"),
        User("4000040"),
        User("4000041"),
        User("4000042"),
        User("4000043"),
        User("4000044"),
        User("4000045"),
        User("4000046"),
        User("4000047"),
        User("4000048"),
        User("4000049"),
        User("4000050"),
        User("4000051"),
        User("4000052"),
        User("4000053"),
        User("4000054"),
        User("4000055"),
        User("4000056"),
        User("4000057"),
        User("4000058"),
        User("4000059"),
        User("4000060"),
        User("4000061"),
        User("4000062"),
        User("4000063"),
        User("4000063"),
        User("4000065"),
        User("4000066"),
        User("4000067"),
        User("4000068"),
        User("4000069"),
        User("4000070"),
        User("4000071"),
        User("4000072"),
        User("4000073"),
        User("4000074"),
        User("4000075"),
        User("4000076"),
        User("4000077"),
        User("4000078"),
        User("4000079"),
        User("4000080"),
    ]

    print("Simulating " + str(len(users)) + " visitors")

    for x in range(0, number_of_event):
        randomuser_id = random.randint(0, len(users) - 1)
        user = users[randomuser_id]
        selected_food = select_food()
        action = select_action(user)
        # if action == 'buy':
        #     user.events[user.userId].append(selected_food)

        # print("===============")
        # print(user.userId)
        # print(action)
        print("user id " + user.userId + " selects food " +
              str(selected_food) + " and " + action)

        l = Log(
            user_id=user.userId,
            content_id=selected_food,
            event=action,
            created=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
        )
        l.save()